Skip to content

Commit

Permalink
Merge pull request #20652 from DrFaust92/route53_zone_arn
Browse files Browse the repository at this point in the history
rd/route53_zone - add `arn` attribute
  • Loading branch information
ewbankkit authored Aug 23, 2021
2 parents 1eb1f09 + b14e2b9 commit ddc12c8
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 4 deletions.
11 changes: 11 additions & 0 deletions .changelog/20652.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:enhancement
resource/aws_route53_zone: Add `arn` attribute
```

```release-note:enhancement
resource/aws_route53_zone: Add plan time validation for `comment`
```

```release-note:enhancement
data-source/aws_route53_zone: Add `arn` attribute
```
12 changes: 12 additions & 0 deletions aws/data_source_aws_route53_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/route53"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
Expand All @@ -15,6 +16,10 @@ func dataSourceAwsRoute53Zone() *schema.Resource {
Read: dataSourceAwsRoute53ZoneRead,

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"zone_id": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -190,6 +195,13 @@ func dataSourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) erro
return fmt.Errorf("error setting tags: %w", err)
}

arn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Service: "route53",
Resource: fmt.Sprintf("hostedzone/%s", d.Id()),
}.String()
d.Set("arn", arn)

return nil
}

Expand Down
1 change: 1 addition & 0 deletions aws/data_source_aws_route53_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestAccAWSRoute53ZoneDataSource_id(t *testing.T) {
{
Config: testAccDataSourceAwsRoute53ZoneConfigId(fqdn),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(resourceName, "arn", dataSourceName, "arn"),
resource.TestCheckResourceAttrPair(resourceName, "id", dataSourceName, "id"),
resource.TestCheckResourceAttrPair(resourceName, "name", dataSourceName, "name"),
resource.TestCheckResourceAttrPair(resourceName, "name_servers.#", dataSourceName, "name_servers.#"),
Expand Down
21 changes: 17 additions & 4 deletions aws/resource_aws_route53_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/route53"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -33,6 +34,10 @@ func resourceAwsRoute53Zone() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"name": {
// AWS Provider 3.0.0 - trailing period removed from name
// returned from API, no longer requiring custom DiffSuppressFunc;
Expand All @@ -46,9 +51,10 @@ func resourceAwsRoute53Zone() *schema.Resource {
},

"comment": {
Type: schema.TypeString,
Optional: true,
Default: "Managed by Terraform",
Type: schema.TypeString,
Optional: true,
Default: "Managed by Terraform",
ValidateFunc: validation.StringLenBetween(0, 256),
},

"vpc": {
Expand Down Expand Up @@ -248,6 +254,13 @@ func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error
return fmt.Errorf("error setting tags_all: %w", err)
}

arn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Service: "route53",
Resource: fmt.Sprintf("hostedzone/%s", d.Id()),
}.String()
d.Set("arn", arn)

return nil
}

Expand Down Expand Up @@ -362,7 +375,7 @@ func deleteAllRecordsInHostedZoneId(hostedZoneId, hostedZoneName string, conn *r
continue
}
changes = append(changes, &route53.Change{
Action: aws.String("DELETE"),
Action: aws.String(route53.ChangeActionDelete),
ResourceRecordSet: set,
})
}
Expand Down
2 changes: 2 additions & 0 deletions aws/resource_aws_route53_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"regexp"
"sort"
"strings"
"testing"
Expand Down Expand Up @@ -179,6 +180,7 @@ func TestAccAWSRoute53Zone_basic(t *testing.T) {
Config: testAccRoute53ZoneConfig(zoneName),
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53ZoneExists(resourceName, &zone),
testAccMatchResourceAttrGlobalARNNoAccount(resourceName, "arn", "route53", regexp.MustCompile("hostedzone/.+")),
resource.TestCheckResourceAttr(resourceName, "name", zoneName),
resource.TestCheckResourceAttr(resourceName, "name_servers.#", "4"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/route53_zone.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ the selected Hosted Zone.

The following attribute is additionally exported:

* `arn` - The Amazon Resource Name (ARN) of the Hosted Zone.
* `caller_reference` - Caller Reference of the Hosted Zone.
* `comment` - The comment field of the Hosted Zone.
* `name_servers` - The list of DNS name servers for the Hosted Zone.
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/route53_zone.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ The following arguments are supported:

In addition to all arguments above, the following attributes are exported:

* `arn` - The Amazon Resource Name (ARN) of the Hosted Zone.
* `zone_id` - The Hosted Zone ID. This can be referenced by zone records.
* `name_servers` - A list of name servers in associated (or default) delegation set.
Find more about delegation sets in [AWS docs](https://docs.aws.amazon.com/Route53/latest/APIReference/actions-on-reusable-delegation-sets.html).
Expand Down

0 comments on commit ddc12c8

Please sign in to comment.