Rely on the FQDN to compare two route53 records

main
William Beuil 2021-01-04 13:47:02 +01:00
parent bee214812f
commit 98d1021505
No known key found for this signature in database
GPG Key ID: BED2072C5C2BF537
10 changed files with 171918 additions and 12 deletions

View File

@ -16,19 +16,21 @@ func TestDefaultRoute53RecordShouldBeIgnored(t *testing.T) {
&aws.AwsRoute53Zone{},
&aws.AwsRoute53Record{
Type: awssdk.String("NS"),
Id: "foobar",
Fqdn: awssdk.String("foobar"),
},
&aws.AwsRoute53Record{
Type: awssdk.String("SOA"),
Fqdn: awssdk.String(""),
},
&aws.AwsRoute53Record{
Type: awssdk.String("A"),
Fqdn: awssdk.String(""),
},
}
stateResources := []resource.Resource{
&aws.AwsRoute53Record{
Type: awssdk.String("NS"),
Id: "barfoo",
Fqdn: awssdk.String("barfoo"),
},
}
err := middleware.Execute(&remoteResources, &stateResources)
@ -52,19 +54,21 @@ func TestDefaultRoute53RecordShouldNotBeIgnoredWhenManaged(t *testing.T) {
&aws.AwsRoute53Zone{},
&aws.AwsRoute53Record{
Type: awssdk.String("NS"),
Id: "foobar",
Fqdn: awssdk.String("foobar"),
},
&aws.AwsRoute53Record{
Type: awssdk.String("SOA"),
Fqdn: awssdk.String(""),
},
&aws.AwsRoute53Record{
Type: awssdk.String("A"),
Fqdn: awssdk.String(""),
},
}
stateResources := []resource.Resource{
&aws.AwsRoute53Record{
Type: awssdk.String("NS"),
Id: "foobar",
Fqdn: awssdk.String("foobar"),
},
}
err := middleware.Execute(&remoteResources, &stateResources)

View File

