Skip to content

Commit eeb4f07

Browse files
Fix issue #122 (#123)
1 parent bf0a03f commit eeb4f07

File tree

13 files changed

+72
-28
lines changed

13 files changed

+72
-28
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Add `catalystcenter_fabric_port_assignment` resource and data source
77
- BREAKING CHANGE: Replace `catalystcenter_peer_transit_network` with `catalystcenter_transit_network` resource and data source to use `/dna/intent/api/v1/sda/transitNetworks` API endpoint, this resource now only works with Catalyst Center version 2.3.7.6+
88
- Add `catalystcenter_authentication_policy_server` resource and data source
9+
- Fix issue with import of `catalystcenter_ip_pool_reservation` resource, [link](https://github.com/CiscoDevNet/terraform-provider-catalystcenter/issues/122)
910

1011
## 0.1.10
1112

docs/data-sources/ip_pool_reservation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ This data source can read the IP Pool Reservation.
1414

1515
```terraform
1616
data "catalystcenter_ip_pool_reservation" "example" {
17-
id = "76d24097-41c4-4558-a4d0-a8c07ac08470"
1817
site_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1"
18+
name = "MyRes1"
1919
}
2020
```
2121

@@ -24,11 +24,12 @@ data "catalystcenter_ip_pool_reservation" "example" {
2424

2525
### Required
2626

27-
- `id` (String) The id of the object
27+
- `name` (String) The name of the IP pool reservation
2828
- `site_id` (String) The site ID
2929

3030
### Read-Only
3131

32+
- `id` (String) The id of the object
3233
- `ipv4_dhcp_servers` (Set of String) List of DHCP Server IPs
3334
- `ipv4_dns_servers` (Set of String) List of DNS Server IPs
3435
- `ipv4_gateway` (String) The gateway for the IP pool reservation
@@ -46,6 +47,5 @@ data "catalystcenter_ip_pool_reservation" "example" {
4647
- `ipv6_prefix_length` (Number) The IPv6 prefix length is required when `ipv6_prefix` value is `true`.
4748
- `ipv6_subnet` (String) The IPv6 subnet, for example `2001:db8:85a3:0:100::`
4849
- `ipv6_total_host` (Number) The total number of IPv6 hosts
49-
- `name` (String) The name of the IP pool reservation
5050
- `slaac_support` (Boolean) Enable SLAAC support
5151
- `type` (String) The type of the IP pool reservation

docs/guides/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ description: |-
1515
- Add `catalystcenter_fabric_port_assignment` resource and data source
1616
- BREAKING CHANGE: Replace `catalystcenter_peer_transit_network` with `catalystcenter_transit_network` resource and data source to use `/dna/intent/api/v1/sda/transitNetworks` API endpoint, this resource now only works with Catalyst Center version 2.3.7.6+
1717
- Add `catalystcenter_authentication_policy_server` resource and data source
18+
- Fix issue with import of `catalystcenter_ip_pool_reservation` resource, [link](https://github.com/CiscoDevNet/terraform-provider-catalystcenter/issues/122)
1819

1920
## 0.1.10
2021

docs/resources/ip_pool_reservation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,5 @@ resource "catalystcenter_ip_pool_reservation" "example" {
6868
Import is supported using the following syntax:
6969

7070
```shell
71-
terraform import catalystcenter_ip_pool_reservation.example "<site_id>,<id>"
71+
terraform import catalystcenter_ip_pool_reservation.example "<site_id>,<name>"
7272
```
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
data "catalystcenter_ip_pool_reservation" "example" {
2-
id = "76d24097-41c4-4558-a4d0-a8c07ac08470"
32
site_id = "5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1"
3+
name = "MyRes1"
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
terraform import catalystcenter_ip_pool_reservation.example "<site_id>,<id>"
1+
terraform import catalystcenter_ip_pool_reservation.example "<site_id>,<name>"

gen/definitions/ip_pool_reservation.yaml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
---
22
name: IP Pool Reservation
33
rest_endpoint: /dna/intent/api/v1/reserve-ip-subpool
4-
get_from_all: true
5-
id_from_query_path: response
4+
id_from_query_path: response.0
5+
id_from_query_path_attribute: id
66
put_id_query_param: id
7+
import_no_id: true
8+
data_source_no_id: true
79
doc_category: Network Settings
810
attributes:
911
- model_name: siteId
1012
type: String
1113
query_param: true
1214
create_query_path: true
15+
response_data_path: response.0.siteId
1316
description: The site ID
1417
example: 5e6f7b3a-2b0b-4a7d-8b1c-0d4b1cd5e1b1
1518
test_value: catalystcenter_area.test.id
1619
- model_name: name
1720
response_model_name: groupName
18-
response_data_path: groupName
21+
query_param: true
22+
query_param_name: groupName
23+
response_data_path: response.0.groupName
1924
type: String
2025
match_id: true
2126
description: The name of the IP pool reservation
@@ -24,6 +29,7 @@ attributes:
2429
type: String
2530
mandatory: true
2631
write_only: true
32+
response_data_path: response.0.type
2733
exclude_from_put: true
2834
enum_values: [Generic, LAN, WAN, management, service]
2935
description: The type of the IP pool reservation
@@ -64,19 +70,19 @@ attributes:
6470
- model_name: ipv4GateWay
6571
tf_name: ipv4_gateway
6672
type: String
67-
write_only: true
73+
response_data_path: response.0.ipPools.0.gateways.0
6874
description: The gateway for the IP pool reservation
6975
example: 172.32.1.1
7076
- model_name: ipv4DhcpServers
7177
type: Set
7278
element_type: String
73-
write_only: true
79+
response_data_path: response.0.ipPools.0.dhcpServerIps
7480
description: List of DHCP Server IPs
7581
example: 1.2.3.4
7682
- model_name: ipv4DnsServers
7783
type: Set
7884
element_type: String
79-
write_only: true
85+
response_data_path: response.0.ipPools.0.dnsServerIps
8086
description: List of DNS Server IPs
8187
example: 2.3.4.5
8288
- model_name: ipv6GlobalPool

internal/provider/data_source_catalystcenter_ip_pool_reservation.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ func (d *IPPoolReservationDataSource) Schema(ctx context.Context, req datasource
6060
Attributes: map[string]schema.Attribute{
6161
"id": schema.StringAttribute{
6262
MarkdownDescription: "The id of the object",
63-
Required: true,
63+
Computed: true,
6464
},
6565
"site_id": schema.StringAttribute{
6666
MarkdownDescription: "The site ID",
6767
Required: true,
6868
},
6969
"name": schema.StringAttribute{
7070
MarkdownDescription: "The name of the IP pool reservation",
71-
Computed: true,
71+
Required: true,
7272
},
7373
"type": schema.StringAttribute{
7474
MarkdownDescription: "The type of the IP pool reservation",
@@ -178,13 +178,12 @@ func (d *IPPoolReservationDataSource) Read(ctx context.Context, req datasource.R
178178
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String()))
179179

180180
params := ""
181-
params += "?siteId=" + url.QueryEscape(config.SiteId.ValueString())
181+
params += "?siteId=" + url.QueryEscape(config.SiteId.ValueString()) + "&groupName=" + url.QueryEscape(config.Name.ValueString())
182182
res, err := d.client.Get(config.getPath() + params)
183183
if err != nil {
184184
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err))
185185
return
186186
}
187-
res = res.Get("response.#(id==\"" + config.Id.ValueString() + "\")")
188187

189188
config.fromBody(ctx, res)
190189

internal/provider/data_source_catalystcenter_ip_pool_reservation_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
func TestAccDataSourceCcIPPoolReservation(t *testing.T) {
3131
var checks []resource.TestCheckFunc
3232
checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_ip_pool_reservation.test", "name", "MyRes1"))
33+
checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_ip_pool_reservation.test", "ipv4_gateway", "172.32.1.1"))
3334
resource.Test(t, resource.TestCase{
3435
PreCheck: func() { testAccPreCheck(t) },
3536
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
@@ -79,8 +80,9 @@ func testAccDataSourceCcIPPoolReservationConfig() string {
7980

8081
config += `
8182
data "catalystcenter_ip_pool_reservation" "test" {
82-
id = catalystcenter_ip_pool_reservation.test.id
8383
site_id = catalystcenter_area.test.id
84+
name = "MyRes1"
85+
depends_on = [catalystcenter_ip_pool_reservation.test]
8486
}
8587
`
8688
return config

internal/provider/model_catalystcenter_ip_pool_reservation.go

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package provider
2121
import (
2222
"context"
2323

24+
"github.com/CiscoDevNet/terraform-provider-catalystcenter/internal/provider/helpers"
2425
"github.com/hashicorp/terraform-plugin-framework/types"
2526
"github.com/tidwall/gjson"
2627
"github.com/tidwall/sjson"
@@ -146,31 +147,64 @@ func (data IPPoolReservation) toBody(ctx context.Context, state IPPoolReservatio
146147

147148
// Section below is generated&owned by "gen/generator.go". //template:begin fromBody
148149
func (data *IPPoolReservation) fromBody(ctx context.Context, res gjson.Result) {
149-
if value := res.Get("groupName"); value.Exists() {
150+
// Retrieve the 'id' attribute, if Data Source doesn't require id
151+
if value := res.Get("response.0.id"); value.Exists() {
152+
data.Id = types.StringValue(value.String())
153+
} else {
154+
data.Id = types.StringNull()
155+
}
156+
if value := res.Get("response.0.groupName"); value.Exists() {
150157
data.Name = types.StringValue(value.String())
151158
} else {
152159
data.Name = types.StringNull()
153160
}
161+
if value := res.Get("response.0.ipPools.0.gateways.0"); value.Exists() {
162+
data.Ipv4Gateway = types.StringValue(value.String())
163+
} else {
164+
data.Ipv4Gateway = types.StringNull()
165+
}
166+
if value := res.Get("response.0.ipPools.0.dhcpServerIps"); value.Exists() && len(value.Array()) > 0 {
167+
data.Ipv4DhcpServers = helpers.GetStringSet(value.Array())
168+
} else {
169+
data.Ipv4DhcpServers = types.SetNull(types.StringType)
170+
}
171+
if value := res.Get("response.0.ipPools.0.dnsServerIps"); value.Exists() && len(value.Array()) > 0 {
172+
data.Ipv4DnsServers = helpers.GetStringSet(value.Array())
173+
} else {
174+
data.Ipv4DnsServers = types.SetNull(types.StringType)
175+
}
154176
}
155177

156178
// End of section. //template:end fromBody
157179

158180
// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody
159181
func (data *IPPoolReservation) updateFromBody(ctx context.Context, res gjson.Result) {
160-
if value := res.Get("groupName"); value.Exists() && !data.Name.IsNull() {
182+
if value := res.Get("response.0.groupName"); value.Exists() && !data.Name.IsNull() {
161183
data.Name = types.StringValue(value.String())
162184
} else {
163185
data.Name = types.StringNull()
164186
}
187+
if value := res.Get("response.0.ipPools.0.gateways.0"); value.Exists() && !data.Ipv4Gateway.IsNull() {
188+
data.Ipv4Gateway = types.StringValue(value.String())
189+
} else {
190+
data.Ipv4Gateway = types.StringNull()
191+
}
192+
if value := res.Get("response.0.ipPools.0.dhcpServerIps"); value.Exists() && !data.Ipv4DhcpServers.IsNull() {
193+
data.Ipv4DhcpServers = helpers.GetStringSet(value.Array())
194+
} else {
195+
data.Ipv4DhcpServers = types.SetNull(types.StringType)
196+
}
197+
if value := res.Get("response.0.ipPools.0.dnsServerIps"); value.Exists() && !data.Ipv4DnsServers.IsNull() {
198+
data.Ipv4DnsServers = helpers.GetStringSet(value.Array())
199+
} else {
200+
data.Ipv4DnsServers = types.SetNull(types.StringType)
201+
}
165202
}
166203

167204
// End of section. //template:end updateFromBody
168205

169206
// Section below is generated&owned by "gen/generator.go". //template:begin isNull
170207
func (data *IPPoolReservation) isNull(ctx context.Context, res gjson.Result) bool {
171-
if !data.Name.IsNull() {
172-
return false
173-
}
174208
if !data.Type.IsNull() {
175209
return false
176210
}

0 commit comments

Comments
 (0)