diff --git a/pkg/iac/terraform/state/test/route53_record/result.golden.json b/pkg/iac/terraform/state/test/route53_record/result.golden.json index 559402dc6..3c47b12d7 100755 --- a/pkg/iac/terraform/state/test/route53_record/result.golden.json +++ b/pkg/iac/terraform/state/test/route53_record/result.golden.json @@ -42,7 +42,7 @@ "AllowOverwrite": null, "Fqdn": "test.elie.ski", "HealthCheckId": "", - "Id": "Z09368953G729AFEX5048_test_A", + "Id": "Z09368953G729AFEX5048_test.elie.ski_A", "MultivalueAnswerRoutingPolicy": null, "Name": "test", "Records": [ diff --git a/pkg/iac/terraform/state/test/route53_record_multiples/result.golden.json b/pkg/iac/terraform/state/test/route53_record_multiples/result.golden.json index 1c7bdf990..66190a180 100755 --- a/pkg/iac/terraform/state/test/route53_record_multiples/result.golden.json +++ b/pkg/iac/terraform/state/test/route53_record_multiples/result.golden.json @@ -58,7 +58,7 @@ "AllowOverwrite": null, "Fqdn": "test2.foo-0.com", "HealthCheckId": "", - "Id": "Z1035360GLIB82T1EH2G_test2_A", + "Id": "Z1035360GLIB82T1EH2G_test2.foo-0.com_A", "MultivalueAnswerRoutingPolicy": null, "Name": "test2", "Records": [ @@ -78,7 +78,7 @@ "AllowOverwrite": null, "Fqdn": "test3.foo-0.com", "HealthCheckId": "", - "Id": "Z1035360GLIB82T1EH2G_test3_A", + "Id": "Z1035360GLIB82T1EH2G_test3.foo-0.com_A", "MultivalueAnswerRoutingPolicy": null, "Name": "test3", "Records": [ @@ -98,7 +98,7 @@ "AllowOverwrite": null, "Fqdn": "test0.foo-0.com", "HealthCheckId": "", - "Id": "Z1035360GLIB82T1EH2G_test0_A", + "Id": "Z1035360GLIB82T1EH2G_test0.foo-0.com_A", "MultivalueAnswerRoutingPolicy": null, "Name": "test0", "Records": [ @@ -118,7 +118,7 @@ "AllowOverwrite": null, "Fqdn": "test1.foo-0.com", "HealthCheckId": "", - "Id": "Z1035360GLIB82T1EH2G_test1_A", + "Id": "Z1035360GLIB82T1EH2G_test1.foo-0.com_A", "MultivalueAnswerRoutingPolicy": null, "Name": "test1", "Records": [ @@ -138,7 +138,7 @@ "AllowOverwrite": null, "Fqdn": "test3.foo-1.com", "HealthCheckId": "", - "Id": "Z10347383HV75H96J919W_test3_A", + "Id": "Z10347383HV75H96J919W_test3.foo-1.com_A", "MultivalueAnswerRoutingPolicy": null, "Name": "test3", "Records": [ @@ -158,7 +158,7 @@ "AllowOverwrite": null, "Fqdn": "test0.foo-1.com", "HealthCheckId": "", - "Id": "Z10347383HV75H96J919W_test0_A", + "Id": "Z10347383HV75H96J919W_test0.foo-1.com_A", "MultivalueAnswerRoutingPolicy": null, "Name": "test0", "Records": [ @@ -178,7 +178,7 @@ "AllowOverwrite": null, "Fqdn": "test1.foo-1.com", "HealthCheckId": "", - "Id": "Z10347383HV75H96J919W_test1_A", + "Id": "Z10347383HV75H96J919W_test1.foo-1.com_A", "MultivalueAnswerRoutingPolicy": null, "Name": "test1", "Records": [ @@ -198,7 +198,7 @@ "AllowOverwrite": null, "Fqdn": "test2.foo-1.com", "HealthCheckId": "", - "Id": "Z10347383HV75H96J919W_test2_A", + "Id": "Z10347383HV75H96J919W_test2.foo-1.com_A", "MultivalueAnswerRoutingPolicy": null, "Name": "test2", "Records": [ diff --git a/pkg/middlewares/route53_records_test.go b/pkg/middlewares/route53_records_test.go index 06f587561..7005258d8 100644 --- a/pkg/middlewares/route53_records_test.go +++ b/pkg/middlewares/route53_records_test.go @@ -16,21 +16,21 @@ func TestDefaultRoute53RecordShouldBeIgnored(t *testing.T) { &aws.AwsRoute53Zone{}, &aws.AwsRoute53Record{ Type: awssdk.String("NS"), - Fqdn: awssdk.String("foobar"), + Id: "123_foobar_NS", }, &aws.AwsRoute53Record{ Type: awssdk.String("SOA"), - Fqdn: awssdk.String(""), + Id: "123_foobar_SOA", }, &aws.AwsRoute53Record{ Type: awssdk.String("A"), - Fqdn: awssdk.String(""), + Id: "123_foobar_A", }, } stateResources := []resource.Resource{ &aws.AwsRoute53Record{ Type: awssdk.String("NS"), - Fqdn: awssdk.String("barfoo"), + Id: "456_barfoo_NS", }, } err := middleware.Execute(&remoteResources, &stateResources) @@ -54,21 +54,21 @@ func TestDefaultRoute53RecordShouldNotBeIgnoredWhenManaged(t *testing.T) { &aws.AwsRoute53Zone{}, &aws.AwsRoute53Record{ Type: awssdk.String("NS"), - Fqdn: awssdk.String("foobar"), + Id: "123_foobar_NS", }, &aws.AwsRoute53Record{ Type: awssdk.String("SOA"), - Fqdn: awssdk.String(""), + Id: "123_foobar_SOA", }, &aws.AwsRoute53Record{ Type: awssdk.String("A"), - Fqdn: awssdk.String(""), + Id: "123_foobar_A", }, } stateResources := []resource.Resource{ &aws.AwsRoute53Record{ Type: awssdk.String("NS"), - Fqdn: awssdk.String("foobar"), + Id: "123_foobar_NS", }, } err := middleware.Execute(&remoteResources, &stateResources) diff --git a/pkg/remote/aws/route53_record_supplier_test.go b/pkg/remote/aws/route53_record_supplier_test.go index b630fa6d8..9f44e37df 100644 --- a/pkg/remote/aws/route53_record_supplier_test.go +++ b/pkg/remote/aws/route53_record_supplier_test.go @@ -150,14 +150,26 @@ func TestRoute53RecordSupplier_Resources(t *testing.T) { Name: awssdk.String("test0"), Type: awssdk.String("TXT"), }, + { + Name: awssdk.String("test0"), + Type: awssdk.String("A"), + }, { Name: awssdk.String("test1.foo-2.com"), Type: awssdk.String("TXT"), }, + { + Name: awssdk.String("test1.foo-2.com"), + Type: awssdk.String("A"), + }, { Name: awssdk.String("_test2.foo-2.com"), Type: awssdk.String("TXT"), }, + { + Name: awssdk.String("_test2.foo-2.com"), + Type: awssdk.String("A"), + }, }, }, "Z06486383UC8WYSBZTWFM", diff --git a/pkg/remote/aws/test/route53_record_explicit_subdomain/aws_route53_record-Z06486383UC8WYSBZTWFM__test2.foo-2.com_A.res.golden.json b/pkg/remote/aws/test/route53_record_explicit_subdomain/aws_route53_record-Z06486383UC8WYSBZTWFM__test2.foo-2.com_A.res.golden.json new file mode 100755 index 000000000..94f1571d1 --- /dev/null +++ b/pkg/remote/aws/test/route53_record_explicit_subdomain/aws_route53_record-Z06486383UC8WYSBZTWFM__test2.foo-2.com_A.res.golden.json @@ -0,0 +1,5 @@ +{ + "Typ": "WyJvYmplY3QiLHsiYWxpYXMiOlsic2V0IixbIm9iamVjdCIseyJldmFsdWF0ZV90YXJnZXRfaGVhbHRoIjoiYm9vbCIsIm5hbWUiOiJzdHJpbmciLCJ6b25lX2lkIjoic3RyaW5nIn1dXSwiYWxsb3dfb3ZlcndyaXRlIjoiYm9vbCIsImZhaWxvdmVyX3JvdXRpbmdfcG9saWN5IjpbImxpc3QiLFsib2JqZWN0Iix7InR5cGUiOiJzdHJpbmcifV1dLCJmcWRuIjoic3RyaW5nIiwiZ2VvbG9jYXRpb25fcm91dGluZ19wb2xpY3kiOlsibGlzdCIsWyJvYmplY3QiLHsiY29udGluZW50Ijoic3RyaW5nIiwiY291bnRyeSI6InN0cmluZyIsInN1YmRpdmlzaW9uIjoic3RyaW5nIn1dXSwiaGVhbHRoX2NoZWNrX2lkIjoic3RyaW5nIiwiaWQiOiJzdHJpbmciLCJsYXRlbmN5X3JvdXRpbmdfcG9saWN5IjpbImxpc3QiLFsib2JqZWN0Iix7InJlZ2lvbiI6InN0cmluZyJ9XV0sIm11bHRpdmFsdWVfYW5zd2VyX3JvdXRpbmdfcG9saWN5IjoiYm9vbCIsIm5hbWUiOiJzdHJpbmciLCJyZWNvcmRzIjpbInNldCIsInN0cmluZyJdLCJzZXRfaWRlbnRpZmllciI6InN0cmluZyIsInR0bCI6Im51bWJlciIsInR5cGUiOiJzdHJpbmciLCJ3ZWlnaHRlZF9yb3V0aW5nX3BvbGljeSI6WyJsaXN0IixbIm9iamVjdCIseyJ3ZWlnaHQiOiJudW1iZXIifV1dLCJ6b25lX2lkIjoic3RyaW5nIn1d", + "Val": "eyJhbGlhcyI6bnVsbCwiYWxsb3dfb3ZlcndyaXRlIjpudWxsLCJmYWlsb3Zlcl9yb3V0aW5nX3BvbGljeSI6bnVsbCwiZnFkbiI6Il90ZXN0Mi5mb28tMi5jb20iLCJnZW9sb2NhdGlvbl9yb3V0aW5nX3BvbGljeSI6bnVsbCwiaGVhbHRoX2NoZWNrX2lkIjoiIiwiaWQiOiJaMDY0ODYzODNVQzhXWVNCWlRXRk1fX3Rlc3QyLmZvby0yLmNvbV9BIiwibGF0ZW5jeV9yb3V0aW5nX3BvbGljeSI6bnVsbCwibXVsdGl2YWx1ZV9hbnN3ZXJfcm91dGluZ19wb2xpY3kiOm51bGwsIm5hbWUiOiJfdGVzdDIuZm9vLTIuY29tIiwicmVjb3JkcyI6WyIxOTIuMC4xLjQiXSwic2V0X2lkZW50aWZpZXIiOiIiLCJ0dGwiOjMwMCwidHlwZSI6IkEiLCJ3ZWlnaHRlZF9yb3V0aW5nX3BvbGljeSI6bnVsbCwiem9uZV9pZCI6IlowNjQ4NjM4M1VDOFdZU0JaVFdGTSJ9", + "Err": null +} \ No newline at end of file diff --git a/pkg/remote/aws/test/route53_record_explicit_subdomain/aws_route53_record-Z06486383UC8WYSBZTWFM_test0_A.res.golden.json b/pkg/remote/aws/test/route53_record_explicit_subdomain/aws_route53_record-Z06486383UC8WYSBZTWFM_test0_A.res.golden.json new file mode 100755 index 000000000..e704ddd1c --- /dev/null +++ b/pkg/remote/aws/test/route53_record_explicit_subdomain/aws_route53_record-Z06486383UC8WYSBZTWFM_test0_A.res.golden.json @@ -0,0 +1,5 @@ +{ + "Typ": "WyJvYmplY3QiLHsiYWxpYXMiOlsic2V0IixbIm9iamVjdCIseyJldmFsdWF0ZV90YXJnZXRfaGVhbHRoIjoiYm9vbCIsIm5hbWUiOiJzdHJpbmciLCJ6b25lX2lkIjoic3RyaW5nIn1dXSwiYWxsb3dfb3ZlcndyaXRlIjoiYm9vbCIsImZhaWxvdmVyX3JvdXRpbmdfcG9saWN5IjpbImxpc3QiLFsib2JqZWN0Iix7InR5cGUiOiJzdHJpbmcifV1dLCJmcWRuIjoic3RyaW5nIiwiZ2VvbG9jYXRpb25fcm91dGluZ19wb2xpY3kiOlsibGlzdCIsWyJvYmplY3QiLHsiY29udGluZW50Ijoic3RyaW5nIiwiY291bnRyeSI6InN0cmluZyIsInN1YmRpdmlzaW9uIjoic3RyaW5nIn1dXSwiaGVhbHRoX2NoZWNrX2lkIjoic3RyaW5nIiwiaWQiOiJzdHJpbmciLCJsYXRlbmN5X3JvdXRpbmdfcG9saWN5IjpbImxpc3QiLFsib2JqZWN0Iix7InJlZ2lvbiI6InN0cmluZyJ9XV0sIm11bHRpdmFsdWVfYW5zd2VyX3JvdXRpbmdfcG9saWN5IjoiYm9vbCIsIm5hbWUiOiJzdHJpbmciLCJyZWNvcmRzIjpbInNldCIsInN0cmluZyJdLCJzZXRfaWRlbnRpZmllciI6InN0cmluZyIsInR0bCI6Im51bWJlciIsInR5cGUiOiJzdHJpbmciLCJ3ZWlnaHRlZF9yb3V0aW5nX3BvbGljeSI6WyJsaXN0IixbIm9iamVjdCIseyJ3ZWlnaHQiOiJudW1iZXIifV1dLCJ6b25lX2lkIjoic3RyaW5nIn1d", + "Val": "eyJhbGlhcyI6bnVsbCwiYWxsb3dfb3ZlcndyaXRlIjpudWxsLCJmYWlsb3Zlcl9yb3V0aW5nX3BvbGljeSI6bnVsbCwiZnFkbiI6InRlc3QwLmZvby0yLmNvbSIsImdlb2xvY2F0aW9uX3JvdXRpbmdfcG9saWN5IjpudWxsLCJoZWFsdGhfY2hlY2tfaWQiOiIiLCJpZCI6IlowNjQ4NjM4M1VDOFdZU0JaVFdGTV90ZXN0MF9BIiwibGF0ZW5jeV9yb3V0aW5nX3BvbGljeSI6bnVsbCwibXVsdGl2YWx1ZV9hbnN3ZXJfcm91dGluZ19wb2xpY3kiOm51bGwsIm5hbWUiOiJ0ZXN0MCIsInJlY29yZHMiOlsiMTkyLjAuMS4yIl0sInNldF9pZGVudGlmaWVyIjoiIiwidHRsIjozMDAsInR5cGUiOiJBIiwid2VpZ2h0ZWRfcm91dGluZ19wb2xpY3kiOm51bGwsInpvbmVfaWQiOiJaMDY0ODYzODNVQzhXWVNCWlRXRk0ifQ==", + "Err": null +} \ No newline at end of file diff --git a/pkg/remote/aws/test/route53_record_explicit_subdomain/aws_route53_record-Z06486383UC8WYSBZTWFM_test1.foo-2.com_A.res.golden.json b/pkg/remote/aws/test/route53_record_explicit_subdomain/aws_route53_record-Z06486383UC8WYSBZTWFM_test1.foo-2.com_A.res.golden.json new file mode 100755 index 000000000..a8954ee7c --- /dev/null +++ b/pkg/remote/aws/test/route53_record_explicit_subdomain/aws_route53_record-Z06486383UC8WYSBZTWFM_test1.foo-2.com_A.res.golden.json @@ -0,0 +1,5 @@ +{ + "Typ": "WyJvYmplY3QiLHsiYWxpYXMiOlsic2V0IixbIm9iamVjdCIseyJldmFsdWF0ZV90YXJnZXRfaGVhbHRoIjoiYm9vbCIsIm5hbWUiOiJzdHJpbmciLCJ6b25lX2lkIjoic3RyaW5nIn1dXSwiYWxsb3dfb3ZlcndyaXRlIjoiYm9vbCIsImZhaWxvdmVyX3JvdXRpbmdfcG9saWN5IjpbImxpc3QiLFsib2JqZWN0Iix7InR5cGUiOiJzdHJpbmcifV1dLCJmcWRuIjoic3RyaW5nIiwiZ2VvbG9jYXRpb25fcm91dGluZ19wb2xpY3kiOlsibGlzdCIsWyJvYmplY3QiLHsiY29udGluZW50Ijoic3RyaW5nIiwiY291bnRyeSI6InN0cmluZyIsInN1YmRpdmlzaW9uIjoic3RyaW5nIn1dXSwiaGVhbHRoX2NoZWNrX2lkIjoic3RyaW5nIiwiaWQiOiJzdHJpbmciLCJsYXRlbmN5X3JvdXRpbmdfcG9saWN5IjpbImxpc3QiLFsib2JqZWN0Iix7InJlZ2lvbiI6InN0cmluZyJ9XV0sIm11bHRpdmFsdWVfYW5zd2VyX3JvdXRpbmdfcG9saWN5IjoiYm9vbCIsIm5hbWUiOiJzdHJpbmciLCJyZWNvcmRzIjpbInNldCIsInN0cmluZyJdLCJzZXRfaWRlbnRpZmllciI6InN0cmluZyIsInR0bCI6Im51bWJlciIsInR5cGUiOiJzdHJpbmciLCJ3ZWlnaHRlZF9yb3V0aW5nX3BvbGljeSI6WyJsaXN0IixbIm9iamVjdCIseyJ3ZWlnaHQiOiJudW1iZXIifV1dLCJ6b25lX2lkIjoic3RyaW5nIn1d", + "Val": "eyJhbGlhcyI6bnVsbCwiYWxsb3dfb3ZlcndyaXRlIjpudWxsLCJmYWlsb3Zlcl9yb3V0aW5nX3BvbGljeSI6bnVsbCwiZnFkbiI6InRlc3QxLmZvby0yLmNvbSIsImdlb2xvY2F0aW9uX3JvdXRpbmdfcG9saWN5IjpudWxsLCJoZWFsdGhfY2hlY2tfaWQiOiIiLCJpZCI6IlowNjQ4NjM4M1VDOFdZU0JaVFdGTV90ZXN0MS5mb28tMi5jb21fQSIsImxhdGVuY3lfcm91dGluZ19wb2xpY3kiOm51bGwsIm11bHRpdmFsdWVfYW5zd2VyX3JvdXRpbmdfcG9saWN5IjpudWxsLCJuYW1lIjoidGVzdDEuZm9vLTIuY29tIiwicmVjb3JkcyI6WyIxOTIuMC4xLjMiXSwic2V0X2lkZW50aWZpZXIiOiIiLCJ0dGwiOjMwMCwidHlwZSI6IkEiLCJ3ZWlnaHRlZF9yb3V0aW5nX3BvbGljeSI6bnVsbCwiem9uZV9pZCI6IlowNjQ4NjM4M1VDOFdZU0JaVFdGTSJ9", + "Err": null +} \ No newline at end of file diff --git a/pkg/remote/aws/test/route53_record_explicit_subdomain/main.tf b/pkg/remote/aws/test/route53_record_explicit_subdomain/main.tf index fb42a77b6..5e0c1f1ab 100644 --- a/pkg/remote/aws/test/route53_record_explicit_subdomain/main.tf +++ b/pkg/remote/aws/test/route53_record_explicit_subdomain/main.tf @@ -15,6 +15,14 @@ resource "aws_route53_record" "foo-record" { records = ["test0"] } +resource "aws_route53_record" "foo-record-2" { + zone_id = aws_route53_zone.foo-zone.zone_id + name = "test0" + type = "A" + ttl = 300 + records = ["192.0.1.2"] +} + resource "aws_route53_record" "foo-record-bis" { zone_id = aws_route53_zone.foo-zone.zone_id name = "test1.foo-2.com" @@ -23,6 +31,14 @@ resource "aws_route53_record" "foo-record-bis" { records = ["test1.foo-2.com"] } +resource "aws_route53_record" "foo-record-bis-2" { + zone_id = aws_route53_zone.foo-zone.zone_id + name = "test1.foo-2.com" + type = "A" + ttl = 300 + records = ["192.0.1.3"] +} + resource "aws_route53_record" "foo-record-bis-bis" { zone_id = aws_route53_zone.foo-zone.zone_id name = "_test2.foo-2.com" @@ -30,3 +46,11 @@ resource "aws_route53_record" "foo-record-bis-bis" { ttl = 300 records = ["_test2.foo-2.com"] } + +resource "aws_route53_record" "foo-record-bis-bis-2" { + zone_id = aws_route53_zone.foo-zone.zone_id + name = "_test2.foo-2.com" + type = "A" + ttl = 300 + records = ["192.0.1.4"] +} diff --git a/pkg/remote/aws/test/route53_record_explicit_subdomain/results.golden.json b/pkg/remote/aws/test/route53_record_explicit_subdomain/results.golden.json index 214c45364..38ad70b04 100755 --- a/pkg/remote/aws/test/route53_record_explicit_subdomain/results.golden.json +++ b/pkg/remote/aws/test/route53_record_explicit_subdomain/results.golden.json @@ -6,16 +6,16 @@ "fqdn": "test1.foo-2.com", "geolocation_routing_policy": null, "health_check_id": "", - "id": "Z06486383UC8WYSBZTWFM_test1.foo-2.com_TXT", + "id": "Z06486383UC8WYSBZTWFM_test1.foo-2.com_A", "latency_routing_policy": null, "multivalue_answer_routing_policy": null, "name": "test1.foo-2.com", "records": [ - "test1.foo-2.com" + "192.0.1.3" ], "set_identifier": "", "ttl": 300, - "type": "TXT", + "type": "A", "weighted_routing_policy": null, "zone_id": "Z06486383UC8WYSBZTWFM" }, @@ -39,6 +39,66 @@ "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_A", + "latency_routing_policy": null, + "multivalue_answer_routing_policy": null, + "name": "_test2.foo-2.com", + "records": [ + "192.0.1.4" + ], + "set_identifier": "", + "ttl": 300, + "type": "A", + "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_A", + "latency_routing_policy": null, + "multivalue_answer_routing_policy": null, + "name": "test0", + "records": [ + "192.0.1.2" + ], + "set_identifier": "", + "ttl": 300, + "type": "A", + "weighted_routing_policy": null, + "zone_id": "Z06486383UC8WYSBZTWFM" + }, + { + "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, diff --git a/pkg/resource/aws/aws_route53_record.go b/pkg/resource/aws/aws_route53_record.go index e7f0a5d6b..49c7df77a 100644 --- a/pkg/resource/aws/aws_route53_record.go +++ b/pkg/resource/aws/aws_route53_record.go @@ -7,7 +7,7 @@ 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" diff:"-" computed:"true"` + Id string `cty:"id" computed:"true"` MultivalueAnswerRoutingPolicy *bool `cty:"multivalue_answer_routing_policy"` Name *string `cty:"name" diff:"-"` Records []string `cty:"records"` @@ -37,7 +37,7 @@ type AwsRoute53Record struct { } func (r *AwsRoute53Record) TerraformId() string { - return *r.Fqdn + return r.Id } func (r *AwsRoute53Record) TerraformType() string { diff --git a/pkg/resource/aws/aws_route53_record_ext.go b/pkg/resource/aws/aws_route53_record_ext.go index 5fc6703e3..2a24893c3 100644 --- a/pkg/resource/aws/aws_route53_record_ext.go +++ b/pkg/resource/aws/aws_route53_record_ext.go @@ -1,6 +1,8 @@ package aws import ( + "strings" + "github.com/aws/aws-sdk-go/aws" "github.com/cloudskiff/driftctl/pkg/resource" ) @@ -24,6 +26,21 @@ func (r *AwsRoute53Record) NormalizeForState() (resource.Resource, error) { r.SetIdentifier = aws.String("") } + // Since AWS returns the FQDN as the name of the remote record, we must change the Id of the + // state record to be equivalent (ZoneId_FQDN_Type_SetIdentifier) + // For a TXT record toto for zone example.com with Id 1234 + // From AWS provider, we retrieve: 1234_toto.example.com_TXT + // From Terraform state, we retrieve: 1234_toto_TXT + vars := []string{ + *r.ZoneId, + *r.Fqdn, + *r.Type, + } + if r.SetIdentifier != nil && *r.SetIdentifier != "" { + vars = append(vars, *r.SetIdentifier) + } + r.Id = strings.Join(vars, "_") + return r, nil } diff --git a/pkg/resource/aws/aws_route53_record_test.go b/pkg/resource/aws/aws_route53_record_test.go index b8f072ae8..48b3d493b 100644 --- a/pkg/resource/aws/aws_route53_record_test.go +++ b/pkg/resource/aws/aws_route53_record_test.go @@ -18,7 +18,7 @@ func TestAcc_AwsRoute53Record_WithFQDNAsId(t *testing.T) { } result.AssertDriftCountTotal(0) result.Equal(0, result.Summary().TotalDeleted) - result.Equal(4, result.Summary().TotalManaged) + result.Equal(8, result.Summary().TotalManaged) }, }, }, diff --git a/pkg/resource/aws/testdata/acc/aws_route53_record/route53.tf b/pkg/resource/aws/testdata/acc/aws_route53_record/route53.tf index 11bb9aa85..369b6c6ac 100644 --- a/pkg/resource/aws/testdata/acc/aws_route53_record/route53.tf +++ b/pkg/resource/aws/testdata/acc/aws_route53_record/route53.tf @@ -10,6 +10,14 @@ resource "aws_route53_record" "foo-record" { records = ["test0"] } +resource "aws_route53_record" "foo-record-a" { + zone_id = aws_route53_zone.foo-zone.zone_id + name = "test0" + type = "A" + ttl = 300 + records = ["192.0.1.2"] +} + resource "aws_route53_record" "foo-record-2" { zone_id = aws_route53_zone.foo-zone.zone_id name = "test1.foo-2.com" @@ -18,7 +26,15 @@ resource "aws_route53_record" "foo-record-2" { records = ["test1.foo-2.com"] } -resource "aws_route53_record" "foo-record-bis-3" { +resource "aws_route53_record" "foo-record-2-a" { + zone_id = aws_route53_zone.foo-zone.zone_id + name = "test1.foo-2.com" + type = "A" + ttl = 300 + records = ["192.0.1.3"] +} + +resource "aws_route53_record" "foo-record-3" { zone_id = aws_route53_zone.foo-zone.zone_id name = "_test2.foo-2.com" type = "TXT" @@ -26,10 +42,26 @@ resource "aws_route53_record" "foo-record-bis-3" { records = ["_test2.foo-2.com"] } -resource "aws_route53_record" "foo-record-bis-4" { +resource "aws_route53_record" "foo-record-3-a" { + zone_id = aws_route53_zone.foo-zone.zone_id + name = "_test2.foo-2.com" + type = "A" + ttl = 300 + records = ["192.0.1.4"] +} + +resource "aws_route53_record" "foo-record-4" { zone_id = aws_route53_zone.foo-zone.zone_id name = "test3." type = "TXT" ttl = 300 records = ["test3."] } + +resource "aws_route53_record" "foo-record-4-a" { + zone_id = aws_route53_zone.foo-zone.zone_id + name = "test3." + type = "A" + ttl = 300 + records = ["192.0.1.5"] +}