Merge remote-tracking branch 'origin/codex/refactor-dynu-blank-a/aaaa-handling'

This commit is contained in:
2026-04-29 10:42:41 +10:00
2 changed files with 61 additions and 4 deletions
+14 -4
View File
@@ -190,10 +190,7 @@ func (r *dnsRecordResource) Read(ctx context.Context, req resource.ReadRequest,
return return
} }
dynamicIntent := false dynamicIntent := inferDynamicIntentFromState(state.RecordType, state.Content, state.Dynamic)
if !state.Dynamic.IsNull() && !state.Dynamic.IsUnknown() {
dynamicIntent = state.Dynamic.ValueBool()
}
nextState := mapDNSRecordToState(*record, dynamicIntent) nextState := mapDNSRecordToState(*record, dynamicIntent)
nextState.ID = state.ID nextState.ID = state.ID
resp.Diagnostics.Append(resp.State.Set(ctx, &nextState)...) resp.Diagnostics.Append(resp.State.Set(ctx, &nextState)...)
@@ -485,6 +482,19 @@ func resolveDynamicIntent(recordType string, content types.String, dynamic types
return true, true return true, true
} }
func inferDynamicIntentFromState(recordType types.String, content types.String, dynamic types.Bool) bool {
if !dynamic.IsNull() && !dynamic.IsUnknown() {
return dynamic.ValueBool()
}
normalizedType := strings.ToUpper(strings.TrimSpace(recordType.ValueString()))
if normalizedType != "A" && normalizedType != "AAAA" {
return false
}
return content.IsNull() || (content.IsUnknown())
}
func normalizeRecordContentForState(recordType string, content string, dynamicIntent bool) types.String { func normalizeRecordContentForState(recordType string, content string, dynamicIntent bool) types.String {
if dynamicIntent { if dynamicIntent {
return types.StringNull() return types.StringNull()
@@ -90,3 +90,50 @@ func TestNormalizeRecordContentForState(t *testing.T) {
t.Fatalf("expected dynamic content to remain null, got %q", got.ValueString()) t.Fatalf("expected dynamic content to remain null, got %q", got.ValueString())
} }
} }
func TestInferDynamicIntentFromState(t *testing.T) {
tests := []struct {
name string
recordType types.String
content types.String
dynamic types.Bool
want bool
}{
{
name: "explicit dynamic false wins",
recordType: types.StringValue("A"),
content: types.StringNull(),
dynamic: types.BoolValue(false),
want: false,
},
{
name: "legacy A null content treated dynamic",
recordType: types.StringValue("A"),
content: types.StringNull(),
dynamic: types.BoolNull(),
want: true,
},
{
name: "legacy AAAA unknown content treated dynamic",
recordType: types.StringValue("AAAA"),
content: types.StringUnknown(),
dynamic: types.BoolNull(),
want: true,
},
{
name: "legacy non-A not dynamic",
recordType: types.StringValue("TXT"),
content: types.StringNull(),
dynamic: types.BoolNull(),
want: false,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if got := inferDynamicIntentFromState(tc.recordType, tc.content, tc.dynamic); got != tc.want {
t.Fatalf("inferDynamicIntentFromState()=%v, want %v", got, tc.want)
}
})
}
}