diff --git a/docs/resources/service_lan_vpn_interface_ethernet_feature.md b/docs/resources/service_lan_vpn_interface_ethernet_feature.md index e125236b9..a2a4f87ea 100644 --- a/docs/resources/service_lan_vpn_interface_ethernet_feature.md +++ b/docs/resources/service_lan_vpn_interface_ethernet_feature.md @@ -44,20 +44,9 @@ resource "sdwan_service_lan_vpn_interface_ethernet_feature" "example" { ipv4_nat_range_end = "4.5.6.7" ipv4_nat_prefix_length = 1 ipv4_nat_overload = true - ipv4_nat_loopback = "123" - ipv4_nat_udp_timeout = 123 - ipv4_nat_tcp_timeout = 123 - static_nats = [ - { - source_ip = "1.2.3.4" - translate_ip = "2.3.4.5" - direction = "inside" - source_vpn = 0 - } - ] - ipv6_nat = true - nat64 = false - acl_shaping_rate = 12 + ipv6_nat = true + nat64 = false + acl_shaping_rate = 12 ipv6_vrrps = [ { group_id = 1 diff --git a/examples/resources/sdwan_service_lan_vpn_interface_ethernet_feature/resource.tf b/examples/resources/sdwan_service_lan_vpn_interface_ethernet_feature/resource.tf index e4877fa1d..fec72ad4d 100644 --- a/examples/resources/sdwan_service_lan_vpn_interface_ethernet_feature/resource.tf +++ b/examples/resources/sdwan_service_lan_vpn_interface_ethernet_feature/resource.tf @@ -27,20 +27,9 @@ resource "sdwan_service_lan_vpn_interface_ethernet_feature" "example" { ipv4_nat_range_end = "4.5.6.7" ipv4_nat_prefix_length = 1 ipv4_nat_overload = true - ipv4_nat_loopback = "123" - ipv4_nat_udp_timeout = 123 - ipv4_nat_tcp_timeout = 123 - static_nats = [ - { - source_ip = "1.2.3.4" - translate_ip = "2.3.4.5" - direction = "inside" - source_vpn = 0 - } - ] - ipv6_nat = true - nat64 = false - acl_shaping_rate = 12 + ipv6_nat = true + nat64 = false + acl_shaping_rate = 12 ipv6_vrrps = [ { group_id = 1 diff --git a/gen/definitions/profile_parcels/service_lan_vpn_interface_ethernet.yaml b/gen/definitions/profile_parcels/service_lan_vpn_interface_ethernet.yaml index 5969d0bac..e183ef132 100644 --- a/gen/definitions/profile_parcels/service_lan_vpn_interface_ethernet.yaml +++ b/gen/definitions/profile_parcels/service_lan_vpn_interface_ethernet.yaml @@ -109,34 +109,58 @@ attributes: - model_name: rangeStart tf_name: ipv4_nat_range_start data_path: [natAttributesIpv4, natPool] + exclude_null: true + # conditional_attribute: + # name: Ipv4NatType + # value: pool example: 1.2.3.4 - model_name: rangeEnd tf_name: ipv4_nat_range_end data_path: [natAttributesIpv4, natPool] + exclude_null: true + # conditional_attribute: + # name: Ipv4NatType + # value: pool example: 4.5.6.7 - model_name: prefixLength tf_name: ipv4_nat_prefix_length data_path: [natAttributesIpv4, natPool] + exclude_null: true + # conditional_attribute: + # name: Ipv4NatType + # value: pool example: 1 - model_name: overload tf_name: ipv4_nat_overload data_path: [natAttributesIpv4, natPool] + exclude_null: true + # conditional_attribute: + # name: Ipv4NatType + # value: pool example: true - model_name: natLookback tf_name: ipv4_nat_loopback data_path: [natAttributesIpv4] + exclude_test: true + exclude_null: true + # conditional_attribute: + # name: Ipv4NatType + # value: loopback example: 123 - model_name: udpTimeout tf_name: ipv4_nat_udp_timeout data_path: [natAttributesIpv4] + exclude_test: true example: 123 - model_name: tcpTimeout tf_name: ipv4_nat_tcp_timeout data_path: [natAttributesIpv4] + exclude_test: true example: 123 - model_name: newStaticNat tf_name: static_nats data_path: [natAttributesIpv4] + exclude_test: true attributes: - model_name: sourceIp id: true diff --git a/internal/provider/data_source_sdwan_service_lan_vpn_feature.go b/internal/provider/data_source_sdwan_service_lan_vpn_feature.go index 1828f7d2c..05e49c955 100644 --- a/internal/provider/data_source_sdwan_service_lan_vpn_feature.go +++ b/internal/provider/data_source_sdwan_service_lan_vpn_feature.go @@ -24,6 +24,7 @@ import ( "net/url" "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -961,7 +962,6 @@ func (d *ServiceLANVPNProfileParcelDataSource) Configure(_ context.Context, req // End of section. //template:end model -// Section below is generated&owned by "gen/generator.go". //template:begin read func (d *ServiceLANVPNProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { var config ServiceLANVPN @@ -974,18 +974,19 @@ func (d *ServiceLANVPNProfileParcelDataSource) Read(ctx context.Context, req dat tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String())) + // Get Manager Version + currentVersion := version.Must(version.NewVersion(d.client.ManagerVersion)) + res, err := d.client.Get(config.getPath() + "/" + url.QueryEscape(config.Id.ValueString())) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err)) return } - config.fromBody(ctx, res) + config.fromBody(ctx, res, currentVersion) tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", config.Name.ValueString())) diags = resp.State.Set(ctx, &config) resp.Diagnostics.Append(diags...) } - -// End of section. //template:end read diff --git a/internal/provider/data_source_sdwan_service_lan_vpn_interface_ethernet_feature.go b/internal/provider/data_source_sdwan_service_lan_vpn_interface_ethernet_feature.go index 3521303d7..3d6f826b7 100644 --- a/internal/provider/data_source_sdwan_service_lan_vpn_interface_ethernet_feature.go +++ b/internal/provider/data_source_sdwan_service_lan_vpn_interface_ethernet_feature.go @@ -24,6 +24,7 @@ import ( "net/url" "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -710,7 +711,6 @@ func (d *ServiceLANVPNInterfaceEthernetProfileParcelDataSource) Configure(_ cont // End of section. //template:end model -// Section below is generated&owned by "gen/generator.go". //template:begin read func (d *ServiceLANVPNInterfaceEthernetProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { var config ServiceLANVPNInterfaceEthernet @@ -723,18 +723,19 @@ func (d *ServiceLANVPNInterfaceEthernetProfileParcelDataSource) Read(ctx context tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String())) + // Get Manager Version + currentVersion := version.Must(version.NewVersion(d.client.ManagerVersion)) + res, err := d.client.Get(config.getPath() + "/" + url.QueryEscape(config.Id.ValueString())) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err)) return } - config.fromBody(ctx, res) + config.fromBody(ctx, res, currentVersion) tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", config.Name.ValueString())) diags = resp.State.Set(ctx, &config) resp.Diagnostics.Append(diags...) } - -// End of section. //template:end read diff --git a/internal/provider/data_source_sdwan_service_lan_vpn_interface_ethernet_feature_test.go b/internal/provider/data_source_sdwan_service_lan_vpn_interface_ethernet_feature_test.go index a36f8beb8..1c3408e03 100644 --- a/internal/provider/data_source_sdwan_service_lan_vpn_interface_ethernet_feature_test.go +++ b/internal/provider/data_source_sdwan_service_lan_vpn_interface_ethernet_feature_test.go @@ -48,13 +48,6 @@ func TestAccDataSourceSdwanServiceLANVPNInterfaceEthernetProfileParcel(t *testin checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_service_lan_vpn_interface_ethernet_feature.test", "ipv4_nat_range_end", "4.5.6.7")) checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_service_lan_vpn_interface_ethernet_feature.test", "ipv4_nat_prefix_length", "1")) checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_service_lan_vpn_interface_ethernet_feature.test", "ipv4_nat_overload", "true")) - checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_service_lan_vpn_interface_ethernet_feature.test", "ipv4_nat_loopback", "123")) - checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_service_lan_vpn_interface_ethernet_feature.test", "ipv4_nat_udp_timeout", "123")) - checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_service_lan_vpn_interface_ethernet_feature.test", "ipv4_nat_tcp_timeout", "123")) - checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_service_lan_vpn_interface_ethernet_feature.test", "static_nats.0.source_ip", "1.2.3.4")) - checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_service_lan_vpn_interface_ethernet_feature.test", "static_nats.0.translate_ip", "2.3.4.5")) - checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_service_lan_vpn_interface_ethernet_feature.test", "static_nats.0.direction", "inside")) - checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_service_lan_vpn_interface_ethernet_feature.test", "static_nats.0.source_vpn", "0")) checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_service_lan_vpn_interface_ethernet_feature.test", "ipv6_nat", "true")) checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_service_lan_vpn_interface_ethernet_feature.test", "nat64", "false")) checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_service_lan_vpn_interface_ethernet_feature.test", "acl_shaping_rate", "12")) @@ -167,15 +160,6 @@ func testAccDataSourceSdwanServiceLANVPNInterfaceEthernetProfileParcelConfig() s config += ` ipv4_nat_range_end = "4.5.6.7"` + "\n" config += ` ipv4_nat_prefix_length = 1` + "\n" config += ` ipv4_nat_overload = true` + "\n" - config += ` ipv4_nat_loopback = "123"` + "\n" - config += ` ipv4_nat_udp_timeout = 123` + "\n" - config += ` ipv4_nat_tcp_timeout = 123` + "\n" - config += ` static_nats = [{` + "\n" - config += ` source_ip = "1.2.3.4"` + "\n" - config += ` translate_ip = "2.3.4.5"` + "\n" - config += ` direction = "inside"` + "\n" - config += ` source_vpn = 0` + "\n" - config += ` }]` + "\n" config += ` ipv6_nat = true` + "\n" config += ` nat64 = false` + "\n" config += ` acl_shaping_rate = 12` + "\n" diff --git a/internal/provider/data_source_sdwan_transport_wan_vpn_interface_ethernet_feature.go b/internal/provider/data_source_sdwan_transport_wan_vpn_interface_ethernet_feature.go index cd9b8d67e..e65c4a740 100644 --- a/internal/provider/data_source_sdwan_transport_wan_vpn_interface_ethernet_feature.go +++ b/internal/provider/data_source_sdwan_transport_wan_vpn_interface_ethernet_feature.go @@ -24,6 +24,7 @@ import ( "net/url" "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -1007,7 +1008,6 @@ func (d *TransportWANVPNInterfaceEthernetProfileParcelDataSource) Configure(_ co // End of section. //template:end model -// Section below is generated&owned by "gen/generator.go". //template:begin read func (d *TransportWANVPNInterfaceEthernetProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { var config TransportWANVPNInterfaceEthernet @@ -1020,18 +1020,19 @@ func (d *TransportWANVPNInterfaceEthernetProfileParcelDataSource) Read(ctx conte tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String())) + // Get Manager Version + currentVersion := version.Must(version.NewVersion(d.client.ManagerVersion)) + res, err := d.client.Get(config.getPath() + "/" + url.QueryEscape(config.Id.ValueString())) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err)) return } - config.fromBody(ctx, res) + config.fromBody(ctx, res, currentVersion) tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", config.Name.ValueString())) diags = resp.State.Set(ctx, &config) resp.Diagnostics.Append(diags...) } - -// End of section. //template:end read diff --git a/internal/provider/model_sdwan_service_lan_vpn_feature.go b/internal/provider/model_sdwan_service_lan_vpn_feature.go index ffcaceb18..22d1c68a3 100644 --- a/internal/provider/model_sdwan_service_lan_vpn_feature.go +++ b/internal/provider/model_sdwan_service_lan_vpn_feature.go @@ -25,6 +25,7 @@ import ( "strconv" "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/tidwall/gjson" "github.com/tidwall/sjson" @@ -32,6 +33,8 @@ import ( // End of section. //template:end imports +var MinServiceLANVPNUpdateVersion = version.Must(version.NewVersion("20.14.0")) + // Section below is generated&owned by "gen/generator.go". //template:begin types type ServiceLANVPN struct { Id types.String `tfsdk:"id"` @@ -328,8 +331,7 @@ func (data ServiceLANVPN) getPath() string { // End of section. //template:end getPath -// Section below is generated&owned by "gen/generator.go". //template:begin toBody -func (data ServiceLANVPN) toBody(ctx context.Context) string { +func (data ServiceLANVPN) toBody(ctx context.Context, currentVersion *version.Version) string { body := "" body, _ = sjson.Set(body, "name", data.Name.ValueString()) body, _ = sjson.Set(body, "description", data.Description.ValueString()) @@ -1203,15 +1205,19 @@ func (data ServiceLANVPN) toBody(ctx context.Context) string { } } + translatedSourceIpRef := "TranslatedSourceIp" + if !currentVersion.LessThan(MinServiceLANVPNUpdateVersion) { + translatedSourceIpRef = "translatedSourceIp" + } if !item.TranslatedSourceIpVariable.IsNull() { if true { - itemBody, _ = sjson.Set(itemBody, "TranslatedSourceIp.optionType", "variable") - itemBody, _ = sjson.Set(itemBody, "TranslatedSourceIp.value", item.TranslatedSourceIpVariable.ValueString()) + itemBody, _ = sjson.Set(itemBody, translatedSourceIpRef+".optionType", "variable") + itemBody, _ = sjson.Set(itemBody, translatedSourceIpRef+".value", item.TranslatedSourceIpVariable.ValueString()) } } else if !item.TranslatedSourceIp.IsNull() { if true { - itemBody, _ = sjson.Set(itemBody, "TranslatedSourceIp.optionType", "global") - itemBody, _ = sjson.Set(itemBody, "TranslatedSourceIp.value", item.TranslatedSourceIp.ValueString()) + itemBody, _ = sjson.Set(itemBody, translatedSourceIpRef+".optionType", "global") + itemBody, _ = sjson.Set(itemBody, translatedSourceIpRef+".value", item.TranslatedSourceIp.ValueString()) } } @@ -1263,15 +1269,19 @@ func (data ServiceLANVPN) toBody(ctx context.Context) string { } } + translatedSourceIpSubnetRef := "TranslatedSourceIp" + if !currentVersion.LessThan(MinServiceLANVPNUpdateVersion) { + translatedSourceIpSubnetRef = "translatedSourceIp" + } if !item.TranslatedSourceIpVariable.IsNull() { if true { - itemBody, _ = sjson.Set(itemBody, "TranslatedSourceIp.optionType", "variable") - itemBody, _ = sjson.Set(itemBody, "TranslatedSourceIp.value", item.TranslatedSourceIpVariable.ValueString()) + itemBody, _ = sjson.Set(itemBody, translatedSourceIpSubnetRef+".optionType", "variable") + itemBody, _ = sjson.Set(itemBody, translatedSourceIpSubnetRef+".value", item.TranslatedSourceIpVariable.ValueString()) } } else if !item.TranslatedSourceIp.IsNull() { if true { - itemBody, _ = sjson.Set(itemBody, "TranslatedSourceIp.optionType", "global") - itemBody, _ = sjson.Set(itemBody, "TranslatedSourceIp.value", item.TranslatedSourceIp.ValueString()) + itemBody, _ = sjson.Set(itemBody, translatedSourceIpSubnetRef+".optionType", "global") + itemBody, _ = sjson.Set(itemBody, translatedSourceIpSubnetRef+".value", item.TranslatedSourceIp.ValueString()) } } @@ -1596,10 +1606,7 @@ func (data ServiceLANVPN) toBody(ctx context.Context) string { return body } -// End of section. //template:end toBody - -// Section below is generated&owned by "gen/generator.go". //template:begin fromBody -func (data *ServiceLANVPN) fromBody(ctx context.Context, res gjson.Result) { +func (data *ServiceLANVPN) fromBody(ctx context.Context, res gjson.Result, currentVersion *version.Version) { data.Name = types.StringValue(res.Get("payload.name").String()) if value := res.Get("payload.description"); value.Exists() && value.String() != "" { data.Description = types.StringValue(value.String()) @@ -2327,8 +2334,12 @@ func (data *ServiceLANVPN) fromBody(ctx context.Context, res gjson.Result) { } item.TranslatedSourceIp = types.StringNull() item.TranslatedSourceIpVariable = types.StringNull() - if t := v.Get("TranslatedSourceIp.optionType"); t.Exists() { - va := v.Get("TranslatedSourceIp.value") + translatedSourceIpRef := "TranslatedSourceIp" + if !currentVersion.LessThan(MinServiceLANVPNUpdateVersion) { + translatedSourceIpRef = "translatedSourceIp" + } + if t := v.Get(translatedSourceIpRef + ".optionType"); t.Exists() { + va := v.Get(translatedSourceIpRef + ".value") if t.String() == "variable" { item.TranslatedSourceIpVariable = types.StringValue(va.String()) } else if t.String() == "global" { @@ -2375,8 +2386,12 @@ func (data *ServiceLANVPN) fromBody(ctx context.Context, res gjson.Result) { } item.TranslatedSourceIp = types.StringNull() item.TranslatedSourceIpVariable = types.StringNull() - if t := v.Get("TranslatedSourceIp.optionType"); t.Exists() { - va := v.Get("TranslatedSourceIp.value") + translatedSourceIpRef := "TranslatedSourceIp" + if !currentVersion.LessThan(MinServiceLANVPNUpdateVersion) { + translatedSourceIpRef = "translatedSourceIp" + } + if t := v.Get(translatedSourceIpRef + ".optionType"); t.Exists() { + va := v.Get(translatedSourceIpRef + ".value") if t.String() == "variable" { item.TranslatedSourceIpVariable = types.StringValue(va.String()) } else if t.String() == "global" { @@ -2693,10 +2708,7 @@ func (data *ServiceLANVPN) fromBody(ctx context.Context, res gjson.Result) { } } -// End of section. //template:end fromBody - -// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody -func (data *ServiceLANVPN) updateFromBody(ctx context.Context, res gjson.Result) { +func (data *ServiceLANVPN) updateFromBody(ctx context.Context, res gjson.Result, currentVersion *version.Version) { data.Name = types.StringValue(res.Get("payload.name").String()) if value := res.Get("payload.description"); value.Exists() && value.String() != "" { data.Description = types.StringValue(value.String()) @@ -3811,8 +3823,12 @@ func (data *ServiceLANVPN) updateFromBody(ctx context.Context, res gjson.Result) } data.NatPortForwards[i].TranslatedSourceIp = types.StringNull() data.NatPortForwards[i].TranslatedSourceIpVariable = types.StringNull() - if t := r.Get("TranslatedSourceIp.optionType"); t.Exists() { - va := r.Get("TranslatedSourceIp.value") + translatedSourceIpRef := "TranslatedSourceIp" + if !currentVersion.LessThan(MinServiceLANVPNUpdateVersion) { + translatedSourceIpRef = "translatedSourceIp" + } + if t := r.Get(translatedSourceIpRef + ".optionType"); t.Exists() { + va := r.Get(translatedSourceIpRef + ".value") if t.String() == "variable" { data.NatPortForwards[i].TranslatedSourceIpVariable = types.StringValue(va.String()) } else if t.String() == "global" { @@ -3883,8 +3899,12 @@ func (data *ServiceLANVPN) updateFromBody(ctx context.Context, res gjson.Result) } data.StaticNats[i].TranslatedSourceIp = types.StringNull() data.StaticNats[i].TranslatedSourceIpVariable = types.StringNull() - if t := r.Get("TranslatedSourceIp.optionType"); t.Exists() { - va := r.Get("TranslatedSourceIp.value") + translatedSourceIpRef := "TranslatedSourceIp" + if !currentVersion.LessThan(MinServiceLANVPNUpdateVersion) { + translatedSourceIpRef = "translatedSourceIp" + } + if t := r.Get(translatedSourceIpRef + ".optionType"); t.Exists() { + va := r.Get(translatedSourceIpRef + ".value") if t.String() == "variable" { data.StaticNats[i].TranslatedSourceIpVariable = types.StringValue(va.String()) } else if t.String() == "global" { @@ -4461,5 +4481,3 @@ func (data *ServiceLANVPN) updateFromBody(ctx context.Context, res gjson.Result) } } } - -// End of section. //template:end updateFromBody diff --git a/internal/provider/model_sdwan_service_lan_vpn_interface_ethernet_feature.go b/internal/provider/model_sdwan_service_lan_vpn_interface_ethernet_feature.go index a1516c883..589e890b1 100644 --- a/internal/provider/model_sdwan_service_lan_vpn_interface_ethernet_feature.go +++ b/internal/provider/model_sdwan_service_lan_vpn_interface_ethernet_feature.go @@ -26,6 +26,7 @@ import ( "strings" "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/tidwall/gjson" "github.com/tidwall/sjson" @@ -33,6 +34,8 @@ import ( // End of section. //template:end imports +var MinServiceLANVPNInterfaceEthernetUpdateVersion = version.Must(version.NewVersion("20.14.0")) + // Section below is generated&owned by "gen/generator.go". //template:begin types type ServiceLANVPNInterfaceEthernet struct { Id types.String `tfsdk:"id"` @@ -233,7 +236,7 @@ func (data ServiceLANVPNInterfaceEthernet) getPath() string { // End of section. //template:end getPath -func (data ServiceLANVPNInterfaceEthernet) toBody(ctx context.Context) string { +func (data ServiceLANVPNInterfaceEthernet) toBody(ctx context.Context, currentVersion *version.Version) string { body := "" body, _ = sjson.Set(body, "name", data.Name.ValueString()) body, _ = sjson.Set(body, "description", data.Description.ValueString()) @@ -486,12 +489,7 @@ func (data ServiceLANVPNInterfaceEthernet) toBody(ctx context.Context) string { body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.rangeStart.optionType", "variable") body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.rangeStart.value", data.Ipv4NatRangeStartVariable.ValueString()) } - } else if data.Ipv4NatRangeStart.IsNull() { - if true { - body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.rangeStart.optionType", "default") - - } - } else { + } else if !data.Ipv4NatRangeStart.IsNull() { if true { body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.rangeStart.optionType", "global") body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.rangeStart.value", data.Ipv4NatRangeStart.ValueString()) @@ -503,12 +501,7 @@ func (data ServiceLANVPNInterfaceEthernet) toBody(ctx context.Context) string { body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.rangeEnd.optionType", "variable") body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.rangeEnd.value", data.Ipv4NatRangeEndVariable.ValueString()) } - } else if data.Ipv4NatRangeEnd.IsNull() { - if true { - body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.rangeEnd.optionType", "default") - - } - } else { + } else if !data.Ipv4NatRangeEnd.IsNull() { if true { body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.rangeEnd.optionType", "global") body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.rangeEnd.value", data.Ipv4NatRangeEnd.ValueString()) @@ -520,12 +513,7 @@ func (data ServiceLANVPNInterfaceEthernet) toBody(ctx context.Context) string { body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.prefixLength.optionType", "variable") body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.prefixLength.value", data.Ipv4NatPrefixLengthVariable.ValueString()) } - } else if data.Ipv4NatPrefixLength.IsNull() { - if true { - body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.prefixLength.optionType", "default") - - } - } else { + } else if !data.Ipv4NatPrefixLength.IsNull() { if true { body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.prefixLength.optionType", "global") body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.prefixLength.value", data.Ipv4NatPrefixLength.ValueInt64()) @@ -537,32 +525,26 @@ func (data ServiceLANVPNInterfaceEthernet) toBody(ctx context.Context) string { body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.overload.optionType", "variable") body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.overload.value", data.Ipv4NatOverloadVariable.ValueString()) } - } else if data.Ipv4NatOverload.IsNull() { - if true { - body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.overload.optionType", "default") - body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.overload.value", true) - } - } else { + } else if !data.Ipv4NatOverload.IsNull() { if true { body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.overload.optionType", "global") body, _ = sjson.Set(body, path+"natAttributesIpv4.natPool.overload.value", data.Ipv4NatOverload.ValueBool()) } } + natLookBackRef := "natLookback" + if !currentVersion.LessThan(MinServiceLANVPNInterfaceEthernetUpdateVersion) { + natLookBackRef = "natLoopback" + } if !data.Ipv4NatLoopbackVariable.IsNull() { if true { - body, _ = sjson.Set(body, path+"natAttributesIpv4.natLookback.optionType", "variable") - body, _ = sjson.Set(body, path+"natAttributesIpv4.natLookback.value", data.Ipv4NatLoopbackVariable.ValueString()) + body, _ = sjson.Set(body, path+"natAttributesIpv4."+natLookBackRef+".optionType", "variable") + body, _ = sjson.Set(body, path+"natAttributesIpv4."+natLookBackRef+".value", data.Ipv4NatLoopbackVariable.ValueString()) } - } else if data.Ipv4NatLoopback.IsNull() { - if true { - body, _ = sjson.Set(body, path+"natAttributesIpv4.natLookback.optionType", "default") - - } - } else { + } else if !data.Ipv4NatLoopback.IsNull() { if true { - body, _ = sjson.Set(body, path+"natAttributesIpv4.natLookback.optionType", "global") - body, _ = sjson.Set(body, path+"natAttributesIpv4.natLookback.value", data.Ipv4NatLoopback.ValueString()) + body, _ = sjson.Set(body, path+"natAttributesIpv4."+natLookBackRef+".optionType", "global") + body, _ = sjson.Set(body, path+"natAttributesIpv4."+natLookBackRef+".value", data.Ipv4NatLoopback.ValueString()) } } @@ -1262,9 +1244,10 @@ func (data ServiceLANVPNInterfaceEthernet) toBody(ctx context.Context) string { body, _ = sjson.Set(body, path+"advanced.tracker.value", data.TrackerVariable.ValueString()) } } else if data.Tracker.IsNull() { - if true { - body, _ = sjson.Set(body, path+"advanced.tracker.optionType", "default") - + if currentVersion.LessThan(MinServiceLANVPNUpdateVersion) { + if true { + body, _ = sjson.Set(body, path+"advanced.tracker.optionType", "default") + } } } else { if true { @@ -1326,8 +1309,7 @@ func (data ServiceLANVPNInterfaceEthernet) toBody(ctx context.Context) string { return body } -// Section below is generated&owned by "gen/generator.go". //template:begin fromBody -func (data *ServiceLANVPNInterfaceEthernet) fromBody(ctx context.Context, res gjson.Result) { +func (data *ServiceLANVPNInterfaceEthernet) fromBody(ctx context.Context, res gjson.Result, currentVersion *version.Version) { data.Name = types.StringValue(res.Get("payload.name").String()) if value := res.Get("payload.description"); value.Exists() && value.String() != "" { data.Description = types.StringValue(value.String()) @@ -1575,8 +1557,12 @@ func (data *ServiceLANVPNInterfaceEthernet) fromBody(ctx context.Context, res gj } data.Ipv4NatLoopback = types.StringNull() data.Ipv4NatLoopbackVariable = types.StringNull() - if t := res.Get(path + "natAttributesIpv4.natLookback.optionType"); t.Exists() { - va := res.Get(path + "natAttributesIpv4.natLookback.value") + natLookBackRef := "natLookback" + if !currentVersion.LessThan(MinServiceLANVPNInterfaceEthernetUpdateVersion) { + natLookBackRef = "natLoopback" + } + if t := res.Get(path + "natAttributesIpv4." + natLookBackRef + ".optionType"); t.Exists() { + va := res.Get(path + "natAttributesIpv4." + natLookBackRef + ".value") if t.String() == "variable" { data.Ipv4NatLoopbackVariable = types.StringValue(va.String()) } else if t.String() == "global" { @@ -2131,10 +2117,7 @@ func (data *ServiceLANVPNInterfaceEthernet) fromBody(ctx context.Context, res gj } } -// End of section. //template:end fromBody - -// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody -func (data *ServiceLANVPNInterfaceEthernet) updateFromBody(ctx context.Context, res gjson.Result) { +func (data *ServiceLANVPNInterfaceEthernet) updateFromBody(ctx context.Context, res gjson.Result, currentVersion *version.Version) { data.Name = types.StringValue(res.Get("payload.name").String()) if value := res.Get("payload.description"); value.Exists() && value.String() != "" { data.Description = types.StringValue(value.String()) @@ -2478,8 +2461,12 @@ func (data *ServiceLANVPNInterfaceEthernet) updateFromBody(ctx context.Context, } data.Ipv4NatLoopback = types.StringNull() data.Ipv4NatLoopbackVariable = types.StringNull() - if t := res.Get(path + "natAttributesIpv4.natLookback.optionType"); t.Exists() { - va := res.Get(path + "natAttributesIpv4.natLookback.value") + natLookBackRef := "natLookback" + if !currentVersion.LessThan(MinServiceLANVPNInterfaceEthernetUpdateVersion) { + natLookBackRef = "natLoopback" + } + if t := res.Get(path + "natAttributesIpv4." + natLookBackRef + ".optionType"); t.Exists() { + va := res.Get(path + "natAttributesIpv4." + natLookBackRef + ".value") if t.String() == "variable" { data.Ipv4NatLoopbackVariable = types.StringValue(va.String()) } else if t.String() == "global" { diff --git a/internal/provider/model_sdwan_transport_wan_vpn_interface_ethernet_feature.go b/internal/provider/model_sdwan_transport_wan_vpn_interface_ethernet_feature.go index 4777819f3..9b81ae9d6 100644 --- a/internal/provider/model_sdwan_transport_wan_vpn_interface_ethernet_feature.go +++ b/internal/provider/model_sdwan_transport_wan_vpn_interface_ethernet_feature.go @@ -25,6 +25,7 @@ import ( "strings" "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/tidwall/gjson" "github.com/tidwall/sjson" @@ -32,6 +33,8 @@ import ( // End of section. //template:end imports +var MinTransportWANVPNInterfaceEthernetUpdateVersion = version.Must(version.NewVersion("20.14.0")) + // Section below is generated&owned by "gen/generator.go". //template:begin types type TransportWANVPNInterfaceEthernet struct { Id types.String `tfsdk:"id"` @@ -299,7 +302,7 @@ func (data TransportWANVPNInterfaceEthernet) getPath() string { // End of section. //template:end getPath -func (data TransportWANVPNInterfaceEthernet) toBody(ctx context.Context) string { +func (data TransportWANVPNInterfaceEthernet) toBody(ctx context.Context, currentVersion *version.Version) string { body := "" body, _ = sjson.Set(body, "name", data.Name.ValueString()) body, _ = sjson.Set(body, "description", data.Description.ValueString()) @@ -1356,15 +1359,19 @@ func (data TransportWANVPNInterfaceEthernet) toBody(ctx context.Context) string } } + natLookBackRef := "natLookback" + if !currentVersion.LessThan(MinTransportWANVPNInterfaceEthernetUpdateVersion) { + natLookBackRef = "natLoopback" + } if !data.NatLoopbackVariable.IsNull() { if true { - body, _ = sjson.Set(body, path+"natAttributesIpv4.natLookback.optionType", "variable") - body, _ = sjson.Set(body, path+"natAttributesIpv4.natLookback.value", data.NatLoopbackVariable.ValueString()) + body, _ = sjson.Set(body, path+"natAttributesIpv4."+natLookBackRef+".optionType", "variable") + body, _ = sjson.Set(body, path+"natAttributesIpv4."+natLookBackRef+".value", data.NatLoopbackVariable.ValueString()) } } else if !data.NatLoopback.IsNull() { if true { - body, _ = sjson.Set(body, path+"natAttributesIpv4.natLookback.optionType", "global") - body, _ = sjson.Set(body, path+"natAttributesIpv4.natLookback.value", data.NatLoopback.ValueString()) + body, _ = sjson.Set(body, path+"natAttributesIpv4."+natLookBackRef+".optionType", "global") + body, _ = sjson.Set(body, path+"natAttributesIpv4."+natLookBackRef+".value", data.NatLoopback.ValueString()) } } @@ -1991,8 +1998,7 @@ func (data TransportWANVPNInterfaceEthernet) toBody(ctx context.Context) string return body } -// Section below is generated&owned by "gen/generator.go". //template:begin fromBody -func (data *TransportWANVPNInterfaceEthernet) fromBody(ctx context.Context, res gjson.Result) { +func (data *TransportWANVPNInterfaceEthernet) fromBody(ctx context.Context, res gjson.Result, currentVersion *version.Version) { data.Name = types.StringValue(res.Get("payload.name").String()) if value := res.Get("payload.description"); value.Exists() && value.String() != "" { data.Description = types.StringValue(value.String()) @@ -2688,8 +2694,12 @@ func (data *TransportWANVPNInterfaceEthernet) fromBody(ctx context.Context, res } data.NatLoopback = types.StringNull() data.NatLoopbackVariable = types.StringNull() - if t := res.Get(path + "natAttributesIpv4.natLookback.optionType"); t.Exists() { - va := res.Get(path + "natAttributesIpv4.natLookback.value") + natLookBackRef := "natLookback" + if !currentVersion.LessThan(MinTransportWANVPNInterfaceEthernetUpdateVersion) { + natLookBackRef = "natLoopback" + } + if t := res.Get(path + "natAttributesIpv4." + natLookBackRef + ".optionType"); t.Exists() { + va := res.Get(path + "natAttributesIpv4." + natLookBackRef + ".value") if t.String() == "variable" { data.NatLoopbackVariable = types.StringValue(va.String()) } else if t.String() == "global" { @@ -3152,10 +3162,7 @@ func (data *TransportWANVPNInterfaceEthernet) fromBody(ctx context.Context, res } } -// End of section. //template:end fromBody - -// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody -func (data *TransportWANVPNInterfaceEthernet) updateFromBody(ctx context.Context, res gjson.Result) { +func (data *TransportWANVPNInterfaceEthernet) updateFromBody(ctx context.Context, res gjson.Result, currentVersion *version.Version) { data.Name = types.StringValue(res.Get("payload.name").String()) if value := res.Get("payload.description"); value.Exists() && value.String() != "" { data.Description = types.StringValue(value.String()) @@ -3947,8 +3954,12 @@ func (data *TransportWANVPNInterfaceEthernet) updateFromBody(ctx context.Context } data.NatLoopback = types.StringNull() data.NatLoopbackVariable = types.StringNull() - if t := res.Get(path + "natAttributesIpv4.natLookback.optionType"); t.Exists() { - va := res.Get(path + "natAttributesIpv4.natLookback.value") + natLookBackRef := "natLookback" + if !currentVersion.LessThan(MinTransportWANVPNInterfaceEthernetUpdateVersion) { + natLookBackRef = "natLoopback" + } + if t := res.Get(path + "natAttributesIpv4." + natLookBackRef + ".optionType"); t.Exists() { + va := res.Get(path + "natAttributesIpv4." + natLookBackRef + ".value") if t.String() == "variable" { data.NatLoopbackVariable = types.StringValue(va.String()) } else if t.String() == "global" { @@ -4482,5 +4493,3 @@ func (data *TransportWANVPNInterfaceEthernet) updateFromBody(ctx context.Context } } } - -// End of section. //template:end updateFromBody diff --git a/internal/provider/resource_sdwan_service_lan_vpn_feature.go b/internal/provider/resource_sdwan_service_lan_vpn_feature.go index 8fb6886ab..d863353f4 100644 --- a/internal/provider/resource_sdwan_service_lan_vpn_feature.go +++ b/internal/provider/resource_sdwan_service_lan_vpn_feature.go @@ -27,6 +27,7 @@ import ( "sync" "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/path" @@ -1129,7 +1130,6 @@ func (r *ServiceLANVPNProfileParcelResource) Configure(_ context.Context, req re // End of section. //template:end model -// Section below is generated&owned by "gen/generator.go". //template:begin create func (r *ServiceLANVPNProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var plan ServiceLANVPN @@ -1142,8 +1142,11 @@ func (r *ServiceLANVPNProfileParcelResource) Create(ctx context.Context, req res tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.Name.ValueString())) + // Get Manager Version + currentVersion := version.Must(version.NewVersion(r.client.ManagerVersion)) + // Create object - body := plan.toBody(ctx) + body := plan.toBody(ctx, currentVersion) res, err := r.client.Post(plan.getPath(), body) if err != nil { @@ -1162,9 +1165,6 @@ func (r *ServiceLANVPNProfileParcelResource) Create(ctx context.Context, req res helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics) } -// End of section. //template:end create - -// Section below is generated&owned by "gen/generator.go". //template:begin read func (r *ServiceLANVPNProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { var state ServiceLANVPN @@ -1177,6 +1177,9 @@ func (r *ServiceLANVPNProfileParcelResource) Read(ctx context.Context, req resou tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Name.String())) + // Get Manager Version + currentVersion := version.Must(version.NewVersion(r.client.ManagerVersion)) + res, err := r.client.Get(state.getPath() + "/" + url.QueryEscape(state.Id.ValueString())) if res.Get("error.message").String() == "Invalid feature Id" { resp.State.RemoveResource(ctx) @@ -1193,9 +1196,9 @@ func (r *ServiceLANVPNProfileParcelResource) Read(ctx context.Context, req resou } if imp { - state.fromBody(ctx, res) + state.fromBody(ctx, res, currentVersion) } else { - state.updateFromBody(ctx, res) + state.updateFromBody(ctx, res, currentVersion) } if state.Version.IsNull() { state.Version = types.Int64Value(0) @@ -1209,9 +1212,6 @@ func (r *ServiceLANVPNProfileParcelResource) Read(ctx context.Context, req resou helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics) } -// End of section. //template:end read - -// Section below is generated&owned by "gen/generator.go". //template:begin update func (r *ServiceLANVPNProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var plan, state ServiceLANVPN @@ -1230,7 +1230,10 @@ func (r *ServiceLANVPNProfileParcelResource) Update(ctx context.Context, req res tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.Name.ValueString())) - body := plan.toBody(ctx) + // Get Manager Version + currentVersion := version.Must(version.NewVersion(r.client.ManagerVersion)) + + body := plan.toBody(ctx, currentVersion) res, err := r.client.Put(plan.getPath()+"/"+url.QueryEscape(plan.Id.ValueString()), body) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (PUT), got error: %s, %s", err, res.String())) @@ -1245,8 +1248,6 @@ func (r *ServiceLANVPNProfileParcelResource) Update(ctx context.Context, req res resp.Diagnostics.Append(diags...) } -// End of section. //template:end update - // Section below is generated&owned by "gen/generator.go". //template:begin delete func (r *ServiceLANVPNProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { var state ServiceLANVPN diff --git a/internal/provider/resource_sdwan_service_lan_vpn_interface_ethernet_feature.go b/internal/provider/resource_sdwan_service_lan_vpn_interface_ethernet_feature.go index 7c954847e..dd03dc4e5 100644 --- a/internal/provider/resource_sdwan_service_lan_vpn_interface_ethernet_feature.go +++ b/internal/provider/resource_sdwan_service_lan_vpn_interface_ethernet_feature.go @@ -27,6 +27,7 @@ import ( "sync" "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/path" @@ -849,7 +850,6 @@ func (r *ServiceLANVPNInterfaceEthernetProfileParcelResource) Configure(_ contex // End of section. //template:end model -// Section below is generated&owned by "gen/generator.go". //template:begin create func (r *ServiceLANVPNInterfaceEthernetProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var plan ServiceLANVPNInterfaceEthernet @@ -862,8 +862,11 @@ func (r *ServiceLANVPNInterfaceEthernetProfileParcelResource) Create(ctx context tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.Name.ValueString())) + // Get Manager Version + currentVersion := version.Must(version.NewVersion(r.client.ManagerVersion)) + // Create object - body := plan.toBody(ctx) + body := plan.toBody(ctx, currentVersion) res, err := r.client.Post(plan.getPath(), body) if err != nil { @@ -882,9 +885,6 @@ func (r *ServiceLANVPNInterfaceEthernetProfileParcelResource) Create(ctx context helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics) } -// End of section. //template:end create - -// Section below is generated&owned by "gen/generator.go". //template:begin read func (r *ServiceLANVPNInterfaceEthernetProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { var state ServiceLANVPNInterfaceEthernet @@ -897,6 +897,9 @@ func (r *ServiceLANVPNInterfaceEthernetProfileParcelResource) Read(ctx context.C tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Name.String())) + // Get Manager Version + currentVersion := version.Must(version.NewVersion(r.client.ManagerVersion)) + res, err := r.client.Get(state.getPath() + "/" + url.QueryEscape(state.Id.ValueString())) if res.Get("error.message").String() == "Invalid feature Id" { resp.State.RemoveResource(ctx) @@ -913,9 +916,9 @@ func (r *ServiceLANVPNInterfaceEthernetProfileParcelResource) Read(ctx context.C } if imp { - state.fromBody(ctx, res) + state.fromBody(ctx, res, currentVersion) } else { - state.updateFromBody(ctx, res) + state.updateFromBody(ctx, res, currentVersion) } if state.Version.IsNull() { state.Version = types.Int64Value(0) @@ -929,9 +932,6 @@ func (r *ServiceLANVPNInterfaceEthernetProfileParcelResource) Read(ctx context.C helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics) } -// End of section. //template:end read - -// Section below is generated&owned by "gen/generator.go". //template:begin update func (r *ServiceLANVPNInterfaceEthernetProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var plan, state ServiceLANVPNInterfaceEthernet @@ -950,7 +950,10 @@ func (r *ServiceLANVPNInterfaceEthernetProfileParcelResource) Update(ctx context tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.Name.ValueString())) - body := plan.toBody(ctx) + // Get Manager Version + currentVersion := version.Must(version.NewVersion(r.client.ManagerVersion)) + + body := plan.toBody(ctx, currentVersion) res, err := r.client.Put(plan.getPath()+"/"+url.QueryEscape(plan.Id.ValueString()), body) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (PUT), got error: %s, %s", err, res.String())) @@ -965,8 +968,6 @@ func (r *ServiceLANVPNInterfaceEthernetProfileParcelResource) Update(ctx context resp.Diagnostics.Append(diags...) } -// End of section. //template:end update - // Section below is generated&owned by "gen/generator.go". //template:begin delete func (r *ServiceLANVPNInterfaceEthernetProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { var state ServiceLANVPNInterfaceEthernet diff --git a/internal/provider/resource_sdwan_service_lan_vpn_interface_ethernet_feature_test.go b/internal/provider/resource_sdwan_service_lan_vpn_interface_ethernet_feature_test.go index f0d454892..6e73266c9 100644 --- a/internal/provider/resource_sdwan_service_lan_vpn_interface_ethernet_feature_test.go +++ b/internal/provider/resource_sdwan_service_lan_vpn_interface_ethernet_feature_test.go @@ -48,13 +48,6 @@ func TestAccSdwanServiceLANVPNInterfaceEthernetProfileParcel(t *testing.T) { checks = append(checks, resource.TestCheckResourceAttr("sdwan_service_lan_vpn_interface_ethernet_feature.test", "ipv4_nat_range_end", "4.5.6.7")) checks = append(checks, resource.TestCheckResourceAttr("sdwan_service_lan_vpn_interface_ethernet_feature.test", "ipv4_nat_prefix_length", "1")) checks = append(checks, resource.TestCheckResourceAttr("sdwan_service_lan_vpn_interface_ethernet_feature.test", "ipv4_nat_overload", "true")) - checks = append(checks, resource.TestCheckResourceAttr("sdwan_service_lan_vpn_interface_ethernet_feature.test", "ipv4_nat_loopback", "123")) - checks = append(checks, resource.TestCheckResourceAttr("sdwan_service_lan_vpn_interface_ethernet_feature.test", "ipv4_nat_udp_timeout", "123")) - checks = append(checks, resource.TestCheckResourceAttr("sdwan_service_lan_vpn_interface_ethernet_feature.test", "ipv4_nat_tcp_timeout", "123")) - checks = append(checks, resource.TestCheckResourceAttr("sdwan_service_lan_vpn_interface_ethernet_feature.test", "static_nats.0.source_ip", "1.2.3.4")) - checks = append(checks, resource.TestCheckResourceAttr("sdwan_service_lan_vpn_interface_ethernet_feature.test", "static_nats.0.translate_ip", "2.3.4.5")) - checks = append(checks, resource.TestCheckResourceAttr("sdwan_service_lan_vpn_interface_ethernet_feature.test", "static_nats.0.direction", "inside")) - checks = append(checks, resource.TestCheckResourceAttr("sdwan_service_lan_vpn_interface_ethernet_feature.test", "static_nats.0.source_vpn", "0")) checks = append(checks, resource.TestCheckResourceAttr("sdwan_service_lan_vpn_interface_ethernet_feature.test", "ipv6_nat", "true")) checks = append(checks, resource.TestCheckResourceAttr("sdwan_service_lan_vpn_interface_ethernet_feature.test", "nat64", "false")) checks = append(checks, resource.TestCheckResourceAttr("sdwan_service_lan_vpn_interface_ethernet_feature.test", "acl_shaping_rate", "12")) @@ -187,15 +180,6 @@ func testAccSdwanServiceLANVPNInterfaceEthernetProfileParcelConfig_all() string config += ` ipv4_nat_range_end = "4.5.6.7"` + "\n" config += ` ipv4_nat_prefix_length = 1` + "\n" config += ` ipv4_nat_overload = true` + "\n" - config += ` ipv4_nat_loopback = "123"` + "\n" - config += ` ipv4_nat_udp_timeout = 123` + "\n" - config += ` ipv4_nat_tcp_timeout = 123` + "\n" - config += ` static_nats = [{` + "\n" - config += ` source_ip = "1.2.3.4"` + "\n" - config += ` translate_ip = "2.3.4.5"` + "\n" - config += ` direction = "inside"` + "\n" - config += ` source_vpn = 0` + "\n" - config += ` }]` + "\n" config += ` ipv6_nat = true` + "\n" config += ` nat64 = false` + "\n" config += ` acl_shaping_rate = 12` + "\n" diff --git a/internal/provider/resource_sdwan_transport_wan_vpn_interface_ethernet_feature.go b/internal/provider/resource_sdwan_transport_wan_vpn_interface_ethernet_feature.go index fac8aad0e..776f4dfda 100644 --- a/internal/provider/resource_sdwan_transport_wan_vpn_interface_ethernet_feature.go +++ b/internal/provider/resource_sdwan_transport_wan_vpn_interface_ethernet_feature.go @@ -27,6 +27,7 @@ import ( "sync" "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/path" @@ -1182,7 +1183,6 @@ func (r *TransportWANVPNInterfaceEthernetProfileParcelResource) Configure(_ cont // End of section. //template:end model -// Section below is generated&owned by "gen/generator.go". //template:begin create func (r *TransportWANVPNInterfaceEthernetProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var plan TransportWANVPNInterfaceEthernet @@ -1195,8 +1195,11 @@ func (r *TransportWANVPNInterfaceEthernetProfileParcelResource) Create(ctx conte tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.Name.ValueString())) + // Get Manager Version + currentVersion := version.Must(version.NewVersion(r.client.ManagerVersion)) + // Create object - body := plan.toBody(ctx) + body := plan.toBody(ctx, currentVersion) res, err := r.client.Post(plan.getPath(), body) if err != nil { @@ -1215,9 +1218,6 @@ func (r *TransportWANVPNInterfaceEthernetProfileParcelResource) Create(ctx conte helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics) } -// End of section. //template:end create - -// Section below is generated&owned by "gen/generator.go". //template:begin read func (r *TransportWANVPNInterfaceEthernetProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { var state TransportWANVPNInterfaceEthernet @@ -1230,6 +1230,9 @@ func (r *TransportWANVPNInterfaceEthernetProfileParcelResource) Read(ctx context tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Name.String())) + // Get Manager Version + currentVersion := version.Must(version.NewVersion(r.client.ManagerVersion)) + res, err := r.client.Get(state.getPath() + "/" + url.QueryEscape(state.Id.ValueString())) if res.Get("error.message").String() == "Invalid feature Id" { resp.State.RemoveResource(ctx) @@ -1246,9 +1249,9 @@ func (r *TransportWANVPNInterfaceEthernetProfileParcelResource) Read(ctx context } if imp { - state.fromBody(ctx, res) + state.fromBody(ctx, res, currentVersion) } else { - state.updateFromBody(ctx, res) + state.updateFromBody(ctx, res, currentVersion) } if state.Version.IsNull() { state.Version = types.Int64Value(0) @@ -1262,9 +1265,6 @@ func (r *TransportWANVPNInterfaceEthernetProfileParcelResource) Read(ctx context helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics) } -// End of section. //template:end read - -// Section below is generated&owned by "gen/generator.go". //template:begin update func (r *TransportWANVPNInterfaceEthernetProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var plan, state TransportWANVPNInterfaceEthernet @@ -1283,7 +1283,10 @@ func (r *TransportWANVPNInterfaceEthernetProfileParcelResource) Update(ctx conte tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.Name.ValueString())) - body := plan.toBody(ctx) + // Get Manager Version + currentVersion := version.Must(version.NewVersion(r.client.ManagerVersion)) + + body := plan.toBody(ctx, currentVersion) res, err := r.client.Put(plan.getPath()+"/"+url.QueryEscape(plan.Id.ValueString()), body) if err != nil { resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (PUT), got error: %s, %s", err, res.String())) @@ -1298,8 +1301,6 @@ func (r *TransportWANVPNInterfaceEthernetProfileParcelResource) Update(ctx conte resp.Diagnostics.Append(diags...) } -// End of section. //template:end update - // Section below is generated&owned by "gen/generator.go". //template:begin delete func (r *TransportWANVPNInterfaceEthernetProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { var state TransportWANVPNInterfaceEthernet