From c09051b89b204ad6841187a81160167387feb6b6 Mon Sep 17 00:00:00 2001 From: danischm Date: Thu, 5 Oct 2023 16:49:54 +0200 Subject: [PATCH] Fix issue with nested conditions --- CHANGELOG.md | 4 ++++ docs/guides/changelog.md | 4 ++++ docs/resources/network_access_condition.md | 4 ++-- gen/definitions/network_access_condition.yaml | 2 -- gen/templates/model.go | 12 ++++++------ .../provider/model_ise_network_access_condition.go | 9 +++++---- .../resource_ise_network_access_condition.go | 4 ++-- templates/guides/changelog.md.tmpl | 4 ++++ 8 files changed, 27 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fce04cc..0a17cf2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.1 (unreleased) + +- Fix issue with nested conditions using `ise_network_access_condition` resource + ## 0.1.0 - Initial Release diff --git a/docs/guides/changelog.md b/docs/guides/changelog.md index 9064ba2..125caa4 100644 --- a/docs/guides/changelog.md +++ b/docs/guides/changelog.md @@ -7,6 +7,10 @@ description: |- # Changelog +## 0.1.1 (unreleased) + +- Fix issue with nested conditions using `ise_network_access_condition` resource + ## 0.1.0 - Initial Release diff --git a/docs/resources/network_access_condition.md b/docs/resources/network_access_condition.md index 6c03cbd..e372dd2 100644 --- a/docs/resources/network_access_condition.md +++ b/docs/resources/network_access_condition.md @@ -57,7 +57,6 @@ Required: - `condition_type` (String) Indicates whether the record is the condition itself or a logical aggregation. Logical aggreation indicates that additional conditions are present under the children attribute. - Choices: `ConditionAndBlock`, `ConditionAttributes`, `ConditionOrBlock`, `ConditionReference` -- `name` (String) Condition name Optional: @@ -69,6 +68,7 @@ Optional: - `dictionary_value` (String) Dictionary value - `id` (String) UUID for condition - `is_negate` (Boolean) Indicates whereas this condition is in negate mode +- `name` (String) Condition name - `operator` (String) Equality operator - Choices: `contains`, `endsWith`, `equals`, `greaterOrEquals`, `greaterThan`, `in`, `ipEquals`, `ipGreaterThan`, `ipLessThan`, `ipNotEquals`, `lessOrEquals`, `lessThan`, `matches`, `notContains`, `notEndsWith`, `notEquals`, `notIn`, `notStartsWith`, `startsWith` @@ -79,7 +79,6 @@ Required: - `condition_type` (String) Indicates whether the record is the condition itself or a logical aggregation. Logical aggreation indicates that additional conditions are present under the children attribute. - Choices: `ConditionAndBlock`, `ConditionAttributes`, `ConditionOrBlock`, `ConditionReference` -- `name` (String) Condition name Optional: @@ -90,6 +89,7 @@ Optional: - `dictionary_value` (String) Dictionary value - `id` (String) UUID for condition - `is_negate` (Boolean) Indicates whereas this condition is in negate mode +- `name` (String) Condition name - `operator` (String) Equality operator - Choices: `contains`, `endsWith`, `equals`, `greaterOrEquals`, `greaterThan`, `in`, `ipEquals`, `ipGreaterThan`, `ipLessThan`, `ipNotEquals`, `lessOrEquals`, `lessThan`, `matches`, `notContains`, `notEndsWith`, `notEquals`, `notIn`, `notStartsWith`, `startsWith` diff --git a/gen/definitions/network_access_condition.yaml b/gen/definitions/network_access_condition.yaml index 404d2cb..861017c 100644 --- a/gen/definitions/network_access_condition.yaml +++ b/gen/definitions/network_access_condition.yaml @@ -56,7 +56,6 @@ attributes: attributes: - model_name: name type: String - id: true description: Condition name example: Cond1 - model_name: description @@ -107,7 +106,6 @@ attributes: attributes: - model_name: name type: String - id: true description: Condition name example: Cond1 - model_name: description diff --git a/gen/templates/model.go b/gen/templates/model.go index ee71c88..e83d4dd 100644 --- a/gen/templates/model.go +++ b/gen/templates/model.go @@ -385,8 +385,8 @@ func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.R {{- else if or (eq .Type "List") (eq .Type "Set")}} {{- $list := (toGoName .TfName)}} for i := range data.{{toGoName .TfName}} { - keys := [...]string{ {{range .Attributes}}{{if .Id}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{end}}{{end}} } - keyValues := [...]string{ {{range .Attributes}}{{if .Id}}{{if eq .Type "Int64"}}strconv.FormatInt(data.{{$list}}[i].{{toGoName .TfName}}.ValueInt64(), 10), {{else if eq .Type "Bool"}}strconv.FormatBool(data.{{$list}}[i].{{toGoName .TfName}}.ValueBool()), {{else}}data.{{$list}}[i].{{toGoName .TfName}}.Value{{.Type}}(), {{end}}{{end}}{{end}} } + keys := [...]string{ {{$noId := not (hasId .Attributes)}}{{range .Attributes}}{{if or .Id $noId}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{end}}{{end}} } + keyValues := [...]string{ {{$noId := not (hasId .Attributes)}}{{range .Attributes}}{{if or .Id $noId}}{{if eq .Type "Int64"}}strconv.FormatInt(data.{{$list}}[i].{{toGoName .TfName}}.ValueInt64(), 10), {{else if eq .Type "Bool"}}strconv.FormatBool(data.{{$list}}[i].{{toGoName .TfName}}.ValueBool()), {{else if eq .Type "String"}}data.{{$list}}[i].{{toGoName .TfName}}.Value{{.Type}}(), {{end}}{{end}}{{end}} } var r gjson.Result res.{{if .ModelName}}Get("{{if $openApi}}response.{{end}}{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}").{{end}}ForEach( @@ -425,8 +425,8 @@ func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.R {{- else if or (eq .Type "List") (eq .Type "Set")}} {{- $clist := (toGoName .TfName)}} for ci := range data.{{$list}}[i].{{toGoName .TfName}} { - keys := [...]string{ {{range .Attributes}}{{if .Id}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{end}}{{end}} } - keyValues := [...]string{ {{range .Attributes}}{{if .Id}}{{if eq .Type "Int64"}}strconv.FormatInt(data.{{$list}}[i].{{toGoName .TfName}}.ValueInt64(), 10), {{else if eq .Type "Bool"}}strconv.FormatBool(data.{{$list}}[i].{{toGoName .TfName}}.ValueBool()), {{else}}data.{{$list}}[i].{{toGoName .TfName}}.Value{{.Type}}(), {{end}}{{end}}{{end}} } + keys := [...]string{ {{$noId := not (hasId .Attributes)}}{{range .Attributes}}{{if or .Id $noId}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{end}}{{end}} } + keyValues := [...]string{ {{$noId := not (hasId .Attributes)}}{{range .Attributes}}{{if or .Id $noId}}{{if eq .Type "Int64"}}strconv.FormatInt(data.{{$list}}[i].{{toGoName .TfName}}.ValueInt64(), 10), {{else if eq .Type "Bool"}}strconv.FormatBool(data.{{$list}}[i].{{toGoName .TfName}}.ValueBool()), {{else if eq .Type "String"}}data.{{$list}}[i].{{toGoName .TfName}}.Value{{.Type}}(), {{end}}{{end}}{{end}} } var cr gjson.Result r.Get("{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}").ForEach( @@ -465,8 +465,8 @@ func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.R {{- else if or (eq .Type "List") (eq .Type "Set")}} {{- $cclist := (toGoName .TfName)}} for cci := range data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}} { - keys := [...]string{ {{range .Attributes}}{{if .Id}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{end}}{{end}} } - keyValues := [...]string{ {{range .Attributes}}{{if .Id}}{{if eq .Type "Int64"}}strconv.FormatInt(data.{{$list}}[i].{{toGoName .TfName}}.ValueInt64(), 10), {{else if eq .Type "Bool"}}strconv.FormatBool(data.{{$list}}[i].{{toGoName .TfName}}.ValueBool()), {{else}}data.{{$list}}[i].{{toGoName .TfName}}.Value{{.Type}}(), {{end}}{{end}}{{end}} } + keys := [...]string{ {{$noId := not (hasId .Attributes)}}{{range .Attributes}}{{if or .Id $noId}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{end}}{{end}} } + keyValues := [...]string{ {{$noId := not (hasId .Attributes)}}{{range .Attributes}}{{if or .Id $noId}}{{if eq .Type "Int64"}}strconv.FormatInt(data.{{$list}}[i].{{toGoName .TfName}}.ValueInt64(), 10), {{else if eq .Type "Bool"}}strconv.FormatBool(data.{{$list}}[i].{{toGoName .TfName}}.ValueBool()), {{else if eq .Type "String"}}data.{{$list}}[i].{{toGoName .TfName}}.Value{{.Type}}(), {{end}}{{end}}{{end}} } var ccr gjson.Result cr.Get("{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}").ForEach( diff --git a/internal/provider/model_ise_network_access_condition.go b/internal/provider/model_ise_network_access_condition.go index bb03519..6183451 100644 --- a/internal/provider/model_ise_network_access_condition.go +++ b/internal/provider/model_ise_network_access_condition.go @@ -22,6 +22,7 @@ package provider //template:begin imports import ( "context" + "strconv" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/tidwall/gjson" @@ -405,8 +406,8 @@ func (data *NetworkAccessCondition) updateFromBody(ctx context.Context, res gjso data.Operator = types.StringNull() } for i := range data.Children { - keys := [...]string{"name"} - keyValues := [...]string{data.Children[i].Name.ValueString()} + keys := [...]string{"name", "description", "conditionType", "id", "isNegate", "attributeName", "attributeValue", "dictionaryName", "dictionaryValue", "operator", "children"} + keyValues := [...]string{data.Children[i].Name.ValueString(), data.Children[i].Description.ValueString(), data.Children[i].ConditionType.ValueString(), data.Children[i].Id.ValueString(), strconv.FormatBool(data.Children[i].IsNegate.ValueBool()), data.Children[i].AttributeName.ValueString(), data.Children[i].AttributeValue.ValueString(), data.Children[i].DictionaryName.ValueString(), data.Children[i].DictionaryValue.ValueString(), data.Children[i].Operator.ValueString()} var r gjson.Result res.Get("response.children").ForEach( @@ -478,8 +479,8 @@ func (data *NetworkAccessCondition) updateFromBody(ctx context.Context, res gjso data.Children[i].Operator = types.StringNull() } for ci := range data.Children[i].Children { - keys := [...]string{"name"} - keyValues := [...]string{data.Children[i].Name.ValueString()} + keys := [...]string{"name", "description", "conditionType", "id", "isNegate", "attributeName", "attributeValue", "dictionaryName", "dictionaryValue", "operator"} + keyValues := [...]string{data.Children[i].Name.ValueString(), data.Children[i].Description.ValueString(), data.Children[i].ConditionType.ValueString(), data.Children[i].Id.ValueString(), strconv.FormatBool(data.Children[i].IsNegate.ValueBool()), data.Children[i].AttributeName.ValueString(), data.Children[i].AttributeValue.ValueString(), data.Children[i].DictionaryName.ValueString(), data.Children[i].DictionaryValue.ValueString(), data.Children[i].Operator.ValueString()} var cr gjson.Result r.Get("children").ForEach( diff --git a/internal/provider/resource_ise_network_access_condition.go b/internal/provider/resource_ise_network_access_condition.go index 4ff761a..ff556bc 100644 --- a/internal/provider/resource_ise_network_access_condition.go +++ b/internal/provider/resource_ise_network_access_condition.go @@ -120,7 +120,7 @@ func (r *NetworkAccessConditionResource) Schema(ctx context.Context, req resourc Attributes: map[string]schema.Attribute{ "name": schema.StringAttribute{ MarkdownDescription: helpers.NewAttributeDescription("Condition name").String, - Required: true, + Optional: true, }, "description": schema.StringAttribute{ MarkdownDescription: helpers.NewAttributeDescription("Condition description").String, @@ -171,7 +171,7 @@ func (r *NetworkAccessConditionResource) Schema(ctx context.Context, req resourc Attributes: map[string]schema.Attribute{ "name": schema.StringAttribute{ MarkdownDescription: helpers.NewAttributeDescription("Condition name").String, - Required: true, + Optional: true, }, "description": schema.StringAttribute{ MarkdownDescription: helpers.NewAttributeDescription("Condition description").String, diff --git a/templates/guides/changelog.md.tmpl b/templates/guides/changelog.md.tmpl index 9064ba2..125caa4 100644 --- a/templates/guides/changelog.md.tmpl +++ b/templates/guides/changelog.md.tmpl @@ -7,6 +7,10 @@ description: |- # Changelog +## 0.1.1 (unreleased) + +- Fix issue with nested conditions using `ise_network_access_condition` resource + ## 0.1.0 - Initial Release