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 de9f231
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Read-Only:
- `null0` (Boolean) IPv6 Route Gateway Next Hop
- `prefix` (String) Prefix
- `prefix_variable` (String) Variable name
- `route_type` (String) Must be set to configure either next_hop, null0 or nat.

<a id="nestedatt--ipv6_static_routes--next_hops"></a>
### Nested Schema for `ipv6_static_routes.next_hops`
Expand Down
6 changes: 5 additions & 1 deletion 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"
route_type = "next_hop"
next_hops = [
{
address = "2001:0:0:1::1"
Expand Down Expand Up @@ -133,6 +134,8 @@ Optional:
- `null0` (Boolean) IPv6 Route Gateway Next Hop
- `prefix` (String) Prefix
- `prefix_variable` (String) Variable name
- `route_type` (String) Must be set to configure either next_hop, null0 or nat.
- Choices: `next_hop`, `null0`, `nat`

<a id="nestedatt--ipv6_static_routes--next_hops"></a>
### Nested Schema for `ipv6_static_routes.next_hops`
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"
route_type = "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: route_type
type: String
tf_only: true
description: Must be set to configure either next_hop, null0 or nat.
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: route_type
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: route_type
value: null0
example: true
- model_name: nat
data_path: [oneOfIpRoute]
exclude_test: true
conditional_attribute:
name: route_type
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,
},
"route_type": schema.StringAttribute{
MarkdownDescription: "Must be set to configure either next_hop, null0 or nat.",
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.route_type", "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 += ` route_type = "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"`
RouteType types.String `tfsdk:"route_type"`
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.RouteType.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.RouteType.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.RouteType.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.RouteType.ValueString() == "nat" {
itemBody, _ = sjson.Set(itemBody, "oneOfIpRoute.nat.optionType", "global")
itemBody, _ = sjson.Set(itemBody, "oneOfIpRoute.nat.value", item.Nat.ValueString())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ func (r *TransportManagementVPNProfileParcelResource) Schema(ctx context.Context
MarkdownDescription: helpers.NewAttributeDescription("Variable name").String,
Optional: true,
},
"route_type": schema.StringAttribute{
MarkdownDescription: helpers.NewAttributeDescription("Must be set to configure either next_hop, null0 or nat.").AddStringEnumDescription("next_hop", "null0", "nat").String,
Optional: true,
Validators: []validator.String{
stringvalidator.OneOf("next_hop", "null0", "nat"),
},
},
"next_hops": schema.ListNestedAttribute{
MarkdownDescription: helpers.NewAttributeDescription("IPv6 Route Gateway Next Hop").String,
Optional: true,
Expand All @@ -262,7 +269,7 @@ func (r *TransportManagementVPNProfileParcelResource) Schema(ctx context.Context
Optional: true,
},
"administrative_distance": schema.Int64Attribute{
MarkdownDescription: helpers.NewAttributeDescription("Administrative distance").AddIntegerRangeDescription(1, 254).String,
MarkdownDescription: helpers.NewAttributeDescription("Administrative distance").AddIntegerRangeDescription(1, 254).AddDefaultValueDescription("1").String,
Optional: true,
Validators: []validator.Int64{
int64validator.Between(1, 254),
Expand Down
Loading

0 comments on commit de9f231

Please sign in to comment.