Skip to content

Commit

Permalink
Resolve CiscoDevNet#381
Browse files Browse the repository at this point in the history
  • Loading branch information
seconroy committed Jan 10, 2025
1 parent 67f41fa commit 70fceee
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 34 deletions.
33 changes: 27 additions & 6 deletions gen/templates/profile_parcels/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,10 @@ func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.R
{{- $noId := not (hasId .Attributes)}}
{{- range .Attributes}}
{{- if or .Id $noId}}
{{- if or (eq .Type "Int64") (eq .Type "Bool") (eq .Type "String") (eq .Type "StringInt64") (eq .Type "List")}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}",{{- end}}
{{- if or (eq .Type "Int64") (eq .Type "Bool") (eq .Type "String") (eq .Type "StringInt64")}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}",
{{- else if or (eq .Type "Set") (eq .Type "List")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}",{{- end}}
{{- end}}
{{- end}}
{{- end}}
}
Expand All @@ -543,7 +546,11 @@ func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.R
{{- if eq .Type "Int64"}}strconv.FormatInt(data.{{$list}}[i].{{toGoName .TfName}}.ValueInt64(), 10),
{{- else if eq .Type "Bool"}}strconv.FormatBool(data.{{$list}}[i].{{toGoName .TfName}}.ValueBool()),
{{- else if or (eq .Type "String") (eq .Type "StringInt64")}}data.{{$list}}[i].{{toGoName .TfName}}.ValueString(),
{{- else if and (eq .Type "List") (eq .ElementType "String")}}strings.Join(data.{{$list}}[i].{{toGoName .TfName}}, ","),{{- end}}
{{- else if (eq .Type "Set")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}helpers.GetStringFromSet(data.{{$list}}[i].{{toGoName .TfName}}).ValueString(),{{- end}}
{{- else if (eq .Type "List")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}helpers.GetStringFromList(data.{{$list}}[i].{{toGoName .TfName}}).ValueString(),{{- end}}
{{- end}}
{{- end}}
{{- end}}
}
Expand Down Expand Up @@ -609,7 +616,10 @@ func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.R
{{- $noId := not (hasId .Attributes)}}
{{- range .Attributes}}
{{- if or .Id $noId}}
{{- if or (eq .Type "Int64") (eq .Type "Bool") (eq .Type "String") (eq .Type "StringInt64") (eq .Type "List")}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}",{{- end}}
{{- if or (eq .Type "Int64") (eq .Type "Bool") (eq .Type "String") (eq .Type "StringInt64")}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}",
{{- else if or (eq .Type "Set") (eq .Type "List")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}",{{- end}}
{{- end}}
{{- end}}
{{- end}}
}
Expand All @@ -620,7 +630,11 @@ func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.R
{{- if eq .Type "Int64"}}strconv.FormatInt(data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}}.ValueInt64(), 10),
{{- else if eq .Type "Bool"}}strconv.FormatBool(data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}}.ValueBool()),
{{- else if or (eq .Type "String") (eq .Type "StringInt64")}}data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}}.ValueString(),
{{- else if and (eq .Type "List") (eq .ElementType "String")}}strings.Join(data.{{$list}}[i].{{toGoName .TfName}}, ","),{{- end}}
{{- else if (eq .Type "Set")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}helpers.GetStringFromSet(data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}}).ValueString(),{{- end}}
{{- else if (eq .Type "List")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}helpers.GetStringFromList(data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}}).ValueString(),{{- end}}
{{- end}}
{{- end}}
{{- end}}
}
Expand Down Expand Up @@ -686,7 +700,10 @@ func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.R
{{- $noId := not (hasId .Attributes)}}
{{- range .Attributes}}
{{- if or .Id $noId}}
{{- if or (eq .Type "Int64") (eq .Type "Bool") (eq .Type "String") (eq .Type "StringInt64") (eq .Type "List")}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}",{{- end}}
{{- if or (eq .Type "Int64") (eq .Type "Bool") (eq .Type "String") (eq .Type "StringInt64")}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}",
{{- else if or (eq .Type "Set") (eq .Type "List")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}",{{- end}}
{{- end}}
{{- end}}
{{- end}}
}
Expand All @@ -697,7 +714,11 @@ func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.R
{{- if eq .Type "Int64"}}strconv.FormatInt(data.{{$list}}[i].{{$clist}}[ci].{{$cclist}}[cci].{{toGoName .TfName}}.ValueInt64(), 10),
{{- else if eq .Type "Bool"}}strconv.FormatBool(data.{{$list}}[i].{{$clist}}[ci].{{$cclist}}[cci].{{toGoName .TfName}}.ValueBool()),
{{- else if or (eq .Type "String") (eq .Type "StringInt64")}}data.{{$list}}[i].{{$clist}}[ci].{{$cclist}}[cci].{{toGoName .TfName}}.ValueString(),
{{- else if and (eq .Type "List") (eq .ElementType "String")}}strings.Join(data.{{$list}}[i].{{toGoName .TfName}}, ","),{{- end}}
{{- else if (eq .Type "Set")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}helpers.GetStringFromSet(data.{{$list}}[i].{{$clist}}[ci].{{$cclist}}[cci].{{toGoName .TfName}}).ValueString(),{{- end}}
{{- else if (eq .Type "List")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}helpers.GetStringFromList(data.{{$list}}[i].{{$clist}}[ci].{{$cclist}}[cci].{{toGoName .TfName}}).ValueString(),{{- end}}
{{- end}}
{{- end}}
{{- end}}
}
Expand Down
17 changes: 17 additions & 0 deletions internal/provider/helpers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/netascode/go-sdwan"
"github.com/tidwall/gjson"
Expand All @@ -42,6 +43,22 @@ func Contains(s []string, str string) bool {
return false
}

func GetStringFromList(list basetypes.ListValue) types.String {
v := make([]string, len(list.Elements()))
for r := range list.Elements() {
v[r] = list.Elements()[r].String()
}
return types.StringValue("[" + strings.Join(v, ",") + "]")
}

func GetStringFromSet(set basetypes.SetValue) types.String {
v := make([]string, len(set.Elements()))
for r := range set.Elements() {
v[r] = set.Elements()[r].String()
}
return types.StringValue("[" + strings.Join(v, ",") + "]")
}

func GetStringList(result []gjson.Result) types.List {
v := make([]attr.Value, len(result))
for r := range result {
Expand Down
Loading

0 comments on commit 70fceee

Please sign in to comment.