Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fx issue #165 in catalystcenter_assign_templates_to_tag #167

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 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

- Add `catalystcenter_fabric_l3_virtual_network` resource and data source
Expand Down
5 changes: 5 additions & 0 deletions docs/guides/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ description: |-

# Changelog

## 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

- Add `catalystcenter_fabric_l3_virtual_network` resource and data source
Expand Down
5 changes: 3 additions & 2 deletions docs/resources/anycast_gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```

Expand All @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 3 additions & 2 deletions gen/definitions/anycast_gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion gen/definitions/assign_templates_to_tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 += `
Expand Down
10 changes: 0 additions & 10 deletions internal/provider/model_catalystcenter_anycast_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/resource_catalystcenter_anycast_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
Expand Down Expand Up @@ -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,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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

Expand Down
5 changes: 5 additions & 0 deletions templates/guides/changelog.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ description: |-

# Changelog

## 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

- Add `catalystcenter_fabric_l3_virtual_network` resource and data source
Expand Down
Loading