Skip to content

Commit 05c9853

Browse files
authored
feat(VPC): add params to vpc subnet resource (#6741)
1 parent 4b19056 commit 05c9853

File tree

3 files changed

+67
-9
lines changed

3 files changed

+67
-9
lines changed

docs/resources/vpc_subnet.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ resource "huaweicloud_vpc_subnet" "subnet_with_dhcp" {
5353
vpc_id = huaweicloud_vpc.vpc.id
5454
availability_zone = var.availability_zone
5555
56-
dhcp_lease_time = "24h"
57-
ntp_server_address = "10.100.0.33,10.100.0.34"
56+
dhcp_lease_time = "24h"
57+
dhcp_ipv6_lease_time = "4h"
58+
ntp_server_address = "10.100.0.33,10.100.0.34"
59+
dhcp_domain_name = "test.domainnanme"
5860
}
5961
6062
```
@@ -107,6 +109,15 @@ The following arguments are supported:
107109
unlimited lease time, or Number+h. the number ranges from 1 to 30,000. For example, the value can be 5h. The default
108110
value is 24h.
109111

112+
* `dhcp_ipv6_lease_time` - (Optional, String) Specifies the DHCP lease expiration time of the IPv6 subnet. The value can
113+
be -1, which indicates unlimited lease time, or Number+h. the number ranges from 1 to 175200. For example, the value
114+
can be 5h. The default value is 2h.
115+
116+
* `dhcp_domain_name` - (Optional, String) Specifies the domain name configured for DNS and is used to obtain the IP address
117+
from the DNS server. A domain name can contain only letters, digits, and hyphens (-) and cannot start or end with a
118+
hyphen (-). Each domain name contains at least two labels separated by periods (.). Max total: 254 characters. Max
119+
label: 63 characters.
120+
110121
* `tags` - (Optional, Map) The key/value pairs to associate with the subnet.
111122

112123
## Attribute Reference

huaweicloud/services/acceptance/vpc/resource_huaweicloud_vpc_subnet_test.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ func TestAccVpcSubnetV1_dhcp(t *testing.T) {
131131
resource.TestCheckResourceAttr(resourceName, "name", rName),
132132
resource.TestCheckResourceAttr(resourceName, "dhcp_lease_time", "48h"),
133133
resource.TestCheckResourceAttr(resourceName, "ntp_server_address", "10.100.0.33"),
134+
resource.TestCheckResourceAttr(resourceName, "dhcp_ipv6_lease_time", "4h"),
135+
resource.TestCheckResourceAttr(resourceName, "dhcp_domain_name", "test.domainname"),
134136
),
135137
},
136138
{
@@ -139,6 +141,8 @@ func TestAccVpcSubnetV1_dhcp(t *testing.T) {
139141
resource.TestCheckResourceAttr(resourceName, "name", rName),
140142
resource.TestCheckResourceAttr(resourceName, "dhcp_lease_time", "72h"),
141143
resource.TestCheckResourceAttr(resourceName, "ntp_server_address", "10.100.0.33,10.100.0.34"),
144+
resource.TestCheckResourceAttr(resourceName, "dhcp_ipv6_lease_time", "8h"),
145+
resource.TestCheckResourceAttr(resourceName, "dhcp_domain_name", "test.domainname.update"),
142146
),
143147
},
144148
},
@@ -278,10 +282,13 @@ resource "huaweicloud_vpc_subnet" "test" {
278282
cidr = "192.168.0.0/24"
279283
gateway_ip = "192.168.0.1"
280284
vpc_id = huaweicloud_vpc.test.id
285+
ipv6_enable = true
281286
availability_zone = data.huaweicloud_availability_zones.test.names[0]
282287
283-
dhcp_lease_time = "48h"
284-
ntp_server_address = "10.100.0.33"
288+
dhcp_lease_time = "48h"
289+
ntp_server_address = "10.100.0.33"
290+
dhcp_ipv6_lease_time = "4h"
291+
dhcp_domain_name = "test.domainname"
285292
}
286293
`, testAccVpcSubnet_base(rName), rName)
287294
}
@@ -295,10 +302,13 @@ resource "huaweicloud_vpc_subnet" "test" {
295302
cidr = "192.168.0.0/24"
296303
gateway_ip = "192.168.0.1"
297304
vpc_id = huaweicloud_vpc.test.id
305+
ipv6_enable = true
298306
availability_zone = data.huaweicloud_availability_zones.test.names[0]
299307
300-
dhcp_lease_time = "72h"
301-
ntp_server_address = "10.100.0.33,10.100.0.34"
308+
dhcp_lease_time = "72h"
309+
ntp_server_address = "10.100.0.33,10.100.0.34"
310+
dhcp_ipv6_lease_time = "8h"
311+
dhcp_domain_name = "test.domainname.update"
302312
}
303313
`, testAccVpcSubnet_base(rName), rName)
304314
}

huaweicloud/services/vpc/resource_huaweicloud_vpc_subnet.go

+40-3
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ func ResourceVpcSubnetV1() *schema.Resource {
194194
Optional: true,
195195
Computed: true,
196196
},
197+
"dhcp_ipv6_lease_time": {
198+
Type: schema.TypeString,
199+
Optional: true,
200+
Computed: true,
201+
},
202+
"dhcp_domain_name": {
203+
Type: schema.TypeString,
204+
Optional: true,
205+
},
197206
"subnet_id": {
198207
Type: schema.TypeString,
199208
Computed: true,
@@ -231,6 +240,15 @@ func buildDhcpOpts(d *schema.ResourceData, update bool) []subnets.ExtraDhcpOpt {
231240
result = append(result, addressTime)
232241
}
233242

243+
if v, ok := d.GetOk("dhcp_ipv6_lease_time"); ok {
244+
ipv6AddressVal := v.(string)
245+
ipv6AddressTime := subnets.ExtraDhcpOpt{
246+
OptName: "ipv6_addresstime",
247+
OptValue: &ipv6AddressVal,
248+
}
249+
result = append(result, ipv6AddressTime)
250+
}
251+
234252
if v, ok := d.GetOk("ntp_server_address"); ok {
235253
ntpVal := v.(string)
236254
ntp := subnets.ExtraDhcpOpt{
@@ -245,6 +263,20 @@ func buildDhcpOpts(d *schema.ResourceData, update bool) []subnets.ExtraDhcpOpt {
245263
result = append(result, ntp)
246264
}
247265

266+
if v, ok := d.GetOk("dhcp_domain_name"); ok {
267+
domainNameVal := v.(string)
268+
domainName := subnets.ExtraDhcpOpt{
269+
OptName: "domainname",
270+
OptValue: &domainNameVal,
271+
}
272+
result = append(result, domainName)
273+
} else if update {
274+
domainName := subnets.ExtraDhcpOpt{
275+
OptName: "domainname",
276+
}
277+
result = append(result, domainName)
278+
}
279+
248280
return result
249281
}
250282

@@ -367,10 +399,15 @@ func resourceVpcSubnetRead(_ context.Context, d *schema.ResourceData, meta inter
367399

368400
// set dhcp extra opts ntp and addresstime
369401
for _, val := range n.ExtraDhcpOpts {
370-
if val.OptName == "ntp" {
402+
switch val.OptName {
403+
case "ntp":
371404
mErr = multierror.Append(mErr, d.Set("ntp_server_address", val.OptValue))
372-
} else if val.OptName == "addresstime" {
405+
case "addresstime":
373406
mErr = multierror.Append(mErr, d.Set("dhcp_lease_time", val.OptValue))
407+
case "ipv6_addresstime":
408+
mErr = multierror.Append(mErr, d.Set("dhcp_ipv6_lease_time", val.OptValue))
409+
case "domainname":
410+
mErr = multierror.Append(mErr, d.Set("dhcp_domain_name", val.OptValue))
374411
}
375412
}
376413

@@ -419,7 +456,7 @@ func resourceVpcSubnetUpdate(ctx context.Context, d *schema.ResourceData, meta i
419456
dnsList := utils.ExpandToStringList(d.Get("dns_list").([]interface{}))
420457
updateOpts.DnsList = &dnsList
421458
}
422-
if d.HasChanges("dhcp_lease_time", "ntp_server_address") {
459+
if d.HasChanges("dhcp_lease_time", "ntp_server_address", "dhcp_ipv6_lease_time", "dhcp_domain_name") {
423460
updateOpts.ExtraDhcpOpts = buildDhcpOpts(d, true)
424461
}
425462

0 commit comments

Comments
 (0)