Archived
Fix location inheritance on record type transitions
This commit is contained in:
@@ -256,7 +256,7 @@ func (r *dnsRecordResource) Update(ctx context.Context, req resource.UpdateReque
|
||||
State: boolPointerFromOptional(preferKnownBool(plan.Enabled, state.Enabled)),
|
||||
Group: stringFromOptional(preferKnownString(plan.Group, state.Group)),
|
||||
Host: stringFromOptional(preferKnownString(plan.Host, state.Host)),
|
||||
Location: stringFromOptional(preferKnownString(plan.Location, state.Location)),
|
||||
Location: locationForUpdate(recordType, plan.Location, state.Location),
|
||||
}
|
||||
updateReq = normalizeDNSRecordUpdateRequestForType(updateReq)
|
||||
if !validateDNSRecordContentForType(updateReq.RecordType, updateReq.Content, dynamicIntent, &resp.Diagnostics) {
|
||||
@@ -602,6 +602,14 @@ func validateLocationForType(recordType string, location string, diagnostics *di
|
||||
return true
|
||||
}
|
||||
|
||||
func locationForUpdate(recordType string, planLocation types.String, stateLocation types.String) string {
|
||||
normalizedType := strings.ToUpper(strings.TrimSpace(recordType))
|
||||
if normalizedType != "A" && normalizedType != "AAAA" {
|
||||
return stringFromOptional(planLocation)
|
||||
}
|
||||
return stringFromOptional(preferKnownString(planLocation, stateLocation))
|
||||
}
|
||||
|
||||
func resolveDynamicIntent(recordType string, content types.String, dynamic types.Bool, diagnostics *diag.Diagnostics) (bool, bool) {
|
||||
normalizedType := strings.ToUpper(strings.TrimSpace(recordType))
|
||||
contentPtr := stringPointerFromOptionalContent(content)
|
||||
|
||||
@@ -203,6 +203,18 @@ func TestValidateLocationForType(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLocationForUpdate(t *testing.T) {
|
||||
if got := locationForUpdate("A", types.StringNull(), types.StringValue("us")); got != "us" {
|
||||
t.Fatalf("expected A record update to preserve state location, got %q", got)
|
||||
}
|
||||
if got := locationForUpdate("CNAME", types.StringNull(), types.StringValue("us")); got != "" {
|
||||
t.Fatalf("expected non-A/AAAA type to ignore prior state location when omitted, got %q", got)
|
||||
}
|
||||
if got := locationForUpdate("TXT", types.StringValue("eu"), types.StringValue("us")); got != "eu" {
|
||||
t.Fatalf("expected explicit plan location to be returned as-is, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInferDynamicIntentFromState(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user