Archived
Merge pull request #31 from beatz174-bit/codex/fix-dynamic-intent-bug-in-dns-record-handling
Follow-up: preserve legacy dynamic intent for A/AAAA state refresh
This commit is contained in:
@@ -190,10 +190,7 @@ func (r *dnsRecordResource) Read(ctx context.Context, req resource.ReadRequest,
|
||||
return
|
||||
}
|
||||
|
||||
dynamicIntent := false
|
||||
if !state.Dynamic.IsNull() && !state.Dynamic.IsUnknown() {
|
||||
dynamicIntent = state.Dynamic.ValueBool()
|
||||
}
|
||||
dynamicIntent := inferDynamicIntentFromState(state.RecordType, state.Content, state.Dynamic)
|
||||
nextState := mapDNSRecordToState(*record, dynamicIntent)
|
||||
nextState.ID = state.ID
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &nextState)...)
|
||||
@@ -485,6 +482,19 @@ func resolveDynamicIntent(recordType string, content types.String, dynamic types
|
||||
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 {
|
||||
if dynamicIntent {
|
||||
return types.StringNull()
|
||||
|
||||
@@ -90,3 +90,50 @@ func TestNormalizeRecordContentForState(t *testing.T) {
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user