From 62ea843ff3ae2fe4c0d071da8f19e4a062f09098 Mon Sep 17 00:00:00 2001 From: Michel Rasschaert Date: Wed, 9 Nov 2016 19:40:35 +0100 Subject: [PATCH 1/3] zone_id exported attribute for db_instance resource --- builtin/providers/aws/resource_aws_db_instance.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index 572f14d69..e3287e0fa 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -236,6 +236,11 @@ func resourceAwsDbInstance() *schema.Resource { Computed: true, }, + "zone_id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "status": &schema.Schema{ Type: schema.TypeString, Computed: true, @@ -669,7 +674,7 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error { if v.Endpoint != nil { d.Set("port", v.Endpoint.Port) d.Set("address", v.Endpoint.Address) - + d.Set("zone_id", v.Endpoint.HostedZoneId) if v.Endpoint.Address != nil && v.Endpoint.Port != nil { d.Set("endpoint", fmt.Sprintf("%s:%d", *v.Endpoint.Address, *v.Endpoint.Port)) From 9774fcdbb0360ea9ae1fb5195a2a784080f0c282 Mon Sep 17 00:00:00 2001 From: Michel Rasschaert Date: Wed, 9 Nov 2016 20:40:40 +0100 Subject: [PATCH 2/3] documentation for db_instance.zone_id. --- website/source/docs/providers/aws/r/db_instance.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/source/docs/providers/aws/r/db_instance.html.markdown b/website/source/docs/providers/aws/r/db_instance.html.markdown index 1dd3a1b5c..cafd6060e 100644 --- a/website/source/docs/providers/aws/r/db_instance.html.markdown +++ b/website/source/docs/providers/aws/r/db_instance.html.markdown @@ -136,6 +136,7 @@ The following attributes are exported: * `status` - The RDS instance status * `username` - The master username for the database * `storage_encrypted` - Specifies whether the DB instance is encrypted +* `zone_id` - The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record) On Oracle instances the following is exported additionally: From e02960810dd34af679bd103eb6cfb3ad93c0d520 Mon Sep 17 00:00:00 2001 From: stack72 Date: Thu, 10 Nov 2016 06:41:43 +0000 Subject: [PATCH 3/3] provider/aws: Rename zone_id to hosted_zone_id in aws_db_instance Also added a test to prove that the computed value gets set ``` % make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSDBInstance_basic' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/11/10 06:26:22 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSDBInstance_basic -timeout 120m === RUN TestAccAWSDBInstance_basic --- PASS: TestAccAWSDBInstance_basic (634.33s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws634.347s ``` --- builtin/providers/aws/resource_aws_db_instance.go | 4 ++-- builtin/providers/aws/resource_aws_db_instance_test.go | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index e3287e0fa..27383a799 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -236,7 +236,7 @@ func resourceAwsDbInstance() *schema.Resource { Computed: true, }, - "zone_id": &schema.Schema{ + "hosted_zone_id": &schema.Schema{ Type: schema.TypeString, Computed: true, }, @@ -674,7 +674,7 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error { if v.Endpoint != nil { d.Set("port", v.Endpoint.Port) d.Set("address", v.Endpoint.Address) - d.Set("zone_id", v.Endpoint.HostedZoneId) + d.Set("hosted_zone_id", v.Endpoint.HostedZoneId) if v.Endpoint.Address != nil && v.Endpoint.Port != nil { d.Set("endpoint", fmt.Sprintf("%s:%d", *v.Endpoint.Address, *v.Endpoint.Port)) diff --git a/builtin/providers/aws/resource_aws_db_instance_test.go b/builtin/providers/aws/resource_aws_db_instance_test.go index 91617faf7..8886736b3 100644 --- a/builtin/providers/aws/resource_aws_db_instance_test.go +++ b/builtin/providers/aws/resource_aws_db_instance_test.go @@ -46,6 +46,7 @@ func TestAccAWSDBInstance_basic(t *testing.T) { "aws_db_instance.bar", "username", "foo"), resource.TestCheckResourceAttr( "aws_db_instance.bar", "parameter_group_name", "default.mysql5.6"), + resource.TestCheckResourceAttrSet("aws_db_instance.bar", "hosted_zone_id"), ), }, },