Skip to content

Commit 534b336

Browse files
Fix issue with global pools update (#91)
1 parent fcb70ab commit 534b336

File tree

12 files changed

+88
-58
lines changed

12 files changed

+88
-58
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+
- BREAKING CHANGE: Fix `ip_pool` update if more than 25 pools are registered
34
- BREAKING CHANGE: Rename `radio_type_a_power_treshold_v1` attribute of `catalystcenter_wireless_rf_profile` resource to `radio_type_a_power_threshold_v1`
45
- BREAKING CHANGE: Rename `radio_type_b_power_treshold_v1` attribute of `catalystcenter_wireless_rf_profile` resource to `radio_type_b_power_threshold_v1`
56
- BREAKING CHANGE: Rename `radio_type_c_power_treshold_v1` attribute of `catalystcenter_wireless_rf_profile` resource to `radio_type_c_power_threshold_v1`

docs/data-sources/ip_pool.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ data "catalystcenter_ip_pool" "example" {
3030

3131
- `dhcp_server_ips` (Set of String) List of DHCP Server IPs
3232
- `dns_server_ips` (Set of String) List of DNS Server IPs
33-
- `gateway` (String) The gateway for the IP pool
33+
- `gateway` (Set of String) The gateway for the IP pool
3434
- `ip_address_space` (String) IP address version
3535
- `ip_subnet` (String) The IP subnet of the IP pool
3636
- `type` (String) Choose `Tunnel` to assign IP addresses to site-to-site VPN for IPSec tunneling. Choose `Generic` for all other network types.

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: Fix `ip_pool` update if more than 25 pools are registered
1213
- BREAKING CHANGE: Rename `radio_type_a_power_treshold_v1` attribute of `catalystcenter_wireless_rf_profile` resource to `radio_type_a_power_threshold_v1`
1314
- BREAKING CHANGE: Rename `radio_type_b_power_treshold_v1` attribute of `catalystcenter_wireless_rf_profile` resource to `radio_type_b_power_threshold_v1`
1415
- BREAKING CHANGE: Rename `radio_type_c_power_treshold_v1` attribute of `catalystcenter_wireless_rf_profile` resource to `radio_type_c_power_threshold_v1`

docs/resources/ip_pool.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ This resource can manage an IP Pool.
1616
resource "catalystcenter_ip_pool" "example" {
1717
name = "MyPool1"
1818
ip_address_space = "IPv4"
19-
type = "Generic"
19+
type = "generic"
2020
ip_subnet = "21.1.1.0/24"
21-
gateway = "21.1.1.1"
21+
gateway = ["21.1.1.1"]
2222
dhcp_server_ips = ["1.2.3.4"]
2323
dns_server_ips = ["2.3.4.5"]
2424
}
@@ -36,13 +36,13 @@ resource "catalystcenter_ip_pool" "example" {
3636

3737
- `dhcp_server_ips` (Set of String) List of DHCP Server IPs
3838
- `dns_server_ips` (Set of String) List of DNS Server IPs
39-
- `gateway` (String) The gateway for the IP pool
39+
- `gateway` (Set of String) The gateway for the IP pool
4040
- `ip_address_space` (String) IP address version
4141
- Choices: `IPv4`, `IPv6`
4242
- Default value: `IPv4`
4343
- `type` (String) Choose `Tunnel` to assign IP addresses to site-to-site VPN for IPSec tunneling. Choose `Generic` for all other network types.
44-
- Choices: `Generic`, `Tunnel`
45-
- Default value: `Generic`
44+
- Choices: `generic`, `tunnel`
45+
- Default value: `generic`
4646

4747
### Read-Only
4848

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
resource "catalystcenter_ip_pool" "example" {
22
name = "MyPool1"
33
ip_address_space = "IPv4"
4-
type = "Generic"
4+
type = "generic"
55
ip_subnet = "21.1.1.0/24"
6-
gateway = "21.1.1.1"
6+
gateway = ["21.1.1.1"]
77
dhcp_server_ips = ["1.2.3.4"]
88
dns_server_ips = ["2.3.4.5"]
99
}

gen/definitions/ip_pool.yaml

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,51 @@
11
---
22
name: IP Pool
3-
rest_endpoint: /dna/intent/api/v1/global-pool
4-
get_rest_endpoint: /api/v2/ippool
5-
put_id_include_path: settings.ippool.0.id
3+
rest_endpoint: /api/v2/ippool
4+
get_requires_id: true
65
id_from_query_path: response
76
doc_category: Network Settings
87
attributes:
98
- model_name: ipPoolName
109
tf_name: name
11-
data_path: settings.ippool.0
1210
response_data_path: response.ipPoolName
1311
type: String
1412
match_id: true
1513
data_source_query: true
1614
description: The name of the IP pool
1715
example: MyPool1
1816
- model_name: IpAddressSpace
19-
data_path: settings.ippool.0
20-
write_only: true
2117
type: String
2218
enum_values: [IPv4, IPv6]
2319
default_value: IPv4
2420
description: IP address version
2521
example: IPv4
2622
- model_name: type
27-
data_path: settings.ippool.0
2823
type: String
29-
write_only: true
30-
enum_values: [Generic, Tunnel]
31-
default_value: Generic
24+
enum_values: [generic, tunnel]
25+
default_value: generic
3226
description: Choose `Tunnel` to assign IP addresses to site-to-site VPN for IPSec tunneling. Choose `Generic` for all other network types.
33-
example: Generic
27+
example: generic
3428
- model_name: ipPoolCidr
3529
tf_name: ip_subnet
36-
data_path: settings.ippool.0
3730
response_data_path: response.ipPoolCidr
3831
type: String
3932
mandatory: true
4033
description: The IP subnet of the IP pool
4134
example: 21.1.1.0/24
42-
- model_name: gateway
43-
data_path: settings.ippool.0
44-
response_data_path: response.gateways.0
45-
type: String
35+
- model_name: gateways
36+
tf_name: gateway
37+
response_data_path: response.gateways
38+
type: Set
39+
element_type: String
4640
description: The gateway for the IP pool
4741
example: 21.1.1.1
4842
- model_name: dhcpServerIps
49-
data_path: settings.ippool.0
5043
response_data_path: response.dhcpServerIps
5144
type: Set
5245
element_type: String
5346
description: List of DHCP Server IPs
5447
example: 1.2.3.4
5548
- model_name: dnsServerIps
56-
data_path: settings.ippool.0
5749
response_data_path: response.dnsServerIps
5850
type: Set
5951
element_type: String

internal/provider/data_source_catalystcenter_ip_pool.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ func (d *IPPoolDataSource) Schema(ctx context.Context, req datasource.SchemaRequ
8383
MarkdownDescription: "The IP subnet of the IP pool",
8484
Computed: true,
8585
},
86-
"gateway": schema.StringAttribute{
86+
"gateway": schema.SetAttribute{
8787
MarkdownDescription: "The gateway for the IP pool",
88+
ElementType: types.StringType,
8889
Computed: true,
8990
},
9091
"dhcp_server_ips": schema.SetAttribute{
@@ -119,6 +120,7 @@ func (d *IPPoolDataSource) Configure(_ context.Context, req datasource.Configure
119120

120121
// End of section. //template:end model
121122

123+
// Section below is generated&owned by "gen/generator.go". //template:begin read
122124
func (d *IPPoolDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
123125
var config IPPool
124126

@@ -131,7 +133,7 @@ func (d *IPPoolDataSource) Read(ctx context.Context, req datasource.ReadRequest,
131133

132134
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String()))
133135
if config.Id.IsNull() && !config.Name.IsNull() {
134-
res, err := d.client.Get("/api/v2/ippool?limit=500")
136+
res, err := d.client.Get(config.getPath())
135137
if err != nil {
136138
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve objects, got error: %s", err))
137139
return
@@ -155,7 +157,7 @@ func (d *IPPoolDataSource) Read(ctx context.Context, req datasource.ReadRequest,
155157

156158
params := ""
157159
params += "/" + url.QueryEscape(config.Id.ValueString())
158-
res, err := d.client.Get("/api/v2/ippool" + params)
160+
res, err := d.client.Get(config.getPath() + params)
159161
if err != nil {
160162
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err))
161163
return
@@ -168,3 +170,5 @@ func (d *IPPoolDataSource) Read(ctx context.Context, req datasource.ReadRequest,
168170
diags = resp.State.Set(ctx, &config)
169171
resp.Diagnostics.Append(diags...)
170172
}
173+
174+
// End of section. //template:end read

internal/provider/data_source_catalystcenter_ip_pool_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ import (
3030
func TestAccDataSourceCcIPPool(t *testing.T) {
3131
var checks []resource.TestCheckFunc
3232
checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_ip_pool.test", "name", "MyPool1"))
33+
checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_ip_pool.test", "ip_address_space", "IPv4"))
34+
checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_ip_pool.test", "type", "generic"))
3335
checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_ip_pool.test", "ip_subnet", "21.1.1.0/24"))
34-
checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_ip_pool.test", "gateway", "21.1.1.1"))
3536
resource.Test(t, resource.TestCase{
3637
PreCheck: func() { testAccPreCheck(t) },
3738
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
@@ -54,9 +55,9 @@ func testAccDataSourceCcIPPoolConfig() string {
5455
config := `resource "catalystcenter_ip_pool" "test" {` + "\n"
5556
config += ` name = "MyPool1"` + "\n"
5657
config += ` ip_address_space = "IPv4"` + "\n"
57-
config += ` type = "Generic"` + "\n"
58+
config += ` type = "generic"` + "\n"
5859
config += ` ip_subnet = "21.1.1.0/24"` + "\n"
59-
config += ` gateway = "21.1.1.1"` + "\n"
60+
config += ` gateway = ["21.1.1.1"]` + "\n"
6061
config += ` dhcp_server_ips = ["1.2.3.4"]` + "\n"
6162
config += ` dns_server_ips = ["2.3.4.5"]` + "\n"
6263
config += `}` + "\n"

internal/provider/model_catalystcenter_ip_pool.go

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type IPPool struct {
3636
IpAddressSpace types.String `tfsdk:"ip_address_space"`
3737
Type types.String `tfsdk:"type"`
3838
IpSubnet types.String `tfsdk:"ip_subnet"`
39-
Gateway types.String `tfsdk:"gateway"`
39+
Gateway types.Set `tfsdk:"gateway"`
4040
DhcpServerIps types.Set `tfsdk:"dhcp_server_ips"`
4141
DnsServerIps types.Set `tfsdk:"dns_server_ips"`
4242
}
@@ -45,44 +45,49 @@ type IPPool struct {
4545

4646
// Section below is generated&owned by "gen/generator.go". //template:begin getPath
4747
func (data IPPool) getPath() string {
48-
return "/dna/intent/api/v1/global-pool"
48+
return "/api/v2/ippool"
4949
}
5050

5151
// End of section. //template:end getPath
5252

53+
// Section below is generated&owned by "gen/generator.go". //template:begin getPathDelete
54+
55+
// End of section. //template:end getPathDelete
56+
5357
// Section below is generated&owned by "gen/generator.go". //template:begin toBody
5458
func (data IPPool) toBody(ctx context.Context, state IPPool) string {
5559
body := ""
5660
put := false
5761
if state.Id.ValueString() != "" {
5862
put = true
59-
body, _ = sjson.Set(body, "settings.ippool.0.id", state.Id.ValueString())
6063
}
6164
_ = put
6265
if !data.Name.IsNull() {
63-
body, _ = sjson.Set(body, "settings.ippool.0.ipPoolName", data.Name.ValueString())
66+
body, _ = sjson.Set(body, "ipPoolName", data.Name.ValueString())
6467
}
6568
if !data.IpAddressSpace.IsNull() {
66-
body, _ = sjson.Set(body, "settings.ippool.0.IpAddressSpace", data.IpAddressSpace.ValueString())
69+
body, _ = sjson.Set(body, "IpAddressSpace", data.IpAddressSpace.ValueString())
6770
}
6871
if !data.Type.IsNull() {
69-
body, _ = sjson.Set(body, "settings.ippool.0.type", data.Type.ValueString())
72+
body, _ = sjson.Set(body, "type", data.Type.ValueString())
7073
}
7174
if !data.IpSubnet.IsNull() {
72-
body, _ = sjson.Set(body, "settings.ippool.0.ipPoolCidr", data.IpSubnet.ValueString())
75+
body, _ = sjson.Set(body, "ipPoolCidr", data.IpSubnet.ValueString())
7376
}
7477
if !data.Gateway.IsNull() {
75-
body, _ = sjson.Set(body, "settings.ippool.0.gateway", data.Gateway.ValueString())
78+
var values []string
79+
data.Gateway.ElementsAs(ctx, &values, false)
80+
body, _ = sjson.Set(body, "gateways", values)
7681
}
7782
if !data.DhcpServerIps.IsNull() {
7883
var values []string
7984
data.DhcpServerIps.ElementsAs(ctx, &values, false)
80-
body, _ = sjson.Set(body, "settings.ippool.0.dhcpServerIps", values)
85+
body, _ = sjson.Set(body, "dhcpServerIps", values)
8186
}
8287
if !data.DnsServerIps.IsNull() {
8388
var values []string
8489
data.DnsServerIps.ElementsAs(ctx, &values, false)
85-
body, _ = sjson.Set(body, "settings.ippool.0.dnsServerIps", values)
90+
body, _ = sjson.Set(body, "dnsServerIps", values)
8691
}
8792
return body
8893
}
@@ -96,15 +101,25 @@ func (data *IPPool) fromBody(ctx context.Context, res gjson.Result) {
96101
} else {
97102
data.Name = types.StringNull()
98103
}
104+
if value := res.Get("IpAddressSpace"); value.Exists() {
105+
data.IpAddressSpace = types.StringValue(value.String())
106+
} else {
107+
data.IpAddressSpace = types.StringValue("IPv4")
108+
}
109+
if value := res.Get("type"); value.Exists() {
110+
data.Type = types.StringValue(value.String())
111+
} else {
112+
data.Type = types.StringValue("generic")
113+
}
99114
if value := res.Get("response.ipPoolCidr"); value.Exists() {
100115
data.IpSubnet = types.StringValue(value.String())
101116
} else {
102117
data.IpSubnet = types.StringNull()
103118
}
104-
if value := res.Get("response.gateways.0"); value.Exists() {
105-
data.Gateway = types.StringValue(value.String())
119+
if value := res.Get("response.gateways"); value.Exists() && len(value.Array()) > 0 {
120+
data.Gateway = helpers.GetStringSet(value.Array())
106121
} else {
107-
data.Gateway = types.StringNull()
122+
data.Gateway = types.SetNull(types.StringType)
108123
}
109124
if value := res.Get("response.dhcpServerIps"); value.Exists() && len(value.Array()) > 0 {
110125
data.DhcpServerIps = helpers.GetStringSet(value.Array())
@@ -127,15 +142,25 @@ func (data *IPPool) updateFromBody(ctx context.Context, res gjson.Result) {
127142
} else {
128143
data.Name = types.StringNull()
129144
}
145+
if value := res.Get("IpAddressSpace"); value.Exists() && !data.IpAddressSpace.IsNull() {
146+
data.IpAddressSpace = types.StringValue(value.String())
147+
} else if data.IpAddressSpace.ValueString() != "IPv4" {
148+
data.IpAddressSpace = types.StringNull()
149+
}
150+
if value := res.Get("type"); value.Exists() && !data.Type.IsNull() {
151+
data.Type = types.StringValue(value.String())
152+
} else if data.Type.ValueString() != "generic" {
153+
data.Type = types.StringNull()
154+
}
130155
if value := res.Get("response.ipPoolCidr"); value.Exists() && !data.IpSubnet.IsNull() {
131156
data.IpSubnet = types.StringValue(value.String())
132157
} else {
133158
data.IpSubnet = types.StringNull()
134159
}
135-
if value := res.Get("response.gateways.0"); value.Exists() && !data.Gateway.IsNull() {
136-
data.Gateway = types.StringValue(value.String())
160+
if value := res.Get("response.gateways"); value.Exists() && !data.Gateway.IsNull() {
161+
data.Gateway = helpers.GetStringSet(value.Array())
137162
} else {
138-
data.Gateway = types.StringNull()
163+
data.Gateway = types.SetNull(types.StringType)
139164
}
140165
if value := res.Get("response.dhcpServerIps"); value.Exists() && !data.DhcpServerIps.IsNull() {
141166
data.DhcpServerIps = helpers.GetStringSet(value.Array())

internal/provider/resource_catalystcenter_ip_pool.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,21 @@ func (r *IPPoolResource) Schema(ctx context.Context, req resource.SchemaRequest,
8888
Default: stringdefault.StaticString("IPv4"),
8989
},
9090
"type": schema.StringAttribute{
91-
MarkdownDescription: helpers.NewAttributeDescription("Choose `Tunnel` to assign IP addresses to site-to-site VPN for IPSec tunneling. Choose `Generic` for all other network types.").AddStringEnumDescription("Generic", "Tunnel").AddDefaultValueDescription("Generic").String,
91+
MarkdownDescription: helpers.NewAttributeDescription("Choose `Tunnel` to assign IP addresses to site-to-site VPN for IPSec tunneling. Choose `Generic` for all other network types.").AddStringEnumDescription("generic", "tunnel").AddDefaultValueDescription("generic").String,
9292
Optional: true,
9393
Computed: true,
9494
Validators: []validator.String{
95-
stringvalidator.OneOf("Generic", "Tunnel"),
95+
stringvalidator.OneOf("generic", "tunnel"),
9696
},
97-
Default: stringdefault.StaticString("Generic"),
97+
Default: stringdefault.StaticString("generic"),
9898
},
9999
"ip_subnet": schema.StringAttribute{
100100
MarkdownDescription: helpers.NewAttributeDescription("The IP subnet of the IP pool").String,
101101
Required: true,
102102
},
103-
"gateway": schema.StringAttribute{
103+
"gateway": schema.SetAttribute{
104104
MarkdownDescription: helpers.NewAttributeDescription("The gateway for the IP pool").String,
105+
ElementType: types.StringType,
105106
Optional: true,
106107
},
107108
"dhcp_server_ips": schema.SetAttribute{
@@ -128,6 +129,7 @@ func (r *IPPoolResource) Configure(_ context.Context, req resource.ConfigureRequ
128129

129130
// End of section. //template:end model
130131

132+
// Section below is generated&owned by "gen/generator.go". //template:begin create
131133
func (r *IPPoolResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
132134
var plan IPPool
133135

@@ -149,8 +151,8 @@ func (r *IPPoolResource) Create(ctx context.Context, req resource.CreateRequest,
149151
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (POST), got error: %s, %s", err, res.String()))
150152
return
151153
}
152-
153-
res, err = r.client.Get("/api/v2/ippool?limit=500")
154+
params = ""
155+
res, err = r.client.Get(plan.getPath() + params)
154156
if err != nil {
155157
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (GET), got error: %s, %s", err, res.String()))
156158
return
@@ -163,6 +165,8 @@ func (r *IPPoolResource) Create(ctx context.Context, req resource.CreateRequest,
163165
resp.Diagnostics.Append(diags...)
164166
}
165167

168+
// End of section. //template:end create
169+
166170
// Section below is generated&owned by "gen/generator.go". //template:begin read
167171
func (r *IPPoolResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
168172
var state IPPool
@@ -178,7 +182,7 @@ func (r *IPPoolResource) Read(ctx context.Context, req resource.ReadRequest, res
178182

179183
params := ""
180184
params += "/" + url.QueryEscape(state.Id.ValueString())
181-
res, err := r.client.Get("/api/v2/ippool" + params)
185+
res, err := r.client.Get(state.getPath() + params)
182186
if err != nil && strings.Contains(err.Error(), "StatusCode 404") {
183187
resp.State.RemoveResource(ctx)
184188
return

0 commit comments

Comments
 (0)