@ -80,11 +80,7 @@ func (s Route53RecordSupplier) listRecordsForZone(zoneId string, zoneName string
s.runner.Run(func() (cty.Value, error) {
vars := []string{
zoneId,
// aws api is appending zone name in record names
// we need to remove zone name and avoid fqdn to match terraform id's
// e.g. : aws api response Name: foobar.example.com. should be converted to `foobar`
// Also remove trailing dot ID_example.com._NS should be ID_example.com_NS
strings.ToLower(strings.TrimSuffix(strings.TrimSuffix(rawName, "."+zoneName), ".")),
strings.ToLower(strings.TrimSuffix(rawName, ".")),
rawType,
}
if rawSetIdentifier != nil {

View File

@ -125,6 +125,46 @@ func TestRoute53RecordSupplier_Resources(t *testing.T) {
},
err: nil,
},
{
test: "explicit subdomain records",
dirName: "route53_record_explicit_subdomain",
zonesPages: mocks.ListHostedZonesPagesOutput{
{
true,
&route53.ListHostedZonesOutput{
HostedZones: []*route53.HostedZone{
{
Id: awssdk.String("Z06486383UC8WYSBZTWFM"),
Name: awssdk.String("foo-2.com"),
},
},
},
},
},
recordsPages: mocks.ListResourceRecordSetsPagesOutput{
{
true,
&route53.ListResourceRecordSetsOutput{
ResourceRecordSets: []*route53.ResourceRecordSet{
{
Name: awssdk.String("test0"),
Type: awssdk.String("TXT"),
},
{
Name: awssdk.String("test1.foo-2.com"),
Type: awssdk.String("TXT"),
},
{
Name: awssdk.String("_test2.foo-2.com"),
Type: awssdk.String("TXT"),
},
},
},
"Z06486383UC8WYSBZTWFM",
},
},
err: nil,
},
}
for _, tt := range tests {
t.Run(tt.test, func(t *testing.T) {

View File

@ -0,0 +1,5 @@
{
"Typ": "WyJvYmplY3QiLHsiYWxpYXMiOlsic2V0IixbIm9iamVjdCIseyJldmFsdWF0ZV90YXJnZXRfaGVhbHRoIjoiYm9vbCIsIm5hbWUiOiJzdHJpbmciLCJ6b25lX2lkIjoic3RyaW5nIn1dXSwiYWxsb3dfb3ZlcndyaXRlIjoiYm9vbCIsImZhaWxvdmVyX3JvdXRpbmdfcG9saWN5IjpbImxpc3QiLFsib2JqZWN0Iix7InR5cGUiOiJzdHJpbmcifV1dLCJmcWRuIjoic3RyaW5nIiwiZ2VvbG9jYXRpb25fcm91dGluZ19wb2xpY3kiOlsibGlzdCIsWyJvYmplY3QiLHsiY29udGluZW50Ijoic3RyaW5nIiwiY291bnRyeSI6InN0cmluZyIsInN1YmRpdmlzaW9uIjoic3RyaW5nIn1dXSwiaGVhbHRoX2NoZWNrX2lkIjoic3RyaW5nIiwiaWQiOiJzdHJpbmciLCJsYXRlbmN5X3JvdXR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aHRlZF9yb3V0aW5nX3BvbGljeSI6WyJsaXN0IixbIm9iamVjdCIseyJ3ZWlnaHQiOiJudW1iZXIifV1dLCJ6b25lX2lkIjoic3RyaW5nIn1d",
"Val": "eyJhbGlhcyI6bnVsbCwiYWxsb3dfb3ZlcndyaXRlIjpudWxsLCJmYWlsb3Zlcl9yb3V0aW5nX3BvbGljeSI6bnVsbCwiZnFkbiI6InRlc3QxLmZvby0yLmNvbSIsImdlb2xvY2F0aW9uX3JvdXRpbmdfcG9saWN5IjpudWxsLCJoZWFsdGhfY2hlY2tfaWQiOiIiLCJpZCI6IlowNjQ4NjM4M1VDOFdZU0JaVFdGTV90ZXN0MS5mb28tMi5jb21fVFhUIiwibGF0ZW5jeV9yb3V0aW5nX3BvbGljeSI6bnVsbCwibXVsdGl2YWx1ZV9hbnN3ZXJfcm91dGluZ19wb2xpY3kiOm51bGwsIm5hbWUiOiJ0ZXN0MS5mb28tMi5jb20iLCJyZWNvcmRzIjpbInRlc3QxLmZvby0yLmNvbSJdLCJzZXRfaWRlbnRpZmllciI6IiIsInR0bCI6MzAwLCJ0eXBlIjoiVFhUIiwid2VpZ2h0ZWRfcm91dGluZ19wb2xpY3kiOm51bGwsInpvbmVfaWQiOiJaMDY0ODYzODNVQzhXWVNCWlRXRk0ifQ==",
"Err": null
}

View File

@ -0,0 +1,32 @@
provider "aws" {
region = "eu-west-3"
version = "3.19.0"
}
resource "aws_route53_zone" "foo-zone" {
name = "foo-2.com"
}
resource "aws_route53_record" "foo-record" {
zone_id = aws_route53_zone.foo-zone.zone_id
name = "test0"
type = "TXT"
ttl = 300
records = ["test0"]
}
resource "aws_route53_record" "foo-record-bis" {
zone_id = aws_route53_zone.foo-zone.zone_id
name = "test1.foo-2.com"
type = "TXT"
ttl = 300
records = ["test1.foo-2.com"]
}
resource "aws_route53_record" "foo-record-bis-bis" {
zone_id = aws_route53_zone.foo-zone.zone_id
name = "_test2.foo-2.com"
type = "TXT"
ttl = 300
records = ["_test2.foo-2.com"]
}

View File

@ -0,0 +1,62 @@
[
{
"alias": null,
"allow_overwrite": null,
"failover_routing_policy": null,
"fqdn": "test1.foo-2.com",
"geolocation_routing_policy": null,
"health_check_id": "",
"id": "Z06486383UC8WYSBZTWFM_test1.foo-2.com_TXT",
"latency_routing_policy": null,
"multivalue_answer_routing_policy": null,
"name": "test1.foo-2.com",
"records": [
"test1.foo-2.com"
],
"set_identifier": "",
"ttl": 300,
"type": "TXT",
"weighted_routing_policy": null,
"zone_id": "Z06486383UC8WYSBZTWFM"
},
{
"alias": null,
"allow_overwrite": null,
"failover_routing_policy": null,
"fqdn": "test0.foo-2.com",
"geolocation_routing_policy": null,
"health_check_id": "",
"id": "Z06486383UC8WYSBZTWFM_test0_TXT",
"latency_routing_policy": null,
"multivalue_answer_routing_policy": null,
"name": "test0",
"records": [
"test0"
],
"set_identifier": "",
"ttl": 300,
"type": "TXT",
"weighted_routing_policy": null,
"zone_id": "Z06486383UC8WYSBZTWFM"
},
{
"alias": null,
"allow_overwrite": null,
"failover_routing_policy": null,
"fqdn": "_test2.foo-2.com",
"geolocation_routing_policy": null,
"health_check_id": "",
"id": "Z06486383UC8WYSBZTWFM__test2.foo-2.com_TXT",
"latency_routing_policy": null,
"multivalue_answer_routing_policy": null,
"name": "_test2.foo-2.com",
"records": [
"_test2.foo-2.com"
],
"set_identifier": "",
"ttl": 300,
"type": "TXT",
"weighted_routing_policy": null,
"zone_id": "Z06486383UC8WYSBZTWFM"
}
]

File diff suppressed because it is too large Load Diff

View File

@ -7,9 +7,9 @@ type AwsRoute53Record struct {
AllowOverwrite *bool `cty:"allow_overwrite" diff:"-" computed:"true"`
Fqdn *string `cty:"fqdn" computed:"true"`
HealthCheckId *string `cty:"health_check_id"`
Id string `cty:"id" computed:"true"`
Id string `cty:"id" diff:"-" computed:"true"`
MultivalueAnswerRoutingPolicy *bool `cty:"multivalue_answer_routing_policy"`
Name *string `cty:"name"`
Name *string `cty:"name" diff:"-"`
Records []string `cty:"records"`
SetIdentifier *string `cty:"set_identifier"`
Ttl *int `cty:"ttl"`
@ -37,7 +37,7 @@ type AwsRoute53Record struct {
}
func (r *AwsRoute53Record) TerraformId() string {
return r.Id
return *r.Fqdn
}
func (r *AwsRoute53Record) TerraformType() string {