From cfd91445942b30579250160bc28f806c6a665c33 Mon Sep 17 00:00:00 2001 From: Sean Conroy Date: Thu, 5 Jun 2025 10:50:34 +0100 Subject: [PATCH] Resolve issue #392 --- CHANGELOG.md | 4 ++ .../cisco_system_feature_template.md | 1 + docs/guides/changelog.md | 4 ++ .../cisco_system_feature_template.md | 3 ++ .../feature_templates/cisco_system.yaml | 11 +++++ ...rce_sdwan_cisco_system_feature_template.go | 4 ++ ...del_sdwan_cisco_system_feature_template.go | 40 ++++++++++++++++--- ...rce_sdwan_cisco_system_feature_template.go | 21 ++++++---- templates/guides/changelog.md.tmpl | 4 ++ 9 files changed, 79 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12e6443bf..b12acaf23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.6.2 + +- Adds `enhanced_app_aware_routing` support to the `sdwan_cisco_system_feature_template` resource and data source + ## 0.6.1 - BREAKING CHANGE: Replaces `no_authentication` attribute of `sdwan_transport_cellular_profile_feature` with `requires_authentication` diff --git a/docs/data-sources/cisco_system_feature_template.md b/docs/data-sources/cisco_system_feature_template.md index 08698d9c6..dbecd5b6e 100644 --- a/docs/data-sources/cisco_system_feature_template.md +++ b/docs/data-sources/cisco_system_feature_template.md @@ -45,6 +45,7 @@ data "sdwan_cisco_system_feature_template" "example" { - `device_groups_variable` (String) Variable name - `device_types` (Set of String) List of supported device types - `enable_mrf_migration` (String) Enable migration mode to Multi-Region Fabric +- `enhanced_app_aware_routing` (String) Enhanced App Aware Routing - `geo_fencing` (Boolean) Enable Geo fencing - `geo_fencing_range` (Number) Set the device’s geo fencing range - `geo_fencing_range_variable` (String) Variable name diff --git a/docs/guides/changelog.md b/docs/guides/changelog.md index a15149d0c..11e32a168 100644 --- a/docs/guides/changelog.md +++ b/docs/guides/changelog.md @@ -7,6 +7,10 @@ description: |- # Changelog +## 0.6.2 + +- Adds `enhanced_app_aware_routing` support to the `sdwan_cisco_system_feature_template` resource and data source + ## 0.6.1 - BREAKING CHANGE: Replaces `no_authentication` attribute of `sdwan_transport_cellular_profile_feature` with `requires_authentication` diff --git a/docs/resources/cisco_system_feature_template.md b/docs/resources/cisco_system_feature_template.md index 55c1ccba3..3c33ec493 100644 --- a/docs/resources/cisco_system_feature_template.md +++ b/docs/resources/cisco_system_feature_template.md @@ -109,6 +109,9 @@ resource "sdwan_cisco_system_feature_template" "example" { - `device_groups_variable` (String) Variable name - `enable_mrf_migration` (String) Enable migration mode to Multi-Region Fabric - Choices: `enabled`, `enabled-from-bgp-core` +- `enhanced_app_aware_routing` (String) Enhanced App Aware Routing + - Choices: `disabled`, `aggressive`, `moderate`, `conservative` + - Default value: `disabled` - `geo_fencing` (Boolean) Enable Geo fencing - Default value: `false` - `geo_fencing_range` (Number) Set the device’s geo fencing range diff --git a/gen/definitions/feature_templates/cisco_system.yaml b/gen/definitions/feature_templates/cisco_system.yaml index a3eb55167..08be36586 100644 --- a/gen/definitions/feature_templates/cisco_system.yaml +++ b/gen/definitions/feature_templates/cisco_system.yaml @@ -1,4 +1,5 @@ --- +# Manual resource - Modals toBody and resources Create and Update methods are manually configured to support enhanced_app_aware_routing added in 20.12. name: Cisco System minimum_version: 15.0.0 attributes: @@ -177,6 +178,16 @@ attributes: example: 1 - model_name: transport-gateway example: true + - model_name: epfr + tf_name: enhanced_app_aware_routing + description: Enhanced App Aware Routing + no_augment_config: true + type: String + default_value_present: true + default_value: "disabled" + exclude_test: true + enum_values: ["disabled", "aggressive", "moderate", "conservative"] + example: aggressive - model_name: enable-mrf-migration example: enabled - model_name: migration-bgp-community diff --git a/internal/provider/data_source_sdwan_cisco_system_feature_template.go b/internal/provider/data_source_sdwan_cisco_system_feature_template.go index b6e6da58f..5b7b40ea6 100644 --- a/internal/provider/data_source_sdwan_cisco_system_feature_template.go +++ b/internal/provider/data_source_sdwan_cisco_system_feature_template.go @@ -545,6 +545,10 @@ func (d *CiscoSystemFeatureTemplateDataSource) Schema(ctx context.Context, req d MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, Computed: true, }, + "enhanced_app_aware_routing": schema.StringAttribute{ + MarkdownDescription: "Enhanced App Aware Routing", + Computed: true, + }, "enable_mrf_migration": schema.StringAttribute{ MarkdownDescription: "Enable migration mode to Multi-Region Fabric", Computed: true, diff --git a/internal/provider/model_sdwan_cisco_system_feature_template.go b/internal/provider/model_sdwan_cisco_system_feature_template.go index 061040c1e..de8c609ba 100644 --- a/internal/provider/model_sdwan_cisco_system_feature_template.go +++ b/internal/provider/model_sdwan_cisco_system_feature_template.go @@ -23,6 +23,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" @@ -30,6 +31,8 @@ import ( // End of section. //template:end imports +var MinCiscoSytemUpdateVersion = version.Must(version.NewVersion("20.12.0")) + // Section below is generated&owned by "gen/generator.go". //template:begin types type CiscoSystem struct { Id types.String `tfsdk:"id"` @@ -105,6 +108,7 @@ type CiscoSystem struct { AffinityGroupPreferenceVariable types.String `tfsdk:"affinity_group_preference_variable"` TransportGateway types.Bool `tfsdk:"transport_gateway"` TransportGatewayVariable types.String `tfsdk:"transport_gateway_variable"` + EnhancedAppAwareRouting types.String `tfsdk:"enhanced_app_aware_routing"` EnableMrfMigration types.String `tfsdk:"enable_mrf_migration"` MigrationBgpCommunity types.Int64 `tfsdk:"migration_bgp_community"` } @@ -171,9 +175,7 @@ func (data CiscoSystem) getModel() string { } // End of section. //template:end getModel - -// Section below is generated&owned by "gen/generator.go". //template:begin toBody -func (data CiscoSystem) toBody(ctx context.Context) string { +func (data CiscoSystem) toBody(ctx context.Context, version *version.Version) string { body := "" var device_types []string @@ -912,6 +914,17 @@ func (data CiscoSystem) toBody(ctx context.Context) string { body, _ = sjson.Set(body, path+"transport-gateway."+"vipType", "constant") body, _ = sjson.Set(body, path+"transport-gateway."+"vipValue", strconv.FormatBool(data.TransportGateway.ValueBool())) } + if version.LessThan(MinCiscoSytemUpdateVersion) { + } else { + if data.EnhancedAppAwareRouting.IsNull() { + body, _ = sjson.Set(body, path+"epfr."+"vipObjectType", "object") + body, _ = sjson.Set(body, path+"epfr."+"vipType", "ignore") + } else { + body, _ = sjson.Set(body, path+"epfr."+"vipObjectType", "object") + body, _ = sjson.Set(body, path+"epfr."+"vipType", "constant") + body, _ = sjson.Set(body, path+"epfr."+"vipValue", data.EnhancedAppAwareRouting.ValueString()) + } + } if data.EnableMrfMigration.IsNull() { body, _ = sjson.Set(body, path+"enable-mrf-migration."+"vipObjectType", "object") body, _ = sjson.Set(body, path+"enable-mrf-migration."+"vipType", "ignore") @@ -931,8 +944,6 @@ func (data CiscoSystem) 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 *CiscoSystem) fromBody(ctx context.Context, res gjson.Result) { if value := res.Get("deviceType"); value.Exists() { @@ -2004,6 +2015,22 @@ func (data *CiscoSystem) fromBody(ctx context.Context, res gjson.Result) { data.TransportGateway = types.BoolNull() data.TransportGatewayVariable = types.StringNull() } + if value := res.Get(path + "epfr.vipType"); value.Exists() { + if value.String() == "variableName" { + data.EnhancedAppAwareRouting = types.StringNull() + + } else if value.String() == "ignore" { + data.EnhancedAppAwareRouting = types.StringNull() + + } else if value.String() == "constant" { + v := res.Get(path + "epfr.vipValue") + data.EnhancedAppAwareRouting = types.StringValue(v.String()) + + } + } else { + data.EnhancedAppAwareRouting = types.StringNull() + + } if value := res.Get(path + "enable-mrf-migration.vipType"); value.Exists() { if value.String() == "variableName" { data.EnableMrfMigration = types.StringNull() @@ -2223,6 +2250,9 @@ func (data *CiscoSystem) hasChanges(ctx context.Context, state *CiscoSystem) boo if !data.TransportGateway.Equal(state.TransportGateway) { hasChanges = true } + if !data.EnhancedAppAwareRouting.Equal(state.EnhancedAppAwareRouting) { + hasChanges = true + } if !data.EnableMrfMigration.Equal(state.EnableMrfMigration) { hasChanges = true } diff --git a/internal/provider/resource_sdwan_cisco_system_feature_template.go b/internal/provider/resource_sdwan_cisco_system_feature_template.go index 655cda21e..f36419c97 100644 --- a/internal/provider/resource_sdwan_cisco_system_feature_template.go +++ b/internal/provider/resource_sdwan_cisco_system_feature_template.go @@ -25,6 +25,7 @@ import ( "sync" "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" @@ -655,6 +656,13 @@ func (r *CiscoSystemFeatureTemplateResource) Schema(ctx context.Context, req res MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, Optional: true, }, + "enhanced_app_aware_routing": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Enhanced App Aware Routing").AddStringEnumDescription("disabled", "aggressive", "moderate", "conservative").AddDefaultValueDescription("disabled").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.OneOf("disabled", "aggressive", "moderate", "conservative"), + }, + }, "enable_mrf_migration": schema.StringAttribute{ MarkdownDescription: helpers.NewAttributeDescription("Enable migration mode to Multi-Region Fabric").AddStringEnumDescription("enabled", "enabled-from-bgp-core").String, Optional: true, @@ -684,7 +692,6 @@ func (r *CiscoSystemFeatureTemplateResource) 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 *CiscoSystemFeatureTemplateResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var plan CiscoSystem @@ -697,8 +704,9 @@ func (r *CiscoSystemFeatureTemplateResource) Create(ctx context.Context, req res tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.Name.ValueString())) + version := version.Must(version.NewVersion(r.client.ManagerVersion)) // Create object - body := plan.toBody(ctx) + body := plan.toBody(ctx, version) res, err := r.client.Post("/template/feature", body) if err != nil { @@ -716,8 +724,6 @@ func (r *CiscoSystemFeatureTemplateResource) Create(ctx context.Context, req res resp.Diagnostics.Append(diags...) } -// End of section. //template:end create - // Section below is generated&owned by "gen/generator.go". //template:begin read func (r *CiscoSystemFeatureTemplateResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { var state CiscoSystem @@ -753,7 +759,6 @@ func (r *CiscoSystemFeatureTemplateResource) Read(ctx context.Context, req resou // End of section. //template:end read -// Section below is generated&owned by "gen/generator.go". //template:begin update func (r *CiscoSystemFeatureTemplateResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var plan, state CiscoSystem @@ -772,7 +777,9 @@ func (r *CiscoSystemFeatureTemplateResource) Update(ctx context.Context, req res tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.Name.ValueString())) - body := plan.toBody(ctx) + version := version.Must(version.NewVersion(r.client.ManagerVersion)) + // Create object + body := plan.toBody(ctx, version) r.updateMutex.Lock() res, err := r.client.Put("/template/feature/"+url.QueryEscape(plan.Id.ValueString()), body) r.updateMutex.Unlock() @@ -797,8 +804,6 @@ func (r *CiscoSystemFeatureTemplateResource) 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 *CiscoSystemFeatureTemplateResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { var state CiscoSystem diff --git a/templates/guides/changelog.md.tmpl b/templates/guides/changelog.md.tmpl index a15149d0c..11e32a168 100644 --- a/templates/guides/changelog.md.tmpl +++ b/templates/guides/changelog.md.tmpl @@ -7,6 +7,10 @@ description: |- # Changelog +## 0.6.2 + +- Adds `enhanced_app_aware_routing` support to the `sdwan_cisco_system_feature_template` resource and data source + ## 0.6.1 - BREAKING CHANGE: Replaces `no_authentication` attribute of `sdwan_transport_cellular_profile_feature` with `requires_authentication`