From 0c2e085acd3e6ebcfc248a56eebcf32dc6a64f51 Mon Sep 17 00:00:00 2001 From: Sean Conroy Date: Fri, 29 Aug 2025 16:36:52 +0100 Subject: [PATCH 1/4] Resolve list version issue --- gen/templates/generic/model.go | 1250 +++++++++-------- .../model_sdwan_centralized_policy.go | 46 +- .../model_sdwan_configuration_group.go | 19 + ...l_sdwan_mesh_topology_policy_definition.go | 16 +- internal/provider/model_sdwan_policy_group.go | 19 + .../model_sdwan_route_policy_definition.go | 16 +- ..._sdwan_vpn_membership_policy_definition.go | 16 +- .../resource_sdwan_configuration_group.go | 13 + .../provider/resource_sdwan_policy_group.go | 13 + 9 files changed, 803 insertions(+), 605 deletions(-) diff --git a/gen/templates/generic/model.go b/gen/templates/generic/model.go index 54b1a83c1..b51c30498 100644 --- a/gen/templates/generic/model.go +++ b/gen/templates/generic/model.go @@ -21,25 +21,25 @@ package provider // Section below is generated&owned by "gen/generator.go". //template:begin imports import ( - "context" - "fmt" - "net/url" - "strconv" + "context" + "fmt" + "net/url" + "strconv" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-log/tflog" - "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" - "github.com/tidwall/gjson" - "github.com/tidwall/sjson" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/tidwall/gjson" + "github.com/tidwall/sjson" ) // End of section. //template:end imports // Section below is generated&owned by "gen/generator.go". //template:begin types {{- $name := camelCase .Name}} type {{camelCase .Name}} struct { - Id types.String `tfsdk:"id"` + Id types.String `tfsdk:"id"` {{- if .HasVersion}} - Version types.Int64 `tfsdk:"version"` + Version types.Int64 `tfsdk:"version"` {{- end}} {{- if .TypeValue}} Type types.String `tfsdk:"type"` @@ -47,13 +47,13 @@ Type types.String `tfsdk:"type"` {{- range .Attributes}} {{- if not .Value}} {{- if isNestedListSet .}} - {{toGoName .TfName}} []{{$name}}{{toGoName .TfName}} `tfsdk:"{{.TfName}}"` + {{toGoName .TfName}} []{{$name}}{{toGoName .TfName}} `tfsdk:"{{.TfName}}"` {{- else if eq .Type "Versions"}} - {{toGoName .TfName}} types.List `tfsdk:"{{.TfName}}"` + {{toGoName .TfName}} types.List `tfsdk:"{{.TfName}}"` {{- else if eq .Type "Version"}} - {{toGoName .TfName}} types.Int64 `tfsdk:"{{.TfName}}"` + {{toGoName .TfName}} types.Int64 `tfsdk:"{{.TfName}}"` {{- else}} - {{toGoName .TfName}} types.{{.Type}} `tfsdk:"{{.TfName}}"` + {{toGoName .TfName}} types.{{.Type}} `tfsdk:"{{.TfName}}"` {{- end}} {{- end}} {{- end}} @@ -68,13 +68,13 @@ type {{$name}}{{toGoName .TfName}} struct { {{- range .Attributes}} {{- if not .Value}} {{- if isNestedListSet .}} - {{toGoName .TfName}} []{{$name}}{{$childName}}{{toGoName .TfName}} `tfsdk:"{{.TfName}}"` + {{toGoName .TfName}} []{{$name}}{{$childName}}{{toGoName .TfName}} `tfsdk:"{{.TfName}}"` {{- else if eq .Type "Versions"}} - {{toGoName .TfName}} types.List `tfsdk:"{{.TfName}}"` + {{toGoName .TfName}} types.List `tfsdk:"{{.TfName}}"` {{- else if eq .Type "Version"}} - {{toGoName .TfName}} types.Int64 `tfsdk:"{{.TfName}}"` + {{toGoName .TfName}} types.Int64 `tfsdk:"{{.TfName}}"` {{- else}} - {{toGoName .TfName}} types.{{.Type}} `tfsdk:"{{.TfName}}"` + {{toGoName .TfName}} types.{{.Type}} `tfsdk:"{{.TfName}}"` {{- end}} {{- end}} {{- end}} @@ -95,13 +95,13 @@ type {{$name}}{{$childName}}{{toGoName .TfName}} struct { {{- range .Attributes}} {{- if not .Value}} {{- if isNestedListSet .}} - {{toGoName .TfName}} []{{$name}}{{$childName}}{{$childChildName}}{{toGoName .TfName}} `tfsdk:"{{.TfName}}"` + {{toGoName .TfName}} []{{$name}}{{$childName}}{{$childChildName}}{{toGoName .TfName}} `tfsdk:"{{.TfName}}"` {{- else if eq .Type "Versions"}} - {{toGoName .TfName}} types.List `tfsdk:"{{.TfName}}"` + {{toGoName .TfName}} types.List `tfsdk:"{{.TfName}}"` {{- else if eq .Type "Version"}} - {{toGoName .TfName}} types.Int64 `tfsdk:"{{.TfName}}"` + {{toGoName .TfName}} types.Int64 `tfsdk:"{{.TfName}}"` {{- else}} - {{toGoName .TfName}} types.{{.Type}} `tfsdk:"{{.TfName}}"` + {{toGoName .TfName}} types.{{.Type}} `tfsdk:"{{.TfName}}"` {{- end}} {{- end}} {{- end}} @@ -128,11 +128,11 @@ type {{$name}}{{$childName}}{{$childChildName}}{{toGoName .TfName}} struct { {{- range .Attributes}} {{- if not .Value}} {{- if eq .Type "Versions"}} - {{toGoName .TfName}} types.List `tfsdk:"{{.TfName}}"` + {{toGoName .TfName}} types.List `tfsdk:"{{.TfName}}"` {{- else if eq .Type "Version"}} - {{toGoName .TfName}} types.Int64 `tfsdk:"{{.TfName}}"` + {{toGoName .TfName}} types.Int64 `tfsdk:"{{.TfName}}"` {{- else}} - {{toGoName .TfName}} types.{{.Type}} `tfsdk:"{{.TfName}}"` + {{toGoName .TfName}} types.{{.Type}} `tfsdk:"{{.TfName}}"` {{- end}} {{- end}} {{- end}} @@ -150,609 +150,661 @@ type {{$name}}{{$childName}}{{$childChildName}}{{toGoName .TfName}} struct { // Section below is generated&owned by "gen/generator.go". //template:begin getPath func (data {{camelCase .Name}}) getPath() string { - {{- if hasReference .Attributes}} - return fmt.Sprintf("{{.RestEndpoint}}"{{range .Attributes}}{{if .Reference}}, url.QueryEscape(data.{{toGoName .TfName}}.Value{{.Type}}()){{end}}{{end}}) - {{- else}} - return "{{.RestEndpoint}}" - {{- end}} + {{- if hasReference .Attributes}} + return fmt.Sprintf("{{.RestEndpoint}}"{{range .Attributes}}{{if .Reference}}, url.QueryEscape(data.{{toGoName .TfName}}.Value{{.Type}}()){{end}}{{end}}) + {{- else}} + return "{{.RestEndpoint}}" + {{- end}} } // End of section. //template:end getPath // Section below is generated&owned by "gen/generator.go". //template:begin toBody func (data {{camelCase .Name}}) toBody(ctx context.Context) string { - body := "" - {{- range .Attributes}} - {{- if .Value}} - if true{{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(data.{{toGoName .ConditionalListLength}}) > 0{{end}} { - body, _ = sjson.Set(body, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if eq .Type "String"}}"{{end}}{{.Value}}{{if eq .Type "String"}}"{{end}}) - } - {{- else if and (not .TfOnly) (not .Reference)}} - {{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64")}} - if {{if not .AlwaysInclude}}!data.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(data.{{toGoName .ConditionalListLength}}) > 0{{end}} { - body, _ = sjson.Set(body, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if .ModelTypeString}}fmt.Sprint({{end}}data.{{toGoName .TfName}}.Value{{.Type}}(){{if .ModelTypeString}}){{end}}) - } - {{- else if eq .Type "Bool"}} - if {{if not .AlwaysInclude}}!data.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(data.{{toGoName .ConditionalListLength}}) > 0{{end}} { - if {{.BoolEmptyString}} && data.{{toGoName .TfName}}.Value{{.Type}}() { - body, _ = sjson.Set(body, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", "") - }{{if not .BoolEmptyString}} else { - body, _ = sjson.Set(body, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if .ModelTypeString}}fmt.Sprint({{end}}data.{{toGoName .TfName}}.Value{{.Type}}(){{if .ModelTypeString}}){{end}}) - } - {{- end}} - } - {{- else if isListSet .}} - if {{if not .AlwaysInclude}}!data.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(data.{{toGoName .ConditionalListLength}}) > 0{{end}} { - var values []{{if isStringListSet .}}string{{else if isInt64ListSet .}}int64{{end}} - data.{{toGoName .TfName}}.ElementsAs(ctx, &values, false) - body, _ = sjson.Set(body, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", values) - } - {{- else if isNestedListSet .}} - if true{{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(data.{{toGoName .ConditionalListLength}}) > 0{{end}} { - body, _ = sjson.Set(body, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", []interface{}{}) - for _, item := range data.{{toGoName .TfName}} { - itemBody := "" - {{- range .Attributes}} - {{- if .Value}} - if true{{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(item.{{toGoName .ConditionalListLength}}) > 0{{end}} { - itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if eq .Type "String"}}"{{end}}{{.Value}}{{if eq .Type "String"}}"{{end}}) - } - {{- else if and (not .TfOnly) (not .Reference)}} - {{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64")}} - if {{if not .AlwaysInclude}}!item.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(item.{{toGoName .ConditionalListLength}}) > 0{{end}} { - itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if .ModelTypeString}}fmt.Sprint({{end}}item.{{toGoName .TfName}}.Value{{.Type}}(){{if .ModelTypeString}}){{end}}) - } - {{- else if eq .Type "Bool"}} - if {{if not .AlwaysInclude}}!item.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(item.{{toGoName .ConditionalListLength}}) > 0{{end}} { - if {{.BoolEmptyString}} && item.{{toGoName .TfName}}.Value{{.Type}}() { - itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", "") - }{{if not .BoolEmptyString}} else { - itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if .ModelTypeString}}fmt.Sprint({{end}}item.{{toGoName .TfName}}.Value{{.Type}}(){{if .ModelTypeString}}){{end}}) - } - {{- end}} - } - {{- else if isListSet .}} - if {{if not .AlwaysInclude}}!item.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(item.{{toGoName .ConditionalListLength}}) > 0{{end}} { - var values []{{if isStringListSet .}}string{{else if isInt64ListSet .}}int64{{end}} - item.{{toGoName .TfName}}.ElementsAs(ctx, &values, false) - itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", values) - } - {{- else if isNestedListSet .}} - if true{{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(item.{{toGoName .ConditionalListLength}}) > 0{{end}} { - itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", []interface{}{}) - for _, childItem := range item.{{toGoName .TfName}} { - itemChildBody := "" - {{- range .Attributes}} - {{- if .Value}} - if true{{if ne .ConditionalAttribute.Name ""}} && childItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(childItem.{{toGoName .ConditionalListLength}}) > 0{{end}} { - itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if eq .Type "String"}}"{{end}}{{.Value}}{{if eq .Type "String"}}"{{end}}) - } - {{- else if and (not .TfOnly) (not .Reference)}} - {{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64")}} - if {{if not .AlwaysInclude}}!childItem.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && childItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(childItem.{{toGoName .ConditionalListLength}}) > 0{{end}} { - itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if .ModelTypeString}}fmt.Sprint({{end}}childItem.{{toGoName .TfName}}.Value{{.Type}}(){{if .ModelTypeString}}){{end}}) - } - {{- else if eq .Type "Bool"}} - if {{if not .AlwaysInclude}}!childItem.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && childItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(childItem.{{toGoName .ConditionalListLength}}) > 0{{end}} { - if {{.BoolEmptyString}} && childItem.{{toGoName .TfName}}.Value{{.Type}}() { - itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", "") - }{{if not .BoolEmptyString}} else { - itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if .ModelTypeString}}fmt.Sprint({{end}}childItem.{{toGoName .TfName}}.Value{{.Type}}(){{if .ModelTypeString}}){{end}}) - } - {{- end}} - } - {{- else if isListSet .}} - if {{if not .AlwaysInclude}}!childItem.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && childItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(childItem.{{toGoName .ConditionalListLength}}) > 0{{end}} { - var values []{{if isStringListSet .}}string{{else if isInt64ListSet .}}int64{{end}} - childItem.{{toGoName .TfName}}.ElementsAs(ctx, &values, false) - itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", values) - } - {{- else if isNestedListSet .}} - if true{{if ne .ConditionalAttribute.Name ""}} && childItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(childItem.{{toGoName .ConditionalListLength}}) > 0{{end}} { - itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", []interface{}{}) - for _, childChildItem := range childItem.{{toGoName .TfName}} { - itemChildChildBody := "" - {{- range .Attributes}} - {{- if .Value}} - if true{{if ne .ConditionalAttribute.Name ""}} && childChildItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(childChildItem.{{toGoName .ConditionalListLength}}) > 0{{end}} { - itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if eq .Type "String"}}"{{end}}{{.Value}}{{if eq .Type "String"}}"{{end}}) - } - {{- else if and (not .TfOnly) (not .Reference)}} - {{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64")}} - if {{if not .AlwaysInclude}}!childChildItem.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && childChildItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(childChildItem.{{toGoName .ConditionalListLength}}) > 0{{end}} { - itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if .ModelTypeString}}fmt.Sprint({{end}}childChildItem.{{toGoName .TfName}}.Value{{.Type}}(){{if .ModelTypeString}}){{end}}) - } - {{- else if eq .Type "Bool"}} - if {{if not .AlwaysInclude}}!childChildItem.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && childChildItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(childChildItem.{{toGoName .ConditionalListLength}}) > 0{{end}} { - if {{.BoolEmptyString}} && childChildItem.{{toGoName .TfName}}.Value{{.Type}}() { - itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", "") - }{{if not .BoolEmptyString}} else { - itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if .ModelTypeString}}fmt.Sprint({{end}}childChildItem.{{toGoName .TfName}}.Value{{.Type}}(){{if .ModelTypeString}}){{end}}) - } - {{- end}} - } - {{- else if isListSet .}} - if {{if not .AlwaysInclude}}!childChildItem.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && childChildItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(childChildItem.{{toGoName .ConditionalListLength}}) > 0{{end}} { - var values []{{if isStringListSet .}}string{{else if isInt64ListSet .}}int64{{end}} - childChildItem.{{toGoName .TfName}}.ElementsAs(ctx, &values, false) - itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", values) - } - {{- end}} - {{- end}} - {{- end}} - itemChildBody, _ = sjson.SetRaw(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.-1", itemChildChildBody) - } - } - {{- end}} - {{- end}} - {{- end}} - itemBody, _ = sjson.SetRaw(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.-1", itemChildBody) - } - } - {{- end}} - {{- end}} - {{- end}} - body, _ = sjson.SetRaw(body, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.-1", itemBody) - } - } - {{- end}} - {{- end}} - {{- end}} - return body + body := "" + {{- range .Attributes}} + {{- if .Value}} + if true{{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(data.{{toGoName .ConditionalListLength}}) > 0{{end}} { + body, _ = sjson.Set(body, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if eq .Type "String"}}"{{end}}{{.Value}}{{if eq .Type "String"}}"{{end}}) + } + {{- else if and (not .TfOnly) (not .Reference)}} + {{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64")}} + if {{if not .AlwaysInclude}}!data.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(data.{{toGoName .ConditionalListLength}}) > 0{{end}} { + body, _ = sjson.Set(body, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if .ModelTypeString}}fmt.Sprint({{end}}data.{{toGoName .TfName}}.Value{{.Type}}(){{if .ModelTypeString}}){{end}}) + } + {{- else if eq .Type "Bool"}} + if {{if not .AlwaysInclude}}!data.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(data.{{toGoName .ConditionalListLength}}) > 0{{end}} { + if {{.BoolEmptyString}} && data.{{toGoName .TfName}}.Value{{.Type}}() { + body, _ = sjson.Set(body, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", "") + }{{if not .BoolEmptyString}} else { + body, _ = sjson.Set(body, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if .ModelTypeString}}fmt.Sprint({{end}}data.{{toGoName .TfName}}.Value{{.Type}}(){{if .ModelTypeString}}){{end}}) + } + {{- end}} + } + {{- else if isListSet .}} + if {{if not .AlwaysInclude}}!data.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(data.{{toGoName .ConditionalListLength}}) > 0{{end}} { + var values []{{if isStringListSet .}}string{{else if isInt64ListSet .}}int64{{end}} + data.{{toGoName .TfName}}.ElementsAs(ctx, &values, false) + body, _ = sjson.Set(body, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", values) + } + {{- else if isNestedListSet .}} + if true{{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(data.{{toGoName .ConditionalListLength}}) > 0{{end}} { + body, _ = sjson.Set(body, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", []interface{}{}) + for _, item := range data.{{toGoName .TfName}} { + itemBody := "" + {{- range .Attributes}} + {{- if .Value}} + if true{{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(item.{{toGoName .ConditionalListLength}}) > 0{{end}} { + itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if eq .Type "String"}}"{{end}}{{.Value}}{{if eq .Type "String"}}"{{end}}) + } + {{- else if and (not .TfOnly) (not .Reference)}} + {{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64")}} + if {{if not .AlwaysInclude}}!item.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(item.{{toGoName .ConditionalListLength}}) > 0{{end}} { + itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if .ModelTypeString}}fmt.Sprint({{end}}item.{{toGoName .TfName}}.Value{{.Type}}(){{if .ModelTypeString}}){{end}}) + } + {{- else if eq .Type "Bool"}} + if {{if not .AlwaysInclude}}!item.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(item.{{toGoName .ConditionalListLength}}) > 0{{end}} { + if {{.BoolEmptyString}} && item.{{toGoName .TfName}}.Value{{.Type}}() { + itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", "") + }{{if not .BoolEmptyString}} else { + itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if .ModelTypeString}}fmt.Sprint({{end}}item.{{toGoName .TfName}}.Value{{.Type}}(){{if .ModelTypeString}}){{end}}) + } + {{- end}} + } + {{- else if isListSet .}} + if {{if not .AlwaysInclude}}!item.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(item.{{toGoName .ConditionalListLength}}) > 0{{end}} { + var values []{{if isStringListSet .}}string{{else if isInt64ListSet .}}int64{{end}} + item.{{toGoName .TfName}}.ElementsAs(ctx, &values, false) + itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", values) + } + {{- else if isNestedListSet .}} + if true{{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(item.{{toGoName .ConditionalListLength}}) > 0{{end}} { + itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", []interface{}{}) + for _, childItem := range item.{{toGoName .TfName}} { + itemChildBody := "" + {{- range .Attributes}} + {{- if .Value}} + if true{{if ne .ConditionalAttribute.Name ""}} && childItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(childItem.{{toGoName .ConditionalListLength}}) > 0{{end}} { + itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if eq .Type "String"}}"{{end}}{{.Value}}{{if eq .Type "String"}}"{{end}}) + } + {{- else if and (not .TfOnly) (not .Reference)}} + {{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64")}} + if {{if not .AlwaysInclude}}!childItem.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && childItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(childItem.{{toGoName .ConditionalListLength}}) > 0{{end}} { + itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if .ModelTypeString}}fmt.Sprint({{end}}childItem.{{toGoName .TfName}}.Value{{.Type}}(){{if .ModelTypeString}}){{end}}) + } + {{- else if eq .Type "Bool"}} + if {{if not .AlwaysInclude}}!childItem.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && childItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(childItem.{{toGoName .ConditionalListLength}}) > 0{{end}} { + if {{.BoolEmptyString}} && childItem.{{toGoName .TfName}}.Value{{.Type}}() { + itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", "") + }{{if not .BoolEmptyString}} else { + itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if .ModelTypeString}}fmt.Sprint({{end}}childItem.{{toGoName .TfName}}.Value{{.Type}}(){{if .ModelTypeString}}){{end}}) + } + {{- end}} + } + {{- else if isListSet .}} + if {{if not .AlwaysInclude}}!childItem.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && childItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(childItem.{{toGoName .ConditionalListLength}}) > 0{{end}} { + var values []{{if isStringListSet .}}string{{else if isInt64ListSet .}}int64{{end}} + childItem.{{toGoName .TfName}}.ElementsAs(ctx, &values, false) + itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", values) + } + {{- else if isNestedListSet .}} + if true{{if ne .ConditionalAttribute.Name ""}} && childItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(childItem.{{toGoName .ConditionalListLength}}) > 0{{end}} { + itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", []interface{}{}) + for _, childChildItem := range childItem.{{toGoName .TfName}} { + itemChildChildBody := "" + {{- range .Attributes}} + {{- if .Value}} + if true{{if ne .ConditionalAttribute.Name ""}} && childChildItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(childChildItem.{{toGoName .ConditionalListLength}}) > 0{{end}} { + itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if eq .Type "String"}}"{{end}}{{.Value}}{{if eq .Type "String"}}"{{end}}) + } + {{- else if and (not .TfOnly) (not .Reference)}} + {{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64")}} + if {{if not .AlwaysInclude}}!childChildItem.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && childChildItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(childChildItem.{{toGoName .ConditionalListLength}}) > 0{{end}} { + itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if .ModelTypeString}}fmt.Sprint({{end}}childChildItem.{{toGoName .TfName}}.Value{{.Type}}(){{if .ModelTypeString}}){{end}}) + } + {{- else if eq .Type "Bool"}} + if {{if not .AlwaysInclude}}!childChildItem.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && childChildItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(childChildItem.{{toGoName .ConditionalListLength}}) > 0{{end}} { + if {{.BoolEmptyString}} && childChildItem.{{toGoName .TfName}}.Value{{.Type}}() { + itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", "") + }{{if not .BoolEmptyString}} else { + itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{if .ModelTypeString}}fmt.Sprint({{end}}childChildItem.{{toGoName .TfName}}.Value{{.Type}}(){{if .ModelTypeString}}){{end}}) + } + {{- end}} + } + {{- else if isListSet .}} + if {{if not .AlwaysInclude}}!childChildItem.{{toGoName .TfName}}.IsNull(){{else}}true{{end}}{{if ne .ConditionalAttribute.Name ""}} && childChildItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{else if ne .ConditionalListLength ""}} && len(childChildItem.{{toGoName .ConditionalListLength}}) > 0{{end}} { + var values []{{if isStringListSet .}}string{{else if isInt64ListSet .}}int64{{end}} + childChildItem.{{toGoName .TfName}}.ElementsAs(ctx, &values, false) + itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", values) + } + {{- end}} + {{- end}} + {{- end}} + itemChildBody, _ = sjson.SetRaw(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.-1", itemChildChildBody) + } + } + {{- end}} + {{- end}} + {{- end}} + itemBody, _ = sjson.SetRaw(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.-1", itemChildBody) + } + } + {{- end}} + {{- end}} + {{- end}} + body, _ = sjson.SetRaw(body, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.-1", itemBody) + } + } + {{- end}} + {{- end}} + {{- end}} + return body } // End of section. //template:end toBody // Section below is generated&owned by "gen/generator.go". //template:begin fromBody func (data *{{camelCase .Name}}) fromBody(ctx context.Context, res gjson.Result) { - {{- if hasVersionAttribute .Attributes}} - state := *data - {{- end}} - {{- range .Attributes}} - {{- if and (not .TfOnly) (not .Value) (not .Reference)}} - {{- $cname := toGoName .TfName}} - {{- if eq .Type "String"}} - if value := res.Get("{{getResponseModelPath .}}"); value.Exists(){{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && value.String() != ""{{end}} { - data.{{toGoName .TfName}} = types.StringValue(value.String()) - } else { - data.{{toGoName .TfName}} = types.StringNull() - } - {{- else if eq .Type "Int64"}} - if value := res.Get("{{getResponseModelPath .}}"); value.Exists(){{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && value.String() != ""{{end}} { - data.{{toGoName .TfName}} = types.Int64Value(value.Int()) - } else { - data.{{toGoName .TfName}} = types.Int64Null() - } - {{- else if eq .Type "Float64"}} - if value := res.Get("{{getResponseModelPath .}}"); value.Exists(){{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && value.String() != ""{{end}} { - data.{{toGoName .TfName}} = types.Float64Value(value.Float()) - } else { - data.{{toGoName .TfName}} = types.Float64Null() - } - {{- else if eq .Type "Bool"}} - if value := res.Get("{{getResponseModelPath .}}"); value.Exists(){{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && value.String() != ""{{end}} { - if {{.BoolEmptyString}} && value.String() == "" { - data.{{toGoName .TfName}} = types.BoolValue(true) - }{{if not .BoolEmptyString}} else { - data.{{toGoName .TfName}} = types.BoolValue(value.Bool()) - } - {{- end}} - } else { - data.{{toGoName .TfName}} = types.BoolNull() - } - {{- else if isListSet .}} - if value := res.Get("{{getResponseModelPath .}}"); value.Exists(){{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && value.String() != ""{{end}} { - data.{{toGoName .TfName}} = helpers.Get{{.ElementType}}{{.Type}}(value.Array()) - } else { - data.{{toGoName .TfName}} = types.{{.Type}}Null(types.{{.ElementType}}Type) - } - {{- else if isNestedListSet .}} - if value := res.Get("{{getResponseModelPath .}}"); value.Exists() && len(value.Array()) > 0{{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}} { - data.{{toGoName .TfName}} = make([]{{$name}}{{toGoName .TfName}}, 0) - value.ForEach(func(k, v gjson.Result) bool { - item := {{$name}}{{toGoName .TfName}}{} - {{- range .Attributes}} - {{- $ccname := toGoName .TfName}} - {{- if and (not .TfOnly) (not .Value) (not .Reference)}} - {{- if eq .Type "String"}} - if cValue := v.Get("{{getResponseModelPath .}}"); cValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && cValue.String() != ""{{end}} { - item.{{toGoName .TfName}} = types.StringValue(cValue.String()) - } else { - item.{{toGoName .TfName}} = types.StringNull() - } - {{- else if eq .Type "Int64"}} - if cValue := v.Get("{{getResponseModelPath .}}"); cValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && cValue.String() != ""{{end}} { - item.{{toGoName .TfName}} = types.Int64Value(cValue.Int()) - } else { - item.{{toGoName .TfName}} = types.Int64Null() - } - {{- else if eq .Type "Float64"}} - if cValue := v.Get("{{getResponseModelPath .}}"); cValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && cValue.String() != ""{{end}} { - item.{{toGoName .TfName}} = types.Float64Value(cValue.Float()) - } else { - item.{{toGoName .TfName}} = types.Float64Null() - } - {{- else if eq .Type "Bool"}} - if cValue := v.Get("{{getResponseModelPath .}}"); cValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && cValue.String() != ""{{end}} { - if {{.BoolEmptyString}} && cValue.String() == "" { - item.{{toGoName .TfName}} = types.BoolValue(true) - }{{if not .BoolEmptyString}} else { - item.{{toGoName .TfName}} = types.BoolValue(cValue.Bool()) - } - {{- end}} - } else { - item.{{toGoName .TfName}} = types.BoolNull() - } - {{- else if isListSet .}} - if cValue := v.Get("{{getResponseModelPath .}}"); cValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && cValue.String() != ""{{end}} { - item.{{toGoName .TfName}} = helpers.Get{{.ElementType}}{{.Type}}(cValue.Array()) - } else { - item.{{toGoName .TfName}} = types.{{.Type}}Null(types.{{.ElementType}}Type) - } - {{- else if isNestedListSet .}} - if cValue := v.Get("{{getResponseModelPath .}}"); cValue.Exists() && len(cValue.Array()) > 0{{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}} { - item.{{toGoName .TfName}} = make([]{{$name}}{{$cname}}{{toGoName .TfName}}, 0) - cValue.ForEach(func(ck, cv gjson.Result) bool { - cItem := {{$name}}{{$cname}}{{toGoName .TfName}}{} - {{- range .Attributes}} - {{- if and (not .TfOnly) (not .Value) (not .Reference)}} - {{- if eq .Type "String"}} - if ccValue := cv.Get("{{getResponseModelPath .}}"); ccValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && cItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && ccValue.String() != ""{{end}} { - cItem.{{toGoName .TfName}} = types.StringValue(ccValue.String()) - } else { - cItem.{{toGoName .TfName}} = types.StringNull() - } - {{- else if eq .Type "Int64"}} - if ccValue := cv.Get("{{getResponseModelPath .}}"); ccValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && cItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && ccValue.String() != ""{{end}} { - cItem.{{toGoName .TfName}} = types.Int64Value(ccValue.Int()) - } else { - cItem.{{toGoName .TfName}} = types.Int64Null() - } - {{- else if eq .Type "Float64"}} - if ccValue := cv.Get("{{getResponseModelPath .}}"); ccValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && cItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && ccValue.String() != ""{{end}} { - cItem.{{toGoName .TfName}} = types.Float64Value(ccValue.Float()) - } else { - cItem.{{toGoName .TfName}} = types.Float64Null() - } - {{- else if eq .Type "Bool"}} - if ccValue := cv.Get("{{getResponseModelPath .}}"); ccValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && cItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && ccValue.String() != ""{{end}} { - if {{.BoolEmptyString}} && ccValue.String() == "" { - cItem.{{toGoName .TfName}} = types.BoolValue(true) - }{{if not .BoolEmptyString}} else { - cItem.{{toGoName .TfName}} = types.BoolValue(ccValue.Bool()) - } - {{- end}} - } else { - cItem.{{toGoName .TfName}} = types.BoolNull() - } - {{- else if isListSet .}} - if ccValue := cv.Get("{{getResponseModelPath .}}"); ccValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && cItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && ccValue.String() != ""{{end}} { - cItem.{{toGoName .TfName}} = helpers.Get{{.ElementType}}{{.Type}}(ccValue.Array()) - } else { - cItem.{{toGoName .TfName}} = types.{{.Type}}Null(types.{{.ElementType}}Type) - } - {{- else if isNestedListSet .}} - if ccValue := cv.Get("{{getResponseModelPath .}}"); ccValue.Exists() && len(ccValue.Array()) > 0{{if ne .ConditionalAttribute.Name ""}} && cItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}} { - cItem.{{toGoName .TfName}} = make([]{{$name}}{{$cname}}{{$ccname}}{{toGoName .TfName}}, 0) - ccValue.ForEach(func(cck, ccv gjson.Result) bool { - ccItem := {{$name}}{{$cname}}{{$ccname}}{{toGoName .TfName}}{} - {{- range .Attributes}} - {{- if and (not .TfOnly) (not .Value) (not .Reference)}} - {{- if eq .Type "String"}} - if cccValue := ccv.Get("{{getResponseModelPath .}}"); cccValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && ccItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && cccValue.String() != ""{{end}} { - ccItem.{{toGoName .TfName}} = types.StringValue(cccValue.String()) - } else { - ccItem.{{toGoName .TfName}} = types.StringNull() - } - {{- else if eq .Type "Int64"}} - if cccValue := ccv.Get("{{getResponseModelPath .}}"); cccValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && ccItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && cccValue.String() != ""{{end}} { - ccItem.{{toGoName .TfName}} = types.Int64Value(cccValue.Int()) - } else { - ccItem.{{toGoName .TfName}} = types.Int64Null() - } - {{- else if eq .Type "Float64"}} - if cccValue := ccv.Get("{{getResponseModelPath .}}"); cccValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && ccItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && cccValue.String() != ""{{end}} { - ccItem.{{toGoName .TfName}} = types.Float64Value(cccValue.Float()) - } else { - ccItem.{{toGoName .TfName}} = types.Float64Null() - } - {{- else if eq .Type "Bool"}} - if cccValue := ccv.Get("{{getResponseModelPath .}}"); cccValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && ccItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && cccValue.String() != ""{{end}} { - if {{.BoolEmptyString}} && cccValue.String() == "" { - ccItem.{{toGoName .TfName}} = types.BoolValue(true) - }{{if not .BoolEmptyString}} else { - ccItem.{{toGoName .TfName}} = types.BoolValue(cccValue.Bool()) - } - {{- end}} - } else { - ccItem.{{toGoName .TfName}} = types.BoolNull() - } - {{- else if isListSet .}} - if cccValue := ccv.Get("{{getResponseModelPath .}}"); cccValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && ccItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && cccValue.String() != ""{{end}} { - ccItem.{{toGoName .TfName}} = helpers.Get{{.ElementType}}{{.Type}}(cccValue.Array()) - } else { - ccItem.{{toGoName .TfName}} = types.{{.Type}}Null(types.{{.ElementType}}Type) - } - {{- end}} - {{- end}} - {{- end}} - cItem.{{toGoName .TfName}} = append(cItem.{{toGoName .TfName}}, ccItem) - return true - }) - } else { - if len(cItem.{{toGoName .TfName}}) > 0 { - cItem.{{toGoName .TfName}} = []{{$name}}{{$cname}}{{$ccname}}{{toGoName .TfName}}{} - } - } - {{- end}} - {{- end}} - {{- end}} - item.{{toGoName .TfName}} = append(item.{{toGoName .TfName}}, cItem) - return true - }) - } else { - if len(item.{{toGoName .TfName}}) > 0 { - item.{{toGoName .TfName}} = []{{$name}}{{$cname}}{{toGoName .TfName}}{} - } - } - {{- end}} - {{- end}} - {{- end}} - data.{{toGoName .TfName}} = append(data.{{toGoName .TfName}}, item) - return true - }) - } else { - if len(data.{{toGoName .TfName}}) > 0 { - data.{{toGoName .TfName}} = []{{$name}}{{toGoName .TfName}}{} - } - } - {{- end}} - {{- end}} - {{- end}} - {{- if hasVersionAttribute .Attributes}} - data.updateVersions(ctx, &state) - {{- end}} + {{- if hasVersionAttribute .Attributes}} + state := *data + {{- end}} + {{- range .Attributes}} + {{- if and (not .TfOnly) (not .Value) (not .Reference)}} + {{- $cname := toGoName .TfName}} + {{- if eq .Type "String"}} + if value := res.Get("{{getResponseModelPath .}}"); value.Exists(){{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && value.String() != ""{{end}} { + data.{{toGoName .TfName}} = types.StringValue(value.String()) + } else { + data.{{toGoName .TfName}} = types.StringNull() + } + {{- else if eq .Type "Int64"}} + if value := res.Get("{{getResponseModelPath .}}"); value.Exists(){{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && value.String() != ""{{end}} { + data.{{toGoName .TfName}} = types.Int64Value(value.Int()) + } else { + data.{{toGoName .TfName}} = types.Int64Null() + } + {{- else if eq .Type "Float64"}} + if value := res.Get("{{getResponseModelPath .}}"); value.Exists(){{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && value.String() != ""{{end}} { + data.{{toGoName .TfName}} = types.Float64Value(value.Float()) + } else { + data.{{toGoName .TfName}} = types.Float64Null() + } + {{- else if eq .Type "Bool"}} + if value := res.Get("{{getResponseModelPath .}}"); value.Exists(){{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && value.String() != ""{{end}} { + if {{.BoolEmptyString}} && value.String() == "" { + data.{{toGoName .TfName}} = types.BoolValue(true) + }{{if not .BoolEmptyString}} else { + data.{{toGoName .TfName}} = types.BoolValue(value.Bool()) + } + {{- end}} + } else { + data.{{toGoName .TfName}} = types.BoolNull() + } + {{- else if isListSet .}} + if value := res.Get("{{getResponseModelPath .}}"); value.Exists(){{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && value.String() != ""{{end}} { + data.{{toGoName .TfName}} = helpers.Get{{.ElementType}}{{.Type}}(value.Array()) + } else { + data.{{toGoName .TfName}} = types.{{.Type}}Null(types.{{.ElementType}}Type) + } + {{- else if isNestedListSet .}} + if value := res.Get("{{getResponseModelPath .}}"); value.Exists() && len(value.Array()) > 0{{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}} { + data.{{toGoName .TfName}} = make([]{{$name}}{{toGoName .TfName}}, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := {{$name}}{{toGoName .TfName}}{} + {{- range .Attributes}} + {{- $ccname := toGoName .TfName}} + {{- if and (not .TfOnly) (not .Value) (not .Reference)}} + {{- if eq .Type "String"}} + if cValue := v.Get("{{getResponseModelPath .}}"); cValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && cValue.String() != ""{{end}} { + item.{{toGoName .TfName}} = types.StringValue(cValue.String()) + } else { + item.{{toGoName .TfName}} = types.StringNull() + } + {{- else if eq .Type "Int64"}} + if cValue := v.Get("{{getResponseModelPath .}}"); cValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && cValue.String() != ""{{end}} { + item.{{toGoName .TfName}} = types.Int64Value(cValue.Int()) + } else { + item.{{toGoName .TfName}} = types.Int64Null() + } + {{- else if eq .Type "Float64"}} + if cValue := v.Get("{{getResponseModelPath .}}"); cValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && cValue.String() != ""{{end}} { + item.{{toGoName .TfName}} = types.Float64Value(cValue.Float()) + } else { + item.{{toGoName .TfName}} = types.Float64Null() + } + {{- else if eq .Type "Bool"}} + if cValue := v.Get("{{getResponseModelPath .}}"); cValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && cValue.String() != ""{{end}} { + if {{.BoolEmptyString}} && cValue.String() == "" { + item.{{toGoName .TfName}} = types.BoolValue(true) + }{{if not .BoolEmptyString}} else { + item.{{toGoName .TfName}} = types.BoolValue(cValue.Bool()) + } + {{- end}} + } else { + item.{{toGoName .TfName}} = types.BoolNull() + } + {{- else if isListSet .}} + if cValue := v.Get("{{getResponseModelPath .}}"); cValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && cValue.String() != ""{{end}} { + item.{{toGoName .TfName}} = helpers.Get{{.ElementType}}{{.Type}}(cValue.Array()) + } else { + item.{{toGoName .TfName}} = types.{{.Type}}Null(types.{{.ElementType}}Type) + } + {{- else if isNestedListSet .}} + if cValue := v.Get("{{getResponseModelPath .}}"); cValue.Exists() && len(cValue.Array()) > 0{{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}} { + item.{{toGoName .TfName}} = make([]{{$name}}{{$cname}}{{toGoName .TfName}}, 0) + cValue.ForEach(func(ck, cv gjson.Result) bool { + cItem := {{$name}}{{$cname}}{{toGoName .TfName}}{} + {{- range .Attributes}} + {{- if and (not .TfOnly) (not .Value) (not .Reference)}} + {{- if eq .Type "String"}} + if ccValue := cv.Get("{{getResponseModelPath .}}"); ccValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && cItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && ccValue.String() != ""{{end}} { + cItem.{{toGoName .TfName}} = types.StringValue(ccValue.String()) + } else { + cItem.{{toGoName .TfName}} = types.StringNull() + } + {{- else if eq .Type "Int64"}} + if ccValue := cv.Get("{{getResponseModelPath .}}"); ccValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && cItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && ccValue.String() != ""{{end}} { + cItem.{{toGoName .TfName}} = types.Int64Value(ccValue.Int()) + } else { + cItem.{{toGoName .TfName}} = types.Int64Null() + } + {{- else if eq .Type "Float64"}} + if ccValue := cv.Get("{{getResponseModelPath .}}"); ccValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && cItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && ccValue.String() != ""{{end}} { + cItem.{{toGoName .TfName}} = types.Float64Value(ccValue.Float()) + } else { + cItem.{{toGoName .TfName}} = types.Float64Null() + } + {{- else if eq .Type "Bool"}} + if ccValue := cv.Get("{{getResponseModelPath .}}"); ccValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && cItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && ccValue.String() != ""{{end}} { + if {{.BoolEmptyString}} && ccValue.String() == "" { + cItem.{{toGoName .TfName}} = types.BoolValue(true) + }{{if not .BoolEmptyString}} else { + cItem.{{toGoName .TfName}} = types.BoolValue(ccValue.Bool()) + } + {{- end}} + } else { + cItem.{{toGoName .TfName}} = types.BoolNull() + } + {{- else if isListSet .}} + if ccValue := cv.Get("{{getResponseModelPath .}}"); ccValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && cItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && ccValue.String() != ""{{end}} { + cItem.{{toGoName .TfName}} = helpers.Get{{.ElementType}}{{.Type}}(ccValue.Array()) + } else { + cItem.{{toGoName .TfName}} = types.{{.Type}}Null(types.{{.ElementType}}Type) + } + {{- else if isNestedListSet .}} + if ccValue := cv.Get("{{getResponseModelPath .}}"); ccValue.Exists() && len(ccValue.Array()) > 0{{if ne .ConditionalAttribute.Name ""}} && cItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}} { + cItem.{{toGoName .TfName}} = make([]{{$name}}{{$cname}}{{$ccname}}{{toGoName .TfName}}, 0) + ccValue.ForEach(func(cck, ccv gjson.Result) bool { + ccItem := {{$name}}{{$cname}}{{$ccname}}{{toGoName .TfName}}{} + {{- range .Attributes}} + {{- if and (not .TfOnly) (not .Value) (not .Reference)}} + {{- if eq .Type "String"}} + if cccValue := ccv.Get("{{getResponseModelPath .}}"); cccValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && ccItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && cccValue.String() != ""{{end}} { + ccItem.{{toGoName .TfName}} = types.StringValue(cccValue.String()) + } else { + ccItem.{{toGoName .TfName}} = types.StringNull() + } + {{- else if eq .Type "Int64"}} + if cccValue := ccv.Get("{{getResponseModelPath .}}"); cccValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && ccItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && cccValue.String() != ""{{end}} { + ccItem.{{toGoName .TfName}} = types.Int64Value(cccValue.Int()) + } else { + ccItem.{{toGoName .TfName}} = types.Int64Null() + } + {{- else if eq .Type "Float64"}} + if cccValue := ccv.Get("{{getResponseModelPath .}}"); cccValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && ccItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && cccValue.String() != ""{{end}} { + ccItem.{{toGoName .TfName}} = types.Float64Value(cccValue.Float()) + } else { + ccItem.{{toGoName .TfName}} = types.Float64Null() + } + {{- else if eq .Type "Bool"}} + if cccValue := ccv.Get("{{getResponseModelPath .}}"); cccValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && ccItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && cccValue.String() != ""{{end}} { + if {{.BoolEmptyString}} && cccValue.String() == "" { + ccItem.{{toGoName .TfName}} = types.BoolValue(true) + }{{if not .BoolEmptyString}} else { + ccItem.{{toGoName .TfName}} = types.BoolValue(cccValue.Bool()) + } + {{- end}} + } else { + ccItem.{{toGoName .TfName}} = types.BoolNull() + } + {{- else if isListSet .}} + if cccValue := ccv.Get("{{getResponseModelPath .}}"); cccValue.Exists(){{if ne .ConditionalAttribute.Name ""}} && ccItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}"{{end}}{{if .AlwaysInclude}} && cccValue.String() != ""{{end}} { + ccItem.{{toGoName .TfName}} = helpers.Get{{.ElementType}}{{.Type}}(cccValue.Array()) + } else { + ccItem.{{toGoName .TfName}} = types.{{.Type}}Null(types.{{.ElementType}}Type) + } + {{- end}} + {{- end}} + {{- end}} + cItem.{{toGoName .TfName}} = append(cItem.{{toGoName .TfName}}, ccItem) + return true + }) + } else { + if len(cItem.{{toGoName .TfName}}) > 0 { + cItem.{{toGoName .TfName}} = []{{$name}}{{$cname}}{{$ccname}}{{toGoName .TfName}}{} + } + } + {{- end}} + {{- end}} + {{- end}} + item.{{toGoName .TfName}} = append(item.{{toGoName .TfName}}, cItem) + return true + }) + } else { + if len(item.{{toGoName .TfName}}) > 0 { + item.{{toGoName .TfName}} = []{{$name}}{{$cname}}{{toGoName .TfName}}{} + } + } + {{- end}} + {{- end}} + {{- end}} + data.{{toGoName .TfName}} = append(data.{{toGoName .TfName}}, item) + return true + }) + } else { + if len(data.{{toGoName .TfName}}) > 0 { + data.{{toGoName .TfName}} = []{{$name}}{{toGoName .TfName}}{} + } + } + {{- end}} + {{- end}} + {{- end}} + {{- if hasVersionAttribute .Attributes}} + data.updateVersions(ctx, &state) + {{- end}} } // End of section. //template:end fromBody // Section below is generated&owned by "gen/generator.go". //template:begin hasChanges func (data *{{camelCase .Name}}) hasChanges(ctx context.Context, state *{{camelCase .Name}}) bool { - hasChanges := false - {{- range .Attributes}} - {{- $name := toGoName .TfName}} - {{- if and (not .Value) (not .TfOnly)}} - {{- if not (isNestedListSet .)}} - if !data.{{toGoName .TfName}}.Equal(state.{{toGoName .TfName}}) { - hasChanges = true - } - {{- else}} - if len(data.{{toGoName .TfName}}) != len(state.{{toGoName .TfName}}) { - hasChanges = true - } else { - for i := range data.{{toGoName .TfName}} { - {{- range .Attributes}} - {{- $cname := toGoName .TfName}} - {{- if and (not .Value) (not .TfOnly)}} - {{- if not (isNestedListSet .)}} - if !data.{{$name}}[i].{{toGoName .TfName}}.Equal(state.{{$name}}[i].{{toGoName .TfName}}) { - hasChanges = true - } - {{- else}} - if len(data.{{$name}}[i].{{toGoName .TfName}}) != len(state.{{$name}}[i].{{toGoName .TfName}}) { - hasChanges = true - } else { - for ii := range data.{{$name}}[i].{{toGoName .TfName}} { - {{- range .Attributes}} - {{- $ccname := toGoName .TfName}} - {{- if and (not .Value) (not .TfOnly)}} - {{- if not (isNestedListSet .)}} - if !data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}}.Equal(state.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}}) { - hasChanges = true - } - {{- else}} - if len(data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}}) != len(state.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}}) { - hasChanges = true - } else { - for iii := range data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} { - {{- range .Attributes}} - {{- if and (not .Value) (not .TfOnly)}} - if !data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}}.Equal(state.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}}) { - hasChanges = true - } - {{- end}} - {{- end}} - } - } - {{- end}} - {{- end}} - {{- end}} - } - } - {{- end}} - {{- end}} - {{- end}} - } - } - {{- end}} - {{- end}} - {{- end}} - return hasChanges + hasChanges := false + {{- range .Attributes}} + {{- $name := toGoName .TfName}} + {{- if and (not .Value) (not .TfOnly)}} + {{- if not (isNestedListSet .)}} + if !data.{{toGoName .TfName}}.Equal(state.{{toGoName .TfName}}) { + hasChanges = true + } + {{- else}} + if len(data.{{toGoName .TfName}}) != len(state.{{toGoName .TfName}}) { + hasChanges = true + } else { + for i := range data.{{toGoName .TfName}} { + {{- range .Attributes}} + {{- $cname := toGoName .TfName}} + {{- if and (not .Value) (not .TfOnly)}} + {{- if not (isNestedListSet .)}} + if !data.{{$name}}[i].{{toGoName .TfName}}.Equal(state.{{$name}}[i].{{toGoName .TfName}}) { + hasChanges = true + } + {{- else}} + if len(data.{{$name}}[i].{{toGoName .TfName}}) != len(state.{{$name}}[i].{{toGoName .TfName}}) { + hasChanges = true + } else { + for ii := range data.{{$name}}[i].{{toGoName .TfName}} { + {{- range .Attributes}} + {{- $ccname := toGoName .TfName}} + {{- if and (not .Value) (not .TfOnly)}} + {{- if not (isNestedListSet .)}} + if !data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}}.Equal(state.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}}) { + hasChanges = true + } + {{- else}} + if len(data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}}) != len(state.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}}) { + hasChanges = true + } else { + for iii := range data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} { + {{- range .Attributes}} + {{- if and (not .Value) (not .TfOnly)}} + if !data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}}.Equal(state.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}}) { + hasChanges = true + } + {{- end}} + {{- end}} + } + } + {{- end}} + {{- end}} + {{- end}} + } + } + {{- end}} + {{- end}} + {{- end}} + } + } + {{- end}} + {{- end}} + {{- end}} + return hasChanges } // End of section. //template:end hasChanges // Section below is generated&owned by "gen/generator.go". //template:begin updateVersions {{if hasVersionAttribute .Attributes}} func (data *{{camelCase .Name}}) updateVersions(ctx context.Context, state *{{camelCase .Name}}) { - {{- range .Attributes}} - {{- $name := toGoName .TfName}} - {{- if or (eq .Type "Version") (eq .Type "Versions")}} - data.{{toGoName .TfName}} = state.{{toGoName .TfName}} - {{- else if and (isNestedListSet .) (hasVersionAttribute .Attributes)}} - for i := range data.{{toGoName .TfName}} { - dataKeys := [...]string{ {{range .Attributes}}{{if .Id}}fmt.Sprintf("%v", data.{{$name}}[i].{{toGoName .TfName}}.{{if isStringListSet .}}String{{else}}Value{{.Type}}{{end}}()), {{end}}{{end}} } - stateIndex := -1 - for j := range state.{{toGoName .TfName}} { - stateKeys := [...]string{ {{range .Attributes}}{{if .Id}}fmt.Sprintf("%v", state.{{$name}}[j].{{toGoName .TfName}}.{{if isStringListSet .}}String{{else}}Value{{.Type}}{{end}}()), {{end}}{{end}} } - if dataKeys == stateKeys { - stateIndex = j + {{- range .Attributes}} + {{- $name := toGoName .TfName}} + {{- if or (eq .Type "Version") (eq .Type "Versions")}} + data.{{toGoName .TfName}} = state.{{toGoName .TfName}} + {{- else if and (isNestedListSet .) (hasVersionAttribute .Attributes)}} + for i := range data.{{toGoName .TfName}} { + dataKeys := [...]string{ {{range .Attributes}}{{if .Id}}fmt.Sprintf("%v", data.{{$name}}[i].{{toGoName .TfName}}.{{if isStringListSet .}}String{{else}}Value{{.Type}}{{end}}()), {{end}}{{end}} } + stateIndex := -1 + for j := range state.{{toGoName .TfName}} { + stateKeys := [...]string{ {{range .Attributes}}{{if .Id}}fmt.Sprintf("%v", state.{{$name}}[j].{{toGoName .TfName}}.{{if isStringListSet .}}String{{else}}Value{{.Type}}{{end}}()), {{end}}{{end}} } + if dataKeys == stateKeys { + stateIndex = j break - } - } - {{- range .Attributes}} - {{- $cname := toGoName .TfName}} - {{- if eq .Type "Version"}} - if stateIndex > -1 { - data.{{$name}}[i].{{toGoName .TfName}} = state.{{$name}}[stateIndex].{{toGoName .TfName}} - } else { - data.{{$name}}[i].{{toGoName .TfName}} = types.Int64Null() - } - {{- else if eq .Type "Versions"}} - if stateIndex > -1 && !state.{{$name}}[stateIndex].{{toGoName .TfName}}.IsNull() { - data.{{$name}}[i].{{toGoName .TfName}} = state.{{$name}}[stateIndex].{{toGoName .TfName}} - } else { - data.{{$name}}[i].{{toGoName .TfName}} = types.ListNull(types.StringType) - } - {{- else if and (isNestedListSet .) (hasVersionAttribute .Attributes)}} - for ii := range data.{{$name}}[i].{{toGoName .TfName}} { - cDataKeys := [...]string{ {{range .Attributes}}{{if .Id}}fmt.Sprintf("%v", data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}}.{{if isStringListSet .}}String{{else}}Value{{.Type}}{{end}}()), {{end}}{{end}} } - cStateIndex := -1 - if stateIndex > -1 { - for jj := range state.{{$name}}[stateIndex].{{toGoName .TfName}} { - cStateKeys := [...]string{ {{range .Attributes}}{{if .Id}}fmt.Sprintf("%v", state.{{$name}}[stateIndex].{{$cname}}[jj].{{toGoName .TfName}}.{{if isStringListSet .}}String{{else}}Value{{.Type}}{{end}}()), {{end}}{{end}} } - if cDataKeys == cStateKeys { - cStateIndex = jj - break - } - } - } - {{- range .Attributes}} - {{- $ccname := toGoName .TfName}} - {{- if eq .Type "Version"}} - if cStateIndex > -1 { - data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} = state.{{$name}}[stateIndex].{{$cname}}[cStateIndex].{{toGoName .TfName}} - } else { - data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} = types.Int64Null() - } - {{- else if eq .Type "Versions"}} - if cStateIndex > -1 && !state.{{$name}}[stateIndex].{{$cname}}[cStateIndex].{{toGoName .TfName}}.IsNull() { - data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} = state.{{$name}}[stateIndex].{{$cname}}[cStateIndex].{{toGoName .TfName}} - } else { - data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} = types.ListNull(types.StringType) - } - {{- else if and (isNestedListSet .) (hasVersionAttribute .Attributes)}} - for iii := range data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} { - ccDataKeys := [...]string{ {{range .Attributes}}{{if .Id}}fmt.Sprintf("%v", data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}}.{{if isStringListSet .}}String{{else}}Value{{.Type}}{{end}}()), {{end}}{{end}} } - ccStateIndex := -1 - if cStateIndex > -1 { - for jjj := range state.{{$name}}[stateIndex].{{$cname}}[cStateIndex].{{toGoName .TfName}} { - ccStateKeys := [...]string{ {{range .Attributes}}{{if .Id}}fmt.Sprintf("%v", state.{{$name}}[stateIndex].{{$cname}}[cStateIndex].{{$ccname}}[jjj].{{toGoName .TfName}}.{{if isStringListSet .}}String{{else}}Value{{.Type}}{{end}}()), {{end}}{{end}} } - if ccDataKeys == ccStateKeys { - ccStateIndex = jjj - break - } - } - } - {{- range .Attributes}} - {{- if eq .Type "Version"}} - if ccStateIndex > -1 { - data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}} = state.{{$name}}[stateIndex].{{$cname}}[cStateIndex].{{$ccname}}[ccStateIndex].{{toGoName .TfName}} - } else { - data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}} = types.Int64Null() - } - {{- else if eq .Type "Versions"}} - if ccStateIndex > -1 && !state.{{$name}}[stateIndex].{{$cname}}[cStateIndex].{{$ccname}}[ccStateIndex].{{toGoName .TfName}}.IsNull() { - data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}} = state.{{$name}}[stateIndex].{{$cname}}[cStateIndex].{{$ccname}}[ccStateIndex].{{toGoName .TfName}} - } else { - data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}} = types.ListNull(types.StringType) - } - {{- end}} - {{- end}} - } - {{- end}} - {{- end}} - } - {{- end}} - {{- end}} - } - {{- end}} - {{- end}} + } + } + {{- range .Attributes}} + {{- $cname := toGoName .TfName}} + {{- if eq .Type "Version"}} + if stateIndex > -1 { + data.{{$name}}[i].{{toGoName .TfName}} = state.{{$name}}[stateIndex].{{toGoName .TfName}} + } else { + data.{{$name}}[i].{{toGoName .TfName}} = types.Int64Null() + } + {{- else if eq .Type "Versions"}} + if stateIndex > -1 && !state.{{$name}}[stateIndex].{{toGoName .TfName}}.IsNull() { + data.{{$name}}[i].{{toGoName .TfName}} = state.{{$name}}[stateIndex].{{toGoName .TfName}} + } else { + data.{{$name}}[i].{{toGoName .TfName}} = types.ListNull(types.StringType) + } + {{- else if and (isNestedListSet .) (hasVersionAttribute .Attributes)}} + for ii := range data.{{$name}}[i].{{toGoName .TfName}} { + cDataKeys := [...]string{ {{range .Attributes}}{{if .Id}}fmt.Sprintf("%v", data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}}.{{if isStringListSet .}}String{{else}}Value{{.Type}}{{end}}()), {{end}}{{end}} } + cStateIndex := -1 + if stateIndex > -1 { + for jj := range state.{{$name}}[stateIndex].{{toGoName .TfName}} { + cStateKeys := [...]string{ {{range .Attributes}}{{if .Id}}fmt.Sprintf("%v", state.{{$name}}[stateIndex].{{$cname}}[jj].{{toGoName .TfName}}.{{if isStringListSet .}}String{{else}}Value{{.Type}}{{end}}()), {{end}}{{end}} } + if cDataKeys == cStateKeys { + cStateIndex = jj + break + } + } + } + {{- range .Attributes}} + {{- $ccname := toGoName .TfName}} + {{- if eq .Type "Version"}} + if cStateIndex > -1 { + data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} = state.{{$name}}[stateIndex].{{$cname}}[cStateIndex].{{toGoName .TfName}} + } else { + data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} = types.Int64Null() + } + {{- else if eq .Type "Versions"}} + if cStateIndex > -1 && !state.{{$name}}[stateIndex].{{$cname}}[cStateIndex].{{toGoName .TfName}}.IsNull() { + data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} = state.{{$name}}[stateIndex].{{$cname}}[cStateIndex].{{toGoName .TfName}} + } else { + data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} = types.ListNull(types.StringType) + } + {{- else if and (isNestedListSet .) (hasVersionAttribute .Attributes)}} + for iii := range data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} { + ccDataKeys := [...]string{ {{range .Attributes}}{{if .Id}}fmt.Sprintf("%v", data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}}.{{if isStringListSet .}}String{{else}}Value{{.Type}}{{end}}()), {{end}}{{end}} } + ccStateIndex := -1 + if cStateIndex > -1 { + for jjj := range state.{{$name}}[stateIndex].{{$cname}}[cStateIndex].{{toGoName .TfName}} { + ccStateKeys := [...]string{ {{range .Attributes}}{{if .Id}}fmt.Sprintf("%v", state.{{$name}}[stateIndex].{{$cname}}[cStateIndex].{{$ccname}}[jjj].{{toGoName .TfName}}.{{if isStringListSet .}}String{{else}}Value{{.Type}}{{end}}()), {{end}}{{end}} } + if ccDataKeys == ccStateKeys { + ccStateIndex = jjj + break + } + } + } + {{- range .Attributes}} + {{- if eq .Type "Version"}} + if ccStateIndex > -1 { + data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}} = state.{{$name}}[stateIndex].{{$cname}}[cStateIndex].{{$ccname}}[ccStateIndex].{{toGoName .TfName}} + } else { + data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}} = types.Int64Null() + } + {{- else if eq .Type "Versions"}} + if ccStateIndex > -1 && !state.{{$name}}[stateIndex].{{$cname}}[cStateIndex].{{$ccname}}[ccStateIndex].{{toGoName .TfName}}.IsNull() { + data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}} = state.{{$name}}[stateIndex].{{$cname}}[cStateIndex].{{$ccname}}[ccStateIndex].{{toGoName .TfName}} + } else { + data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}} = types.ListNull(types.StringType) + } + {{- end}} + {{- end}} + } + {{- end}} + {{- end}} + } + {{- end}} + {{- end}} + } + {{- end}} + {{- end}} } {{end}} // End of section. //template:end updateVersions // Section below is generated&owned by "gen/generator.go". //template:begin processImport func (data *{{camelCase .Name}}) processImport(ctx context.Context) { - {{- if .HasVersion}} - data.Version = types.Int64Value(0) - {{- end}} - {{- if .TypeValue}} - data.Type = types.StringValue("{{ .TypeValue }}") - {{- end}} - {{- range .Attributes}} - {{- $name := toGoName .TfName}} - {{- if not .Value}} - {{- if .Value}} - data.{{toGoName .TfName}} = {{if eq .Type "String"}}types.StringValue("{{ .Value }}"){{else if eq .Type "Bool"}}types.BoolValue({{ .Value }}){{else if eq .Type "List"}}{{ .Value }}{{else}}types.ListNull({{ .Value }}){{end}} - {{- end}} - {{- if eq .Type "Version"}} - if data.{{toVersionName .TfName}} != types.StringNull() { - data.{{toGoName .TfName}} = types.Int64Value(0) - } - {{- else if eq .Type "Versions"}} - if !data.{{toVersionName .TfName}}.IsNull() { - data.{{toGoName .TfName}} = types.ListNull(types.StringType) - } - {{- else if and (isNestedListSet .) (hasVersionAttribute .Attributes)}} - for i := range data.{{toGoName .TfName}} { + {{- if .HasVersion}} + data.Version = types.Int64Value(0) + {{- end}} + {{- if .TypeValue}} + data.Type = types.StringValue("{{ .TypeValue }}") + {{- end}} + {{- range .Attributes}} + {{- $name := toGoName .TfName}} + {{- if not .Value}} + {{- if .Value}} + data.{{toGoName .TfName}} = {{if eq .Type "String"}}types.StringValue("{{ .Value }}"){{else if eq .Type "Bool"}}types.BoolValue({{ .Value }}){{else if eq .Type "List"}}{{ .Value }}{{else}}types.ListNull({{ .Value }}){{end}} + {{- end}} + {{- if eq .Type "Version"}} + if data.{{toVersionName .TfName}} != types.StringNull() { + data.{{toGoName .TfName}} = types.Int64Value(0) + } + {{- else if eq .Type "Versions"}} + if !data.{{toVersionName .TfName}}.IsNull() { + var elements{{toGoName .TfName}} []attr.Value + var count{{toGoName .TfName}} int = 0 + if !(data.{{toVersionName .TfName}}.IsNull() || data.{{toVersionName .TfName}}.IsUnknown()) { + count{{toGoName .TfName}} = len(data.{{toVersionName .TfName}}.Elements()) + } + if count{{toGoName .TfName}} > 0 { + elements{{toGoName .TfName}} = make([]attr.Value, count{{toGoName .TfName}}) + for i := 0; i < count{{toGoName .TfName}}; i++ { + elements{{toGoName .TfName}}[i] = types.StringValue("0") + } + data.{{toGoName .TfName}} = types.ListValueMust(types.StringType, elements{{toGoName .TfName}}) + } else { + data.{{toGoName .TfName}} = types.ListNull(types.StringType) + } + } + {{- else if and (isNestedListSet .) (hasVersionAttribute .Attributes)}} + for i := range data.{{toGoName .TfName}} { - {{- range .Attributes}} - {{- $cname := toGoName .TfName}} - {{- if not .Value}} - {{- if eq .Type "Version"}} - if data.{{$name}}[i].{{toVersionName .TfName}} != types.StringNull() { - data.{{$name}}[i].{{toGoName .TfName}} = types.Int64Value(0) - } - {{- else if eq .Type "Versions"}} - if !data.{{$name}}[i].{{toVersionName .TfName}}.IsNull() { - data.{{$name}}[i].{{toGoName .TfName}} = types.ListNull(types.StringType) - } - {{- else if and (isNestedListSet .) (hasVersionAttribute .Attributes)}} - for ii := range data.{{$name}}[i].{{toGoName .TfName}} { + {{- range .Attributes}} + {{- $cname := toGoName .TfName}} + {{- if not .Value}} + {{- if eq .Type "Version"}} + if data.{{$name}}[i].{{toVersionName .TfName}} != types.StringNull() { + data.{{$name}}[i].{{toGoName .TfName}} = types.Int64Value(0) + } + {{- else if eq .Type "Versions"}} + if !data.{{$name}}[i].{{toVersionName .TfName}}.IsNull() { + var elements{{toGoName .TfName}} []attr.Value + var count{{toGoName .TfName}} int = 0 + if !(data.{{$name}}[i].{{toVersionName .TfName}}.IsNull() || data.{{$name}}[i].{{toVersionName .TfName}}.IsUnknown()) { + count{{toGoName .TfName}} = len(data.{{$name}}[i].{{toVersionName .TfName}}.Elements()) + } + if count{{toGoName .TfName}} > 0 { + elements{{toGoName .TfName}} = make([]attr.Value, count{{toGoName .TfName}}) + for i := 0; i < count{{toGoName .TfName}}; i++ { + elements{{toGoName .TfName}}[i] = types.StringValue("0") + } + data.{{$name}}[i].{{toGoName .TfName}} = types.ListValueMust(types.StringType, elements{{toGoName .TfName}}) + } else { + data.{{$name}}[i].{{toGoName .TfName}} = types.ListNull(types.StringType) + } + } + {{- else if and (isNestedListSet .) (hasVersionAttribute .Attributes)}} + for ii := range data.{{$name}}[i].{{toGoName .TfName}} { - {{- range .Attributes}} - {{- $ccname := toGoName .TfName}} - {{- if not .Value}} - {{- if eq .Type "Version"}} - if data.{{$name}}[i].{{$cname}}[ii].{{toVersionName .TfName}} != types.StringNull() { - data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} = types.Int64Value(0) - } - {{- else if eq .Type "Versions"}} - if !data.{{$name}}[i].{{$cname}}[ii].{{toVersionName .TfName}}.IsNull() { - data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} = types.ListNull(types.StringType) - } - {{- else if and (isNestedListSet .) (hasVersionAttribute .Attributes)}} - for iii := range data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} { + {{- range .Attributes}} + {{- $ccname := toGoName .TfName}} + {{- if not .Value}} + {{- if eq .Type "Version"}} + if data.{{$name}}[i].{{$cname}}[ii].{{toVersionName .TfName}} != types.StringNull() { + data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} = types.Int64Value(0) + } + {{- else if eq .Type "Versions"}} + if !data.{{$name}}[i].{{$cname}}[ii].{{toVersionName .TfName}}.IsNull() { + var elements{{toGoName .TfName}} []attr.Value + var count{{toGoName .TfName}} int = 0 + if !(data.{{$name}}[i].{{$cname}}[ii].{{toVersionName .TfName}}.IsNull() || data.{{$name}}[i].{{$cname}}[ii].{{toVersionName .TfName}}.IsUnknown()) { + count{{toGoName .TfName}} = len(data.{{$name}}[i].{{$cname}}[ii].{{toVersionName .TfName}}.Elements()) + } + if count{{toGoName .TfName}} > 0 { + elements{{toGoName .TfName}} = make([]attr.Value, count{{toGoName .TfName}}) + for i := 0; i < count{{toGoName .TfName}}; i++ { + elements{{toGoName .TfName}}[i] = types.StringValue("0") + } + data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} = types.ListValueMust(types.StringType, elements{{toGoName .TfName}}) + } else { + data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} = types.ListNull(types.StringType) + } + } + {{- else if and (isNestedListSet .) (hasVersionAttribute .Attributes)}} + for iii := range data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} { - {{- range .Attributes}} - {{- if eq .Type "Version"}} - if data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toVersionName .TfName}} != types.StringNull() { - data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}} = types.Int64Value(0) - } - {{- else if eq .Type "Versions"}} - if !data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toVersionName .TfName}}.IsNull() { - data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}} = types.ListNull(types.StringType) - } - {{- end}} - {{- end}} - } - {{- end}} - {{- end}} - {{- end}} - } - {{- end}} - {{- end}} - {{- end}} - } - {{- end}} - {{- end}} - {{- end}} + {{- range .Attributes}} + {{- if eq .Type "Version"}} + if data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toVersionName .TfName}} != types.StringNull() { + data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}} = types.Int64Value(0) + } + {{- else if eq .Type "Versions"}} + if !data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toVersionName .TfName}}.IsNull() { + var elements{{toGoName .TfName}} []attr.Value + var count{{toGoName .TfName}} int = 0 + if !(data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toVersionName .TfName}}.IsNull() || data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toVersionName .TfName}}.IsUnknown()) { + count{{toGoName .TfName}} = len(data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toVersionName .TfName}}.Elements()) + } + if count{{toGoName .TfName}} > 0 { + elements{{toGoName .TfName}} = make([]attr.Value, count{{toGoName .TfName}}) + for i := 0; i < count{{toGoName .TfName}}; i++ { + elements{{toGoName .TfName}}[i] = types.StringValue("0") + } + data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}} = types.ListValueMust(types.StringType, elements{{toGoName .TfName}}) + } else { + data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}} = types.ListNull(types.StringType) + } + } + {{- end}} + {{- end}} + } + {{- end}} + {{- end}} + {{- end}} + } + {{- end}} + {{- end}} + {{- end}} + } + {{- end}} + {{- end}} + {{- end}} } // End of section. //template:end processImport \ No newline at end of file diff --git a/internal/provider/model_sdwan_centralized_policy.go b/internal/provider/model_sdwan_centralized_policy.go index a1d629a3a..97df5721f 100644 --- a/internal/provider/model_sdwan_centralized_policy.go +++ b/internal/provider/model_sdwan_centralized_policy.go @@ -23,6 +23,7 @@ import ( "fmt" "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/tidwall/gjson" "github.com/tidwall/sjson" @@ -310,13 +311,52 @@ func (data *CentralizedPolicy) processImport(ctx context.Context) { } for ii := range data.Definitions[i].Entries { if !data.Definitions[i].Entries[ii].SiteListIds.IsNull() { - data.Definitions[i].Entries[ii].SiteListVersions = types.ListNull(types.StringType) + var elementsSiteListVersions []attr.Value + var countSiteListVersions int = 0 + if !(data.Definitions[i].Entries[ii].SiteListIds.IsNull() || data.Definitions[i].Entries[ii].SiteListIds.IsUnknown()) { + countSiteListVersions = len(data.Definitions[i].Entries[ii].SiteListIds.Elements()) + } + if countSiteListVersions > 0 { + elementsSiteListVersions = make([]attr.Value, countSiteListVersions) + for i := 0; i < countSiteListVersions; i++ { + elementsSiteListVersions[i] = types.StringValue("0") + } + data.Definitions[i].Entries[ii].SiteListVersions = types.ListValueMust(types.StringType, elementsSiteListVersions) + } else { + data.Definitions[i].Entries[ii].SiteListVersions = types.ListNull(types.StringType) + } } if !data.Definitions[i].Entries[ii].VpnListIds.IsNull() { - data.Definitions[i].Entries[ii].VpnListVersions = types.ListNull(types.StringType) + var elementsVpnListVersions []attr.Value + var countVpnListVersions int = 0 + if !(data.Definitions[i].Entries[ii].VpnListIds.IsNull() || data.Definitions[i].Entries[ii].VpnListIds.IsUnknown()) { + countVpnListVersions = len(data.Definitions[i].Entries[ii].VpnListIds.Elements()) + } + if countVpnListVersions > 0 { + elementsVpnListVersions = make([]attr.Value, countVpnListVersions) + for i := 0; i < countVpnListVersions; i++ { + elementsVpnListVersions[i] = types.StringValue("0") + } + data.Definitions[i].Entries[ii].VpnListVersions = types.ListValueMust(types.StringType, elementsVpnListVersions) + } else { + data.Definitions[i].Entries[ii].VpnListVersions = types.ListNull(types.StringType) + } } if !data.Definitions[i].Entries[ii].RegionListIds.IsNull() { - data.Definitions[i].Entries[ii].RegionListVersions = types.ListNull(types.StringType) + var elementsRegionListVersions []attr.Value + var countRegionListVersions int = 0 + if !(data.Definitions[i].Entries[ii].RegionListIds.IsNull() || data.Definitions[i].Entries[ii].RegionListIds.IsUnknown()) { + countRegionListVersions = len(data.Definitions[i].Entries[ii].RegionListIds.Elements()) + } + if countRegionListVersions > 0 { + elementsRegionListVersions = make([]attr.Value, countRegionListVersions) + for i := 0; i < countRegionListVersions; i++ { + elementsRegionListVersions[i] = types.StringValue("0") + } + data.Definitions[i].Entries[ii].RegionListVersions = types.ListValueMust(types.StringType, elementsRegionListVersions) + } else { + data.Definitions[i].Entries[ii].RegionListVersions = types.ListNull(types.StringType) + } } } } diff --git a/internal/provider/model_sdwan_configuration_group.go b/internal/provider/model_sdwan_configuration_group.go index 9e982c0d4..66b4747e5 100644 --- a/internal/provider/model_sdwan_configuration_group.go +++ b/internal/provider/model_sdwan_configuration_group.go @@ -568,3 +568,22 @@ func (data ConfigurationGroup) hasFeatureVersionChanges(ctx context.Context, sta } return false } + +func (data ConfigurationGroup) processImport(ctx context.Context) { + var elementsFeatureList []attr.Value + var countFeatureProfile int = 0 + + if !(data.FeatureProfileIds.IsNull() || data.FeatureProfileIds.IsUnknown()) { + countFeatureProfile = len(data.FeatureProfileIds.Elements()) + } + + if countFeatureProfile > 0 { + elementsFeatureList = make([]attr.Value, countFeatureProfile) + for i := 0; i < countFeatureProfile; i++ { + elementsFeatureList[i] = types.Int64Value(0) + } + data.FeatureVersions = types.ListValueMust(types.Int64Type, elementsFeatureList) + } else { + data.FeatureVersions = types.ListNull(types.StringType) + } +} diff --git a/internal/provider/model_sdwan_mesh_topology_policy_definition.go b/internal/provider/model_sdwan_mesh_topology_policy_definition.go index ea468407a..bf3c6c1f1 100644 --- a/internal/provider/model_sdwan_mesh_topology_policy_definition.go +++ b/internal/provider/model_sdwan_mesh_topology_policy_definition.go @@ -23,6 +23,7 @@ import ( "fmt" "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/tidwall/gjson" "github.com/tidwall/sjson" @@ -199,7 +200,20 @@ func (data *MeshTopologyPolicyDefinition) processImport(ctx context.Context) { } for i := range data.Regions { if !data.Regions[i].SiteListIds.IsNull() { - data.Regions[i].SiteListVersions = types.ListNull(types.StringType) + var elementsSiteListVersions []attr.Value + var countSiteListVersions int = 0 + if !(data.Regions[i].SiteListIds.IsNull() || data.Regions[i].SiteListIds.IsUnknown()) { + countSiteListVersions = len(data.Regions[i].SiteListIds.Elements()) + } + if countSiteListVersions > 0 { + elementsSiteListVersions = make([]attr.Value, countSiteListVersions) + for i := 0; i < countSiteListVersions; i++ { + elementsSiteListVersions[i] = types.StringValue("0") + } + data.Regions[i].SiteListVersions = types.ListValueMust(types.StringType, elementsSiteListVersions) + } else { + data.Regions[i].SiteListVersions = types.ListNull(types.StringType) + } } } } diff --git a/internal/provider/model_sdwan_policy_group.go b/internal/provider/model_sdwan_policy_group.go index ca2725352..7dbce9bda 100644 --- a/internal/provider/model_sdwan_policy_group.go +++ b/internal/provider/model_sdwan_policy_group.go @@ -410,3 +410,22 @@ func (data PolicyGroup) hasPolicyVersionChanges(ctx context.Context, state *Poli } return false } + +func (data PolicyGroup) processImport(ctx context.Context) { + var elementsFeatureList []attr.Value + var countFeatureProfile int = 0 + + if !(data.FeatureProfileIds.IsNull() || data.FeatureProfileIds.IsUnknown()) { + countFeatureProfile = len(data.FeatureProfileIds.Elements()) + } + + if countFeatureProfile > 0 { + elementsFeatureList = make([]attr.Value, countFeatureProfile) + for i := 0; i < countFeatureProfile; i++ { + elementsFeatureList[i] = types.Int64Value(0) + } + data.PolicyVersions = types.ListValueMust(types.Int64Type, elementsFeatureList) + } else { + data.PolicyVersions = types.ListNull(types.StringType) + } +} diff --git a/internal/provider/model_sdwan_route_policy_definition.go b/internal/provider/model_sdwan_route_policy_definition.go index 200d3ff72..c77717ffe 100644 --- a/internal/provider/model_sdwan_route_policy_definition.go +++ b/internal/provider/model_sdwan_route_policy_definition.go @@ -23,6 +23,7 @@ import ( "fmt" "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/tidwall/gjson" "github.com/tidwall/sjson" @@ -743,7 +744,20 @@ func (data *RoutePolicyDefinition) processImport(ctx context.Context) { data.Sequences[i].MatchEntries[ii].AsPathListVersion = types.Int64Value(0) } if !data.Sequences[i].MatchEntries[ii].CommunityListIds.IsNull() { - data.Sequences[i].MatchEntries[ii].CommunityListVersions = types.ListNull(types.StringType) + var elementsCommunityListVersions []attr.Value + var countCommunityListVersions int = 0 + if !(data.Sequences[i].MatchEntries[ii].CommunityListIds.IsNull() || data.Sequences[i].MatchEntries[ii].CommunityListIds.IsUnknown()) { + countCommunityListVersions = len(data.Sequences[i].MatchEntries[ii].CommunityListIds.Elements()) + } + if countCommunityListVersions > 0 { + elementsCommunityListVersions = make([]attr.Value, countCommunityListVersions) + for i := 0; i < countCommunityListVersions; i++ { + elementsCommunityListVersions[i] = types.StringValue("0") + } + data.Sequences[i].MatchEntries[ii].CommunityListVersions = types.ListValueMust(types.StringType, elementsCommunityListVersions) + } else { + data.Sequences[i].MatchEntries[ii].CommunityListVersions = types.ListNull(types.StringType) + } } if data.Sequences[i].MatchEntries[ii].ExpandedCommunityListId != types.StringNull() { data.Sequences[i].MatchEntries[ii].ExpandedCommunityListVersion = types.Int64Value(0) diff --git a/internal/provider/model_sdwan_vpn_membership_policy_definition.go b/internal/provider/model_sdwan_vpn_membership_policy_definition.go index 746b8470b..7b9b38133 100644 --- a/internal/provider/model_sdwan_vpn_membership_policy_definition.go +++ b/internal/provider/model_sdwan_vpn_membership_policy_definition.go @@ -23,6 +23,7 @@ import ( "fmt" "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/tidwall/gjson" "github.com/tidwall/sjson" @@ -191,7 +192,20 @@ func (data *VPNMembershipPolicyDefinition) processImport(ctx context.Context) { data.Sites[i].SiteListVersion = types.Int64Value(0) } if !data.Sites[i].VpnListIds.IsNull() { - data.Sites[i].VpnListVersions = types.ListNull(types.StringType) + var elementsVpnListVersions []attr.Value + var countVpnListVersions int = 0 + if !(data.Sites[i].VpnListIds.IsNull() || data.Sites[i].VpnListIds.IsUnknown()) { + countVpnListVersions = len(data.Sites[i].VpnListIds.Elements()) + } + if countVpnListVersions > 0 { + elementsVpnListVersions = make([]attr.Value, countVpnListVersions) + for i := 0; i < countVpnListVersions; i++ { + elementsVpnListVersions[i] = types.StringValue("0") + } + data.Sites[i].VpnListVersions = types.ListValueMust(types.StringType, elementsVpnListVersions) + } else { + data.Sites[i].VpnListVersions = types.ListNull(types.StringType) + } } } } diff --git a/internal/provider/resource_sdwan_configuration_group.go b/internal/provider/resource_sdwan_configuration_group.go index a775e54c1..5ca056d41 100644 --- a/internal/provider/resource_sdwan_configuration_group.go +++ b/internal/provider/resource_sdwan_configuration_group.go @@ -264,6 +264,8 @@ func (r *ConfigurationGroupResource) Create(ctx context.Context, req resource.Cr diags = resp.State.Set(ctx, &plan) resp.Diagnostics.Append(diags...) + + helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics) } func (r *ConfigurationGroupResource) Deploy(ctx context.Context, plan ConfigurationGroup, state *ConfigurationGroup, diag *diag.Diagnostics, deleteOnError bool) { @@ -350,6 +352,15 @@ func (r *ConfigurationGroupResource) Read(ctx context.Context, req resource.Read state.fromBodyConfigGroup(ctx, res) + imp, diags := helpers.IsFlagImporting(ctx, req) + if resp.Diagnostics.Append(diags...); resp.Diagnostics.HasError() { + return + } + + if imp { + state.processImport(ctx) + } + // Read config group device associations if value := res.Get("devices"); value.Exists() && len(value.Array()) > 0 { path := fmt.Sprintf("/v1/config-group/%v/device/associate/", state.Id.ValueString()) @@ -386,6 +397,8 @@ func (r *ConfigurationGroupResource) Read(ctx context.Context, req resource.Read diags = resp.State.Set(ctx, &state) resp.Diagnostics.Append(diags...) + + helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics) } func (r *ConfigurationGroupResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { diff --git a/internal/provider/resource_sdwan_policy_group.go b/internal/provider/resource_sdwan_policy_group.go index 645346006..2268548de 100644 --- a/internal/provider/resource_sdwan_policy_group.go +++ b/internal/provider/resource_sdwan_policy_group.go @@ -217,6 +217,8 @@ func (r *PolicyGroupResource) Create(ctx context.Context, req resource.CreateReq diags = resp.State.Set(ctx, &plan) resp.Diagnostics.Append(diags...) + + helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics) } func (r *PolicyGroupResource) Deploy(ctx context.Context, plan PolicyGroup, state *PolicyGroup, diag *diag.Diagnostics, deleteOnError bool) { @@ -303,6 +305,15 @@ func (r *PolicyGroupResource) Read(ctx context.Context, req resource.ReadRequest state.fromBodyPolicyGroup(ctx, res) + imp, diags := helpers.IsFlagImporting(ctx, req) + if resp.Diagnostics.Append(diags...); resp.Diagnostics.HasError() { + return + } + + if imp { + state.processImport(ctx) + } + // Read policy group device associations path := fmt.Sprintf("/v1/policy-group/%v/device/associate/", state.Id.ValueString()) res, err = r.client.Get(path) @@ -335,6 +346,8 @@ func (r *PolicyGroupResource) Read(ctx context.Context, req resource.ReadRequest diags = resp.State.Set(ctx, &state) resp.Diagnostics.Append(diags...) + + helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics) } func (r *PolicyGroupResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { From df413cfae88f79ba6e9cca33b388bd0c472e2814 Mon Sep 17 00:00:00 2001 From: Sean Conroy Date: Tue, 2 Sep 2025 14:40:15 +0100 Subject: [PATCH 2/4] fix route policy community list issue --- CHANGELOG.md | 4 + docs/data-sources/route_policy_definition.md | 7 +- docs/guides/changelog.md | 4 + docs/resources/route_policy_definition.md | 12 +- .../generic/route_policy_definition.yaml | 34 ++++- ...ta_source_sdwan_route_policy_definition.go | 18 ++- .../model_sdwan_route_policy_definition.go | 121 +++++++++++------- .../resource_sdwan_route_policy_definition.go | 25 +++- templates/guides/changelog.md.tmpl | 4 + 9 files changed, 168 insertions(+), 61 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8767a9a73..42dbe09ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.7.2 + +- Add `community` support to the `sdwan_route_policy_definition` resource and data source + ## 0.7.1 - Fix issue, where concurrent update of `localized_policy` resources fails with `Failed to update variables` error diff --git a/docs/data-sources/route_policy_definition.md b/docs/data-sources/route_policy_definition.md index 3a67d57e2..b0c3de7b0 100644 --- a/docs/data-sources/route_policy_definition.md +++ b/docs/data-sources/route_policy_definition.md @@ -76,11 +76,14 @@ Read-Only: Read-Only: +- `advanced_community_list_ids` (Set of String) Community list IDs +- `advanced_community_list_match_flag` (String) Community list match flag +- `advanced_community_list_versions` (List of String) Community list versions - `as_path_list_id` (String) AS path list ID - `as_path_list_version` (Number) AS path list version -- `community_list_ids` (Set of String) Community list IDs +- `community_list_id` (String) Community list ID - `community_list_match_flag` (String) Community list match flag -- `community_list_versions` (List of String) Community list versions +- `community_list_version` (Number) Community list version - `expanded_community_list_id` (String) Expanded community list ID - `expanded_community_list_variable` (String) Expanded community list variable - `expanded_community_list_version` (Number) Expanded community list version diff --git a/docs/guides/changelog.md b/docs/guides/changelog.md index 0f85324f4..788305428 100644 --- a/docs/guides/changelog.md +++ b/docs/guides/changelog.md @@ -7,6 +7,10 @@ description: |- # Changelog +## 0.7.2 + +- Add `community` support to the `sdwan_route_policy_definition` resource and data source + ## 0.7.1 - Fix issue, where concurrent update of `localized_policy` resources fails with `Failed to update variables` error diff --git a/docs/resources/route_policy_definition.md b/docs/resources/route_policy_definition.md index 27d177723..0511cdeb0 100644 --- a/docs/resources/route_policy_definition.md +++ b/docs/resources/route_policy_definition.md @@ -122,16 +122,20 @@ Optional: Required: - `type` (String) Type of match entry - - Choices: `address`, `asPath`, `advancedCommunity`, `expandedCommunity`, `expandedCommunityInline`, `extCommunity`, `localPreference`, `metric`, `nextHop`, `origin`, `peer`, `ompTag`, `ospfTag` + - Choices: `address`, `asPath`, `community`, `advancedCommunity`, `expandedCommunity`, `expandedCommunityInline`, `extCommunity`, `localPreference`, `metric`, `nextHop`, `origin`, `peer`, `ompTag`, `ospfTag` Optional: +- `advanced_community_list_ids` (Set of String) Community list IDs, Attribute conditional on `type` being equal to `advancedCommunity` +- `advanced_community_list_match_flag` (String) Community list match flag, Attribute conditional on `type` being equal to `advancedCommunity` + - Choices: `and`, `or`, `exact` +- `advanced_community_list_versions` (List of String) Community list versions - `as_path_list_id` (String) AS path list ID, Attribute conditional on `type` being equal to `asPath` - `as_path_list_version` (Number) AS path list version -- `community_list_ids` (Set of String) Community list IDs, Attribute conditional on `type` being equal to `advancedCommunity` -- `community_list_match_flag` (String) Community list match flag, Attribute conditional on `type` being equal to `advancedCommunity` +- `community_list_id` (String) Community list ID, Attribute conditional on `type` being equal to `community` +- `community_list_match_flag` (String) Community list match flag, Attribute conditional on `type` being equal to `community` - Choices: `and`, `or`, `exact` -- `community_list_versions` (List of String) Community list versions +- `community_list_version` (Number) Community list version - `expanded_community_list_id` (String) Expanded community list ID, Attribute conditional on `type` being equal to `expandedCommunity` - `expanded_community_list_variable` (String) Expanded community list variable, Attribute conditional on `type` being equal to `expandedCommunityInline` - `expanded_community_list_version` (Number) Expanded community list version diff --git a/gen/definitions/generic/route_policy_definition.yaml b/gen/definitions/generic/route_policy_definition.yaml index 49eb8d345..ca7e7e34b 100644 --- a/gen/definitions/generic/route_policy_definition.yaml +++ b/gen/definitions/generic/route_policy_definition.yaml @@ -79,6 +79,7 @@ attributes: [ address, asPath, + community, advancedCommunity, expandedCommunity, expandedCommunityInline, @@ -121,8 +122,34 @@ attributes: type: Version description: AS path list version exclude_test: true + + - model_name: ref + tf_name: community_list_id + conditional_attribute: + name: type + value: community + type: String + description: Community list ID + example: 2081c2f4-3f9f-4fee-8078-dcc8904e368d + exclude_test: true + - tf_name: community_list_version + tf_only: true + type: Version + description: Community list version + exclude_test: true + - model_name: matchFlag + tf_name: community_list_match_flag + conditional_attribute: + name: type + value: community + type: String + enum_values: [and, or, exact] + description: Community list match flag + example: and + exclude_test: true + - model_name: refs - tf_name: community_list_ids + tf_name: advanced_community_list_ids conditional_attribute: name: type value: advancedCommunity @@ -131,13 +158,13 @@ attributes: description: Community list IDs example: 2081c2f4-3f9f-4fee-8078-dcc8904e368d exclude_test: true - - tf_name: community_list_versions + - tf_name: advanced_community_list_versions tf_only: true type: Versions description: Community list versions exclude_test: true - model_name: matchFlag - tf_name: community_list_match_flag + tf_name: advanced_community_list_match_flag conditional_attribute: name: type value: advancedCommunity @@ -146,6 +173,7 @@ attributes: description: Community list match flag example: and exclude_test: true + - model_name: ref tf_name: expanded_community_list_id conditional_attribute: diff --git a/internal/provider/data_source_sdwan_route_policy_definition.go b/internal/provider/data_source_sdwan_route_policy_definition.go index 77d84c7b0..09dbacd7b 100644 --- a/internal/provider/data_source_sdwan_route_policy_definition.go +++ b/internal/provider/data_source_sdwan_route_policy_definition.go @@ -128,17 +128,29 @@ func (d *RoutePolicyDefinitionDataSource) Schema(ctx context.Context, req dataso MarkdownDescription: "AS path list version", Computed: true, }, - "community_list_ids": schema.SetAttribute{ + "community_list_id": schema.StringAttribute{ + MarkdownDescription: "Community list ID", + Computed: true, + }, + "community_list_version": schema.Int64Attribute{ + MarkdownDescription: "Community list version", + Computed: true, + }, + "community_list_match_flag": schema.StringAttribute{ + MarkdownDescription: "Community list match flag", + Computed: true, + }, + "advanced_community_list_ids": schema.SetAttribute{ MarkdownDescription: "Community list IDs", ElementType: types.StringType, Computed: true, }, - "community_list_versions": schema.ListAttribute{ + "advanced_community_list_versions": schema.ListAttribute{ MarkdownDescription: "Community list versions", ElementType: types.StringType, Computed: true, }, - "community_list_match_flag": schema.StringAttribute{ + "advanced_community_list_match_flag": schema.StringAttribute{ MarkdownDescription: "Community list match flag", Computed: true, }, diff --git a/internal/provider/model_sdwan_route_policy_definition.go b/internal/provider/model_sdwan_route_policy_definition.go index c77717ffe..88d2edee8 100644 --- a/internal/provider/model_sdwan_route_policy_definition.go +++ b/internal/provider/model_sdwan_route_policy_definition.go @@ -52,27 +52,30 @@ type RoutePolicyDefinitionSequences struct { } type RoutePolicyDefinitionSequencesMatchEntries struct { - Type types.String `tfsdk:"type"` - PrefixListId types.String `tfsdk:"prefix_list_id"` - PrefixListVersion types.Int64 `tfsdk:"prefix_list_version"` - AsPathListId types.String `tfsdk:"as_path_list_id"` - AsPathListVersion types.Int64 `tfsdk:"as_path_list_version"` - CommunityListIds types.Set `tfsdk:"community_list_ids"` - CommunityListVersions types.List `tfsdk:"community_list_versions"` - CommunityListMatchFlag types.String `tfsdk:"community_list_match_flag"` - ExpandedCommunityListId types.String `tfsdk:"expanded_community_list_id"` - ExpandedCommunityListVariable types.String `tfsdk:"expanded_community_list_variable"` - ExpandedCommunityListVersion types.Int64 `tfsdk:"expanded_community_list_version"` - ExtendedCommunityListId types.String `tfsdk:"extended_community_list_id"` - ExtendedCommunityListVersion types.Int64 `tfsdk:"extended_community_list_version"` - LocalPreference types.Int64 `tfsdk:"local_preference"` - Metric types.Int64 `tfsdk:"metric"` - NextHopPrefixListId types.String `tfsdk:"next_hop_prefix_list_id"` - NextHopPrefixListVersion types.Int64 `tfsdk:"next_hop_prefix_list_version"` - Origin types.String `tfsdk:"origin"` - Peer types.String `tfsdk:"peer"` - OmpTag types.Int64 `tfsdk:"omp_tag"` - OspfTag types.Int64 `tfsdk:"ospf_tag"` + Type types.String `tfsdk:"type"` + PrefixListId types.String `tfsdk:"prefix_list_id"` + PrefixListVersion types.Int64 `tfsdk:"prefix_list_version"` + AsPathListId types.String `tfsdk:"as_path_list_id"` + AsPathListVersion types.Int64 `tfsdk:"as_path_list_version"` + CommunityListId types.String `tfsdk:"community_list_id"` + CommunityListVersion types.Int64 `tfsdk:"community_list_version"` + CommunityListMatchFlag types.String `tfsdk:"community_list_match_flag"` + AdvancedCommunityListIds types.Set `tfsdk:"advanced_community_list_ids"` + AdvancedCommunityListVersions types.List `tfsdk:"advanced_community_list_versions"` + AdvancedCommunityListMatchFlag types.String `tfsdk:"advanced_community_list_match_flag"` + ExpandedCommunityListId types.String `tfsdk:"expanded_community_list_id"` + ExpandedCommunityListVariable types.String `tfsdk:"expanded_community_list_variable"` + ExpandedCommunityListVersion types.Int64 `tfsdk:"expanded_community_list_version"` + ExtendedCommunityListId types.String `tfsdk:"extended_community_list_id"` + ExtendedCommunityListVersion types.Int64 `tfsdk:"extended_community_list_version"` + LocalPreference types.Int64 `tfsdk:"local_preference"` + Metric types.Int64 `tfsdk:"metric"` + NextHopPrefixListId types.String `tfsdk:"next_hop_prefix_list_id"` + NextHopPrefixListVersion types.Int64 `tfsdk:"next_hop_prefix_list_version"` + Origin types.String `tfsdk:"origin"` + Peer types.String `tfsdk:"peer"` + OmpTag types.Int64 `tfsdk:"omp_tag"` + OspfTag types.Int64 `tfsdk:"ospf_tag"` } type RoutePolicyDefinitionSequencesActionEntries struct { Type types.String `tfsdk:"type"` @@ -151,13 +154,19 @@ func (data RoutePolicyDefinition) toBody(ctx context.Context) string { if !childItem.AsPathListId.IsNull() && childItem.Type.ValueString() == "asPath" { itemChildBody, _ = sjson.Set(itemChildBody, "ref", childItem.AsPathListId.ValueString()) } - if !childItem.CommunityListIds.IsNull() && childItem.Type.ValueString() == "advancedCommunity" { + if !childItem.CommunityListId.IsNull() && childItem.Type.ValueString() == "community" { + itemChildBody, _ = sjson.Set(itemChildBody, "ref", childItem.CommunityListId.ValueString()) + } + if !childItem.CommunityListMatchFlag.IsNull() && childItem.Type.ValueString() == "community" { + itemChildBody, _ = sjson.Set(itemChildBody, "matchFlag", childItem.CommunityListMatchFlag.ValueString()) + } + if !childItem.AdvancedCommunityListIds.IsNull() && childItem.Type.ValueString() == "advancedCommunity" { var values []string - childItem.CommunityListIds.ElementsAs(ctx, &values, false) + childItem.AdvancedCommunityListIds.ElementsAs(ctx, &values, false) itemChildBody, _ = sjson.Set(itemChildBody, "refs", values) } - if !childItem.CommunityListMatchFlag.IsNull() && childItem.Type.ValueString() == "advancedCommunity" { - itemChildBody, _ = sjson.Set(itemChildBody, "matchFlag", childItem.CommunityListMatchFlag.ValueString()) + if !childItem.AdvancedCommunityListMatchFlag.IsNull() && childItem.Type.ValueString() == "advancedCommunity" { + itemChildBody, _ = sjson.Set(itemChildBody, "matchFlag", childItem.AdvancedCommunityListMatchFlag.ValueString()) } if !childItem.ExpandedCommunityListId.IsNull() && childItem.Type.ValueString() == "expandedCommunity" { itemChildBody, _ = sjson.Set(itemChildBody, "ref", childItem.ExpandedCommunityListId.ValueString()) @@ -333,16 +342,26 @@ func (data *RoutePolicyDefinition) fromBody(ctx context.Context, res gjson.Resul } else { cItem.AsPathListId = types.StringNull() } - if ccValue := cv.Get("refs"); ccValue.Exists() && cItem.Type.ValueString() == "advancedCommunity" { - cItem.CommunityListIds = helpers.GetStringSet(ccValue.Array()) + if ccValue := cv.Get("ref"); ccValue.Exists() && cItem.Type.ValueString() == "community" { + cItem.CommunityListId = types.StringValue(ccValue.String()) } else { - cItem.CommunityListIds = types.SetNull(types.StringType) + cItem.CommunityListId = types.StringNull() } - if ccValue := cv.Get("matchFlag"); ccValue.Exists() && cItem.Type.ValueString() == "advancedCommunity" { + if ccValue := cv.Get("matchFlag"); ccValue.Exists() && cItem.Type.ValueString() == "community" { cItem.CommunityListMatchFlag = types.StringValue(ccValue.String()) } else { cItem.CommunityListMatchFlag = types.StringNull() } + if ccValue := cv.Get("refs"); ccValue.Exists() && cItem.Type.ValueString() == "advancedCommunity" { + cItem.AdvancedCommunityListIds = helpers.GetStringSet(ccValue.Array()) + } else { + cItem.AdvancedCommunityListIds = types.SetNull(types.StringType) + } + if ccValue := cv.Get("matchFlag"); ccValue.Exists() && cItem.Type.ValueString() == "advancedCommunity" { + cItem.AdvancedCommunityListMatchFlag = types.StringValue(ccValue.String()) + } else { + cItem.AdvancedCommunityListMatchFlag = types.StringNull() + } if ccValue := cv.Get("ref"); ccValue.Exists() && cItem.Type.ValueString() == "expandedCommunity" { cItem.ExpandedCommunityListId = types.StringValue(ccValue.String()) } else { @@ -565,12 +584,18 @@ func (data *RoutePolicyDefinition) hasChanges(ctx context.Context, state *RouteP if !data.Sequences[i].MatchEntries[ii].AsPathListId.Equal(state.Sequences[i].MatchEntries[ii].AsPathListId) { hasChanges = true } - if !data.Sequences[i].MatchEntries[ii].CommunityListIds.Equal(state.Sequences[i].MatchEntries[ii].CommunityListIds) { + if !data.Sequences[i].MatchEntries[ii].CommunityListId.Equal(state.Sequences[i].MatchEntries[ii].CommunityListId) { hasChanges = true } if !data.Sequences[i].MatchEntries[ii].CommunityListMatchFlag.Equal(state.Sequences[i].MatchEntries[ii].CommunityListMatchFlag) { hasChanges = true } + if !data.Sequences[i].MatchEntries[ii].AdvancedCommunityListIds.Equal(state.Sequences[i].MatchEntries[ii].AdvancedCommunityListIds) { + hasChanges = true + } + if !data.Sequences[i].MatchEntries[ii].AdvancedCommunityListMatchFlag.Equal(state.Sequences[i].MatchEntries[ii].AdvancedCommunityListMatchFlag) { + hasChanges = true + } if !data.Sequences[i].MatchEntries[ii].ExpandedCommunityListId.Equal(state.Sequences[i].MatchEntries[ii].ExpandedCommunityListId) { hasChanges = true } @@ -705,10 +730,15 @@ func (data *RoutePolicyDefinition) updateVersions(ctx context.Context, state *Ro } else { data.Sequences[i].MatchEntries[ii].AsPathListVersion = types.Int64Null() } - if cStateIndex > -1 && !state.Sequences[stateIndex].MatchEntries[cStateIndex].CommunityListVersions.IsNull() { - data.Sequences[i].MatchEntries[ii].CommunityListVersions = state.Sequences[stateIndex].MatchEntries[cStateIndex].CommunityListVersions + if cStateIndex > -1 { + data.Sequences[i].MatchEntries[ii].CommunityListVersion = state.Sequences[stateIndex].MatchEntries[cStateIndex].CommunityListVersion } else { - data.Sequences[i].MatchEntries[ii].CommunityListVersions = types.ListNull(types.StringType) + data.Sequences[i].MatchEntries[ii].CommunityListVersion = types.Int64Null() + } + if cStateIndex > -1 && !state.Sequences[stateIndex].MatchEntries[cStateIndex].AdvancedCommunityListVersions.IsNull() { + data.Sequences[i].MatchEntries[ii].AdvancedCommunityListVersions = state.Sequences[stateIndex].MatchEntries[cStateIndex].AdvancedCommunityListVersions + } else { + data.Sequences[i].MatchEntries[ii].AdvancedCommunityListVersions = types.ListNull(types.StringType) } if cStateIndex > -1 { data.Sequences[i].MatchEntries[ii].ExpandedCommunityListVersion = state.Sequences[stateIndex].MatchEntries[cStateIndex].ExpandedCommunityListVersion @@ -743,20 +773,23 @@ func (data *RoutePolicyDefinition) processImport(ctx context.Context) { if data.Sequences[i].MatchEntries[ii].AsPathListId != types.StringNull() { data.Sequences[i].MatchEntries[ii].AsPathListVersion = types.Int64Value(0) } - if !data.Sequences[i].MatchEntries[ii].CommunityListIds.IsNull() { - var elementsCommunityListVersions []attr.Value - var countCommunityListVersions int = 0 - if !(data.Sequences[i].MatchEntries[ii].CommunityListIds.IsNull() || data.Sequences[i].MatchEntries[ii].CommunityListIds.IsUnknown()) { - countCommunityListVersions = len(data.Sequences[i].MatchEntries[ii].CommunityListIds.Elements()) + if data.Sequences[i].MatchEntries[ii].CommunityListId != types.StringNull() { + data.Sequences[i].MatchEntries[ii].CommunityListVersion = types.Int64Value(0) + } + if !data.Sequences[i].MatchEntries[ii].AdvancedCommunityListIds.IsNull() { + var elementsAdvancedCommunityListVersions []attr.Value + var countAdvancedCommunityListVersions int = 0 + if !(data.Sequences[i].MatchEntries[ii].AdvancedCommunityListIds.IsNull() || data.Sequences[i].MatchEntries[ii].AdvancedCommunityListIds.IsUnknown()) { + countAdvancedCommunityListVersions = len(data.Sequences[i].MatchEntries[ii].AdvancedCommunityListIds.Elements()) } - if countCommunityListVersions > 0 { - elementsCommunityListVersions = make([]attr.Value, countCommunityListVersions) - for i := 0; i < countCommunityListVersions; i++ { - elementsCommunityListVersions[i] = types.StringValue("0") + if countAdvancedCommunityListVersions > 0 { + elementsAdvancedCommunityListVersions = make([]attr.Value, countAdvancedCommunityListVersions) + for i := 0; i < countAdvancedCommunityListVersions; i++ { + elementsAdvancedCommunityListVersions[i] = types.StringValue("0") } - data.Sequences[i].MatchEntries[ii].CommunityListVersions = types.ListValueMust(types.StringType, elementsCommunityListVersions) + data.Sequences[i].MatchEntries[ii].AdvancedCommunityListVersions = types.ListValueMust(types.StringType, elementsAdvancedCommunityListVersions) } else { - data.Sequences[i].MatchEntries[ii].CommunityListVersions = types.ListNull(types.StringType) + data.Sequences[i].MatchEntries[ii].AdvancedCommunityListVersions = types.ListNull(types.StringType) } } if data.Sequences[i].MatchEntries[ii].ExpandedCommunityListId != types.StringNull() { diff --git a/internal/provider/resource_sdwan_route_policy_definition.go b/internal/provider/resource_sdwan_route_policy_definition.go index e85508644..c972ada34 100644 --- a/internal/provider/resource_sdwan_route_policy_definition.go +++ b/internal/provider/resource_sdwan_route_policy_definition.go @@ -135,10 +135,10 @@ func (r *RoutePolicyDefinitionResource) Schema(ctx context.Context, req resource NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "type": schema.StringAttribute{ - MarkdownDescription: helpers.NewAttributeDescription("Type of match entry").AddStringEnumDescription("address", "asPath", "advancedCommunity", "expandedCommunity", "expandedCommunityInline", "extCommunity", "localPreference", "metric", "nextHop", "origin", "peer", "ompTag", "ospfTag").String, + MarkdownDescription: helpers.NewAttributeDescription("Type of match entry").AddStringEnumDescription("address", "asPath", "community", "advancedCommunity", "expandedCommunity", "expandedCommunityInline", "extCommunity", "localPreference", "metric", "nextHop", "origin", "peer", "ompTag", "ospfTag").String, Required: true, Validators: []validator.String{ - stringvalidator.OneOf("address", "asPath", "advancedCommunity", "expandedCommunity", "expandedCommunityInline", "extCommunity", "localPreference", "metric", "nextHop", "origin", "peer", "ompTag", "ospfTag"), + stringvalidator.OneOf("address", "asPath", "community", "advancedCommunity", "expandedCommunity", "expandedCommunityInline", "extCommunity", "localPreference", "metric", "nextHop", "origin", "peer", "ompTag", "ospfTag"), }, }, "prefix_list_id": schema.StringAttribute{ @@ -157,17 +157,32 @@ func (r *RoutePolicyDefinitionResource) Schema(ctx context.Context, req resource MarkdownDescription: helpers.NewAttributeDescription("AS path list version").String, Optional: true, }, - "community_list_ids": schema.SetAttribute{ + "community_list_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Community list ID, Attribute conditional on `type` being equal to `community`").String, + Optional: true, + }, + "community_list_version": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("Community list version").String, + Optional: true, + }, + "community_list_match_flag": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Community list match flag, Attribute conditional on `type` being equal to `community`").AddStringEnumDescription("and", "or", "exact").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.OneOf("and", "or", "exact"), + }, + }, + "advanced_community_list_ids": schema.SetAttribute{ MarkdownDescription: helpers.NewAttributeDescription("Community list IDs, Attribute conditional on `type` being equal to `advancedCommunity`").String, ElementType: types.StringType, Optional: true, }, - "community_list_versions": schema.ListAttribute{ + "advanced_community_list_versions": schema.ListAttribute{ MarkdownDescription: helpers.NewAttributeDescription("Community list versions").String, ElementType: types.StringType, Optional: true, }, - "community_list_match_flag": schema.StringAttribute{ + "advanced_community_list_match_flag": schema.StringAttribute{ MarkdownDescription: helpers.NewAttributeDescription("Community list match flag, Attribute conditional on `type` being equal to `advancedCommunity`").AddStringEnumDescription("and", "or", "exact").String, Optional: true, Validators: []validator.String{ diff --git a/templates/guides/changelog.md.tmpl b/templates/guides/changelog.md.tmpl index 0f85324f4..788305428 100644 --- a/templates/guides/changelog.md.tmpl +++ b/templates/guides/changelog.md.tmpl @@ -7,6 +7,10 @@ description: |- # Changelog +## 0.7.2 + +- Add `community` support to the `sdwan_route_policy_definition` resource and data source + ## 0.7.1 - Fix issue, where concurrent update of `localized_policy` resources fails with `Failed to update variables` error From 9f77e78954708416d3b14bdd1eb6b72cf54ee4a2 Mon Sep 17 00:00:00 2001 From: Sean Conroy Date: Tue, 2 Sep 2025 15:31:11 +0100 Subject: [PATCH 3/4] Rename parameters --- docs/data-sources/route_policy_definition.md | 6 +- docs/resources/route_policy_definition.md | 10 +- .../generic/route_policy_definition.yaml | 10 +- ...ta_source_sdwan_route_policy_definition.go | 8 +- .../model_sdwan_route_policy_definition.go | 106 +++++++++--------- .../resource_sdwan_route_policy_definition.go | 8 +- 6 files changed, 73 insertions(+), 75 deletions(-) diff --git a/docs/data-sources/route_policy_definition.md b/docs/data-sources/route_policy_definition.md index b0c3de7b0..f4bc5b7f3 100644 --- a/docs/data-sources/route_policy_definition.md +++ b/docs/data-sources/route_policy_definition.md @@ -76,14 +76,14 @@ Read-Only: Read-Only: -- `advanced_community_list_ids` (Set of String) Community list IDs -- `advanced_community_list_match_flag` (String) Community list match flag -- `advanced_community_list_versions` (List of String) Community list versions - `as_path_list_id` (String) AS path list ID - `as_path_list_version` (Number) AS path list version - `community_list_id` (String) Community list ID +- `community_list_ids` (Set of String) Community list IDs - `community_list_match_flag` (String) Community list match flag +- `community_list_match_flag_single` (String) Community list match flag - `community_list_version` (Number) Community list version +- `community_list_versions` (List of String) Community list versions - `expanded_community_list_id` (String) Expanded community list ID - `expanded_community_list_variable` (String) Expanded community list variable - `expanded_community_list_version` (Number) Expanded community list version diff --git a/docs/resources/route_policy_definition.md b/docs/resources/route_policy_definition.md index 0511cdeb0..b3b212144 100644 --- a/docs/resources/route_policy_definition.md +++ b/docs/resources/route_policy_definition.md @@ -126,16 +126,16 @@ Required: Optional: -- `advanced_community_list_ids` (Set of String) Community list IDs, Attribute conditional on `type` being equal to `advancedCommunity` -- `advanced_community_list_match_flag` (String) Community list match flag, Attribute conditional on `type` being equal to `advancedCommunity` - - Choices: `and`, `or`, `exact` -- `advanced_community_list_versions` (List of String) Community list versions - `as_path_list_id` (String) AS path list ID, Attribute conditional on `type` being equal to `asPath` - `as_path_list_version` (Number) AS path list version - `community_list_id` (String) Community list ID, Attribute conditional on `type` being equal to `community` -- `community_list_match_flag` (String) Community list match flag, Attribute conditional on `type` being equal to `community` +- `community_list_ids` (Set of String) Community list IDs, Attribute conditional on `type` being equal to `advancedCommunity` +- `community_list_match_flag` (String) Community list match flag, Attribute conditional on `type` being equal to `advancedCommunity` + - Choices: `and`, `or`, `exact` +- `community_list_match_flag_single` (String) Community list match flag, Attribute conditional on `type` being equal to `community` - Choices: `and`, `or`, `exact` - `community_list_version` (Number) Community list version +- `community_list_versions` (List of String) Community list versions - `expanded_community_list_id` (String) Expanded community list ID, Attribute conditional on `type` being equal to `expandedCommunity` - `expanded_community_list_variable` (String) Expanded community list variable, Attribute conditional on `type` being equal to `expandedCommunityInline` - `expanded_community_list_version` (Number) Expanded community list version diff --git a/gen/definitions/generic/route_policy_definition.yaml b/gen/definitions/generic/route_policy_definition.yaml index ca7e7e34b..a5e1458de 100644 --- a/gen/definitions/generic/route_policy_definition.yaml +++ b/gen/definitions/generic/route_policy_definition.yaml @@ -138,7 +138,7 @@ attributes: description: Community list version exclude_test: true - model_name: matchFlag - tf_name: community_list_match_flag + tf_name: community_list_match_flag_single conditional_attribute: name: type value: community @@ -147,9 +147,8 @@ attributes: description: Community list match flag example: and exclude_test: true - - model_name: refs - tf_name: advanced_community_list_ids + tf_name: community_list_ids conditional_attribute: name: type value: advancedCommunity @@ -158,13 +157,13 @@ attributes: description: Community list IDs example: 2081c2f4-3f9f-4fee-8078-dcc8904e368d exclude_test: true - - tf_name: advanced_community_list_versions + - tf_name: community_list_versions tf_only: true type: Versions description: Community list versions exclude_test: true - model_name: matchFlag - tf_name: advanced_community_list_match_flag + tf_name: community_list_match_flag conditional_attribute: name: type value: advancedCommunity @@ -173,7 +172,6 @@ attributes: description: Community list match flag example: and exclude_test: true - - model_name: ref tf_name: expanded_community_list_id conditional_attribute: diff --git a/internal/provider/data_source_sdwan_route_policy_definition.go b/internal/provider/data_source_sdwan_route_policy_definition.go index 09dbacd7b..9eaa57f9e 100644 --- a/internal/provider/data_source_sdwan_route_policy_definition.go +++ b/internal/provider/data_source_sdwan_route_policy_definition.go @@ -136,21 +136,21 @@ func (d *RoutePolicyDefinitionDataSource) Schema(ctx context.Context, req dataso MarkdownDescription: "Community list version", Computed: true, }, - "community_list_match_flag": schema.StringAttribute{ + "community_list_match_flag_single": schema.StringAttribute{ MarkdownDescription: "Community list match flag", Computed: true, }, - "advanced_community_list_ids": schema.SetAttribute{ + "community_list_ids": schema.SetAttribute{ MarkdownDescription: "Community list IDs", ElementType: types.StringType, Computed: true, }, - "advanced_community_list_versions": schema.ListAttribute{ + "community_list_versions": schema.ListAttribute{ MarkdownDescription: "Community list versions", ElementType: types.StringType, Computed: true, }, - "advanced_community_list_match_flag": schema.StringAttribute{ + "community_list_match_flag": schema.StringAttribute{ MarkdownDescription: "Community list match flag", Computed: true, }, diff --git a/internal/provider/model_sdwan_route_policy_definition.go b/internal/provider/model_sdwan_route_policy_definition.go index 88d2edee8..169fb73ba 100644 --- a/internal/provider/model_sdwan_route_policy_definition.go +++ b/internal/provider/model_sdwan_route_policy_definition.go @@ -52,30 +52,30 @@ type RoutePolicyDefinitionSequences struct { } type RoutePolicyDefinitionSequencesMatchEntries struct { - Type types.String `tfsdk:"type"` - PrefixListId types.String `tfsdk:"prefix_list_id"` - PrefixListVersion types.Int64 `tfsdk:"prefix_list_version"` - AsPathListId types.String `tfsdk:"as_path_list_id"` - AsPathListVersion types.Int64 `tfsdk:"as_path_list_version"` - CommunityListId types.String `tfsdk:"community_list_id"` - CommunityListVersion types.Int64 `tfsdk:"community_list_version"` - CommunityListMatchFlag types.String `tfsdk:"community_list_match_flag"` - AdvancedCommunityListIds types.Set `tfsdk:"advanced_community_list_ids"` - AdvancedCommunityListVersions types.List `tfsdk:"advanced_community_list_versions"` - AdvancedCommunityListMatchFlag types.String `tfsdk:"advanced_community_list_match_flag"` - ExpandedCommunityListId types.String `tfsdk:"expanded_community_list_id"` - ExpandedCommunityListVariable types.String `tfsdk:"expanded_community_list_variable"` - ExpandedCommunityListVersion types.Int64 `tfsdk:"expanded_community_list_version"` - ExtendedCommunityListId types.String `tfsdk:"extended_community_list_id"` - ExtendedCommunityListVersion types.Int64 `tfsdk:"extended_community_list_version"` - LocalPreference types.Int64 `tfsdk:"local_preference"` - Metric types.Int64 `tfsdk:"metric"` - NextHopPrefixListId types.String `tfsdk:"next_hop_prefix_list_id"` - NextHopPrefixListVersion types.Int64 `tfsdk:"next_hop_prefix_list_version"` - Origin types.String `tfsdk:"origin"` - Peer types.String `tfsdk:"peer"` - OmpTag types.Int64 `tfsdk:"omp_tag"` - OspfTag types.Int64 `tfsdk:"ospf_tag"` + Type types.String `tfsdk:"type"` + PrefixListId types.String `tfsdk:"prefix_list_id"` + PrefixListVersion types.Int64 `tfsdk:"prefix_list_version"` + AsPathListId types.String `tfsdk:"as_path_list_id"` + AsPathListVersion types.Int64 `tfsdk:"as_path_list_version"` + CommunityListId types.String `tfsdk:"community_list_id"` + CommunityListVersion types.Int64 `tfsdk:"community_list_version"` + CommunityListMatchFlagSingle types.String `tfsdk:"community_list_match_flag_single"` + CommunityListIds types.Set `tfsdk:"community_list_ids"` + CommunityListVersions types.List `tfsdk:"community_list_versions"` + CommunityListMatchFlag types.String `tfsdk:"community_list_match_flag"` + ExpandedCommunityListId types.String `tfsdk:"expanded_community_list_id"` + ExpandedCommunityListVariable types.String `tfsdk:"expanded_community_list_variable"` + ExpandedCommunityListVersion types.Int64 `tfsdk:"expanded_community_list_version"` + ExtendedCommunityListId types.String `tfsdk:"extended_community_list_id"` + ExtendedCommunityListVersion types.Int64 `tfsdk:"extended_community_list_version"` + LocalPreference types.Int64 `tfsdk:"local_preference"` + Metric types.Int64 `tfsdk:"metric"` + NextHopPrefixListId types.String `tfsdk:"next_hop_prefix_list_id"` + NextHopPrefixListVersion types.Int64 `tfsdk:"next_hop_prefix_list_version"` + Origin types.String `tfsdk:"origin"` + Peer types.String `tfsdk:"peer"` + OmpTag types.Int64 `tfsdk:"omp_tag"` + OspfTag types.Int64 `tfsdk:"ospf_tag"` } type RoutePolicyDefinitionSequencesActionEntries struct { Type types.String `tfsdk:"type"` @@ -157,16 +157,16 @@ func (data RoutePolicyDefinition) toBody(ctx context.Context) string { if !childItem.CommunityListId.IsNull() && childItem.Type.ValueString() == "community" { itemChildBody, _ = sjson.Set(itemChildBody, "ref", childItem.CommunityListId.ValueString()) } - if !childItem.CommunityListMatchFlag.IsNull() && childItem.Type.ValueString() == "community" { - itemChildBody, _ = sjson.Set(itemChildBody, "matchFlag", childItem.CommunityListMatchFlag.ValueString()) + if !childItem.CommunityListMatchFlagSingle.IsNull() && childItem.Type.ValueString() == "community" { + itemChildBody, _ = sjson.Set(itemChildBody, "matchFlag", childItem.CommunityListMatchFlagSingle.ValueString()) } - if !childItem.AdvancedCommunityListIds.IsNull() && childItem.Type.ValueString() == "advancedCommunity" { + if !childItem.CommunityListIds.IsNull() && childItem.Type.ValueString() == "advancedCommunity" { var values []string - childItem.AdvancedCommunityListIds.ElementsAs(ctx, &values, false) + childItem.CommunityListIds.ElementsAs(ctx, &values, false) itemChildBody, _ = sjson.Set(itemChildBody, "refs", values) } - if !childItem.AdvancedCommunityListMatchFlag.IsNull() && childItem.Type.ValueString() == "advancedCommunity" { - itemChildBody, _ = sjson.Set(itemChildBody, "matchFlag", childItem.AdvancedCommunityListMatchFlag.ValueString()) + if !childItem.CommunityListMatchFlag.IsNull() && childItem.Type.ValueString() == "advancedCommunity" { + itemChildBody, _ = sjson.Set(itemChildBody, "matchFlag", childItem.CommunityListMatchFlag.ValueString()) } if !childItem.ExpandedCommunityListId.IsNull() && childItem.Type.ValueString() == "expandedCommunity" { itemChildBody, _ = sjson.Set(itemChildBody, "ref", childItem.ExpandedCommunityListId.ValueString()) @@ -348,19 +348,19 @@ func (data *RoutePolicyDefinition) fromBody(ctx context.Context, res gjson.Resul cItem.CommunityListId = types.StringNull() } if ccValue := cv.Get("matchFlag"); ccValue.Exists() && cItem.Type.ValueString() == "community" { - cItem.CommunityListMatchFlag = types.StringValue(ccValue.String()) + cItem.CommunityListMatchFlagSingle = types.StringValue(ccValue.String()) } else { - cItem.CommunityListMatchFlag = types.StringNull() + cItem.CommunityListMatchFlagSingle = types.StringNull() } if ccValue := cv.Get("refs"); ccValue.Exists() && cItem.Type.ValueString() == "advancedCommunity" { - cItem.AdvancedCommunityListIds = helpers.GetStringSet(ccValue.Array()) + cItem.CommunityListIds = helpers.GetStringSet(ccValue.Array()) } else { - cItem.AdvancedCommunityListIds = types.SetNull(types.StringType) + cItem.CommunityListIds = types.SetNull(types.StringType) } if ccValue := cv.Get("matchFlag"); ccValue.Exists() && cItem.Type.ValueString() == "advancedCommunity" { - cItem.AdvancedCommunityListMatchFlag = types.StringValue(ccValue.String()) + cItem.CommunityListMatchFlag = types.StringValue(ccValue.String()) } else { - cItem.AdvancedCommunityListMatchFlag = types.StringNull() + cItem.CommunityListMatchFlag = types.StringNull() } if ccValue := cv.Get("ref"); ccValue.Exists() && cItem.Type.ValueString() == "expandedCommunity" { cItem.ExpandedCommunityListId = types.StringValue(ccValue.String()) @@ -587,13 +587,13 @@ func (data *RoutePolicyDefinition) hasChanges(ctx context.Context, state *RouteP if !data.Sequences[i].MatchEntries[ii].CommunityListId.Equal(state.Sequences[i].MatchEntries[ii].CommunityListId) { hasChanges = true } - if !data.Sequences[i].MatchEntries[ii].CommunityListMatchFlag.Equal(state.Sequences[i].MatchEntries[ii].CommunityListMatchFlag) { + if !data.Sequences[i].MatchEntries[ii].CommunityListMatchFlagSingle.Equal(state.Sequences[i].MatchEntries[ii].CommunityListMatchFlagSingle) { hasChanges = true } - if !data.Sequences[i].MatchEntries[ii].AdvancedCommunityListIds.Equal(state.Sequences[i].MatchEntries[ii].AdvancedCommunityListIds) { + if !data.Sequences[i].MatchEntries[ii].CommunityListIds.Equal(state.Sequences[i].MatchEntries[ii].CommunityListIds) { hasChanges = true } - if !data.Sequences[i].MatchEntries[ii].AdvancedCommunityListMatchFlag.Equal(state.Sequences[i].MatchEntries[ii].AdvancedCommunityListMatchFlag) { + if !data.Sequences[i].MatchEntries[ii].CommunityListMatchFlag.Equal(state.Sequences[i].MatchEntries[ii].CommunityListMatchFlag) { hasChanges = true } if !data.Sequences[i].MatchEntries[ii].ExpandedCommunityListId.Equal(state.Sequences[i].MatchEntries[ii].ExpandedCommunityListId) { @@ -735,10 +735,10 @@ func (data *RoutePolicyDefinition) updateVersions(ctx context.Context, state *Ro } else { data.Sequences[i].MatchEntries[ii].CommunityListVersion = types.Int64Null() } - if cStateIndex > -1 && !state.Sequences[stateIndex].MatchEntries[cStateIndex].AdvancedCommunityListVersions.IsNull() { - data.Sequences[i].MatchEntries[ii].AdvancedCommunityListVersions = state.Sequences[stateIndex].MatchEntries[cStateIndex].AdvancedCommunityListVersions + if cStateIndex > -1 && !state.Sequences[stateIndex].MatchEntries[cStateIndex].CommunityListVersions.IsNull() { + data.Sequences[i].MatchEntries[ii].CommunityListVersions = state.Sequences[stateIndex].MatchEntries[cStateIndex].CommunityListVersions } else { - data.Sequences[i].MatchEntries[ii].AdvancedCommunityListVersions = types.ListNull(types.StringType) + data.Sequences[i].MatchEntries[ii].CommunityListVersions = types.ListNull(types.StringType) } if cStateIndex > -1 { data.Sequences[i].MatchEntries[ii].ExpandedCommunityListVersion = state.Sequences[stateIndex].MatchEntries[cStateIndex].ExpandedCommunityListVersion @@ -776,20 +776,20 @@ func (data *RoutePolicyDefinition) processImport(ctx context.Context) { if data.Sequences[i].MatchEntries[ii].CommunityListId != types.StringNull() { data.Sequences[i].MatchEntries[ii].CommunityListVersion = types.Int64Value(0) } - if !data.Sequences[i].MatchEntries[ii].AdvancedCommunityListIds.IsNull() { - var elementsAdvancedCommunityListVersions []attr.Value - var countAdvancedCommunityListVersions int = 0 - if !(data.Sequences[i].MatchEntries[ii].AdvancedCommunityListIds.IsNull() || data.Sequences[i].MatchEntries[ii].AdvancedCommunityListIds.IsUnknown()) { - countAdvancedCommunityListVersions = len(data.Sequences[i].MatchEntries[ii].AdvancedCommunityListIds.Elements()) + if !data.Sequences[i].MatchEntries[ii].CommunityListIds.IsNull() { + var elementsCommunityListVersions []attr.Value + var countCommunityListVersions int = 0 + if !(data.Sequences[i].MatchEntries[ii].CommunityListIds.IsNull() || data.Sequences[i].MatchEntries[ii].CommunityListIds.IsUnknown()) { + countCommunityListVersions = len(data.Sequences[i].MatchEntries[ii].CommunityListIds.Elements()) } - if countAdvancedCommunityListVersions > 0 { - elementsAdvancedCommunityListVersions = make([]attr.Value, countAdvancedCommunityListVersions) - for i := 0; i < countAdvancedCommunityListVersions; i++ { - elementsAdvancedCommunityListVersions[i] = types.StringValue("0") + if countCommunityListVersions > 0 { + elementsCommunityListVersions = make([]attr.Value, countCommunityListVersions) + for i := 0; i < countCommunityListVersions; i++ { + elementsCommunityListVersions[i] = types.StringValue("0") } - data.Sequences[i].MatchEntries[ii].AdvancedCommunityListVersions = types.ListValueMust(types.StringType, elementsAdvancedCommunityListVersions) + data.Sequences[i].MatchEntries[ii].CommunityListVersions = types.ListValueMust(types.StringType, elementsCommunityListVersions) } else { - data.Sequences[i].MatchEntries[ii].AdvancedCommunityListVersions = types.ListNull(types.StringType) + data.Sequences[i].MatchEntries[ii].CommunityListVersions = types.ListNull(types.StringType) } } if data.Sequences[i].MatchEntries[ii].ExpandedCommunityListId != types.StringNull() { diff --git a/internal/provider/resource_sdwan_route_policy_definition.go b/internal/provider/resource_sdwan_route_policy_definition.go index c972ada34..89a841838 100644 --- a/internal/provider/resource_sdwan_route_policy_definition.go +++ b/internal/provider/resource_sdwan_route_policy_definition.go @@ -165,24 +165,24 @@ func (r *RoutePolicyDefinitionResource) Schema(ctx context.Context, req resource MarkdownDescription: helpers.NewAttributeDescription("Community list version").String, Optional: true, }, - "community_list_match_flag": schema.StringAttribute{ + "community_list_match_flag_single": schema.StringAttribute{ MarkdownDescription: helpers.NewAttributeDescription("Community list match flag, Attribute conditional on `type` being equal to `community`").AddStringEnumDescription("and", "or", "exact").String, Optional: true, Validators: []validator.String{ stringvalidator.OneOf("and", "or", "exact"), }, }, - "advanced_community_list_ids": schema.SetAttribute{ + "community_list_ids": schema.SetAttribute{ MarkdownDescription: helpers.NewAttributeDescription("Community list IDs, Attribute conditional on `type` being equal to `advancedCommunity`").String, ElementType: types.StringType, Optional: true, }, - "advanced_community_list_versions": schema.ListAttribute{ + "community_list_versions": schema.ListAttribute{ MarkdownDescription: helpers.NewAttributeDescription("Community list versions").String, ElementType: types.StringType, Optional: true, }, - "advanced_community_list_match_flag": schema.StringAttribute{ + "community_list_match_flag": schema.StringAttribute{ MarkdownDescription: helpers.NewAttributeDescription("Community list match flag, Attribute conditional on `type` being equal to `advancedCommunity`").AddStringEnumDescription("and", "or", "exact").String, Optional: true, Validators: []validator.String{ From d03c0d323b790e6aa7197e27564e131ace760fe9 Mon Sep 17 00:00:00 2001 From: Sean Conroy Date: Tue, 2 Sep 2025 15:39:58 +0100 Subject: [PATCH 4/4] remove redundant parameter --- docs/data-sources/route_policy_definition.md | 1 - docs/resources/route_policy_definition.md | 4 +-- .../generic/route_policy_definition.yaml | 14 +--------- ...ta_source_sdwan_route_policy_definition.go | 6 +---- .../model_sdwan_route_policy_definition.go | 26 +++++-------------- .../resource_sdwan_route_policy_definition.go | 11 ++------ 6 files changed, 12 insertions(+), 50 deletions(-) diff --git a/docs/data-sources/route_policy_definition.md b/docs/data-sources/route_policy_definition.md index f4bc5b7f3..64987eb43 100644 --- a/docs/data-sources/route_policy_definition.md +++ b/docs/data-sources/route_policy_definition.md @@ -81,7 +81,6 @@ Read-Only: - `community_list_id` (String) Community list ID - `community_list_ids` (Set of String) Community list IDs - `community_list_match_flag` (String) Community list match flag -- `community_list_match_flag_single` (String) Community list match flag - `community_list_version` (Number) Community list version - `community_list_versions` (List of String) Community list versions - `expanded_community_list_id` (String) Expanded community list ID diff --git a/docs/resources/route_policy_definition.md b/docs/resources/route_policy_definition.md index b3b212144..007a34611 100644 --- a/docs/resources/route_policy_definition.md +++ b/docs/resources/route_policy_definition.md @@ -130,9 +130,7 @@ Optional: - `as_path_list_version` (Number) AS path list version - `community_list_id` (String) Community list ID, Attribute conditional on `type` being equal to `community` - `community_list_ids` (Set of String) Community list IDs, Attribute conditional on `type` being equal to `advancedCommunity` -- `community_list_match_flag` (String) Community list match flag, Attribute conditional on `type` being equal to `advancedCommunity` - - Choices: `and`, `or`, `exact` -- `community_list_match_flag_single` (String) Community list match flag, Attribute conditional on `type` being equal to `community` +- `community_list_match_flag` (String) Community list match flag - Choices: `and`, `or`, `exact` - `community_list_version` (Number) Community list version - `community_list_versions` (List of String) Community list versions diff --git a/gen/definitions/generic/route_policy_definition.yaml b/gen/definitions/generic/route_policy_definition.yaml index a5e1458de..f0deaa501 100644 --- a/gen/definitions/generic/route_policy_definition.yaml +++ b/gen/definitions/generic/route_policy_definition.yaml @@ -138,10 +138,8 @@ attributes: description: Community list version exclude_test: true - model_name: matchFlag - tf_name: community_list_match_flag_single + tf_name: community_list_match_flag conditional_attribute: - name: type - value: community type: String enum_values: [and, or, exact] description: Community list match flag @@ -162,16 +160,6 @@ attributes: type: Versions description: Community list versions exclude_test: true - - model_name: matchFlag - tf_name: community_list_match_flag - conditional_attribute: - name: type - value: advancedCommunity - type: String - enum_values: [and, or, exact] - description: Community list match flag - example: and - exclude_test: true - model_name: ref tf_name: expanded_community_list_id conditional_attribute: diff --git a/internal/provider/data_source_sdwan_route_policy_definition.go b/internal/provider/data_source_sdwan_route_policy_definition.go index 9eaa57f9e..27c32e8e2 100644 --- a/internal/provider/data_source_sdwan_route_policy_definition.go +++ b/internal/provider/data_source_sdwan_route_policy_definition.go @@ -136,7 +136,7 @@ func (d *RoutePolicyDefinitionDataSource) Schema(ctx context.Context, req dataso MarkdownDescription: "Community list version", Computed: true, }, - "community_list_match_flag_single": schema.StringAttribute{ + "community_list_match_flag": schema.StringAttribute{ MarkdownDescription: "Community list match flag", Computed: true, }, @@ -150,10 +150,6 @@ func (d *RoutePolicyDefinitionDataSource) Schema(ctx context.Context, req dataso ElementType: types.StringType, Computed: true, }, - "community_list_match_flag": schema.StringAttribute{ - MarkdownDescription: "Community list match flag", - Computed: true, - }, "expanded_community_list_id": schema.StringAttribute{ MarkdownDescription: "Expanded community list ID", Computed: true, diff --git a/internal/provider/model_sdwan_route_policy_definition.go b/internal/provider/model_sdwan_route_policy_definition.go index 169fb73ba..67f2158dd 100644 --- a/internal/provider/model_sdwan_route_policy_definition.go +++ b/internal/provider/model_sdwan_route_policy_definition.go @@ -59,10 +59,9 @@ type RoutePolicyDefinitionSequencesMatchEntries struct { AsPathListVersion types.Int64 `tfsdk:"as_path_list_version"` CommunityListId types.String `tfsdk:"community_list_id"` CommunityListVersion types.Int64 `tfsdk:"community_list_version"` - CommunityListMatchFlagSingle types.String `tfsdk:"community_list_match_flag_single"` + CommunityListMatchFlag types.String `tfsdk:"community_list_match_flag"` CommunityListIds types.Set `tfsdk:"community_list_ids"` CommunityListVersions types.List `tfsdk:"community_list_versions"` - CommunityListMatchFlag types.String `tfsdk:"community_list_match_flag"` ExpandedCommunityListId types.String `tfsdk:"expanded_community_list_id"` ExpandedCommunityListVariable types.String `tfsdk:"expanded_community_list_variable"` ExpandedCommunityListVersion types.Int64 `tfsdk:"expanded_community_list_version"` @@ -157,17 +156,14 @@ func (data RoutePolicyDefinition) toBody(ctx context.Context) string { if !childItem.CommunityListId.IsNull() && childItem.Type.ValueString() == "community" { itemChildBody, _ = sjson.Set(itemChildBody, "ref", childItem.CommunityListId.ValueString()) } - if !childItem.CommunityListMatchFlagSingle.IsNull() && childItem.Type.ValueString() == "community" { - itemChildBody, _ = sjson.Set(itemChildBody, "matchFlag", childItem.CommunityListMatchFlagSingle.ValueString()) + if !childItem.CommunityListMatchFlag.IsNull() { + itemChildBody, _ = sjson.Set(itemChildBody, "matchFlag", childItem.CommunityListMatchFlag.ValueString()) } if !childItem.CommunityListIds.IsNull() && childItem.Type.ValueString() == "advancedCommunity" { var values []string childItem.CommunityListIds.ElementsAs(ctx, &values, false) itemChildBody, _ = sjson.Set(itemChildBody, "refs", values) } - if !childItem.CommunityListMatchFlag.IsNull() && childItem.Type.ValueString() == "advancedCommunity" { - itemChildBody, _ = sjson.Set(itemChildBody, "matchFlag", childItem.CommunityListMatchFlag.ValueString()) - } if !childItem.ExpandedCommunityListId.IsNull() && childItem.Type.ValueString() == "expandedCommunity" { itemChildBody, _ = sjson.Set(itemChildBody, "ref", childItem.ExpandedCommunityListId.ValueString()) } @@ -347,21 +343,16 @@ func (data *RoutePolicyDefinition) fromBody(ctx context.Context, res gjson.Resul } else { cItem.CommunityListId = types.StringNull() } - if ccValue := cv.Get("matchFlag"); ccValue.Exists() && cItem.Type.ValueString() == "community" { - cItem.CommunityListMatchFlagSingle = types.StringValue(ccValue.String()) + if ccValue := cv.Get("matchFlag"); ccValue.Exists() { + cItem.CommunityListMatchFlag = types.StringValue(ccValue.String()) } else { - cItem.CommunityListMatchFlagSingle = types.StringNull() + cItem.CommunityListMatchFlag = types.StringNull() } if ccValue := cv.Get("refs"); ccValue.Exists() && cItem.Type.ValueString() == "advancedCommunity" { cItem.CommunityListIds = helpers.GetStringSet(ccValue.Array()) } else { cItem.CommunityListIds = types.SetNull(types.StringType) } - if ccValue := cv.Get("matchFlag"); ccValue.Exists() && cItem.Type.ValueString() == "advancedCommunity" { - cItem.CommunityListMatchFlag = types.StringValue(ccValue.String()) - } else { - cItem.CommunityListMatchFlag = types.StringNull() - } if ccValue := cv.Get("ref"); ccValue.Exists() && cItem.Type.ValueString() == "expandedCommunity" { cItem.ExpandedCommunityListId = types.StringValue(ccValue.String()) } else { @@ -587,15 +578,12 @@ func (data *RoutePolicyDefinition) hasChanges(ctx context.Context, state *RouteP if !data.Sequences[i].MatchEntries[ii].CommunityListId.Equal(state.Sequences[i].MatchEntries[ii].CommunityListId) { hasChanges = true } - if !data.Sequences[i].MatchEntries[ii].CommunityListMatchFlagSingle.Equal(state.Sequences[i].MatchEntries[ii].CommunityListMatchFlagSingle) { + if !data.Sequences[i].MatchEntries[ii].CommunityListMatchFlag.Equal(state.Sequences[i].MatchEntries[ii].CommunityListMatchFlag) { hasChanges = true } if !data.Sequences[i].MatchEntries[ii].CommunityListIds.Equal(state.Sequences[i].MatchEntries[ii].CommunityListIds) { hasChanges = true } - if !data.Sequences[i].MatchEntries[ii].CommunityListMatchFlag.Equal(state.Sequences[i].MatchEntries[ii].CommunityListMatchFlag) { - hasChanges = true - } if !data.Sequences[i].MatchEntries[ii].ExpandedCommunityListId.Equal(state.Sequences[i].MatchEntries[ii].ExpandedCommunityListId) { hasChanges = true } diff --git a/internal/provider/resource_sdwan_route_policy_definition.go b/internal/provider/resource_sdwan_route_policy_definition.go index 89a841838..2da0c1a62 100644 --- a/internal/provider/resource_sdwan_route_policy_definition.go +++ b/internal/provider/resource_sdwan_route_policy_definition.go @@ -165,8 +165,8 @@ func (r *RoutePolicyDefinitionResource) Schema(ctx context.Context, req resource MarkdownDescription: helpers.NewAttributeDescription("Community list version").String, Optional: true, }, - "community_list_match_flag_single": schema.StringAttribute{ - MarkdownDescription: helpers.NewAttributeDescription("Community list match flag, Attribute conditional on `type` being equal to `community`").AddStringEnumDescription("and", "or", "exact").String, + "community_list_match_flag": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Community list match flag").AddStringEnumDescription("and", "or", "exact").String, Optional: true, Validators: []validator.String{ stringvalidator.OneOf("and", "or", "exact"), @@ -182,13 +182,6 @@ func (r *RoutePolicyDefinitionResource) Schema(ctx context.Context, req resource ElementType: types.StringType, Optional: true, }, - "community_list_match_flag": schema.StringAttribute{ - MarkdownDescription: helpers.NewAttributeDescription("Community list match flag, Attribute conditional on `type` being equal to `advancedCommunity`").AddStringEnumDescription("and", "or", "exact").String, - Optional: true, - Validators: []validator.String{ - stringvalidator.OneOf("and", "or", "exact"), - }, - }, "expanded_community_list_id": schema.StringAttribute{ MarkdownDescription: helpers.NewAttributeDescription("Expanded community list ID, Attribute conditional on `type` being equal to `expandedCommunity`").String, Optional: true,