Skip to content

Commit

Permalink
Fix additional_cacheable_ports empty case
Browse files Browse the repository at this point in the history
  • Loading branch information
foreseaz committed Oct 17, 2023
1 parent a0e96dc commit 5005765
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
19 changes: 0 additions & 19 deletions internal/framework/flatteners/int64set.go

This file was deleted.

12 changes: 12 additions & 0 deletions internal/framework/flatteners/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
14 changes: 6 additions & 8 deletions internal/framework/service/rulesets/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand All @@ -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))
Expand Down

0 comments on commit 5005765

Please sign in to comment.