Skip to content

Commit

Permalink
fix[aws_route53_record]: Allow importing with empty record name
Browse files Browse the repository at this point in the history
Fixes: #4792
  • Loading branch information
tmccombs committed Nov 1, 2023
1 parent 06ce5b6 commit e708305
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion internal/service/route53/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ func ResourceRecord() *schema.Resource {
parts := ParseRecordID(d.Id())
// We check that we have parsed the id into the correct number of segments.
// We need at least 3 segments!
if parts[0] == "" || parts[1] == "" || parts[2] == "" {
// However, parts[1] can be the empty string if it is the root domain of the zone,
// and isn't using a FQDN. See https://github.com/hashicorp/terraform-provider-aws/issues/4792
if parts[0] == "" || parts[2] == "" {
return nil, fmt.Errorf("unexpected format of ID (%q), expected ZONEID_RECORDNAME_TYPE_SET-IDENTIFIER (e.g. Z4KAPRWWNC7JR_dev.example.com_NS_dev), where SET-IDENTIFIER is optional", d.Id())
}

Expand Down
7 changes: 7 additions & 0 deletions internal/service/route53/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func TestParseRecordId(t *testing.T) {
{"ABCDEF_prefix._underscore.example.com_A", "ABCDEF", "prefix._underscore.example.com", "A", ""},
{"ABCDEF_prefix._underscore.example.com_A_set", "ABCDEF", "prefix._underscore.example.com", "A", "set"},
{"ABCDEF_prefix._underscore.example.com_A_set_underscore", "ABCDEF", "prefix._underscore.example.com", "A", "set_underscore"},
{"ABCDEF__A", "ABCDEF", "", "A", ""},
}

for _, tc := range cases {
Expand Down Expand Up @@ -1404,6 +1405,12 @@ func TestAccRoute53Record_empty(t *testing.T) {
testAccCheckRecordExists(ctx, resourceName, &record1),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"allow_overwrite", "weight"},
},
},
})
}
Expand Down
9 changes: 9 additions & 0 deletions website/docs/r/route53_record.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ import {
}
```

If the record name is the empty string, it can be omitted:

```terraform
import {
to = aws_route53_record.myrecord
id = "Z4KAPRWWNC7JR__NS"
}
```

**Using `terraform import` to import** Route53 Records using the ID of the record, record name, record type, and set identifier. For example:

Using the ID of the record, which is the zone identifier, record name, and record type, separated by underscores (`_`):
Expand Down

0 comments on commit e708305

Please sign in to comment.