Skip to content

Commit 79b2087

Browse files
Modify transit_peer_network resource to add id (#100)
1 parent 59c274e commit 79b2087

17 files changed

+47
-81
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 0.1.10 (unreleased)
22

3+
- Add `transitPeerNetworkId` as `id` to `transit_peer_network` resource
34
- Add `anycast_gateway` resource and data source, this resource now only works with Catalyst Center version 2.3.7.5+ `/sda/anycastGateways`
45
- BREAKING CHANGE: Modified `fabric_site` resource to use `/dna/intent/api/v1/sda/fabricSites` API endpoint, this resource now only works with Catalyst Center version 2.3.7.5+
56
- Fix issue with mandatory attributes in `transit_peer_network` resource, [link](https://github.com/CiscoDevNet/terraform-provider-catalystcenter/issues/92)

docs/data-sources/transit_peer_network.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ This data source can read the Transit Peer Network.
1414

1515
```terraform
1616
data "catalystcenter_transit_peer_network" "example" {
17-
id = "TRANSIT_1"
17+
transit_peer_network_name = "TRANSIT_1"
1818
}
1919
```
2020

2121
<!-- schema generated by tfplugindocs -->
2222
## Schema
2323

24-
### Optional
24+
### Required
2525

26-
- `id` (String) The id of the object
2726
- `transit_peer_network_name` (String) Transit Peer Network Name
2827

2928
### Read-Only
3029

3130
- `autonomous_system_number` (String) Autonomous System Number
31+
- `id` (String) The id of the object
3232
- `routing_protocol_name` (String) Routing Protocol Name
3333
- `transit_control_plane_settings` (Attributes List) Transit Control Plane Settings info (see [below for nested schema](#nestedatt--transit_control_plane_settings))
3434
- `transit_peer_network_type` (String) Transit Peer Network Type

docs/guides/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ description: |-
99

1010
## 0.1.10 (unreleased)
1111

12+
- Add `transitPeerNetworkId` as `id` to `transit_peer_network` resource
1213
- Add `anycast_gateway` resource and data source, this resource now only works with Catalyst Center version 2.3.7.5+ `/sda/anycastGateways`
1314
- BREAKING CHANGE: Modified `fabric_site` resource to use `/dna/intent/api/v1/sda/fabricSites` API endpoint, this resource now only works with Catalyst Center version 2.3.7.5+
1415
- Fix issue with mandatory attributes in `transit_peer_network` resource, [link](https://github.com/CiscoDevNet/terraform-provider-catalystcenter/issues/92)

docs/resources/transit_peer_network.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ resource "catalystcenter_transit_peer_network" "example" {
1818
transit_peer_network_type = "ip_transit"
1919
routing_protocol_name = "BGP"
2020
autonomous_system_number = "65010"
21-
transit_control_plane_settings = [
22-
{
23-
site_name_hierarchy = "Global/Area1"
24-
device_management_ip_address = "10.0.0.1"
25-
}
26-
]
2721
}
2822
```
2923

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
data "catalystcenter_transit_peer_network" "example" {
2-
id = "TRANSIT_1"
2+
transit_peer_network_name = "TRANSIT_1"
33
}

examples/resources/catalystcenter_transit_peer_network/resource.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,4 @@ resource "catalystcenter_transit_peer_network" "example" {
33
transit_peer_network_type = "ip_transit"
44
routing_protocol_name = "BGP"
55
autonomous_system_number = "65010"
6-
transit_control_plane_settings = [
7-
{
8-
site_name_hierarchy = "Global/Area1"
9-
device_management_ip_address = "10.0.0.1"
10-
}
11-
]
126
}

gen/definitions/transit_peer_network.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
---
22
name: Transit Peer Network
33
rest_endpoint: /dna/intent/api/v1/business/sda/transit-peer-network
4-
id_from_attribute: true
5-
id_query_param: transitPeerNetworkName
6-
delete_id_query_param: transitPeerNetworkName
4+
id_from_query_path: .
5+
id_from_query_path_attribute: transitPeerNetworkId
6+
import_no_id: true
7+
data_source_no_id: true
78
no_update: true
89
skip_minimum_test: true
910
doc_category: SDA
1011
attributes:
1112
- model_name: transitPeerNetworkName
1213
type: String
13-
id: true
14-
data_source_query: true
14+
query_param: true
15+
delete_query_param: true
16+
mandatory: true
17+
requires_replace: true
1518
description: Transit Peer Network Name
1619
example: TRANSIT_1
1720
- model_name: transitPeerNetworkType
@@ -37,6 +40,7 @@ attributes:
3740
- model_name: transitControlPlaneSettings
3841
data_path: sdaTransitSettings
3942
write_only: true
43+
exclude_test: true
4044
type: List
4145
description: Transit Control Plane Settings info
4246
attributes:

gen/definitions/wireless_profile.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ doc_category: Wireless
1313
attributes:
1414
- model_name: wirelessProfileName
1515
tf_name: name
16+
delete_query_param_name: name
1617
delete_query_param: true
1718
type: String
1819
match_id: true

gen/templates/model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func (data {{camelCase .Name}}) toBody(ctx context.Context, state {{camelCase .N
307307
func (data *{{camelCase .Name}}) fromBody(ctx context.Context, res gjson.Result) {
308308
{{- if .DataSourceNoId}}
309309
// Retrieve the 'id' attribute, if Data Source doesn't require id
310-
if value := res.Get("{{if .IdFromQueryPath}}{{.IdFromQueryPath}}.{{if .IdFromQueryPathAttribute}}{{.IdFromQueryPathAttribute}}{{else}}id{{end}}{{end}}"); value.Exists() {
310+
if value := res.Get("{{if .IdFromQueryPath}}{{if eq .IdFromQueryPath "." }}{{else}}{{.IdFromQueryPath}}.{{end}}{{if .IdFromQueryPathAttribute}}{{.IdFromQueryPathAttribute}}{{else}}id{{end}}{{end}}"); value.Exists() {
311311
data.Id = types.StringValue(value.String())
312312
} else {
313313
data.Id = types.StringNull()

gen/templates/resource.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ func (r *{{camelCase .Name}}Resource) Create(ctx context.Context, req resource.C
457457
return
458458
}
459459
{{- if and .IdFromQueryPathAttribute .IdFromQueryPath (not .GetExtraQueryParams) (not .GetFromAll) }}
460-
plan.Id = types.StringValue(res.Get("{{if .IdFromQueryPath}}{{.IdFromQueryPath}}.{{end}}{{.IdFromQueryPathAttribute}}").String())
460+
plan.Id = types.StringValue(res.Get("{{if eq .IdFromQueryPath "." }}{{else}}{{.IdFromQueryPath}}.{{end}}{{.IdFromQueryPathAttribute}}").String())
461461
{{- else}}
462462
plan.Id = types.StringValue(res.Get("{{.IdFromQueryPath}}.#({{if $id.ResponseModelName}}{{$id.ResponseModelName}}{{else}}{{$id.ModelName}}{{end}}==\""+ plan.{{toGoName $id.TfName}}.Value{{$id.Type}}() +"\").{{if .IdFromQueryPathAttribute}}{{.IdFromQueryPathAttribute}}{{else}}id{{end}}").String())
463463
{{- end}}
@@ -611,9 +611,12 @@ func (r *{{camelCase .Name}}Resource) Delete(ctx context.Context, req resource.D
611611
res, err := r.client.Delete({{if .DeleteRestEndpoint}}state.getPathDelete(){{else}}state.getPath(){{end}})
612612
{{- else if .DeleteIdQueryParam}}
613613
res, err := r.client.Delete({{if .DeleteRestEndpoint}}state.getPathDelete(){{else}}state.getPath(){{end}} + "?{{.DeleteIdQueryParam}}=" + url.QueryEscape(state.Id.ValueString()))
614-
{{- else if hasDeleteQueryParam .Attributes}}
615-
{{- $deleteQueryParam := getDeleteQueryParam .Attributes}}
616-
res, err := r.client.Delete({{if .DeleteRestEndpoint}}state.getPathDelete(){{else}}state.getPath(){{end}} + "?{{$deleteQueryParam.TfName}}=" + url.QueryEscape(state.{{toGoName $deleteQueryParam.TfName}}.Value{{$deleteQueryParam.Type}}()))
614+
{{- else if hasDeleteQueryParam .Attributes }}
615+
{{- $queryParams := generateQueryParamString "DELETE" "state" .Attributes }}
616+
{{- if $queryParams }}
617+
params := {{$queryParams}}
618+
{{- end}}
619+
res, err := r.client.Delete({{if .DeleteRestEndpoint}}state.getPathDelete(){{else}}state.getPath(){{end}} + params)
617620
{{- else}}
618621
res, err := r.client.Delete({{if .DeleteRestEndpoint}}state.getPathDelete(){{else}}state.getPath(){{end}} + "/" + url.QueryEscape(state.Id.ValueString()))
619622
{{- end}}

0 commit comments

Comments
 (0)