Skip to content

Commit 932f0d3

Browse files
committed
Fix update issue for route53.Record
Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
1 parent a15cc92 commit 932f0d3

File tree

2 files changed

+50
-8
lines changed

2 files changed

+50
-8
lines changed

config/cluster/route53/config.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,32 @@ func Configure(p *config.Provider) { //nolint:gocyclo
4040
return diff, nil
4141
}
4242
nameDiff, ok := diff.Attributes["name"]
43-
if !ok {
44-
return diff, nil
43+
if ok {
44+
if strings.TrimSuffix(nameDiff.New, ".") == strings.TrimSuffix(nameDiff.Old, ".") {
45+
delete(diff.Attributes, "name")
46+
}
4547
}
46-
if strings.TrimSuffix(nameDiff.New, ".") == strings.TrimSuffix(nameDiff.Old, ".") {
47-
delete(diff.Attributes, "name")
48+
// When `records` are being modified, AWS SDK expects `ttl` to be
49+
// present in the request body. The underlying TF provider checks
50+
// the RawPlan to find `ttl` and inject it to request body, but
51+
// it can't find since we are converting the diff to RawPlan during
52+
// diff calculation. So, if `ttl` isn't being changed by user, we
53+
// need to inject it manually from the current state for a successful
54+
// update.
55+
for k := range diff.Attributes {
56+
if strings.HasPrefix(k, "records.") {
57+
if _, exists := diff.Attributes["ttl"]; !exists {
58+
if state != nil && state.Attributes != nil {
59+
if ttlState, ok := state.Attributes["ttl"]; ok {
60+
diff.Attributes["ttl"] = &terraform.ResourceAttrDiff{
61+
Old: ttlState,
62+
New: ttlState,
63+
}
64+
}
65+
}
66+
}
67+
break
68+
}
4869
}
4970
return diff, nil
5071
}

config/namespaced/route53/config.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,32 @@ func Configure(p *config.Provider) { //nolint:gocyclo
4040
return diff, nil
4141
}
4242
nameDiff, ok := diff.Attributes["name"]
43-
if !ok {
44-
return diff, nil
43+
if ok {
44+
if strings.TrimSuffix(nameDiff.New, ".") == strings.TrimSuffix(nameDiff.Old, ".") {
45+
delete(diff.Attributes, "name")
46+
}
4547
}
46-
if strings.TrimSuffix(nameDiff.New, ".") == strings.TrimSuffix(nameDiff.Old, ".") {
47-
delete(diff.Attributes, "name")
48+
// When `records` are being modified, AWS SDK expects `ttl` to be
49+
// present in the request body. The underlying TF provider checks
50+
// the RawPlan to find `ttl` and inject it to request body, but
51+
// it can't find since we are converting the diff to RawPlan during
52+
// diff calculation. So, if `ttl` isn't being changed by user, we
53+
// need to inject it manually from the current state for a successful
54+
// update.
55+
for k := range diff.Attributes {
56+
if strings.HasPrefix(k, "records.") {
57+
if _, exists := diff.Attributes["ttl"]; !exists {
58+
if state != nil && state.Attributes != nil {
59+
if ttlState, ok := state.Attributes["ttl"]; ok {
60+
diff.Attributes["ttl"] = &terraform.ResourceAttrDiff{
61+
Old: ttlState,
62+
New: ttlState,
63+
}
64+
}
65+
}
66+
}
67+
break
68+
}
4869
}
4970
return diff, nil
5071
}

0 commit comments

Comments
 (0)