From fed8ed31caa5988886f0c2b1c6578cf10e137477 Mon Sep 17 00:00:00 2001 From: beatz174-bit Date: Wed, 29 Apr 2026 11:42:19 +1000 Subject: [PATCH] Handle Dynu 505 dynamic A/AAAA validation fallback --- internal/provider/resource_dns_record.go | 5 +- internal/provider/resource_dns_record_test.go | 54 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/internal/provider/resource_dns_record.go b/internal/provider/resource_dns_record.go index 760df03..9189211 100644 --- a/internal/provider/resource_dns_record.go +++ b/internal/provider/resource_dns_record.go @@ -539,7 +539,10 @@ func normalizeRecordContentForState(recordType string, content string, dynamicIn func isUnsupportedEmptyContentError(err error) bool { var apiErr *dynuclient.APIError - if !errors.As(err, &apiErr) || apiErr.StatusCode != 400 { + if !errors.As(err, &apiErr) { + return false + } + if apiErr.StatusCode != 400 && apiErr.StatusCode != 505 { return false } normalizedType := strings.ToLower(strings.TrimSpace(apiErr.Type)) diff --git a/internal/provider/resource_dns_record_test.go b/internal/provider/resource_dns_record_test.go index d58ba4c..eb9f702 100644 --- a/internal/provider/resource_dns_record_test.go +++ b/internal/provider/resource_dns_record_test.go @@ -4,6 +4,7 @@ import ( "strings" "testing" + "github.com/dynu/terraform-provider-dynu/internal/dynuclient" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -191,3 +192,56 @@ func TestInferDynamicIntentFromState(t *testing.T) { }) } } + +func TestIsUnsupportedEmptyContentError(t *testing.T) { + tests := []struct { + name string + err error + want bool + }{ + { + name: "status 400 content required", + err: &dynuclient.APIError{ + StatusCode: 400, + Type: "Validation Exception", + Message: "content is required", + }, + want: true, + }, + { + name: "status 505 invalid ip address", + err: &dynuclient.APIError{ + StatusCode: 505, + Type: "Validation Exception", + Message: "Invalid IP address.", + }, + want: true, + }, + { + name: "status 505 unrelated message", + err: &dynuclient.APIError{ + StatusCode: 505, + Type: "Validation Exception", + Message: "Some other validation failure", + }, + want: false, + }, + { + name: "non validation exception", + err: &dynuclient.APIError{ + StatusCode: 505, + Type: "Unauthorized", + Message: "Invalid IP address.", + }, + want: false, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + if got := isUnsupportedEmptyContentError(tc.err); got != tc.want { + t.Fatalf("isUnsupportedEmptyContentError()=%v, want %v", got, tc.want) + } + }) + } +}