From 50057658c87801ebc74003b34f168f9e40107d2d Mon Sep 17 00:00:00 2001 From: Chenxi Zhang Date: Mon, 16 Oct 2023 17:21:48 -0700 Subject: [PATCH] Fix additional_cacheable_ports empty case --- internal/framework/flatteners/int64set.go | 19 ------------------- internal/framework/flatteners/set.go | 12 ++++++++++++ .../framework/service/rulesets/resource.go | 14 ++++++-------- 3 files changed, 18 insertions(+), 27 deletions(-) delete mode 100644 internal/framework/flatteners/int64set.go diff --git a/internal/framework/flatteners/int64set.go b/internal/framework/flatteners/int64set.go deleted file mode 100644 index 5baaf12218d..00000000000 --- a/internal/framework/flatteners/int64set.go +++ /dev/null @@ -1,19 +0,0 @@ -package flatteners - -import ( - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" -) - -// Int64Set accepts a `[]attr.Value` and returns a `basetypes.SetValue`. The -// return type automatically handles `SetNull` for empty results and coercing -// all element values to a string if there are any elements. -// -// nolint: contextcheck -func Int64Set(in []attr.Value) basetypes.SetValue { - if len(in) == 0 { - return types.SetNull(types.Int64Type) - } - return types.SetValueMust(types.Int64Type, in) -} diff --git a/internal/framework/flatteners/set.go b/internal/framework/flatteners/set.go index e5d4381a30d..a19b484c21d 100644 --- a/internal/framework/flatteners/set.go +++ b/internal/framework/flatteners/set.go @@ -17,3 +17,15 @@ func StringSet(in []attr.Value) basetypes.SetValue { } return types.SetValueMust(types.StringType, in) } + +// Int64Set accepts a `[]attr.Value` and returns a `basetypes.SetValue`. The +// return type automatically handles `SetNull` for empty results and coercing +// all element values to a string if there are any elements. +// +// nolint: contextcheck +func Int64Set(in []attr.Value) basetypes.SetValue { + if len(in) == 0 { + return types.SetNull(types.Int64Type) + } + return types.SetValueMust(types.Int64Type, in) +} diff --git a/internal/framework/service/rulesets/resource.go b/internal/framework/service/rulesets/resource.go index f7c1b6f92a6..32b2535eb41 100644 --- a/internal/framework/service/rulesets/resource.go +++ b/internal/framework/service/rulesets/resource.go @@ -359,14 +359,6 @@ func toRulesetResourceModel(ctx context.Context, zoneID, accountID basetypes.Str Version: flatteners.String(cloudflare.String(ruleResponse.ActionParameters.Version)), }) - if !reflect.ValueOf(ruleResponse.ActionParameters.AdditionalCacheablePorts).IsNil() { - var ports []attr.Value - for _, s := range ruleResponse.ActionParameters.AdditionalCacheablePorts { - ports = append(ports, types.Int64Value((int64(s)))) - } - rule.ActionParameters[0].AdditionalCacheablePorts = flatteners.Int64Set(ports) - } - if !reflect.ValueOf(ruleResponse.ActionParameters.Polish).IsNil() { rule.ActionParameters[0].Polish = flatteners.String(ruleResponse.ActionParameters.Polish.String()) } @@ -379,6 +371,12 @@ func toRulesetResourceModel(ctx context.Context, zoneID, accountID basetypes.Str rule.ActionParameters[0].SSL = flatteners.String(ruleResponse.ActionParameters.SSL.String()) } + var ports []attr.Value + for _, s := range ruleResponse.ActionParameters.AdditionalCacheablePorts { + ports = append(ports, types.Int64Value((int64(s)))) + } + rule.ActionParameters[0].AdditionalCacheablePorts = flatteners.Int64Set(ports) + var phases []attr.Value for _, s := range ruleResponse.ActionParameters.Phases { phases = append(phases, types.StringValue(s))