Skip to content

Commit ca7c4d3

Browse files
eliecharrasundowndev-snyk
authored andcommitted
Merge pull request #1440 from snyk/fix/route53_record_name_parsing
Fix route53 record name parsing
1 parent d08cd70 commit ca7c4d3

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed

pkg/remote/aws/route53_record_enumerator.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package aws
22

33
import (
4+
"strconv"
45
"strings"
56

67
"github.com/snyk/driftctl/pkg/remote/aws/repository"
@@ -75,7 +76,7 @@ func (e *Route53RecordEnumerator) listRecordsForZone(zoneId string) ([]*resource
7576
results,
7677
e.factory.CreateAbstractResource(
7778
string(e.SupportedType()),
78-
strings.Join(vars, "_"),
79+
e.cleanRecordName(strings.Join(vars, "_")),
7980
map[string]interface{}{
8081
"type": rawType,
8182
},
@@ -85,3 +86,16 @@ func (e *Route53RecordEnumerator) listRecordsForZone(zoneId string) ([]*resource
8586

8687
return results, nil
8788
}
89+
90+
// cleanRecordName
91+
// Route 53 stores certain characters with the octal equivalent in ASCII format.
92+
// This function converts all of these characters back into the original character.
93+
// E.g. "*" is stored as "\\052" and "@" as "\\100"
94+
func (e *Route53RecordEnumerator) cleanRecordName(name string) string {
95+
str := name
96+
s, err := strconv.Unquote(`"` + str + `"`)
97+
if err != nil {
98+
return str
99+
}
100+
return s
101+
}

pkg/remote/aws_route53_scanner_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func TestRoute53_Record(t *testing.T) {
324324
Type: awssdk.String("A"),
325325
},
326326
{
327-
Name: awssdk.String("test3"),
327+
Name: awssdk.String("*.test4."),
328328
Type: awssdk.String("A"),
329329
},
330330
}, nil)
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"Typ":"WyJvYmplY3QiLHsiYWxpYXMiOlsic2V0IixbIm9iamVjdCIseyJldmFsdWF0ZV90YXJnZXRfaGVhbHRoIjoiYm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yJ3ZWlnaHQiOiJudW1iZXIifV1dLCJ6b25lX2lkIjoic3RyaW5nIn1d","Val":"eyJhbGlhcyI6bnVsbCwiYWxsb3dfb3ZlcndyaXRlIjpudWxsLCJmYWlsb3Zlcl9yb3V0aW5nX3BvbGljeSI6bnVsbCwiZnFkbiI6IioudGVzdDQuZm9vLTAuY29tIiwiZ2VvbG9jYXRpb25fcm91dGluZ19wb2xpY3kiOm51bGwsImhlYWx0aF9jaGVja19pZCI6IiIsImlkIjoiWjEwMzUzNjBHTElCODJUMUVIMkdfKi50ZXN0NC5fQSIsImxhdGVuY3lfcm91dGluZ19wb2xpY3kiOm51bGwsIm11bHRpdmFsdWVfYW5zd2VyX3JvdXRpbmdfcG9saWN5IjpudWxsLCJuYW1lIjoiKi50ZXN0NCIsInJlY29yZHMiOlsiMS4yLjMuNCJdLCJzZXRfaWRlbnRpZmllciI6IiIsInR0bCI6MzAwLCJ0eXBlIjoiQSIsIndlaWdodGVkX3JvdXRpbmdfcG9saWN5IjpudWxsLCJ6b25lX2lkIjoiWjEwMzUzNjBHTElCODJUMUVIMkcifQ==","Err":null}

pkg/remote/test/aws_route53_record_multiples/results.golden.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@
8686
"alias": null,
8787
"allow_overwrite": null,
8888
"failover_routing_policy": null,
89-
"fqdn": "test3.foo-0.com",
89+
"fqdn": "*.test4.foo-0.com",
9090
"geolocation_routing_policy": null,
9191
"health_check_id": "",
92-
"id": "Z1035360GLIB82T1EH2G_test3_A",
92+
"id": "Z1035360GLIB82T1EH2G_*.test4._A",
9393
"latency_routing_policy": null,
9494
"multivalue_answer_routing_policy": null,
95-
"name": "test3",
95+
"name": "*.test4",
9696
"records": [
9797
"1.2.3.4"
9898
],

pkg/resource/aws/aws_route53_record_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestAcc_Aws_Route53Record_WithFQDNAsId(t *testing.T) {
2323
}
2424
result.AssertDriftCountTotal(0)
2525
result.Equal(0, result.Summary().TotalDeleted)
26-
result.Equal(8, result.Summary().TotalManaged)
26+
result.Equal(9, result.Summary().TotalManaged)
2727
},
2828
},
2929
},

pkg/resource/aws/testdata/acc/aws_route53_record/route53.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,11 @@ resource "aws_route53_record" "foo-record-4-a" {
6565
ttl = 300
6666
records = ["192.0.1.5"]
6767
}
68+
69+
resource "aws_route53_record" "foo-record-4-b" {
70+
zone_id = aws_route53_zone.foo-zone.zone_id
71+
name = "*.test4."
72+
type = "A"
73+
ttl = 300
74+
records = ["192.0.1.5"]
75+
}

0 commit comments

Comments
 (0)