diff --git a/.changelog/4414.txt b/.changelog/4414.txt new file mode 100644 index 0000000000..ddee351811 --- /dev/null +++ b/.changelog/4414.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/cloudflare_ruleset: unexpected validation error when ttl default is set with variable +``` diff --git a/internal/framework/service/rulesets/validators.go b/internal/framework/service/rulesets/validators.go index f18ced0fd7..acdec50e77 100644 --- a/internal/framework/service/rulesets/validators.go +++ b/internal/framework/service/rulesets/validators.go @@ -62,6 +62,9 @@ func (v EdgeTTLValidator) ValidateObject(ctx context.Context, req validator.Obje if resp.Diagnostics.HasError() { return } + if parameter.Default.IsUnknown() { + return + } if parameter.Mode.ValueString() == "override_origin" { if parameter.Default.ValueInt64() <= 0 { @@ -105,6 +108,9 @@ func (v BrowserTTLValidator) ValidateObject(ctx context.Context, req validator.O if resp.Diagnostics.HasError() { return } + if parameter.Default.IsUnknown() { + return + } if parameter.Mode.ValueString() == "override_origin" { if parameter.Default.ValueInt64() <= 0 { diff --git a/internal/framework/service/rulesets/validators_test.go b/internal/framework/service/rulesets/validators_test.go index 38b2e68204..e7d1f33338 100644 --- a/internal/framework/service/rulesets/validators_test.go +++ b/internal/framework/service/rulesets/validators_test.go @@ -61,6 +61,30 @@ func TestEdgeTTLValidation(t *testing.T) { } }) + t.Run("passes when ttl is unknown", func(t *testing.T) { + t.Parallel() + + mode := "override_origin" + _, statusCodeAttr, listType := constructStatusTTLObject() + resp := &validator.ObjectResponse{} + req := validator.ObjectRequest{ + Path: path.Root("edge_ttl"), + ConfigValue: types.ObjectValueMust( + map[string]attr.Type{"mode": types.StringType, "status_code_ttl": listType, "default": types.Int64Type}, + map[string]attr.Value{"mode": types.StringValue(mode), "status_code_ttl": statusCodeAttr, "default": types.Int64Unknown()}, + ), + } + edgeValidator.ValidateObject(ctx, req, resp) + + expected := &validator.ObjectResponse{ + Diagnostics: nil, + } + + if diff := cmp.Diff(resp, expected); diff != "" { + t.Errorf("unexpected difference: %s", diff) + } + }) + t.Run("passes valid ttl values", func(t *testing.T) { t.Parallel() @@ -162,6 +186,29 @@ func TestBrowserTTLValidation(t *testing.T) { } }) + t.Run("passes when ttl is unknown", func(t *testing.T) { + t.Parallel() + + mode := "override_origin" + resp := &validator.ObjectResponse{} + req := validator.ObjectRequest{ + Path: path.Root("brower_ttl"), + ConfigValue: types.ObjectValueMust( + map[string]attr.Type{"mode": types.StringType, "default": types.Int64Type}, + map[string]attr.Value{"mode": types.StringValue(mode), "default": types.Int64Unknown()}, + ), + } + browserValidator.ValidateObject(ctx, req, resp) + + expected := &validator.ObjectResponse{ + Diagnostics: nil, + } + + if diff := cmp.Diff(resp, expected); diff != "" { + t.Errorf("unexpected difference: %s", diff) + } + }) + t.Run("errors when invalid ttl is passed", func(t *testing.T) { t.Parallel()