Skip to content

Commit 1c70fc2

Browse files
tongyimingmikatong
andauthored
fix(dnspod): [123456789] weight set zero (#3460)
* fix dnspod weight set zero * add changelog * remove weight default 0 * update changelog * update changelog --------- Co-authored-by: mikatong <mikatong@tencent.com>
1 parent e8d6a9f commit 1c70fc2

File tree

5 files changed

+115
-5
lines changed

5 files changed

+115
-5
lines changed

.changelog/3460.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_dnspod_record: fix weight set zero
3+
```

schema/metadata.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
provider_meta:
22
metadata:
33
display_name: 腾讯云资源
4+
icon_url: tencentcloud
45
attr_orders:
56
- name: domain
67
- name: profile

tencentcloud/services/dnspod/resource_tc_dnspod_record.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ func ResourceTencentCloudDnspodRecord() *schema.Resource {
6969
"weight": {
7070
Type: schema.TypeInt,
7171
Optional: true,
72-
Default: 0,
73-
Description: "Weight information. An integer from 0 to 100. Only enterprise VIP domain names are available, 0 means off, does not pass this parameter, means that the weight information is not set. Default is 0.",
72+
Description: "Weight information. An integer from 0 to 100. Only enterprise VIP domain names are available, 0 means off, does not pass this parameter, means that the weight information is not set.",
7473
},
7574
"status": {
7675
Type: schema.TypeString,
@@ -118,7 +117,7 @@ func resourceTencentCloudDnspodRecordCreate(d *schema.ResourceData, meta interfa
118117
request.MX = helper.IntUint64(v.(int))
119118
}
120119
request.TTL = helper.IntUint64(ttl)
121-
if v, ok := d.GetOk("weight"); ok {
120+
if v, ok := d.GetOkExists("weight"); ok {
122121
request.Weight = helper.IntUint64(v.(int))
123122
}
124123
request.Status = &status
@@ -269,7 +268,7 @@ func resourceTencentCloudDnspodRecordUpdate(d *schema.ResourceData, meta interfa
269268
ttl := v.(int)
270269
request.TTL = helper.IntUint64(ttl)
271270
}
272-
if v, ok := d.GetOk("weight"); ok {
271+
if v, ok := d.GetOkExists("weight"); ok {
273272
weight := v.(int)
274273
request.Weight = helper.IntUint64(weight)
275274
}

tencentcloud/services/dnspod/resource_tc_dnspod_record_test.go

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,90 @@ func TestAccTencentCloudDnspodRecordResource_MX(t *testing.T) {
136136
})
137137
}
138138

139+
func TestAccTencentCloudDnspodRecordResource_WeightZero(t *testing.T) {
140+
t.Parallel()
141+
resource.Test(t, resource.TestCase{
142+
PreCheck: func() { tcacctest.AccPreCheck(t) },
143+
Providers: tcacctest.AccProviders,
144+
CheckDestroy: testAccCheckDnspodRecordDestroy,
145+
Steps: []resource.TestStep{
146+
{
147+
Config: testAccTencentCloudDnspodRecordWeightZero,
148+
Check: resource.ComposeTestCheckFunc(
149+
testAccCheckDnspodRecordExists("tencentcloud_dnspod_record.weight"),
150+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "domain", "tencentcloud-terraform-provider.cn"),
151+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "record_type", "A"),
152+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "record_line", "默认"),
153+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "value", "1.2.3.10"),
154+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "sub_domain", "weight"),
155+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "remark", "terraform-test"),
156+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "weight", "0"),
157+
),
158+
},
159+
{
160+
Config: testAccTencentCloudDnspodRecordWeight,
161+
Check: resource.ComposeTestCheckFunc(
162+
testAccCheckDnspodRecordExists("tencentcloud_dnspod_record.weight"),
163+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "domain", "tencentcloud-terraform-provider.cn"),
164+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "record_type", "A"),
165+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "record_line", "默认"),
166+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "value", "1.2.3.10"),
167+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "sub_domain", "weight"),
168+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "remark", "terraform-test"),
169+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "weight", "10"),
170+
),
171+
},
172+
{
173+
ResourceName: "tencentcloud_dnspod_record.weight",
174+
ImportState: true,
175+
ImportStateVerify: true,
176+
},
177+
},
178+
})
179+
}
180+
181+
func TestAccTencentCloudDnspodRecordResource_Weight(t *testing.T) {
182+
t.Parallel()
183+
resource.Test(t, resource.TestCase{
184+
PreCheck: func() { tcacctest.AccPreCheck(t) },
185+
Providers: tcacctest.AccProviders,
186+
CheckDestroy: testAccCheckDnspodRecordDestroy,
187+
Steps: []resource.TestStep{
188+
{
189+
Config: testAccTencentCloudDnspodRecordWeight,
190+
Check: resource.ComposeTestCheckFunc(
191+
testAccCheckDnspodRecordExists("tencentcloud_dnspod_record.weight"),
192+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "domain", "tencentcloud-terraform-provider.cn"),
193+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "record_type", "A"),
194+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "record_line", "默认"),
195+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "value", "1.2.3.10"),
196+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "sub_domain", "weight"),
197+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "remark", "terraform-test"),
198+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "weight", "10"),
199+
),
200+
},
201+
{
202+
Config: testAccTencentCloudDnspodRecordWeightZero,
203+
Check: resource.ComposeTestCheckFunc(
204+
testAccCheckDnspodRecordExists("tencentcloud_dnspod_record.weight"),
205+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "domain", "tencentcloud-terraform-provider.cn"),
206+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "record_type", "A"),
207+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "record_line", "默认"),
208+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "value", "1.2.3.10"),
209+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "sub_domain", "weight"),
210+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "remark", "terraform-test"),
211+
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "weight", "0"),
212+
),
213+
},
214+
{
215+
ResourceName: "tencentcloud_dnspod_record.weight",
216+
ImportState: true,
217+
ImportStateVerify: true,
218+
},
219+
},
220+
})
221+
}
222+
139223
func testAccCheckDnspodRecordExists(n string) resource.TestCheckFunc {
140224
return func(s *terraform.State) error {
141225
rs, ok := s.RootModule().Resources[n]
@@ -287,3 +371,26 @@ resource "tencentcloud_dnspod_record" "demo" {
287371
remark = "terraform-test"
288372
}
289373
`
374+
375+
const testAccTencentCloudDnspodRecordWeightZero = `
376+
resource "tencentcloud_dnspod_record" "weight" {
377+
domain="tencentcloud-terraform-provider.cn"
378+
record_type="A"
379+
record_line="默认"
380+
value="1.2.3.10"
381+
sub_domain="weight"
382+
remark="terraform-test"
383+
weight=0
384+
}
385+
`
386+
const testAccTencentCloudDnspodRecordWeight = `
387+
resource "tencentcloud_dnspod_record" "weight" {
388+
domain="tencentcloud-terraform-provider.cn"
389+
record_type="A"
390+
record_line="默认"
391+
value="1.2.3.10"
392+
sub_domain="weight"
393+
remark="terraform-test"
394+
weight=10
395+
}
396+
`

website/docs/r/dnspod_record.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ The following arguments are supported:
3838
* `status` - (Optional, String) Records the initial state, with values ranging from ENABLE and DISABLE. The default is ENABLE, and if DISABLE is passed in, resolution will not take effect and the limits of load balancing will not be verified.
3939
* `sub_domain` - (Optional, String) The host records, default value is `@`.
4040
* `ttl` - (Optional, Int) TTL, the range is 1-604800, and the minimum value of different levels of domain names is different. Default is 600.
41-
* `weight` - (Optional, Int) Weight information. An integer from 0 to 100. Only enterprise VIP domain names are available, 0 means off, does not pass this parameter, means that the weight information is not set. Default is 0.
41+
* `weight` - (Optional, Int) Weight information. An integer from 0 to 100. Only enterprise VIP domain names are available, 0 means off, does not pass this parameter, means that the weight information is not set.
4242

4343
## Attributes Reference
4444

0 commit comments

Comments
 (0)