Added the ability to create a domain without specifying the inital A records IP address
This commit is contained in:
parent
fe9492c23d
commit
993d73f797
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"github.com/digitalocean/godo"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/hashicorp/terraform/helper/validation"
|
||||
)
|
||||
|
||||
func resourceDigitalOceanDomain() *schema.Resource {
|
||||
|
@ -20,15 +21,17 @@ func resourceDigitalOceanDomain() *schema.Resource {
|
|||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
ValidateFunc: validation.NoZeroValues,
|
||||
},
|
||||
|
||||
"ip_address": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
ValidateFunc: validation.NoZeroValues,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -40,8 +43,11 @@ func resourceDigitalOceanDomainCreate(d *schema.ResourceData, meta interface{})
|
|||
// Build up our creation options
|
||||
|
||||
opts := &godo.DomainCreateRequest{
|
||||
Name: d.Get("name").(string),
|
||||
IPAddress: d.Get("ip_address").(string),
|
||||
Name: d.Get("name").(string),
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("ip_address"); ok {
|
||||
opts.IPAddress = v.(string)
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Domain create configuration: %#v", opts)
|
||||
|
|
|
@ -35,6 +35,30 @@ func TestAccDigitalOceanDomain_Basic(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccDigitalOceanDomain_WithoutIp(t *testing.T) {
|
||||
var domain godo.Domain
|
||||
domainName := fmt.Sprintf("foobar-test-terraform-%s.com", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckDigitalOceanDomainDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: fmt.Sprintf(testAccCheckDigitalOceanDomainConfig_withoutIp, domainName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckDigitalOceanDomainExists("digitalocean_domain.foobar", &domain),
|
||||
testAccCheckDigitalOceanDomainAttributes(&domain, domainName),
|
||||
resource.TestCheckResourceAttr(
|
||||
"digitalocean_domain.foobar", "name", domainName),
|
||||
resource.TestCheckNoResourceAttr(
|
||||
"digitalocean_domain.foobar", "ip_address"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccCheckDigitalOceanDomainDestroy(s *terraform.State) error {
|
||||
client := testAccProvider.Meta().(*godo.Client)
|
||||
|
||||
|
@ -100,3 +124,8 @@ resource "digitalocean_domain" "foobar" {
|
|||
name = "%s"
|
||||
ip_address = "192.168.0.10"
|
||||
}`
|
||||
|
||||
const testAccCheckDigitalOceanDomainConfig_withoutIp = `
|
||||
resource "digitalocean_domain" "foobar" {
|
||||
name = "%s"
|
||||
}`
|
||||
|
|
|
@ -25,9 +25,8 @@ resource "digitalocean_domain" "default" {
|
|||
The following arguments are supported:
|
||||
|
||||
* `name` - (Required) The name of the domain
|
||||
* `ip_address` - (Required) The IP address of the domain. This IP
|
||||
is used to created an initial A record for the domain. It is required
|
||||
upstream by the DigitalOcean API.
|
||||
* `ip_address` - (Optional) The IP address of the domain. If specified, this IP
|
||||
is used to created an initial A record for the domain.
|
||||
|
||||
## Attributes Reference
|
||||
|
||||
|
@ -35,8 +34,6 @@ The following attributes are exported:
|
|||
|
||||
* `id` - The name of the domain
|
||||
|
||||
|
||||
|
||||
## Import
|
||||
|
||||
Domains can be imported using the `domain name`, e.g.
|
||||
|
|
Loading…
Reference in New Issue