From 19c8b8b3800aa82fa033be123996e100ca1bef87 Mon Sep 17 00:00:00 2001 From: kuba-mazurkiewicz Date: Tue, 14 Jan 2025 11:23:29 +0100 Subject: [PATCH 1/3] fx issue #165 in catalystcenter_assign_templates_to_tag --- CHANGELOG.md | 4 +++ docs/guides/changelog.md | 4 +++ gen/definitions/assign_templates_to_tag.yaml | 2 +- ..._catalystcenter_assign_templates_to_tag.go | 34 +++++++++++++++++-- templates/guides/changelog.md.tmpl | 4 +++ 5 files changed, 44 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d5605b..569cd3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.19 (unreleased) + +- Fix issue with tags removal from templates in `catalystcenter_assign_templates_to_tag` resource, [link](https://github.com/CiscoDevNet/terraform-provider-catalystcenter/issues/165) + ## 0.1.18 - Add `catalystcenter_fabric_l3_virtual_network` resource and data source diff --git a/docs/guides/changelog.md b/docs/guides/changelog.md index 751777b..2d0726a 100644 --- a/docs/guides/changelog.md +++ b/docs/guides/changelog.md @@ -7,6 +7,10 @@ description: |- # Changelog +## 0.1.19 (unreleased) + +- Fix issue with tags removal from templates in `catalystcenter_assign_templates_to_tag` resource, [link](https://github.com/CiscoDevNet/terraform-provider-catalystcenter/issues/165) + ## 0.1.18 - Add `catalystcenter_fabric_l3_virtual_network` resource and data source diff --git a/gen/definitions/assign_templates_to_tag.yaml b/gen/definitions/assign_templates_to_tag.yaml index a41de28..b3eaeaf 100644 --- a/gen/definitions/assign_templates_to_tag.yaml +++ b/gen/definitions/assign_templates_to_tag.yaml @@ -3,7 +3,7 @@ name: Assign Templates to Tag rest_endpoint: /dna/intent/api/v1/tag/%v/member get_extra_query_params: '?memberType=template' get_no_id: true -# Manual updates in Delete function to handle removal of templates from tag in resource file, and fromBody, updateFromBody functions in model file +# Manual updates in Update and Delete function to handle removal of templates from tag in resource file, and fromBody, updateFromBody functions in model file res_description: 'This resource is responsible for assigning templates to a specified tag during creation and removing the template from the tag during destroy operation.' post_update: true diff --git a/internal/provider/resource_catalystcenter_assign_templates_to_tag.go b/internal/provider/resource_catalystcenter_assign_templates_to_tag.go index 7881863..a410fe3 100644 --- a/internal/provider/resource_catalystcenter_assign_templates_to_tag.go +++ b/internal/provider/resource_catalystcenter_assign_templates_to_tag.go @@ -163,7 +163,6 @@ func (r *AssignTemplatesToTagResource) Read(ctx context.Context, req resource.Re // End of section. //template:end read -// Section below is generated&owned by "gen/generator.go". //template:begin update func (r *AssignTemplatesToTagResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var plan, state AssignTemplatesToTag @@ -182,6 +181,37 @@ func (r *AssignTemplatesToTagResource) Update(ctx context.Context, req resource. tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.Id.ValueString())) + // Handle removed template IDs + stateTemplateIds := make(map[string]struct{}) + planTemplateIds := make(map[string]struct{}) + + if !state.TemplateIds.IsNull() { + var stateValues []string + state.TemplateIds.ElementsAs(ctx, &stateValues, false) + for _, id := range stateValues { + stateTemplateIds[id] = struct{}{} + } + } + + if !plan.TemplateIds.IsNull() { + var planValues []string + plan.TemplateIds.ElementsAs(ctx, &planValues, false) + for _, id := range planValues { + planTemplateIds[id] = struct{}{} + } + } + + for id := range stateTemplateIds { + if _, exists := planTemplateIds[id]; !exists { + _, err := r.client.Delete(plan.getPath() + "/" + url.QueryEscape(id)) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete template (%s), got error: %s", id, err)) + return + } + } + } + // + body := plan.toBody(ctx, state) params := "" res, err := r.client.Post(plan.getPath()+params, body) @@ -196,8 +226,6 @@ func (r *AssignTemplatesToTagResource) Update(ctx context.Context, req resource. resp.Diagnostics.Append(diags...) } -// End of section. //template:end update - func (r *AssignTemplatesToTagResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { var state AssignTemplatesToTag diff --git a/templates/guides/changelog.md.tmpl b/templates/guides/changelog.md.tmpl index 751777b..2d0726a 100644 --- a/templates/guides/changelog.md.tmpl +++ b/templates/guides/changelog.md.tmpl @@ -7,6 +7,10 @@ description: |- # Changelog +## 0.1.19 (unreleased) + +- Fix issue with tags removal from templates in `catalystcenter_assign_templates_to_tag` resource, [link](https://github.com/CiscoDevNet/terraform-provider-catalystcenter/issues/165) + ## 0.1.18 - Add `catalystcenter_fabric_l3_virtual_network` resource and data source From b104f506f010c900e4564bc80b3be769753c657a Mon Sep 17 00:00:00 2001 From: kuba-mazurkiewicz Date: Thu, 16 Jan 2025 12:21:52 +0100 Subject: [PATCH 2/3] add support for auto_generated_vlan_name in catalystcenter_anycast_gatewy resource --- CHANGELOG.md | 1 + docs/guides/changelog.md | 1 + docs/resources/anycast_gateway.md | 5 +++-- .../catalystcenter_anycast_gateway/resource.tf | 1 + gen/definitions/anycast_gateway.yaml | 5 +++-- .../data_source_catalystcenter_anycast_gateway_test.go | 1 + .../provider/model_catalystcenter_anycast_gateway.go | 10 ---------- .../resource_catalystcenter_anycast_gateway.go | 4 ++-- .../resource_catalystcenter_anycast_gateway_test.go | 3 ++- templates/guides/changelog.md.tmpl | 1 + 10 files changed, 15 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 569cd3f..ef8fe21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 0.1.19 (unreleased) +- Add support for auto_generated_vlan_name in `catalystcenter_anycast_gateway` resource - Fix issue with tags removal from templates in `catalystcenter_assign_templates_to_tag` resource, [link](https://github.com/CiscoDevNet/terraform-provider-catalystcenter/issues/165) ## 0.1.18 diff --git a/docs/guides/changelog.md b/docs/guides/changelog.md index 2d0726a..fa6468c 100644 --- a/docs/guides/changelog.md +++ b/docs/guides/changelog.md @@ -9,6 +9,7 @@ description: |- ## 0.1.19 (unreleased) +- Add support for auto_generated_vlan_name in `catalystcenter_anycast_gateway` resource - Fix issue with tags removal from templates in `catalystcenter_assign_templates_to_tag` resource, [link](https://github.com/CiscoDevNet/terraform-provider-catalystcenter/issues/165) ## 0.1.18 diff --git a/docs/resources/anycast_gateway.md b/docs/resources/anycast_gateway.md index 97ece4c..85fd2a0 100644 --- a/docs/resources/anycast_gateway.md +++ b/docs/resources/anycast_gateway.md @@ -27,6 +27,7 @@ resource "catalystcenter_anycast_gateway" "example" { ip_directed_broadcast = false intra_subnet_routing_enabled = false multiple_ip_to_mac_addresses = false + auto_generate_vlan_name = false } ``` @@ -35,16 +36,15 @@ resource "catalystcenter_anycast_gateway" "example" { ### Required +- `auto_generate_vlan_name` (Boolean) This field cannot be true when vlanName is provided. the vlanName will be generated as ipPoolGroupV4Cidr-virtualNetworkName for non-critical VLANs. for critical VLANs with DATA trafficType, vlanName will be CRITICAL_VLAN. for critical VLANs with VOICE trafficType, vlanName will be VOICE_VLAN - `fabric_id` (String) ID of the fabric to contain this anycast gateway - `ip_pool_name` (String) Name of the IP pool associated with the anycast gateway - `traffic_type` (String) The type of traffic the anycast gateway serves - Choices: `DATA`, `VOICE` - `virtual_network_name` (String) Name of the layer 3 virtual network associated with the anycast gateway. the virtual network must have already been added to the site before creating an anycast gateway with it -- `vlan_name` (String) Name of the VLAN of the anycast gateway ### Optional -- `auto_generate_vlan_name` (Boolean) This field cannot be true when vlanName is provided. the vlanName will be generated as ipPoolGroupV4Cidr-virtualNetworkName for non-critical VLANs. for critical VLANs with DATA trafficType, vlanName will be CRITICAL_VLAN. for critical VLANs with VOICE trafficType, vlanName will be VOICE_VLAN - `critical_pool` (Boolean) Enable/disable critical VLAN. if true, autoGenerateVlanName must also be true. (isCriticalPool is not applicable to INFRA_VN) - `intra_subnet_routing_enabled` (Boolean) Enable/disable Intra-Subnet Routing (not applicable to INFRA_VN) - `ip_directed_broadcast` (Boolean) Enable/disable IP-directed broadcast (not applicable to INFRA_VN) @@ -57,6 +57,7 @@ resource "catalystcenter_anycast_gateway" "example" { - `tcp_mss_adjustment` (Number) TCP maximum segment size adjustment - Range: `500`-`1440` - `vlan_id` (Number) ID of the VLAN of the anycast gateway. allowed VLAN range is 2-4093 except for reserved VLANs 1002-1005, 2046, and 4094. if deploying an anycast gateway on a fabric zone, this vlanId must match the vlanId of the corresponding anycast gateway on the fabric site +- `vlan_name` (String) Name of the VLAN of the anycast gateway - `wireless_pool` (Boolean) Enable/disable fabric-enabled wireless (not applicable to INFRA_VN) ### Read-Only diff --git a/examples/resources/catalystcenter_anycast_gateway/resource.tf b/examples/resources/catalystcenter_anycast_gateway/resource.tf index 6920b96..bc92fc8 100644 --- a/examples/resources/catalystcenter_anycast_gateway/resource.tf +++ b/examples/resources/catalystcenter_anycast_gateway/resource.tf @@ -12,4 +12,5 @@ resource "catalystcenter_anycast_gateway" "example" { ip_directed_broadcast = false intra_subnet_routing_enabled = false multiple_ip_to_mac_addresses = false + auto_generate_vlan_name = false } diff --git a/gen/definitions/anycast_gateway.yaml b/gen/definitions/anycast_gateway.yaml index f950df2..7461474 100644 --- a/gen/definitions/anycast_gateway.yaml +++ b/gen/definitions/anycast_gateway.yaml @@ -56,7 +56,6 @@ attributes: response_data_path: response.0.vlanName type: String description: Name of the VLAN of the anycast gateway - mandatory: true example: VLAN401 - model_name: vlanId requires_replace: true @@ -141,8 +140,10 @@ attributes: data_path: '0' response_data_path: response.0.autoGenerateVlanName type: Bool + mandatory: true + write_only: true description: 'This field cannot be true when vlanName is provided. the vlanName will be generated as ipPoolGroupV4Cidr-virtualNetworkName for non-critical VLANs. for critical VLANs with DATA trafficType, vlanName will be CRITICAL_VLAN. for critical VLANs with VOICE trafficType, vlanName will be VOICE_VLAN' - exclude_test: true + example: false test_prerequisites: | resource "catalystcenter_area" "test" { name = "Area1" diff --git a/internal/provider/data_source_catalystcenter_anycast_gateway_test.go b/internal/provider/data_source_catalystcenter_anycast_gateway_test.go index ac49402..053b88b 100644 --- a/internal/provider/data_source_catalystcenter_anycast_gateway_test.go +++ b/internal/provider/data_source_catalystcenter_anycast_gateway_test.go @@ -108,6 +108,7 @@ func testAccDataSourceCcAnycastGatewayConfig() string { config += ` ip_directed_broadcast = false` + "\n" config += ` intra_subnet_routing_enabled = false` + "\n" config += ` multiple_ip_to_mac_addresses = false` + "\n" + config += ` auto_generate_vlan_name = false` + "\n" config += `}` + "\n" config += ` diff --git a/internal/provider/model_catalystcenter_anycast_gateway.go b/internal/provider/model_catalystcenter_anycast_gateway.go index 6ed8574..f5da522 100644 --- a/internal/provider/model_catalystcenter_anycast_gateway.go +++ b/internal/provider/model_catalystcenter_anycast_gateway.go @@ -216,11 +216,6 @@ func (data *AnycastGateway) fromBody(ctx context.Context, res gjson.Result) { } else { data.SupplicantBasedExtendedNodeOnboarding = types.BoolNull() } - if value := res.Get("response.0.autoGenerateVlanName"); value.Exists() { - data.AutoGenerateVlanName = types.BoolValue(value.Bool()) - } else { - data.AutoGenerateVlanName = types.BoolNull() - } } // End of section. //template:end fromBody @@ -307,11 +302,6 @@ func (data *AnycastGateway) updateFromBody(ctx context.Context, res gjson.Result } else { data.SupplicantBasedExtendedNodeOnboarding = types.BoolNull() } - if value := res.Get("response.0.autoGenerateVlanName"); value.Exists() && !data.AutoGenerateVlanName.IsNull() { - data.AutoGenerateVlanName = types.BoolValue(value.Bool()) - } else { - data.AutoGenerateVlanName = types.BoolNull() - } } // End of section. //template:end updateFromBody diff --git a/internal/provider/resource_catalystcenter_anycast_gateway.go b/internal/provider/resource_catalystcenter_anycast_gateway.go index 5964265..2b76bcf 100644 --- a/internal/provider/resource_catalystcenter_anycast_gateway.go +++ b/internal/provider/resource_catalystcenter_anycast_gateway.go @@ -103,7 +103,7 @@ func (r *AnycastGatewayResource) Schema(ctx context.Context, req resource.Schema }, "vlan_name": schema.StringAttribute{ MarkdownDescription: helpers.NewAttributeDescription("Name of the VLAN of the anycast gateway").String, - Required: true, + Optional: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.RequiresReplace(), }, @@ -169,7 +169,7 @@ func (r *AnycastGatewayResource) Schema(ctx context.Context, req resource.Schema }, "auto_generate_vlan_name": schema.BoolAttribute{ MarkdownDescription: helpers.NewAttributeDescription("This field cannot be true when vlanName is provided. the vlanName will be generated as ipPoolGroupV4Cidr-virtualNetworkName for non-critical VLANs. for critical VLANs with DATA trafficType, vlanName will be CRITICAL_VLAN. for critical VLANs with VOICE trafficType, vlanName will be VOICE_VLAN").String, - Optional: true, + Required: true, }, }, } diff --git a/internal/provider/resource_catalystcenter_anycast_gateway_test.go b/internal/provider/resource_catalystcenter_anycast_gateway_test.go index 6cae5de..d90ff16 100644 --- a/internal/provider/resource_catalystcenter_anycast_gateway_test.go +++ b/internal/provider/resource_catalystcenter_anycast_gateway_test.go @@ -100,8 +100,8 @@ func testAccCcAnycastGatewayConfig_minimum() string { config += ` fabric_id = catalystcenter_fabric_site.test.id` + "\n" config += ` virtual_network_name = catalystcenter_virtual_network_to_fabric_site.test.virtual_network_name` + "\n" config += ` ip_pool_name = catalystcenter_ip_pool_reservation.test.name` + "\n" - config += ` vlan_name = "VLAN401"` + "\n" config += ` traffic_type = "DATA"` + "\n" + config += ` auto_generate_vlan_name = false` + "\n" config += `}` + "\n" return config } @@ -124,6 +124,7 @@ func testAccCcAnycastGatewayConfig_all() string { config += ` ip_directed_broadcast = false` + "\n" config += ` intra_subnet_routing_enabled = false` + "\n" config += ` multiple_ip_to_mac_addresses = false` + "\n" + config += ` auto_generate_vlan_name = false` + "\n" config += `}` + "\n" return config } diff --git a/templates/guides/changelog.md.tmpl b/templates/guides/changelog.md.tmpl index 2d0726a..fa6468c 100644 --- a/templates/guides/changelog.md.tmpl +++ b/templates/guides/changelog.md.tmpl @@ -9,6 +9,7 @@ description: |- ## 0.1.19 (unreleased) +- Add support for auto_generated_vlan_name in `catalystcenter_anycast_gateway` resource - Fix issue with tags removal from templates in `catalystcenter_assign_templates_to_tag` resource, [link](https://github.com/CiscoDevNet/terraform-provider-catalystcenter/issues/165) ## 0.1.18 From dad71b7ada6e9337fd3a0655f0bde9a476f887ce Mon Sep 17 00:00:00 2001 From: kuba-mazurkiewicz Date: Thu, 16 Jan 2025 12:36:07 +0100 Subject: [PATCH 3/3] fix pipeline --- .github/workflows/test.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b356877..f5490a3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,6 +22,11 @@ jobs: name: Build runs-on: ubuntu-latest timeout-minutes: 5 + strategy: + matrix: + terraform: + - "1.0.*" + - "1.5.*" steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 @@ -31,6 +36,10 @@ jobs: with: go-version-file: "go.mod" cache: true + - uses: hashicorp/setup-terraform@v3 + with: + terraform_version: ${{ matrix.terraform }} + terraform_wrapper: false - run: pip install yamale - run: yamale -s gen/schema/schema.yaml gen/definitions/ - run: go mod download