Skip to content

Commit

Permalink
Merge pull request #76 from cloudskiff/fix/records
Browse files Browse the repository at this point in the history
Fix records that has the same FQDN
  • Loading branch information
eliecharra authored Jan 6, 2021
2 parents 063ff82 + 7d6b6a8 commit 1abe965
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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": [
Expand All @@ -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": [
Expand All @@ -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": [
Expand All @@ -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": [
Expand All @@ -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": [
Expand All @@ -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": [
Expand All @@ -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": [
Expand Down
16 changes: 8 additions & 8 deletions pkg/middlewares/route53_records_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions pkg/remote/aws/route53_record_supplier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Typ": "WyJvYmplY3QiLHsiYWxpYXMiOlsic2V0IixbIm9iamVjdCIseyJldmFsdWF0ZV90YXJnZXRfaGVhbHRoIjoiYm9vbCIsIm5hbWUiOiJzdHJpbmciLCJ6b25lX2lkIjoic3RyaW5nIn1dXSwiYWxsb3dfb3ZlcndyaXRlIjoiYm9vbCIsImZhaWxvdmVyX3JvdXRpbmdfcG9saWN5IjpbImxpc3QiLFsib2JqZWN0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XSwic2V0X2lkZW50aWZpZXIiOiIiLCJ0dGwiOjMwMCwidHlwZSI6IkEiLCJ3ZWlnaHRlZF9yb3V0aW5nX3BvbGljeSI6bnVsbCwiem9uZV9pZCI6IlowNjQ4NjM4M1VDOFdZU0JaVFdGTSJ9",
"Err": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Typ": "WyJvYmplY3QiLHsiYWxpYXMiOlsic2V0IixbIm9iamVjdCIseyJldmFsdWF0ZV90YXJnZXRfaGVhbHRoIjoiYm9vbCIsIm5hbWUiOiJzdHJpbmciLCJ6b25lX2lkIjoic3RyaW5nIn1dXSwiYWxsb3dfb3ZlcndyaXRlIjoiYm9vbCIsImZhaWxvdmVyX3JvdXRpbmdfcG9saWN5IjpbImxpc3QiLFsib2JqZWN0Iix7InR5cGUiOiJzdHJpbmcifV1dLCJmcWRuIjoic3RyaW5nIiwiZ2VvbG9jYXRpb25fcm91dGluZ19wb2xpY3kiOlsibGlzdCIsWyJvYmplY3QiLHsiY29udGluZW50Ijoic3RyaW5nIiwiY291bnRyeSI6InN0cmluZyIsInN1YmRpdmlzaW9uIjoic3RyaW5nIn1dXSwiaGVhbHRoX2NoZWNrX2lkIjoic3RyaW5nIiwiaWQiOiJzdHJpbmciLCJsYXRlbmN5X3JvdXRpbmdfcG9saWN5IjpbImxpc3QiLFsib2JqZWN0Iix7InJlZ2lvbiI6InN0cmluZyJ9XV0sIm11bHRpdmFsdWVfYW5zd2VyX3JvdXRpbmdfcG9saWN5IjoiYm9vbCIsIm5hbWUiOiJzdHJpbmciLCJyZWNvcmRzIjpbInNldCIsInN0cmluZyJdLCJzZXRfaWRlbnRpZmllciI6InN0cmluZyIsInR0bCI6Im51bWJlciIsInR5cGUiOiJzdHJpbmciLCJ3ZWlnaHRlZF9yb3V0aW5nX3BvbGljeSI6WyJsaXN0IixbIm9iamVjdCIseyJ3ZWlnaHQiOiJudW1iZXIifV1dLCJ6b25lX2lkIjoic3RyaW5nIn1d",
"Val": "eyJhbGlhcyI6bnVsbCwiYWxsb3dfb3ZlcndyaXRlIjpudWxsLCJmYWlsb3Zlcl9yb3V0aW5nX3BvbGljeSI6bnVsbCwiZnFkbiI6InRlc3QwLmZvby0yLmNvbSIsImdlb2xvY2F0aW9uX3JvdXRpbmdfcG9saWN5IjpudWxsLCJoZWFsdGhfY2hlY2tfaWQiOiIiLCJpZCI6IlowNjQ4NjM4M1VDOFdZU0JaVFdGTV90ZXN0MF9BIiwibGF0ZW5jeV9yb3V0aW5nX3BvbGljeSI6bnVsbCwibXVsdGl2YWx1ZV9hbnN3ZXJfcm91dGluZ19wb2xpY3kiOm51bGwsIm5hbWUiOiJ0ZXN0MCIsInJlY29yZHMiOlsiMTkyLjAuMS4yIl0sInNldF9pZGVudGlmaWVyIjoiIiwidHRsIjozMDAsInR5cGUiOiJBIiwid2VpZ2h0ZWRfcm91dGluZ19wb2xpY3kiOm51bGwsInpvbmVfaWQiOiJaMDY0ODYzODNVQzhXWVNCWlRXRk0ifQ==",
"Err": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Typ": "WyJvYmplY3QiLHsiYWxpYXMiOlsic2V0IixbIm9iamVjdCIseyJldmFsdWF0ZV90YXJnZXRfaGVhbHRoIjoiYm9vbCIsIm5hbWUiOiJzdHJpbmciLCJ6b25lX2lkIjoic3RyaW5nIn1dXSwiYWxsb3dfb3ZlcndyaXRlIjoiYm9vbCIsImZhaWxvdmVyX3JvdXRpbmdfcG9saWN5IjpbImxpc3QiLFsib2JqZWN0Iix7InR5cGUiOiJzdHJpbmcifV1dLCJmcWRuIjoic3RyaW5nIiwiZ2VvbG9jYXRpb25fcm91dGluZ19wb2xpY3kiOlsibGlzdCIsWyJvYmplY3QiLHsiY29udGluZW50Ijoic3RyaW5nIiwiY291bnRyeSI6InN0cmluZyIsInN1YmRpdmlzaW9uIjoic3RyaW5nIn1dXSwiaGVhbHRoX2NoZWNrX2lkIjoic3RyaW5nIiwiaWQiOiJzdHJpbmciLCJsYXRlbmN5X3JvdXRpbmdfcG9saWN5IjpbImxpc3QiLFsib2JqZWN0Iix7InJlZ2lvbiI6InN0cmluZyJ9XV0sIm11bHRpdmFsdWVfYW5zd2VyX3JvdXRpbmdfcG9saWN5IjoiYm9vbCIsIm5hbWUiOiJzdHJpbmciLCJyZWNvcmRzIjpbInNldCIsInN0cmluZyJdLCJzZXRfaWRlbnRpZmllciI6InN0cmluZyIsInR0bCI6Im51bWJlciIsInR5cGUiOiJzdHJpbmciLCJ3ZWlnaHRlZF9yb3V0aW5nX3BvbGljeSI6WyJsaXN0IixbIm9iamVjdCIseyJ3ZWlnaHQiOiJudW1iZXIifV1dLCJ6b25lX2lkIjoic3RyaW5nIn1d",
"Val": "eyJhbGlhcyI6bnVsbCwiYWxsb3dfb3ZlcndyaXRlIjpudWxsLCJmYWlsb3Zlcl9yb3V0aW5nX3BvbGljeSI6bnVsbCwiZnFkbiI6InRlc3QxLmZvby0yLmNvbSIsImdlb2xvY2F0aW9uX3JvdXRpbmdfcG9saWN5IjpudWxsLCJoZWFsdGhfY2hlY2tfaWQiOiIiLCJpZCI6IlowNjQ4NjM4M1VDOFdZU0JaVFdGTV90ZXN0MS5mb28tMi5jb21fQSIsImxhdGVuY3lfcm91dGluZ19wb2xpY3kiOm51bGwsIm11bHRpdmFsdWVfYW5zd2VyX3JvdXRpbmdfcG9saWN5IjpudWxsLCJuYW1lIjoidGVzdDEuZm9vLTIuY29tIiwicmVjb3JkcyI6WyIxOTIuMC4xLjMiXSwic2V0X2lkZW50aWZpZXIiOiIiLCJ0dGwiOjMwMCwidHlwZSI6IkEiLCJ3ZWlnaHRlZF9yb3V0aW5nX3BvbGljeSI6bnVsbCwiem9uZV9pZCI6IlowNjQ4NjM4M1VDOFdZU0JaVFdGTSJ9",
"Err": null
}
24 changes: 24 additions & 0 deletions pkg/remote/aws/test/route53_record_explicit_subdomain/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -23,10 +31,26 @@ 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"
type = "TXT"
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"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pkg/resource/aws/aws_route53_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -37,7 +37,7 @@ type AwsRoute53Record struct {
}

func (r *AwsRoute53Record) TerraformId() string {
return *r.Fqdn
return r.Id
}

func (r *AwsRoute53Record) TerraformType() string {
Expand Down
17 changes: 17 additions & 0 deletions pkg/resource/aws/aws_route53_record_ext.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package aws

import (
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/cloudskiff/driftctl/pkg/resource"
)
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/resource/aws/aws_route53_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
},
},
Expand Down
Loading

0 comments on commit 1abe965

Please sign in to comment.