Skip to content

fix(dnspod): [123456789] weight set zero #3460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3460.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_dnspod_record: fix weight set zero
```
1 change: 1 addition & 0 deletions schema/metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
provider_meta:
metadata:
display_name: 腾讯云资源
icon_url: tencentcloud
attr_orders:
- name: domain
- name: profile
Expand Down
7 changes: 3 additions & 4 deletions tencentcloud/services/dnspod/resource_tc_dnspod_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ func ResourceTencentCloudDnspodRecord() *schema.Resource {
"weight": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
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.",
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.",
},
"status": {
Type: schema.TypeString,
Expand Down Expand Up @@ -118,7 +117,7 @@ func resourceTencentCloudDnspodRecordCreate(d *schema.ResourceData, meta interfa
request.MX = helper.IntUint64(v.(int))
}
request.TTL = helper.IntUint64(ttl)
if v, ok := d.GetOk("weight"); ok {
if v, ok := d.GetOkExists("weight"); ok {
request.Weight = helper.IntUint64(v.(int))
}
request.Status = &status
Expand Down Expand Up @@ -269,7 +268,7 @@ func resourceTencentCloudDnspodRecordUpdate(d *schema.ResourceData, meta interfa
ttl := v.(int)
request.TTL = helper.IntUint64(ttl)
}
if v, ok := d.GetOk("weight"); ok {
if v, ok := d.GetOkExists("weight"); ok {
weight := v.(int)
request.Weight = helper.IntUint64(weight)
}
Expand Down
107 changes: 107 additions & 0 deletions tencentcloud/services/dnspod/resource_tc_dnspod_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,90 @@ func TestAccTencentCloudDnspodRecordResource_MX(t *testing.T) {
})
}

func TestAccTencentCloudDnspodRecordResource_WeightZero(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { tcacctest.AccPreCheck(t) },
Providers: tcacctest.AccProviders,
CheckDestroy: testAccCheckDnspodRecordDestroy,
Steps: []resource.TestStep{
{
Config: testAccTencentCloudDnspodRecordWeightZero,
Check: resource.ComposeTestCheckFunc(
testAccCheckDnspodRecordExists("tencentcloud_dnspod_record.weight"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "domain", "tencentcloud-terraform-provider.cn"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "record_type", "A"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "record_line", "默认"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "value", "1.2.3.10"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "sub_domain", "weight"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "remark", "terraform-test"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "weight", "0"),
),
},
{
Config: testAccTencentCloudDnspodRecordWeight,
Check: resource.ComposeTestCheckFunc(
testAccCheckDnspodRecordExists("tencentcloud_dnspod_record.weight"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "domain", "tencentcloud-terraform-provider.cn"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "record_type", "A"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "record_line", "默认"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "value", "1.2.3.10"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "sub_domain", "weight"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "remark", "terraform-test"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "weight", "10"),
),
},
{
ResourceName: "tencentcloud_dnspod_record.weight",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccTencentCloudDnspodRecordResource_Weight(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { tcacctest.AccPreCheck(t) },
Providers: tcacctest.AccProviders,
CheckDestroy: testAccCheckDnspodRecordDestroy,
Steps: []resource.TestStep{
{
Config: testAccTencentCloudDnspodRecordWeight,
Check: resource.ComposeTestCheckFunc(
testAccCheckDnspodRecordExists("tencentcloud_dnspod_record.weight"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "domain", "tencentcloud-terraform-provider.cn"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "record_type", "A"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "record_line", "默认"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "value", "1.2.3.10"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "sub_domain", "weight"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "remark", "terraform-test"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "weight", "10"),
),
},
{
Config: testAccTencentCloudDnspodRecordWeightZero,
Check: resource.ComposeTestCheckFunc(
testAccCheckDnspodRecordExists("tencentcloud_dnspod_record.weight"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "domain", "tencentcloud-terraform-provider.cn"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "record_type", "A"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "record_line", "默认"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "value", "1.2.3.10"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "sub_domain", "weight"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "remark", "terraform-test"),
resource.TestCheckResourceAttr("tencentcloud_dnspod_record.weight", "weight", "0"),
),
},
{
ResourceName: "tencentcloud_dnspod_record.weight",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckDnspodRecordExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -287,3 +371,26 @@ resource "tencentcloud_dnspod_record" "demo" {
remark = "terraform-test"
}
`

const testAccTencentCloudDnspodRecordWeightZero = `
resource "tencentcloud_dnspod_record" "weight" {
domain="tencentcloud-terraform-provider.cn"
record_type="A"
record_line="默认"
value="1.2.3.10"
sub_domain="weight"
remark="terraform-test"
weight=0
}
`
const testAccTencentCloudDnspodRecordWeight = `
resource "tencentcloud_dnspod_record" "weight" {
domain="tencentcloud-terraform-provider.cn"
record_type="A"
record_line="默认"
value="1.2.3.10"
sub_domain="weight"
remark="terraform-test"
weight=10
}
`
2 changes: 1 addition & 1 deletion website/docs/r/dnspod_record.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The following arguments are supported:
* `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.
* `sub_domain` - (Optional, String) The host records, default value is `@`.
* `ttl` - (Optional, Int) TTL, the range is 1-604800, and the minimum value of different levels of domain names is different. Default is 600.
* `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.
* `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.

## Attributes Reference

Expand Down
Loading