Skip to content

Commit 4695e66

Browse files
Modified fabric site resource to use new endpoint (#98)
1 parent b062e3f commit 4695e66

File tree

15 files changed

+168
-91
lines changed

15 files changed

+168
-91
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@ log*.txt
4444
.terraform.lock.hcl
4545
# Transient Terraform backend lock
4646
.terraform.tfstate.lock.info
47+
48+
.envrc

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+
- 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+
34
- Fix issue with mandatory attributes in `transit_peer_network` resource, [link](https://github.com/CiscoDevNet/terraform-provider-catalystcenter/issues/92)
45
- BREAKING CHANGE: Fix `ip_pool` update if more than 25 pools are registered
56
- BREAKING CHANGE: Rename `radio_type_a_power_treshold_v1` attribute of `catalystcenter_wireless_rf_profile` resource to `radio_type_a_power_threshold_v1`

docs/data-sources/fabric_site.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This data source can read the Fabric Site.
1414

1515
```terraform
1616
data "catalystcenter_fabric_site" "example" {
17-
id = "Global/Site1"
17+
id = "76d24097-41c4-4558-a4d0-a8c07ac08470"
1818
}
1919
```
2020

@@ -24,8 +24,9 @@ data "catalystcenter_fabric_site" "example" {
2424
### Optional
2525

2626
- `id` (String) The id of the object
27-
- `site_name_hierarchy` (String) Existing site name hierarchy available at global level
27+
- `site_id` (String) ID of the network hierarchy
2828

2929
### Read-Only
3030

31-
- `fabric_type` (String) Type of SD-Access Fabric
31+
- `authentication_profile_name` (String) Authentication profile used for this fabric
32+
- `pub_sub_enabled` (Boolean) Specifies whether this fabric site will use pub/sub for control nodes

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+
- 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+
1213
- Fix issue with mandatory attributes in `transit_peer_network` resource, [link](https://github.com/CiscoDevNet/terraform-provider-catalystcenter/issues/92)
1314
- BREAKING CHANGE: Fix `ip_pool` update if more than 25 pools are registered
1415
- BREAKING CHANGE: Rename `radio_type_a_power_treshold_v1` attribute of `catalystcenter_wireless_rf_profile` resource to `radio_type_a_power_threshold_v1`

docs/resources/fabric_site.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
page_title: "catalystcenter_fabric_site Resource - terraform-provider-catalystcenter"
44
subcategory: "SDA"
55
description: |-
6-
This resource can manage a Fabric Site.
6+
Manages Fabric Sites
77
---
88

99
# catalystcenter_fabric_site (Resource)
1010

11-
This resource can manage a Fabric Site.
11+
Manages Fabric Sites
1212

1313
## Example Usage
1414

1515
```terraform
1616
resource "catalystcenter_fabric_site" "example" {
17-
site_name_hierarchy = "Global/Site1"
18-
fabric_type = "FABRIC_SITE"
17+
site_id = "8e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1"
18+
authentication_profile_name = "No Authentication"
19+
pub_sub_enabled = false
1920
}
2021
```
2122

@@ -24,13 +25,10 @@ resource "catalystcenter_fabric_site" "example" {
2425

2526
### Required
2627

27-
- `site_name_hierarchy` (String) Existing site name hierarchy available at global level
28-
29-
### Optional
30-
31-
- `fabric_type` (String) Type of SD-Access Fabric
32-
- Choices: `FABRIC_SITE`, `FABRIC_ZONE`
33-
- Default value: `FABRIC_SITE`
28+
- `authentication_profile_name` (String) Authentication profile used for this fabric
29+
- Choices: `Closed Authentication`, `Low Impact`, `No Authentication`, `Open Authentication`
30+
- `pub_sub_enabled` (Boolean) Specifies whether this fabric site will use pub/sub for control nodes
31+
- `site_id` (String) ID of the network hierarchy
3432

3533
### Read-Only
3634

@@ -41,5 +39,5 @@ resource "catalystcenter_fabric_site" "example" {
4139
Import is supported using the following syntax:
4240

4341
```shell
44-
terraform import catalystcenter_fabric_site.example "<site_name_hierarchy>"
42+
terraform import catalystcenter_fabric_site.example "<id>"
4543
```
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
data "catalystcenter_fabric_site" "example" {
2-
id = "Global/Site1"
2+
id = "76d24097-41c4-4558-a4d0-a8c07ac08470"
33
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
terraform import catalystcenter_fabric_site.example "<site_name_hierarchy>"
1+
terraform import catalystcenter_fabric_site.example "<id>"
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
resource "catalystcenter_fabric_site" "example" {
2-
site_name_hierarchy = "Global/Site1"
3-
fabric_type = "FABRIC_SITE"
2+
site_id = "8e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1"
3+
authentication_profile_name = "No Authentication"
4+
pub_sub_enabled = false
45
}

gen/definitions/fabric_site.yaml

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,41 @@
11
---
22
name: Fabric Site
3-
rest_endpoint: /dna/intent/api/v1/business/sda/fabric-site
4-
id_from_attribute: true
5-
id_query_param: siteNameHierarchy
6-
delete_id_query_param: siteNameHierarchy
7-
no_update: true
8-
skip_minimum_test: true
3+
rest_endpoint: /dna/intent/api/v1/sda/fabricSites
4+
get_rest_endpoint: /dna/intent/api/v1/sda/fabricSites?limit=500
5+
res_description: Manages Fabric Sites
6+
id_from_query_path: response
7+
get_from_all: true
8+
put_id_include_path: "0.id"
9+
put_no_id: true
910
doc_category: SDA
1011
attributes:
11-
- model_name: siteNameHierarchy
12-
type: String
13-
id: true
12+
- model_name: siteId
13+
requires_replace: true
14+
data_path: '0'
15+
match_id: true
1416
data_source_query: true
15-
description: Existing site name hierarchy available at global level
16-
example: Global/Site1
17-
test_value: '"${catalystcenter_area.test.parent_name}/${catalystcenter_area.test.name}"'
18-
- model_name: fabricType
17+
response_data_path: siteId
18+
mandatory: true
19+
type: String
20+
description: ID of the network hierarchy
21+
example: 8e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1
22+
test_value: catalystcenter_area.test.id
23+
- model_name: authenticationProfileName
24+
data_path: '0'
25+
response_data_path: authenticationProfileName
26+
mandatory: true
1927
type: String
20-
description: Type of SD-Access Fabric
21-
enum_values: [FABRIC_SITE, FABRIC_ZONE]
22-
write_only: true # when configuring FABRIC_SITE, GET return FABRIC_LAN (v2.3.7.4)
23-
requires_replace: true # PUT not implemented
24-
example: FABRIC_SITE
25-
default_value: FABRIC_SITE
28+
description: Authentication profile used for this fabric
29+
enum_values: [Closed Authentication, Low Impact, No Authentication, Open Authentication]
30+
example: No Authentication
31+
- model_name: isPubSubEnabled
32+
data_path: '0'
33+
response_data_path: isPubSubEnabled
34+
tf_name: pub_sub_enabled
35+
type: Bool
36+
mandatory: true
37+
description: Specifies whether this fabric site will use pub/sub for control nodes
38+
example: false
2639
test_prerequisites: |
2740
resource "catalystcenter_area" "test" {
2841
name = "Area 1"

internal/provider/data_source_catalystcenter_fabric_site.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ package provider
2121
import (
2222
"context"
2323
"fmt"
24-
"net/url"
2524

2625
"github.com/hashicorp/terraform-plugin-framework-validators/datasourcevalidator"
2726
"github.com/hashicorp/terraform-plugin-framework/datasource"
@@ -66,13 +65,17 @@ func (d *FabricSiteDataSource) Schema(ctx context.Context, req datasource.Schema
6665
Optional: true,
6766
Computed: true,
6867
},
69-
"site_name_hierarchy": schema.StringAttribute{
70-
MarkdownDescription: "Existing site name hierarchy available at global level",
68+
"site_id": schema.StringAttribute{
69+
MarkdownDescription: "ID of the network hierarchy",
7170
Optional: true,
7271
Computed: true,
7372
},
74-
"fabric_type": schema.StringAttribute{
75-
MarkdownDescription: "Type of SD-Access Fabric",
73+
"authentication_profile_name": schema.StringAttribute{
74+
MarkdownDescription: "Authentication profile used for this fabric",
75+
Computed: true,
76+
},
77+
"pub_sub_enabled": schema.BoolAttribute{
78+
MarkdownDescription: "Specifies whether this fabric site will use pub/sub for control nodes",
7679
Computed: true,
7780
},
7881
},
@@ -82,7 +85,7 @@ func (d *FabricSiteDataSource) ConfigValidators(ctx context.Context) []datasourc
8285
return []datasource.ConfigValidator{
8386
datasourcevalidator.ExactlyOneOf(
8487
path.MatchRoot("id"),
85-
path.MatchRoot("site_name_hierarchy"),
88+
path.MatchRoot("site_id"),
8689
),
8790
}
8891
}
@@ -109,36 +112,36 @@ func (d *FabricSiteDataSource) Read(ctx context.Context, req datasource.ReadRequ
109112
}
110113

111114
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String()))
112-
if config.Id.IsNull() && !config.SiteNameHierarchy.IsNull() {
113-
res, err := d.client.Get(config.getPath())
115+
if config.Id.IsNull() && !config.SiteId.IsNull() {
116+
res, err := d.client.Get("/dna/intent/api/v1/sda/fabricSites?limit=500")
114117
if err != nil {
115118
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve objects, got error: %s", err))
116119
return
117120
}
118-
if value := res; len(value.Array()) > 0 {
121+
if value := res.Get("response"); len(value.Array()) > 0 {
119122
value.ForEach(func(k, v gjson.Result) bool {
120-
if config.SiteNameHierarchy.ValueString() == v.Get("siteNameHierarchy").String() {
123+
if config.SiteId.ValueString() == v.Get("siteId").String() {
121124
config.Id = types.StringValue(v.Get("id").String())
122-
tflog.Debug(ctx, fmt.Sprintf("%s: Found object with siteNameHierarchy '%v', id: %v", config.Id.String(), config.SiteNameHierarchy.ValueString(), config.Id.String()))
125+
tflog.Debug(ctx, fmt.Sprintf("%s: Found object with siteId '%v', id: %v", config.Id.String(), config.SiteId.ValueString(), config.Id.String()))
123126
return false
124127
}
125128
return true
126129
})
127130
}
128131

129132
if config.Id.IsNull() {
130-
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to find object with siteNameHierarchy: %s", config.SiteNameHierarchy.ValueString()))
133+
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to find object with siteId: %s", config.SiteId.ValueString()))
131134
return
132135
}
133136
}
134137

135138
params := ""
136-
params += "?siteNameHierarchy=" + url.QueryEscape(config.Id.ValueString())
137-
res, err := d.client.Get(config.getPath() + params)
139+
res, err := d.client.Get("/dna/intent/api/v1/sda/fabricSites?limit=500" + params)
138140
if err != nil {
139141
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err))
140142
return
141143
}
144+
res = res.Get("response.#(id==\"" + config.Id.ValueString() + "\")")
142145

143146
config.fromBody(ctx, res)
144147

0 commit comments

Comments
 (0)