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 import of aws_route53_record with underscore #20803

Closed
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
25 changes: 15 additions & 10 deletions aws/resource_aws_route53_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,18 +968,23 @@ func parseRecordId(id string) [4]string {
parts := strings.SplitN(id, "_", 2)
if len(parts) == 2 {
recZone = parts[0]
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:]

// Look backwards for underscores from the end until a valid type is found
index := strings.LastIndex(parts[1], "_")
recType = parts[1][index+1:]
for index != -1 && !r53ValidRecordTypes.MatchString(recType) {
index = strings.LastIndex(parts[1][0:index-1], "_")
if index != -1 {
nextPart := strings.SplitN(parts[1][index+1:], "_", 2)
recType = nextPart[0]

// Set identifier is everything after the type
recSet = nextPart[1]
}
}

// Name is everything up to the type
recName = parts[1][0:index]
}
recName = strings.TrimSuffix(recName, ".")
return [4]string{recZone, recName, recType, recSet}
Expand Down
3 changes: 3 additions & 0 deletions aws/resource_aws_route53_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ func TestParseRecordId(t *testing.T) {
{"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"},
{"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"},
}

for _, tc := range cases {
Expand Down