Skip to content

Commit

Permalink
Merge pull request #13453 from angeloskaltsikis/fix-11677
Browse files Browse the repository at this point in the history
resources/aws_route53_record: Fix set_identifier with underscore
  • Loading branch information
ewbankkit authored Aug 27, 2021
2 parents 6239d0e + 33b2970 commit f4f2d2b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .changelog/13453.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_route53_record: Support `set_identifier` values containing `_`
```
19 changes: 10 additions & 9 deletions aws/resource_aws_route53_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,15 +968,16 @@ func parseRecordId(id string) [4]string {
parts := strings.SplitN(id, "_", 2)
if len(parts) == 2 {
recZone = parts[0]
lastUnderscore := strings.LastIndex(parts[1], "_")
if lastUnderscore != -1 {
recName, recType = parts[1][0:lastUnderscore], parts[1][lastUnderscore+1:]
if !r53ValidRecordTypes.MatchString(recType) {
recSet, recType = recType, ""
lastUnderscore = strings.LastIndex(recName, "_")
if lastUnderscore != -1 {
recName, recType = recName[0:lastUnderscore], recName[lastUnderscore+1:]
}
firstUnderscore := strings.Index(parts[1][:], "_")
// Handles the case of having a DNS name that starts with _
if firstUnderscore == 0 {
firstUnderscore = strings.Index(parts[1][1:], "_") + 1
}
recName, recType = parts[1][0:firstUnderscore], parts[1][firstUnderscore+1:]
if !r53ValidRecordTypes.MatchString(recType) {
firstUnderscore = strings.Index(recType, "_")
if firstUnderscore != -1 {
recType, recSet = recType[0:firstUnderscore], recType[firstUnderscore+1:]
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions aws/resource_aws_route53_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ func TestParseRecordId(t *testing.T) {
{"ABCDEF_test.example.com_A_set1", "ABCDEF", "test.example.com", "A", "set1"},
{"ABCDEF__underscore.example.com_A", "ABCDEF", "_underscore.example.com", "A", ""},
{"ABCDEF__underscore.example.com_A_set1", "ABCDEF", "_underscore.example.com", "A", "set1"},
{"ABCDEF__underscore.example.com_A_set_with1", "ABCDEF", "_underscore.example.com", "A", "set_with1"},
{"ABCDEF__underscore.example.com_A_set_with_1", "ABCDEF", "_underscore.example.com", "A", "set_with_1"},
}

for _, tc := range cases {
Expand Down

0 comments on commit f4f2d2b

Please sign in to comment.