Skip to content

Commit

Permalink
Resolve issue CiscoDevNet#284
Browse files Browse the repository at this point in the history
  • Loading branch information
seconroy committed Aug 13, 2024
1 parent 0b3c4a1 commit c8ece71
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Read-Only:

Read-Only:

- `gateway` (String) Gateway
- `nat` (String) IPv6 Nat
- `nat_variable` (String) Variable name
- `next_hops` (Attributes List) IPv6 Route Gateway Next Hop (see [below for nested schema](#nestedatt--ipv6_static_routes--next_hops))
Expand Down
12 changes: 8 additions & 4 deletions docs/resources/transport_management_vpn_profile_parcel.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ resource "sdwan_transport_management_vpn_profile_parcel" "example" {
]
ipv6_static_routes = [
{
prefix = "2002::/16"
prefix = "2002::/16"
gateway = "next_hop"
next_hops = [
{
address = "2001:0:0:1::1"
Expand Down Expand Up @@ -126,11 +127,13 @@ Optional:

Optional:

- `nat` (String) IPv6 Nat
- `gateway` (String) Gateway
- Choices: `next_hop`, `null0`, `nat`
- `nat` (String) IPv6 Nat, Attribute conditional on `gateway` being equal to `nat`
- Choices: `NAT64`, `NAT66`
- `nat_variable` (String) Variable name
- `next_hops` (Attributes List) IPv6 Route Gateway Next Hop (see [below for nested schema](#nestedatt--ipv6_static_routes--next_hops))
- `null0` (Boolean) IPv6 Route Gateway Next Hop
- `next_hops` (Attributes List) IPv6 Route Gateway Next Hop, Attribute conditional on `gateway` being equal to `next_hop` (see [below for nested schema](#nestedatt--ipv6_static_routes--next_hops))
- `null0` (Boolean) IPv6 Route Gateway Next Hop, Attribute conditional on `gateway` being equal to `null0`
- `prefix` (String) Prefix
- `prefix_variable` (String) Variable name

Expand All @@ -143,6 +146,7 @@ Optional:
- `address_variable` (String) Variable name
- `administrative_distance` (Number) Administrative distance
- Range: `1`-`254`
- Default value: `1`
- `administrative_distance_variable` (String) Variable name


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ resource "sdwan_transport_management_vpn_profile_parcel" "example" {
]
ipv6_static_routes = [
{
prefix = "2002::/16"
prefix = "2002::/16"
gateway = "next_hop"
next_hops = [
{
address = "2001:0:0:1::1"
Expand Down
21 changes: 21 additions & 0 deletions gen/definitions/profile_parcels/transport_management_vpn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,36 +65,57 @@ attributes:
- model_name: distance
tf_name: administrative_distance
example: 1
default_value: 1
default_value_present: true
- model_name: distance
tf_name: administrative_distance
conditional_attribute:
name: gateway
value: null0
default_value: 1
default_value_present: true
example: 1
- model_name: ipv6Route
tf_name: ipv6_static_routes
attributes:
- model_name: prefix
id: true
example: 2002::/16
- tf_name: gateway
type: String
tf_only: true
description: Gateway
enum_values: [next_hop, null0, nat]
example: next_hop
- model_name: nextHop
tf_name: next_hops
data_path: [oneOfIpRoute, nextHopContainer]
mandatory: true
conditional_attribute:
name: gateway
value: next_hop
attributes:
- model_name: address
id: true
example: 2001:0:0:1::1
- model_name: distance
tf_name: administrative_distance
example: 1
default_value: 1
default_value_present: true
- model_name: null0
data_path: [oneOfIpRoute]
exclude_test: true
conditional_attribute:
name: gateway
value: null0
example: true
- model_name: nat
data_path: [oneOfIpRoute]
exclude_test: true
conditional_attribute:
name: gateway
value: nat
example: NAT64

test_prerequisites: |
Expand Down
22 changes: 11 additions & 11 deletions gen/templates/profile_parcels/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (data {{camelCase .Name}}) toBody(ctx context.Context) string {
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "default")
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.value", {{if eq .Type "String"}}"{{end}}{{.Value}}{{if eq .Type "String"}}"{{end}})
}
{{- else if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .Reference)}}
{{- else if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .TfOnly) (not .Reference)}}
{{if .Variable}}
if !data.{{toGoName .TfName}}Variable.IsNull() {
if true{{if ne .ConditionalAttribute.Name ""}} {{if eq .ConditionalAttribute.Type "Bool"}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueBool() == {{.ConditionalAttribute.Value}} {{else}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}" {{end}}{{end}} {
Expand Down Expand Up @@ -200,7 +200,7 @@ func (data {{camelCase .Name}}) toBody(ctx context.Context) string {
itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "default")
itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.value", {{if eq .Type "String"}}"{{end}}{{.Value}}{{if eq .Type "String"}}"{{end}})
}
{{- else if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)}}
{{- else if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .TfOnly)}}
{{if .Variable}}
if !item.{{toGoName .TfName}}Variable.IsNull() {
if true{{if ne .ConditionalAttribute.Name ""}} {{if eq .ConditionalAttribute.Type "Bool"}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueBool() == {{.ConditionalAttribute.Value}} {{else}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}" {{end}}{{end}} {
Expand Down Expand Up @@ -270,7 +270,7 @@ func (data {{camelCase .Name}}) toBody(ctx context.Context) string {
itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "default")
itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.value", {{if eq .Type "String"}}"{{end}}{{.Value}}{{if eq .Type "String"}}"{{end}})
}
{{- else if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)}}
{{- else if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .TfOnly)}}
{{if .Variable}}
if !childChildItem.{{toGoName .TfName}}Variable.IsNull() {
if true{{if ne .ConditionalAttribute.Name ""}} {{if eq .ConditionalAttribute.Type "Bool"}} && childChildItem.{{toGoName .ConditionalAttribute.Name}}.ValueBool() == {{.ConditionalAttribute.Value}} {{else}} && childChildItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}" {{end}}{{end}} {
Expand Down Expand Up @@ -325,7 +325,7 @@ func (data *{{camelCase .Name}}) fromBody(ctx context.Context, res gjson.Result)
path := "payload.data."
{{- range .Attributes}}
{{- $cname := toGoName .TfName}}
{{- if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .Reference) (not .WriteOnly) (not .Value)}}
{{- if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .Reference) (not .TfOnly) (not .WriteOnly) (not .Value)}}
data.{{toGoName .TfName}} = types.{{.Type}}Null({{if isListSet .}}types.{{.ElementType}}Type{{end}})
{{ if .Variable}}data.{{toGoName .TfName}}Variable = types.StringNull(){{end}}
if t := res.Get(path + "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType"); t.Exists() {
Expand All @@ -343,7 +343,7 @@ func (data *{{camelCase .Name}}) fromBody(ctx context.Context, res gjson.Result)
item := {{$name}}{{toGoName .TfName}}{}
{{- range .Attributes}}
{{- $ccname := toGoName .TfName}}
{{- if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .Reference) (not .WriteOnly) (not .Value)}}
{{- if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .Reference) (not .TfOnly) (not .WriteOnly) (not .Value)}}
item.{{toGoName .TfName}} = types.{{.Type}}Null({{if isListSet .}}types.{{.ElementType}}Type{{end}})
{{ if .Variable}}item.{{toGoName .TfName}}Variable = types.StringNull(){{end}}
if t := v.Get("{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType"); t.Exists() {
Expand All @@ -360,7 +360,7 @@ func (data *{{camelCase .Name}}) fromBody(ctx context.Context, res gjson.Result)
cValue.ForEach(func(ck, cv gjson.Result) bool {
cItem := {{$name}}{{$cname}}{{toGoName .TfName}}{}
{{- range .Attributes}}
{{- if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .Reference) (not .WriteOnly) (not .Value)}}
{{- if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .Reference) (not .TfOnly) (not .WriteOnly) (not .Value)}}
cItem.{{toGoName .TfName}} = types.{{.Type}}Null({{if isListSet .}}types.{{.ElementType}}Type{{end}})
{{ if .Variable}}cItem.{{toGoName .TfName}}Variable = types.StringNull(){{end}}
if t := cv.Get("{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType"); t.Exists() {
Expand All @@ -377,7 +377,7 @@ func (data *{{camelCase .Name}}) fromBody(ctx context.Context, res gjson.Result)
ccValue.ForEach(func(cck, ccv gjson.Result) bool {
ccItem := {{$name}}{{$cname}}{{$ccname}}{{toGoName .TfName}}{}
{{- range .Attributes}}
{{- if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .Reference) (not .WriteOnly) (not .Value)}}
{{- if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .Reference) (not .TfOnly) (not .WriteOnly) (not .Value)}}
ccItem.{{toGoName .TfName}} = types.{{.Type}}Null({{if isListSet .}}types.{{.ElementType}}Type{{end}})
{{ if .Variable}}ccItem.{{toGoName .TfName}}Variable = types.StringNull(){{end}}
if t := ccv.Get("{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType"); t.Exists() {
Expand Down Expand Up @@ -421,7 +421,7 @@ func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.R
}
path := "payload.data."
{{- range .Attributes}}
{{- if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .Reference) (not .WriteOnly) (not .Value)}}
{{- if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .Reference) (not .TfOnly) (not .WriteOnly) (not .Value)}}
data.{{toGoName .TfName}} = types.{{.Type}}Null({{if isListSet .}}types.{{.ElementType}}Type{{end}})
{{ if .Variable}}data.{{toGoName .TfName}}Variable = types.StringNull(){{end}}
if t := res.Get(path + "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType"); t.Exists() {
Expand Down Expand Up @@ -462,7 +462,7 @@ func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.R
)

{{- range .Attributes}}
{{- if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .Reference) (not .WriteOnly) (not .Value)}}
{{- if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .Reference) (not .TfOnly) (not .WriteOnly) (not .Value)}}
data.{{$list}}[i].{{toGoName .TfName}} = types.{{.Type}}Null({{if isListSet .}}types.{{.ElementType}}Type{{end}})
{{ if .Variable}}data.{{$list}}[i].{{toGoName .TfName}}Variable = types.StringNull(){{end}}
if t := r.Get("{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType"); t.Exists() {
Expand Down Expand Up @@ -503,7 +503,7 @@ func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.R
)

{{- range .Attributes}}
{{- if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .Reference) (not .WriteOnly) (not .Value)}}
{{- if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .Reference) (not .TfOnly) (not .WriteOnly) (not .Value)}}
data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}} = types.{{.Type}}Null({{if isListSet .}}types.{{.ElementType}}Type{{end}})
{{ if .Variable}}data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}}Variable = types.StringNull(){{end}}
if t := cr.Get("{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType"); t.Exists() {
Expand Down Expand Up @@ -544,7 +544,7 @@ func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.R
)

