Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add primary_name_server attribute to aws_route53_zone #27293

Merged
merged 6 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions internal/service/route53/zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ func ResourceZone() *schema.Resource {
Computed: true,
},

"primary_name_server": {
Type: schema.TypeString,
Computed: true,
}

"tags": tftags.TagsSchema(),
"tags_all": tftags.TagsSchemaComputed(),

Expand Down Expand Up @@ -236,6 +241,10 @@ func resourceZoneRead(d *schema.ResourceData, meta interface{}) error {
}
}

if err := d.Set("primary_name_server", nameServers[0]); err != nil {
return fmt.Errorf("setting primary_name_server: %s", err)
}

sort.Strings(nameServers)
if err := d.Set("name_servers", nameServers); err != nil {
return fmt.Errorf("setting name_servers: %s", err)
Expand Down
8 changes: 8 additions & 0 deletions internal/service/route53/zone_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func DataSourceZone() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
},
"primary_name_server": {
Type: schema.TypeString,
Computed: true,
},
"linked_service_principal": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -182,6 +186,10 @@ func dataSourceZoneRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("getting Route 53 Hosted Zone (%s) name servers: %w", idHostedZone, err)
}

if err := d.Set("primary_name_server", nameServers[0]); err != nil {
return fmt.Errorf("setting primary_name_server: %w", err)
}

if err := d.Set("name_servers", nameServers); err != nil {
return fmt.Errorf("setting name_servers: %w", err)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/service/route53/zone_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestAccRoute53ZoneDataSource_id(t *testing.T) {
resource.TestCheckResourceAttrPair(resourceName, "id", dataSourceName, "id"),
resource.TestCheckResourceAttrPair(resourceName, "name", dataSourceName, "name"),
resource.TestCheckResourceAttrPair(resourceName, "name_servers.#", dataSourceName, "name_servers.#"),
resource.TestCheckResourceAttrPair(resourceName, "primary_name_server", dataSourceName, "primary_name_server"),
resource.TestCheckResourceAttrPair(resourceName, "tags", dataSourceName, "tags"),
),
},
Expand All @@ -54,6 +55,7 @@ func TestAccRoute53ZoneDataSource_name(t *testing.T) {
resource.TestCheckResourceAttrPair(resourceName, "id", dataSourceName, "id"),
resource.TestCheckResourceAttrPair(resourceName, "name", dataSourceName, "name"),
resource.TestCheckResourceAttrPair(resourceName, "name_servers.#", dataSourceName, "name_servers.#"),
resource.TestCheckResourceAttrPair(resourceName, "primary_name_server", dataSourceName, "primary_name_server"),
resource.TestCheckResourceAttrPair(resourceName, "tags", dataSourceName, "tags"),
),
},
Expand All @@ -80,6 +82,7 @@ func TestAccRoute53ZoneDataSource_tags(t *testing.T) {
resource.TestCheckResourceAttrPair(resourceName, "id", dataSourceName, "id"),
resource.TestCheckResourceAttrPair(resourceName, "name", dataSourceName, "name"),
resource.TestCheckResourceAttrPair(resourceName, "name_servers.#", dataSourceName, "name_servers.#"),
resource.TestCheckResourceAttrPair(resourceName, "primary_name_server", dataSourceName, "primary_name_server"),
resource.TestCheckResourceAttrPair(resourceName, "tags", dataSourceName, "tags"),
),
},
Expand All @@ -104,6 +107,7 @@ func TestAccRoute53ZoneDataSource_vpc(t *testing.T) {
resource.TestCheckResourceAttrPair(resourceName, "id", dataSourceName, "id"),
resource.TestCheckResourceAttrPair(resourceName, "name", dataSourceName, "name"),
resource.TestCheckResourceAttrPair(resourceName, "name_servers.#", dataSourceName, "name_servers.#"),
resource.TestCheckResourceAttrPair(resourceName, "primary_name_server", dataSourceName, "primary_name_server"),
resource.TestCheckResourceAttrPair(resourceName, "tags", dataSourceName, "tags"),
),
},
Expand Down
1 change: 1 addition & 0 deletions internal/service/route53/zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func TestAccRoute53Zone_basic(t *testing.T) {
acctest.MatchResourceAttrGlobalARNNoAccount(resourceName, "arn", "route53", regexp.MustCompile("hostedzone/.+")),
resource.TestCheckResourceAttr(resourceName, "name", zoneName),
resource.TestCheckResourceAttr(resourceName, "name_servers.#", "4"),
resource.TestCheckResourceAttr(resourceName, "primary_name_server", "4"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "vpc.#", "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 @@ -57,6 +57,7 @@ The following attribute is additionally exported:
* `caller_reference` - Caller Reference of the Hosted Zone.
* `comment` - Comment field of the Hosted Zone.
* `name_servers` - List of DNS name servers for the Hosted Zone.
* `primary_name_server` - The Route 53 name server that created the SOA record.
* `resource_record_set_count` - The number of Record Set in the Hosted Zone.
* `linked_service_principal` - The service that created the Hosted Zone (e.g., `servicediscovery.amazonaws.com`).
* `linked_service_description` - The description provided by the service that created the Hosted Zone (e.g., `arn:aws:servicediscovery:us-east-1:1234567890:namespace/ns-xxxxxxxxxxxxxxxx`).
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 @@ -88,6 +88,7 @@ In addition to all arguments above, the following attributes are exported:
* `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).
* `primary_name_server` - The Route 53 name server that created the SOA record.
* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block).

## Import
Expand Down