Updates the domain resource with the URN computed attribute

This commit is contained in:
Trent Rosenbaum 2019-04-15 14:26:38 +01:00
parent 6eb3f27492
commit e5e792d994
5 changed files with 20 additions and 1 deletions

View File

@ -20,6 +20,11 @@ func dataSourceDigitalOceanDomain() *schema.Resource {
ValidateFunc: validation.NoZeroValues, ValidateFunc: validation.NoZeroValues,
}, },
// computed attributes // computed attributes
"urn": {
Type: schema.TypeString,
Computed: true,
Description: "the uniform resource name for the domain",
},
"ttl": { "ttl": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
@ -49,6 +54,7 @@ func dataSourceDigitalOceanDomainRead(d *schema.ResourceData, meta interface{})
d.SetId(domain.Name) d.SetId(domain.Name)
d.Set("name", domain.Name) d.Set("name", domain.Name)
d.Set("urn", domain.URN())
d.Set("ttl", domain.TTL) d.Set("ttl", domain.TTL)
d.Set("zone_file", domain.ZoneFile) d.Set("zone_file", domain.ZoneFile)

View File

@ -15,6 +15,8 @@ func TestAccDataSourceDigitalOceanDomain_Basic(t *testing.T) {
var domain godo.Domain var domain godo.Domain
domainName := fmt.Sprintf("foobar-test-terraform-%s.com", acctest.RandString(10)) domainName := fmt.Sprintf("foobar-test-terraform-%s.com", acctest.RandString(10))
expectedURN := fmt.Sprintf("do:domain:%s", domainName)
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
@ -26,6 +28,8 @@ func TestAccDataSourceDigitalOceanDomain_Basic(t *testing.T) {
testAccCheckDataSourceDigitalOceanDomainAttributes(&domain, domainName), testAccCheckDataSourceDigitalOceanDomainAttributes(&domain, domainName),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"data.digitalocean_domain.foobar", "name", domainName), "data.digitalocean_domain.foobar", "name", domainName),
resource.TestCheckResourceAttr(
"data.digitalocean_domain.foobar", "urn", expectedURN),
), ),
}, },
}, },

View File

@ -26,13 +26,16 @@ func resourceDigitalOceanDomain() *schema.Resource {
ForceNew: true, ForceNew: true,
ValidateFunc: validation.NoZeroValues, ValidateFunc: validation.NoZeroValues,
}, },
"ip_address": { "ip_address": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
ForceNew: true, ForceNew: true,
ValidateFunc: validation.NoZeroValues, ValidateFunc: validation.NoZeroValues,
}, },
"urn": {
Type: schema.TypeString,
Computed: true,
},
}, },
} }
} }
@ -78,6 +81,7 @@ func resourceDigitalOceanDomainRead(d *schema.ResourceData, meta interface{}) er
} }
d.Set("name", domain.Name) d.Set("name", domain.Name)
d.Set("urn", domain.URN())
return nil return nil
} }

View File

@ -52,6 +52,8 @@ func TestAccDigitalOceanDomain_Basic(t *testing.T) {
var domain godo.Domain var domain godo.Domain
domainName := fmt.Sprintf("foobar-test-terraform-%s.com", acctest.RandString(10)) domainName := fmt.Sprintf("foobar-test-terraform-%s.com", acctest.RandString(10))
expectedURN := fmt.Sprintf("do:domain:%s", domainName)
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
@ -66,6 +68,8 @@ func TestAccDigitalOceanDomain_Basic(t *testing.T) {
"digitalocean_domain.foobar", "name", domainName), "digitalocean_domain.foobar", "name", domainName),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"digitalocean_domain.foobar", "ip_address", "192.168.0.10"), "digitalocean_domain.foobar", "ip_address", "192.168.0.10"),
resource.TestCheckResourceAttr(
"digitalocean_domain.foobar", "urn", expectedURN),
), ),
}, },
}, },

View File

@ -33,6 +33,7 @@ The following arguments are supported:
The following attributes are exported: The following attributes are exported:
* `id` - The name of the domain * `id` - The name of the domain
* `urn` - The uniform resource name of the domain
## Import ## Import