{{- range .Attributes}}
{{- if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .Reference) (not .WriteOnly) (not .Value)}}
{{- if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .Reference) (not .TfOnly) (not .WriteOnly) (not .Value)}}
data.{{$list}}[i].{{$clist}}[ci].{{$cclist}}[cci].{{toGoName .TfName}} = types.{{.Type}}Null({{if isListSet .}}types.{{.ElementType}}Type{{end}})
{{ if .Variable}}data.{{$list}}[i].{{$clist}}[ci].{{$cclist}}[cci].{{toGoName .TfName}}Variable = types.StringNull(){{end}}
if t := ccr.Get("{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType"); t.Exists() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ func (d *TransportManagementVPNProfileParcelDataSource) Schema(ctx context.Conte
MarkdownDescription: helpers.NewAttributeDescription("Variable name").String,
Computed: true,
},
"gateway": schema.StringAttribute{
MarkdownDescription: "Gateway",
Computed: true,
},
"next_hops": schema.ListNestedAttribute{
MarkdownDescription: "IPv6 Route Gateway Next Hop",
Computed: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestAccDataSourceSdwanTransportManagementVPNProfileParcel(t *testing.T) {
checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_transport_management_vpn_profile_parcel.test", "ipv4_static_routes.0.next_hops.0.administrative_distance", "1"))
checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_transport_management_vpn_profile_parcel.test", "ipv4_static_routes.0.administrative_distance", "1"))
checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_transport_management_vpn_profile_parcel.test", "ipv6_static_routes.0.prefix", "2002::/16"))
checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_transport_management_vpn_profile_parcel.test", "ipv6_static_routes.0.gateway", "next_hop"))
checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_transport_management_vpn_profile_parcel.test", "ipv6_static_routes.0.next_hops.0.address", "2001:0:0:1::1"))
checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_transport_management_vpn_profile_parcel.test", "ipv6_static_routes.0.next_hops.0.administrative_distance", "1"))
resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -100,6 +101,7 @@ func testAccDataSourceSdwanTransportManagementVPNProfileParcelConfig() string {
config += ` }]` + "\n"
config += ` ipv6_static_routes = [{` + "\n"
config += ` prefix = "2002::/16"` + "\n"
config += ` gateway = "next_hop"` + "\n"
config += ` next_hops = [{` + "\n"
config += ` address = "2001:0:0:1::1"` + "\n"
config += ` administrative_distance = 1` + "\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type TransportManagementVPNIpv4StaticRoutes struct {
type TransportManagementVPNIpv6StaticRoutes struct {
Prefix types.String `tfsdk:"prefix"`
PrefixVariable types.String `tfsdk:"prefix_variable"`
Gateway types.String `tfsdk:"gateway"`
NextHops []TransportManagementVPNIpv6StaticRoutesNextHops `tfsdk:"next_hops"`
Null0 types.Bool `tfsdk:"null0"`
Nat types.String `tfsdk:"nat"`
Expand Down Expand Up @@ -349,7 +350,7 @@ func (data TransportManagementVPN) toBody(ctx context.Context) string {
itemBody, _ = sjson.Set(itemBody, "prefix.value", item.Prefix.ValueString())
}
}
if true {
if true && item.Gateway.ValueString() == "next_hop" {

for _, childItem := range item.NextHops {
itemChildBody := ""
Expand All @@ -371,7 +372,12 @@ func (data TransportManagementVPN) toBody(ctx context.Context) string {
itemChildBody, _ = sjson.Set(itemChildBody, "distance.optionType", "variable")
itemChildBody, _ = sjson.Set(itemChildBody, "distance.value", childItem.AdministrativeDistanceVariable.ValueString())
}
} else if !childItem.AdministrativeDistance.IsNull() {
} else if childItem.AdministrativeDistance.IsNull() {
if true {
itemChildBody, _ = sjson.Set(itemChildBody, "distance.optionType", "default")
itemChildBody, _ = sjson.Set(itemChildBody, "distance.value", 1)
}
} else {
if true {
itemChildBody, _ = sjson.Set(itemChildBody, "distance.optionType", "global")
itemChildBody, _ = sjson.Set(itemChildBody, "distance.value", childItem.AdministrativeDistance.ValueInt64())
Expand All @@ -381,19 +387,19 @@ func (data TransportManagementVPN) toBody(ctx context.Context) string {
}
}
if !item.Null0.IsNull() {
if true {
if true && item.Gateway.ValueString() == "null0" {
itemBody, _ = sjson.Set(itemBody, "oneOfIpRoute.null0.optionType", "global")
itemBody, _ = sjson.Set(itemBody, "oneOfIpRoute.null0.value", item.Null0.ValueBool())
}
}

if !item.NatVariable.IsNull() {
if true {
if true && item.Gateway.ValueString() == "nat" {
itemBody, _ = sjson.Set(itemBody, "oneOfIpRoute.nat.optionType", "variable")
itemBody, _ = sjson.Set(itemBody, "oneOfIpRoute.nat.value", item.NatVariable.ValueString())
}
} else if !item.Nat.IsNull() {
if true {
if true && item.Gateway.ValueString() == "nat" {
itemBody, _ = sjson.Set(itemBody, "oneOfIpRoute.nat.optionType", "global")
itemBody, _ = sjson.Set(itemBody, "oneOfIpRoute.nat.value", item.Nat.ValueString())
}
Expand Down
Loading

0 comments on commit c8ece71

Please sign in to comment.