Skip to content

Commit 69fe235

Browse files
committed
add
1 parent 1b48be1 commit 69fe235

6 files changed

+68
-34
lines changed

tencentcloud/services/waf/resource_tc_waf_bot_scene_status_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func resourceTencentCloudWafBotSceneStatusConfigCreate(d *schema.ResourceData, m
7979
}
8080

8181
if v, ok := d.GetOk("scene_id"); ok {
82-
domain = v.(string)
82+
sceneId = v.(string)
8383
}
8484

8585
d.SetId(strings.Join([]string{domain, sceneId}, tccommon.FILED_SP))

tencentcloud/services/waf/resource_tc_waf_bot_status_config.go

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package waf
22

33
import (
44
"context"
5+
"fmt"
56
"log"
7+
"strings"
68

79
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
810
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -18,6 +20,9 @@ func ResourceTencentCloudWafBotStatusConfig() *schema.Resource {
1820
Read: resourceTencentCloudWafBotStatusConfigRead,
1921
Update: resourceTencentCloudWafBotStatusConfigUpdate,
2022
Delete: resourceTencentCloudWafBotStatusConfigDelete,
23+
Importer: &schema.ResourceImporter{
24+
State: schema.ImportStatePassthrough,
25+
},
2126
Schema: map[string]*schema.Schema{
2227
"status": {
2328
Type: schema.TypeString,
@@ -34,7 +39,8 @@ func ResourceTencentCloudWafBotStatusConfig() *schema.Resource {
3439

3540
"instance_id": {
3641
Type: schema.TypeString,
37-
Optional: true,
42+
Required: true,
43+
ForceNew: true,
3844
Description: "Instance ID.",
3945
},
4046

@@ -93,13 +99,20 @@ func resourceTencentCloudWafBotStatusConfigCreate(d *schema.ResourceData, meta i
9399
defer tccommon.LogElapsed("resource.tencentcloud_waf_bot_status_config.create")()
94100
defer tccommon.InconsistentCheck(d, meta)()
95101

96-
var domain string
102+
var (
103+
instanceId string
104+
domain string
105+
)
106+
107+
if v, ok := d.GetOk("instance_id"); ok {
108+
instanceId = v.(string)
109+
}
97110

98111
if v, ok := d.GetOk("domain"); ok {
99112
domain = v.(string)
100113
}
101114

102-
d.SetId(domain)
115+
d.SetId(strings.Join([]string{instanceId, domain}, tccommon.FILED_SP))
103116

104117
return resourceTencentCloudWafBotStatusConfigUpdate(d, meta)
105118
}
@@ -112,9 +125,16 @@ func resourceTencentCloudWafBotStatusConfigRead(d *schema.ResourceData, meta int
112125
logId = tccommon.GetLogId(tccommon.ContextNil)
113126
ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)
114127
service = WafService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
115-
domain = d.Id()
116128
)
117129

130+
idSplit := strings.Split(d.Id(), tccommon.FILED_SP)
131+
if len(idSplit) != 2 {
132+
return fmt.Errorf("id is broken,%s", d.Id())
133+
}
134+
135+
instanceId := idSplit[0]
136+
domain := idSplit[1]
137+
118138
respData, err := service.DescribeWafBotStatusConfigById(ctx, domain)
119139
if err != nil {
120140
return err
@@ -127,9 +147,14 @@ func resourceTencentCloudWafBotStatusConfigRead(d *schema.ResourceData, meta int
127147
}
128148

129149
_ = d.Set("domain", domain)
150+
_ = d.Set("instance_id", instanceId)
130151

131152
if respData.Status != nil {
132-
_ = d.Set("status", respData.Status)
153+
if *respData.Status == true {
154+
_ = d.Set("status", "1")
155+
} else {
156+
_ = d.Set("status", "0")
157+
}
133158
}
134159

135160
if respData.SceneCount != nil {
@@ -178,18 +203,22 @@ func resourceTencentCloudWafBotStatusConfigUpdate(d *schema.ResourceData, meta i
178203
logId = tccommon.GetLogId(tccommon.ContextNil)
179204
ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)
180205
request = wafv20180125.NewModifyBotStatusRequest()
181-
domain = d.Id()
182206
)
183207

184-
if v, ok := d.GetOk("status"); ok {
185-
request.Status = helper.String(v.(string))
208+
idSplit := strings.Split(d.Id(), tccommon.FILED_SP)
209+
if len(idSplit) != 2 {
210+
return fmt.Errorf("id is broken,%s", d.Id())
186211
}
187212

188-
if v, ok := d.GetOk("instance_id"); ok {
189-
request.InstanceID = helper.String(v.(string))
213+
instanceId := idSplit[0]
214+
domain := idSplit[1]
215+
216+
if v, ok := d.GetOk("status"); ok {
217+
request.Status = helper.String(v.(string))
190218
}
191219

192-
request.Domain = helper.String(domain)
220+
request.InstanceID = &instanceId
221+
request.Domain = &domain
193222
request.Category = helper.String("bot")
194223
request.IsVersionFour = helper.Bool(true)
195224
request.BotVersion = helper.String("4.1.0")

tencentcloud/services/waf/resource_tc_waf_bot_status_config.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ Example Usage
44

55
```hcl
66
resource "tencentcloud_waf_bot_status_config" "example" {
7-
domain = "example.com"
8-
status = "1"
7+
instance_id = "waf_2kxtlbky11bbcr4b"
8+
domain = "example.com"
9+
status = "0"
910
}
1011
```
1112

12-
Or
13+
Import
1314

14-
```hcl
15-
resource "tencentcloud_waf_bot_status_config" "example" {
16-
domain = "example.com"
17-
status = "0"
18-
instance_id = "waf_2kxtlbky11bbcr4b"
19-
}
15+
WAF bot status config can be imported using the id, e.g.
16+
17+
```
18+
terraform import tencentcloud_waf_bot_status_config.example waf_2kw1ente05223fcr#example.com
2019
```

tencentcloud/services/waf/resource_tc_waf_bot_status_config_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func TestAccTencentCloudWafBotStatusConfigResource_basic(t *testing.T) {
2020
Config: testAccWafBotStatusConfig,
2121
Check: resource.ComposeTestCheckFunc(
2222
resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "id"),
23+
resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "instance_id"),
2324
resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "domain"),
2425
resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "status"),
2526
),
@@ -28,6 +29,7 @@ func TestAccTencentCloudWafBotStatusConfigResource_basic(t *testing.T) {
2829
Config: testAccWafBotStatusConfigUpdate,
2930
Check: resource.ComposeTestCheckFunc(
3031
resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "id"),
32+
resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "instance_id"),
3133
resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "domain"),
3234
resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "status"),
3335
),
@@ -43,14 +45,16 @@ func TestAccTencentCloudWafBotStatusConfigResource_basic(t *testing.T) {
4345

4446
const testAccWafBotStatusConfig = `
4547
resource "tencentcloud_waf_bot_status_config" "example" {
48+
instance_id = "waf_2kxtlbky11bbcr4b"
4649
domain = "example.com"
47-
status = "1"
50+
status = "0"
4851
}
4952
`
5053

5154
const testAccWafBotStatusConfigUpdate = `
5255
resource "tencentcloud_waf_bot_status_config" "example" {
56+
instance_id = "waf_2kxtlbky11bbcr4b"
5357
domain = "example.com"
54-
status = "0"
58+
status = "1"
5559
}
5660
`

tencentcloud/services/waf/service_tencentcloud_waf.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,9 @@ func (me *WafService) DescribeWafBotSceneStatusConfigById(ctx context.Context, d
17051705
request := waf.NewDescribeBotSceneListRequest()
17061706
response := waf.NewDescribeBotSceneListResponse()
17071707
request.Domain = helper.String(domain)
1708+
// wait waf sdk update
1709+
// request.BusinessType = common.StringPtrs([]string{"all"})
1710+
request.BusinessType = common.StringPtrs([]string{"login", "seckill", "crawl", "scan", "key-protect", "click-farming", "junk-mail", "social-media", "auto-download", "custom"})
17081711

17091712
defer func() {
17101713
if errRet != nil {

website/docs/r/waf_bot_status_config.html.markdown

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,9 @@ Provides a resource to create a WAF bot status config
1515

1616
```hcl
1717
resource "tencentcloud_waf_bot_status_config" "example" {
18-
domain = "example.com"
19-
status = "1"
20-
}
21-
```
22-
23-
### Or
24-
25-
```hcl
26-
resource "tencentcloud_waf_bot_status_config" "example" {
18+
instance_id = "waf_2kxtlbky11bbcr4b"
2719
domain = "example.com"
2820
status = "0"
29-
instance_id = "waf_2kxtlbky11bbcr4b"
3021
}
3122
```
3223

@@ -35,8 +26,8 @@ resource "tencentcloud_waf_bot_status_config" "example" {
3526
The following arguments are supported:
3627

3728
* `domain` - (Required, String, ForceNew) Domain.
29+
* `instance_id` - (Required, String, ForceNew) Instance ID.
3830
* `status` - (Required, String) Bot status. 1 - enable; 0 - disable.
39-
* `instance_id` - (Optional, String) Instance ID.
4031

4132
## Attributes Reference
4233

@@ -53,3 +44,11 @@ In addition to all arguments above, the following attributes are exported:
5344
* `valid_scene_count` - Number of effective scenarios.
5445

5546

47+
## Import
48+
49+
WAF bot status config can be imported using the id, e.g.
50+
51+
```
52+
terraform import tencentcloud_waf_bot_status_config.example waf_2kw1ente05223fcr#example.com
53+
```
54+

0 commit comments

Comments
 (0)