Skip to content

Commit 8d60ca7

Browse files
authored
feat(dns): the private zone supports proxy_pattern parameter and modification status (#6355)
* feat(dns): private zone supports modification status * feat(zone): the private zone supports 'proxy_pattern' parameter
1 parent 6dcbf85 commit 8d60ca7

File tree

3 files changed

+43
-19
lines changed

3 files changed

+43
-19
lines changed

docs/resources/dns_zone.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ The following arguments are supported:
5757
* `router` - (Optional, List) Router configuration block which is required if zone_type is private. The router
5858
structure is documented below.
5959

60+
-> Before changing this parameter, make sure the zone status is enabled.
61+
6062
* `ttl` - (Optional, Int) The time to live (TTL) of the zone.
6163
The valid value is range from `1` to `2,147,483,647`.
6264

@@ -73,7 +75,18 @@ The following arguments are supported:
7375
+ **ENABLE**
7476
+ **DISABLE**
7577

76-
-> This parameter is only supported by the public zone, and it is a one-time action.
78+
-> This is a one-time action.
79+
80+
* `proxy_pattern` - (Optional, String, ForceNew) Specifies the recursive resolution proxy mode for subdomains of
81+
the private zone.
82+
Defaults to **AUTHORITY**.
83+
The valid values are as follows:
84+
+ **AUTHORITY**: The recursive resolution proxy is disabled for the private zone.
85+
+ **RECURSIVE**: The recursive resolution proxy is enabled for the private zone.
86+
87+
-> 1. This parameter ia available only when the `zone_type` parameter is set to **private**.
88+
<br>2. If this parameter is set to **RECURSIVE**, but you query subdomains that are not configured in the zone namespace,
89+
the DNS will recursively resolve the subdomains on the Internet and use the result from authoritative DNS servers.
7790

7891
The `router` block supports:
7992

huaweicloud/services/acceptance/dns/resource_huaweicloud_dns_zone_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ func TestAccDNSZone_private(t *testing.T) {
107107
resource.TestCheckResourceAttr(resourceName, "router.#", "2"),
108108
resource.TestCheckResourceAttr(resourceName, "tags.zone_type", "private"),
109109
resource.TestCheckResourceAttr(resourceName, "tags.owner", "terraform"),
110+
resource.TestCheckResourceAttr(resourceName, "status", "DISABLE"),
111+
resource.TestCheckResourceAttr(resourceName, "proxy_pattern", "RECURSIVE"),
110112
),
111113
},
112114
{
@@ -117,6 +119,7 @@ func TestAccDNSZone_private(t *testing.T) {
117119
resource.TestCheckResourceAttr(resourceName, "router.#", "2"),
118120
resource.TestCheckResourceAttrSet(resourceName, "router.0.router_id"),
119121
resource.TestCheckResourceAttrSet(resourceName, "router.0.router_region"),
122+
resource.TestCheckResourceAttr(resourceName, "status", "ENABLE"),
120123
),
121124
},
122125
{
@@ -182,6 +185,7 @@ func TestAccDNSZone_withEpsId(t *testing.T) {
182185
resource.TestCheckResourceAttr(resourceName, "name", nameWithDotSuffix),
183186
resource.TestCheckResourceAttr(resourceName, "zone_type", "private"),
184187
resource.TestCheckResourceAttr(resourceName, "enterprise_project_id", acceptance.HW_ENTERPRISE_PROJECT_ID_TEST),
188+
resource.TestCheckResourceAttr(resourceName, "proxy_pattern", "AUTHORITY"),
185189
),
186190
},
187191
{
@@ -253,6 +257,7 @@ resource "huaweicloud_dns_zone" "test" {
253257
254258
description = "a private zone"
255259
zone_type = "private"
260+
status = "DISABLE"
256261
257262
dynamic "router" {
258263
for_each = slice(huaweicloud_vpc.test[*].id, 0, 2)
@@ -262,6 +267,8 @@ resource "huaweicloud_dns_zone" "test" {
262267
}
263268
}
264269
270+
proxy_pattern = "RECURSIVE"
271+
265272
tags = {
266273
zone_type = "private"
267274
owner = "terraform"
@@ -279,6 +286,7 @@ resource "huaweicloud_dns_zone" "test" {
279286
280287
description = "a private zone"
281288
zone_type = "private"
289+
status = "ENABLE"
282290
283291
dynamic "router" {
284292
for_each = slice(huaweicloud_vpc.test[*].id, 1, 3)
@@ -288,6 +296,8 @@ resource "huaweicloud_dns_zone" "test" {
288296
}
289297
}
290298
299+
proxy_pattern = "RECURSIVE"
300+
291301
tags = {
292302
zone_type = "private"
293303
owner = "terraform"

huaweicloud/services/dns/resource_huaweicloud_dns_zone.go

+19-18
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,14 @@ func ResourceDNSZone() *schema.Resource {
112112
Type: schema.TypeString,
113113
Optional: true,
114114
Computed: true,
115-
Description: `Specifies the status of the public zone.`,
115+
Description: `The status of the zone.`,
116+
},
117+
"proxy_pattern": {
118+
Type: schema.TypeString,
119+
Optional: true,
120+
Computed: true,
121+
ForceNew: true,
122+
Description: `The recursive resolution proxy mode for subdomains of the private zone.`,
116123
},
117124
"masters": {
118125
Type: schema.TypeSet,
@@ -176,6 +183,7 @@ func resourceDNSZoneCreate(ctx context.Context, d *schema.ResourceData, meta int
176183
ZoneType: zoneType,
177184
EnterpriseProjectID: cfg.GetEnterpriseProjectID(d),
178185
Router: resourceDNSRouter(d, region),
186+
ProxyPattern: d.Get("proxy_pattern").(string),
179187
}
180188

181189
log.Printf("[DEBUG] Create options: %#v", createOpts)
@@ -242,11 +250,7 @@ func resourceDNSZoneCreate(ctx context.Context, d *schema.ResourceData, meta int
242250
// After zone is created, the status is ACTIVE (ENABLE).
243251
// This action cannot be called repeatedly.
244252
if v, ok := d.GetOk("status"); ok && v != "ENABLE" {
245-
if zoneType == "private" {
246-
return diag.Errorf("The private zone do not support updating status.")
247-
}
248-
249-
if err := updatePublicZoneStatus(ctx, d, dnsClient, d.Timeout(schema.TimeoutCreate)); err != nil {
253+
if err := updateZoneStatus(ctx, d, dnsClient, d.Timeout(schema.TimeoutCreate)); err != nil {
250254
return diag.FromErr(err)
251255
}
252256
}
@@ -309,8 +313,8 @@ func resourceDNSZoneRead(_ context.Context, d *schema.ResourceData, meta interfa
309313
d.Set("zone_type", zoneInfo.ZoneType),
310314
d.Set("router", flattenPrivateZoneRouters(zoneInfo.Routers)),
311315
d.Set("enterprise_project_id", zoneInfo.EnterpriseProjectID),
312-
// The private zone also returns the "status" attribute.
313316
d.Set("status", parseZoneStatus(zoneInfo.Status)),
317+
d.Set("proxy_pattern", zoneInfo.ProxyPattern),
314318
// Attributes
315319
d.Set("masters", zoneInfo.Masters),
316320
)
@@ -386,18 +390,15 @@ func resourceDNSZoneUpdate(ctx context.Context, d *schema.ResourceData, meta int
386390
}
387391
}
388392

389-
if d.HasChange("router") && zoneType == "private" {
390-
if err := updateDNSZoneRouters(ctx, d, dnsClient, region); err != nil {
393+
if d.HasChange("status") {
394+
if err := updateZoneStatus(ctx, d, dnsClient, d.Timeout(schema.TimeoutUpdate)); err != nil {
391395
return diag.FromErr(err)
392396
}
393397
}
394398

395-
if d.HasChange("status") {
396-
if zoneType == "private" {
397-
return diag.Errorf("The private zone do not support updating status.")
398-
}
399-
400-
if err := updatePublicZoneStatus(ctx, d, dnsClient, d.Timeout(schema.TimeoutUpdate)); err != nil {
399+
// This operation is supported only when the zone status is enabled.
400+
if d.HasChange("router") && zoneType == "private" {
401+
if err := updateDNSZoneRouters(ctx, d, dnsClient, region); err != nil {
401402
return diag.FromErr(err)
402403
}
403404
}
@@ -514,14 +515,14 @@ func updateDNSZoneRouters(ctx context.Context, d *schema.ResourceData, client *g
514515
return nil
515516
}
516517

517-
func updatePublicZoneStatus(ctx context.Context, d *schema.ResourceData, client *golangsdk.ServiceClient, timeout time.Duration) error {
518+
func updateZoneStatus(ctx context.Context, d *schema.ResourceData, client *golangsdk.ServiceClient, timeout time.Duration) error {
518519
opts := zones.UpdateStatusOpts{
519520
ZoneId: d.Id(),
520521
Status: d.Get("status").(string),
521522
}
522523
err := zones.UpdateZoneStatus(client, opts)
523524
if err != nil {
524-
return fmt.Errorf("error updating public zone status: %s", err)
525+
return fmt.Errorf("error updating the status of the zone: %s", err)
525526
}
526527

527528
stateConf := &resource.StateChangeConf{
@@ -534,7 +535,7 @@ func updatePublicZoneStatus(ctx context.Context, d *schema.ResourceData, client
534535

535536
_, err = stateConf.WaitForStateContext(ctx)
536537
if err != nil {
537-
return fmt.Errorf("error waiting for updating public zone status completed: %s", err)
538+
return fmt.Errorf("error waiting for updating the zone status completed: %s", err)
538539
}
539540

540541
return nil

0 commit comments

Comments
 (0)