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

fix[aws_route53_record]: Allow importing with empty record name #34212

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .changelog/34212.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_route53_record: Allow import of records with an empty record name.
```
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
Loading