Skip to content

Commit d03584a

Browse files
tongyimingmikatong
andauthored
fix(dnspod): [123456789]fix weight (#3521)
* fix weight * update --------- Co-authored-by: mikatong <mikatong@tencent.com>
1 parent 0fcdbea commit d03584a

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

tencentcloud/services/dnspod/resource_tc_dnspod_record.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dnspod
22

33
import (
4+
"context"
45
"fmt"
56
"log"
67
"strconv"
@@ -69,8 +70,7 @@ func ResourceTencentCloudDnspodRecord() *schema.Resource {
6970
"weight": {
7071
Type: schema.TypeInt,
7172
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.",
73+
Description: "Weight information. An integer from 1 to 100. Only enterprise VIP domain names are available, does not pass this parameter, means that the weight information is not set.",
7474
},
7575
"status": {
7676
Type: schema.TypeString,
@@ -89,6 +89,16 @@ func ResourceTencentCloudDnspodRecord() *schema.Resource {
8989
Description: "The Remark of record.",
9090
},
9191
},
92+
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error {
93+
// weight设置后不能单独关闭
94+
if d.HasChange("weight") {
95+
old, new := d.GetChange("weight")
96+
if old.(int) != 0 && new.(int) == 0 {
97+
return fmt.Errorf("field `weight` cannot be unset once specified")
98+
}
99+
}
100+
return nil
101+
},
92102
}
93103
}
94104

@@ -207,7 +217,9 @@ func resourceTencentCloudDnspodRecordRead(d *schema.ResourceData, meta interface
207217
_ = d.Set("mx", recordInfo.MX)
208218
_ = d.Set("ttl", recordInfo.TTL)
209219
_ = d.Set("monitor_status", recordInfo.MonitorStatus)
210-
_ = d.Set("weight", recordInfo.Weight)
220+
if recordInfo.Weight != nil {
221+
_ = d.Set("weight", recordInfo.Weight)
222+
}
211223
_ = d.Set("domain", items[0])
212224
_ = d.Set("record_line", recordInfo.RecordLine)
213225
_ = d.Set("record_type", recordInfo.RecordType)

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 1 to 100. Only enterprise VIP domain names are available, does not pass this parameter, means that the weight information is not set.
4242

4343
## Attributes Reference
4444

0 commit comments

Comments
 (0)