From 9a2e18736daa0dd0814b1d5bc86bbcd0719c6bdf Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Tue, 13 May 2025 11:16:01 +0800 Subject: [PATCH 1/6] add --- tencentcloud/provider.go | 7 +- tencentcloud/provider.md | 6 +- ...resource_tc_waf_bot_scene_status_config.go | 189 +++ ...resource_tc_waf_bot_scene_status_config.md | 19 + ...rce_tc_waf_bot_scene_status_config_test.go | 60 + .../waf/resource_tc_waf_bot_status_config.go | 220 +++ .../waf/resource_tc_waf_bot_status_config.md | 20 + .../resource_tc_waf_bot_status_config_test.go | 56 + .../waf/resource_tc_waf_domain_post_action.md | 19 - ...ource_tc_waf_domain_post_action_config.go} | 34 +- ...source_tc_waf_domain_post_action_config.md | 19 + ..._tc_waf_domain_post_action_config_test.go} | 24 +- ...esource_tc_waf_instance_attack_log_post.md | 20 - ...tc_waf_instance_attack_log_post_config.go} | 34 +- ..._tc_waf_instance_attack_log_post_config.md | 20 + ...f_instance_attack_log_post_config_test.go} | 20 +- .../resource_tc_waf_waf_bot_scene_ucb_rule.go | 1315 +++++++++++++++++ .../services/waf/service_tencentcloud_waf.go | 195 +++ .../waf_bot_scene_status_config.html.markdown | 49 + .../r/waf_bot_status_config.html.markdown | 55 + ...af_domain_post_action_config.html.markdown | 47 + ...tance_attack_log_post_config.html.markdown | 47 + website/tencentcloud.erb | 10 +- 23 files changed, 2384 insertions(+), 101 deletions(-) create mode 100644 tencentcloud/services/waf/resource_tc_waf_bot_scene_status_config.go create mode 100644 tencentcloud/services/waf/resource_tc_waf_bot_scene_status_config.md create mode 100644 tencentcloud/services/waf/resource_tc_waf_bot_scene_status_config_test.go create mode 100644 tencentcloud/services/waf/resource_tc_waf_bot_status_config.go create mode 100644 tencentcloud/services/waf/resource_tc_waf_bot_status_config.md create mode 100644 tencentcloud/services/waf/resource_tc_waf_bot_status_config_test.go delete mode 100644 tencentcloud/services/waf/resource_tc_waf_domain_post_action.md rename tencentcloud/services/waf/{resource_tc_waf_domain_post_action.go => resource_tc_waf_domain_post_action_config.go} (73%) create mode 100644 tencentcloud/services/waf/resource_tc_waf_domain_post_action_config.md rename tencentcloud/services/waf/{resource_tc_waf_domain_post_action_test.go => resource_tc_waf_domain_post_action_config_test.go} (69%) delete mode 100644 tencentcloud/services/waf/resource_tc_waf_instance_attack_log_post.md rename tencentcloud/services/waf/{resource_tc_waf_instance_attack_log_post.go => resource_tc_waf_instance_attack_log_post_config.go} (69%) create mode 100644 tencentcloud/services/waf/resource_tc_waf_instance_attack_log_post_config.md rename tencentcloud/services/waf/{resource_tc_waf_instance_attack_log_post_test.go => resource_tc_waf_instance_attack_log_post_config_test.go} (71%) create mode 100644 tencentcloud/services/waf/resource_tc_waf_waf_bot_scene_ucb_rule.go create mode 100644 website/docs/r/waf_bot_scene_status_config.html.markdown create mode 100644 website/docs/r/waf_bot_status_config.html.markdown create mode 100644 website/docs/r/waf_domain_post_action_config.html.markdown create mode 100644 website/docs/r/waf_instance_attack_log_post_config.html.markdown diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index a7ea730de6..d05dca4693 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -2238,8 +2238,11 @@ func Provider() *schema.Provider { "tencentcloud_waf_ip_access_control_v2": waf.ResourceTencentCloudWafIpAccessControlV2(), "tencentcloud_waf_log_post_cls_flow": waf.ResourceTencentCloudWafLogPostClsFlow(), "tencentcloud_waf_log_post_ckafka_flow": waf.ResourceTencentCloudWafLogPostCkafkaFlow(), - "tencentcloud_waf_domain_post_action": waf.ResourceTencentCloudWafDomainPostAction(), - "tencentcloud_waf_instance_attack_log_post": waf.ResourceTencentCloudWafInstanceAttackLogPost(), + "tencentcloud_waf_domain_post_action_config": waf.ResourceTencentCloudWafDomainPostActionConfig(), + "tencentcloud_waf_instance_attack_log_post_config": waf.ResourceTencentCloudWafInstanceAttackLogPostConfig(), + "tencentcloud_waf_bot_scene_status_config": waf.ResourceTencentCloudWafBotSceneStatusConfig(), + "tencentcloud_waf_bot_status_config": waf.ResourceTencentCloudWafBotStatusConfig(), + "tencentcloud_waf_bot_scene_ucb_rule": waf.ResourceTencentCloudWafBotSceneUCBRule(), "tencentcloud_wedata_rule_template": wedata.ResourceTencentCloudWedataRuleTemplate(), "tencentcloud_wedata_datasource": wedata.ResourceTencentCloudWedataDatasource(), "tencentcloud_wedata_function": wedata.ResourceTencentCloudWedataFunction(), diff --git a/tencentcloud/provider.md b/tencentcloud/provider.md index 49f79a6910..ce3f3cc937 100644 --- a/tencentcloud/provider.md +++ b/tencentcloud/provider.md @@ -2183,8 +2183,10 @@ tencentcloud_waf_ip_access_control tencentcloud_waf_ip_access_control_v2 tencentcloud_waf_log_post_cls_flow tencentcloud_waf_log_post_ckafka_flow -tencentcloud_waf_domain_post_action -tencentcloud_waf_instance_attack_log_post +tencentcloud_waf_domain_post_action_config +tencentcloud_waf_instance_attack_log_post_config +tencentcloud_waf_bot_scene_status_config +tencentcloud_waf_bot_status_config Wedata Data Source diff --git a/tencentcloud/services/waf/resource_tc_waf_bot_scene_status_config.go b/tencentcloud/services/waf/resource_tc_waf_bot_scene_status_config.go new file mode 100644 index 0000000000..9aa2060b04 --- /dev/null +++ b/tencentcloud/services/waf/resource_tc_waf_bot_scene_status_config.go @@ -0,0 +1,189 @@ +package waf + +import ( + "context" + "fmt" + "log" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + wafv20180125 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf/v20180125" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func ResourceTencentCloudWafBotSceneStatusConfig() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudWafBotSceneStatusConfigCreate, + Read: resourceTencentCloudWafBotSceneStatusConfigRead, + Update: resourceTencentCloudWafBotSceneStatusConfigUpdate, + Delete: resourceTencentCloudWafBotSceneStatusConfigDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "domain": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Domain.", + }, + + "scene_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Scene ID.", + }, + + "status": { + Type: schema.TypeBool, + Required: true, + Description: "Bot status. true - enable; false - disable.", + }, + + "type": { + Type: schema.TypeString, + Computed: true, + Description: "Scene type, default: Default scenario, custom: Non default scenario.", + }, + + "scene_name": { + Type: schema.TypeString, + Computed: true, + Description: "Scene name.", + }, + + "priority": { + Type: schema.TypeInt, + Computed: true, + Description: "Priority.", + }, + }, + } +} + +func resourceTencentCloudWafBotSceneStatusConfigCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_waf_bot_scene_status_config.create")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + domain string + sceneId string + ) + + if v, ok := d.GetOk("domain"); ok { + domain = v.(string) + } + + if v, ok := d.GetOk("scene_id"); ok { + domain = v.(string) + } + + d.SetId(strings.Join([]string{domain, sceneId}, tccommon.FILED_SP)) + + return resourceTencentCloudWafBotSceneStatusConfigUpdate(d, meta) +} + +func resourceTencentCloudWafBotSceneStatusConfigRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_waf_bot_scene_status_config.read")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + service = WafService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + ) + + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + + domain := idSplit[0] + sceneId := idSplit[1] + + respData, err := service.DescribeWafBotSceneStatusConfigById(ctx, domain, sceneId) + if err != nil { + return err + } + + if respData == nil { + d.SetId("") + log.Printf("[WARN]%s resource `waf_bot_scene_status_config` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + return nil + } + + _ = d.Set("domain", domain) + _ = d.Set("scene_id", sceneId) + + if respData.SceneStatus != nil { + _ = d.Set("status", respData.SceneStatus) + } + + if respData.Type != nil { + _ = d.Set("type", respData.Type) + } + + if respData.SceneName != nil { + _ = d.Set("scene_name", respData.SceneName) + } + + if respData.Priority != nil { + _ = d.Set("priority", respData.Priority) + } + + return nil +} + +func resourceTencentCloudWafBotSceneStatusConfigUpdate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_waf_bot_scene_status_config.update")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + request = wafv20180125.NewModifyBotSceneStatusRequest() + ) + + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + + domain := idSplit[0] + sceneId := idSplit[1] + + if v, ok := d.GetOkExists("status"); ok { + request.Status = helper.Bool(v.(bool)) + } + + request.Domain = &domain + request.SceneId = &sceneId + reqErr := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseWafV20180125Client().ModifyBotSceneStatusWithContext(ctx, request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + return nil + }) + + if reqErr != nil { + log.Printf("[CRITAL]%s update waf bot scene status config failed, reason:%+v", logId, reqErr) + return reqErr + } + + return resourceTencentCloudWafBotSceneStatusConfigRead(d, meta) +} + +func resourceTencentCloudWafBotSceneStatusConfigDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_waf_bot_scene_status_config.delete")() + defer tccommon.InconsistentCheck(d, meta)() + + return nil +} diff --git a/tencentcloud/services/waf/resource_tc_waf_bot_scene_status_config.md b/tencentcloud/services/waf/resource_tc_waf_bot_scene_status_config.md new file mode 100644 index 0000000000..10c4536749 --- /dev/null +++ b/tencentcloud/services/waf/resource_tc_waf_bot_scene_status_config.md @@ -0,0 +1,19 @@ +Provides a resource to create a WAF bot scene status config + +Example Usage + +```hcl +resource "tencentcloud_waf_bot_scene_status_config" "example" { + domain = "example.com" + scene_id = "3024324123" + status = true +} +``` + +Import + +WAF bot scene status config can be imported using the id, e.g. + +``` +terraform import tencentcloud_waf_bot_scene_status_config.example example.com#3024324123 +``` diff --git a/tencentcloud/services/waf/resource_tc_waf_bot_scene_status_config_test.go b/tencentcloud/services/waf/resource_tc_waf_bot_scene_status_config_test.go new file mode 100644 index 0000000000..708a76efd1 --- /dev/null +++ b/tencentcloud/services/waf/resource_tc_waf_bot_scene_status_config_test.go @@ -0,0 +1,60 @@ +package waf_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudWafBotSceneStatusConfigResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testAccWafBotSceneStatusConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_scene_status_config.example", "id"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_scene_status_config.example", "domain"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_scene_status_config.example", "scene_id"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_scene_status_config.example", "status"), + ), + }, + { + Config: testAccWafBotSceneStatusConfigUpdate, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_scene_status_config.example", "id"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_scene_status_config.example", "domain"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_scene_status_config.example", "scene_id"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_scene_status_config.example", "status"), + ), + }, + { + ResourceName: "tencentcloud_waf_bot_scene_status_config.example", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccWafBotSceneStatusConfig = ` +resource "tencentcloud_waf_bot_scene_status_config" "example" { + domain = "example.com" + scene_id = "3024324123" + status = true +} +` + +const testAccWafBotSceneStatusConfigUpdate = ` +resource "tencentcloud_waf_bot_scene_status_config" "example" { + domain = "example.com" + scene_id = "3024324123" + status = false +} +` diff --git a/tencentcloud/services/waf/resource_tc_waf_bot_status_config.go b/tencentcloud/services/waf/resource_tc_waf_bot_status_config.go new file mode 100644 index 0000000000..69225dc07f --- /dev/null +++ b/tencentcloud/services/waf/resource_tc_waf_bot_status_config.go @@ -0,0 +1,220 @@ +package waf + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + wafv20180125 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf/v20180125" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func ResourceTencentCloudWafBotStatusConfig() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudWafBotStatusConfigCreate, + Read: resourceTencentCloudWafBotStatusConfigRead, + Update: resourceTencentCloudWafBotStatusConfigUpdate, + Delete: resourceTencentCloudWafBotStatusConfigDelete, + Schema: map[string]*schema.Schema{ + "status": { + Type: schema.TypeString, + Required: true, + Description: "Bot status. 1 - enable; 0 - disable.", + }, + + "domain": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Domain.", + }, + + "instance_id": { + Type: schema.TypeString, + Optional: true, + Description: "Instance ID.", + }, + + "scene_count": { + Type: schema.TypeInt, + Computed: true, + Description: "Scene total count.", + }, + + "valid_scene_count": { + Type: schema.TypeInt, + Computed: true, + Description: "Number of effective scenarios.", + }, + + "current_global_scene": { + Type: schema.TypeList, + Computed: true, + Description: "The currently enabled scenario with a global matching range and the highest priority.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "scene_id": { + Type: schema.TypeString, + Computed: true, + Description: "Scene ID.", + }, + "scene_name": { + Type: schema.TypeString, + Computed: true, + Description: "Scene name.", + }, + "priority": { + Type: schema.TypeInt, + Computed: true, + Description: "Priority.", + }, + "update_time": { + Type: schema.TypeInt, + Computed: true, + Description: "Update time.", + }, + }, + }, + }, + + "custom_rule_nums": { + Type: schema.TypeInt, + Computed: true, + Description: "Total number of custom rules, excluding BOT whitelist.", + }, + }, + } +} + +func resourceTencentCloudWafBotStatusConfigCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_waf_bot_status_config.create")() + defer tccommon.InconsistentCheck(d, meta)() + + var domain string + + if v, ok := d.GetOk("domain"); ok { + domain = v.(string) + } + + d.SetId(domain) + + return resourceTencentCloudWafBotStatusConfigUpdate(d, meta) +} + +func resourceTencentCloudWafBotStatusConfigRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_waf_bot_status_config.read")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + service = WafService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + domain = d.Id() + ) + + respData, err := service.DescribeWafBotStatusConfigById(ctx, domain) + if err != nil { + return err + } + + if respData == nil { + d.SetId("") + log.Printf("[WARN]%s resource `waf_bot_status_config` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + return nil + } + + _ = d.Set("domain", domain) + + if respData.Status != nil { + _ = d.Set("status", respData.Status) + } + + if respData.SceneCount != nil { + _ = d.Set("scene_count", respData.SceneCount) + } + + if respData.ValidSceneCount != nil { + _ = d.Set("valid_scene_count", respData.ValidSceneCount) + } + + if respData.CurrentGlobalScene != nil { + tmpList := make([]map[string]interface{}, 0, 1) + dMap := make(map[string]interface{}) + if respData.CurrentGlobalScene.SceneId != nil { + dMap["scene_id"] = respData.CurrentGlobalScene.SceneId + } + + if respData.CurrentGlobalScene.SceneName != nil { + dMap["scene_name"] = respData.CurrentGlobalScene.SceneName + } + + if respData.CurrentGlobalScene.Priority != nil { + dMap["priority"] = respData.CurrentGlobalScene.Priority + } + + if respData.CurrentGlobalScene.UpdateTime != nil { + dMap["update_time"] = respData.CurrentGlobalScene.UpdateTime + } + + tmpList = append(tmpList, dMap) + _ = d.Set("current_global_scene", tmpList) + } + + if respData.CustomRuleNums != nil { + _ = d.Set("custom_rule_nums", respData.CustomRuleNums) + } + + return nil +} + +func resourceTencentCloudWafBotStatusConfigUpdate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_waf_bot_status_config.update")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + request = wafv20180125.NewModifyBotStatusRequest() + domain = d.Id() + ) + + if v, ok := d.GetOk("status"); ok { + request.Status = helper.String(v.(string)) + } + + if v, ok := d.GetOk("instance_id"); ok { + request.InstanceID = helper.String(v.(string)) + } + + request.Domain = helper.String(domain) + request.Category = helper.String("bot") + request.IsVersionFour = helper.Bool(true) + request.BotVersion = helper.String("4.1.0") + reqErr := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseWafV20180125Client().ModifyBotStatusWithContext(ctx, request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + return nil + }) + + if reqErr != nil { + log.Printf("[CRITAL]%s update waf bot status config failed, reason:%+v", logId, reqErr) + return reqErr + } + + return resourceTencentCloudWafBotStatusConfigRead(d, meta) +} + +func resourceTencentCloudWafBotStatusConfigDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_waf_bot_status_config.delete")() + defer tccommon.InconsistentCheck(d, meta)() + + return nil +} diff --git a/tencentcloud/services/waf/resource_tc_waf_bot_status_config.md b/tencentcloud/services/waf/resource_tc_waf_bot_status_config.md new file mode 100644 index 0000000000..220c0061ea --- /dev/null +++ b/tencentcloud/services/waf/resource_tc_waf_bot_status_config.md @@ -0,0 +1,20 @@ +Provides a resource to create a WAF bot status config + +Example Usage + +```hcl +resource "tencentcloud_waf_bot_status_config" "example" { + domain = "example.com" + status = "1" +} +``` + +Or + +```hcl +resource "tencentcloud_waf_bot_status_config" "example" { + domain = "example.com" + status = "0" + instance_id = "waf_2kxtlbky11bbcr4b" +} +``` diff --git a/tencentcloud/services/waf/resource_tc_waf_bot_status_config_test.go b/tencentcloud/services/waf/resource_tc_waf_bot_status_config_test.go new file mode 100644 index 0000000000..d5f8193690 --- /dev/null +++ b/tencentcloud/services/waf/resource_tc_waf_bot_status_config_test.go @@ -0,0 +1,56 @@ +package waf_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudWafBotStatusConfigResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testAccWafBotStatusConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "id"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "domain"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "status"), + ), + }, + { + Config: testAccWafBotStatusConfigUpdate, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "id"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "domain"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "status"), + ), + }, + { + ResourceName: "tencentcloud_waf_bot_status_config.example", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccWafBotStatusConfig = ` +resource "tencentcloud_waf_bot_status_config" "example" { + domain = "example.com" + status = "1" +} +` + +const testAccWafBotStatusConfigUpdate = ` +resource "tencentcloud_waf_bot_status_config" "example" { + domain = "example.com" + status = "0" +} +` diff --git a/tencentcloud/services/waf/resource_tc_waf_domain_post_action.md b/tencentcloud/services/waf/resource_tc_waf_domain_post_action.md deleted file mode 100644 index 6ef2b54d3a..0000000000 --- a/tencentcloud/services/waf/resource_tc_waf_domain_post_action.md +++ /dev/null @@ -1,19 +0,0 @@ -Provides a resource to create a WAF domain post action - -Example Usage - -```hcl -resource "tencentcloud_waf_domain_post_action" "example" { - domain = "example.com" - post_cls_action = 1 - post_ckafka_action = 0 -} -``` - -Import - -WAF domain post action can be imported using the id, e.g. - -``` -terraform import tencentcloud_waf_domain_post_action.example example.com -``` diff --git a/tencentcloud/services/waf/resource_tc_waf_domain_post_action.go b/tencentcloud/services/waf/resource_tc_waf_domain_post_action_config.go similarity index 73% rename from tencentcloud/services/waf/resource_tc_waf_domain_post_action.go rename to tencentcloud/services/waf/resource_tc_waf_domain_post_action_config.go index 0e664561e4..6c4227bd1f 100644 --- a/tencentcloud/services/waf/resource_tc_waf_domain_post_action.go +++ b/tencentcloud/services/waf/resource_tc_waf_domain_post_action_config.go @@ -12,12 +12,12 @@ import ( "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" ) -func ResourceTencentCloudWafDomainPostAction() *schema.Resource { +func ResourceTencentCloudWafDomainPostActionConfig() *schema.Resource { return &schema.Resource{ - Create: resourceTencentCloudWafDomainPostActionCreate, - Read: resourceTencentCloudWafDomainPostActionRead, - Update: resourceTencentCloudWafDomainPostActionUpdate, - Delete: resourceTencentCloudWafDomainPostActionDelete, + Create: resourceTencentCloudWafDomainPostActionConfigCreate, + Read: resourceTencentCloudWafDomainPostActionConfigRead, + Update: resourceTencentCloudWafDomainPostActionConfigUpdate, + Delete: resourceTencentCloudWafDomainPostActionConfigDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -46,8 +46,8 @@ func ResourceTencentCloudWafDomainPostAction() *schema.Resource { } } -func resourceTencentCloudWafDomainPostActionCreate(d *schema.ResourceData, meta interface{}) error { - defer tccommon.LogElapsed("resource.tencentcloud_waf_domain_post_action.create")() +func resourceTencentCloudWafDomainPostActionConfigCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_waf_domain_post_action_config.create")() defer tccommon.InconsistentCheck(d, meta)() var domain string @@ -57,11 +57,11 @@ func resourceTencentCloudWafDomainPostActionCreate(d *schema.ResourceData, meta d.SetId(domain) - return resourceTencentCloudWafDomainPostActionUpdate(d, meta) + return resourceTencentCloudWafDomainPostActionConfigUpdate(d, meta) } -func resourceTencentCloudWafDomainPostActionRead(d *schema.ResourceData, meta interface{}) error { - defer tccommon.LogElapsed("resource.tencentcloud_waf_domain_post_action.read")() +func resourceTencentCloudWafDomainPostActionConfigRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_waf_domain_post_action_config.read")() defer tccommon.InconsistentCheck(d, meta)() var ( @@ -78,7 +78,7 @@ func resourceTencentCloudWafDomainPostActionRead(d *schema.ResourceData, meta in if respData == nil || len(respData) < 1 { d.SetId("") - log.Printf("[WARN]%s resource `waf_domain_post_action` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + log.Printf("[WARN]%s resource `waf_domain_post_action_config` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) return nil } @@ -97,8 +97,8 @@ func resourceTencentCloudWafDomainPostActionRead(d *schema.ResourceData, meta in return nil } -func resourceTencentCloudWafDomainPostActionUpdate(d *schema.ResourceData, meta interface{}) error { - defer tccommon.LogElapsed("resource.tencentcloud_waf_domain_post_action.update")() +func resourceTencentCloudWafDomainPostActionConfigUpdate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_waf_domain_post_action_config.update")() defer tccommon.InconsistentCheck(d, meta)() var ( @@ -129,15 +129,15 @@ func resourceTencentCloudWafDomainPostActionUpdate(d *schema.ResourceData, meta }) if reqErr != nil { - log.Printf("[CRITAL]%s update waf domain post action failed, reason:%+v", logId, reqErr) + log.Printf("[CRITAL]%s update waf domain post action config failed, reason:%+v", logId, reqErr) return reqErr } - return resourceTencentCloudWafDomainPostActionRead(d, meta) + return resourceTencentCloudWafDomainPostActionConfigRead(d, meta) } -func resourceTencentCloudWafDomainPostActionDelete(d *schema.ResourceData, meta interface{}) error { - defer tccommon.LogElapsed("resource.tencentcloud_waf_domain_post_action.delete")() +func resourceTencentCloudWafDomainPostActionConfigDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_waf_domain_post_action_config.delete")() defer tccommon.InconsistentCheck(d, meta)() return nil diff --git a/tencentcloud/services/waf/resource_tc_waf_domain_post_action_config.md b/tencentcloud/services/waf/resource_tc_waf_domain_post_action_config.md new file mode 100644 index 0000000000..fdd8bf881e --- /dev/null +++ b/tencentcloud/services/waf/resource_tc_waf_domain_post_action_config.md @@ -0,0 +1,19 @@ +Provides a resource to create a WAF domain post action config + +Example Usage + +```hcl +resource "tencentcloud_waf_domain_post_action_config" "example" { + domain = "example.com" + post_cls_action = 1 + post_ckafka_action = 0 +} +``` + +Import + +WAF domain post action config can be imported using the id, e.g. + +``` +terraform import tencentcloud_waf_domain_post_action_config.example example.com +``` diff --git a/tencentcloud/services/waf/resource_tc_waf_domain_post_action_test.go b/tencentcloud/services/waf/resource_tc_waf_domain_post_action_config_test.go similarity index 69% rename from tencentcloud/services/waf/resource_tc_waf_domain_post_action_test.go rename to tencentcloud/services/waf/resource_tc_waf_domain_post_action_config_test.go index 102d808cae..165612fa32 100644 --- a/tencentcloud/services/waf/resource_tc_waf_domain_post_action_test.go +++ b/tencentcloud/services/waf/resource_tc_waf_domain_post_action_config_test.go @@ -8,7 +8,7 @@ import ( tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" ) -func TestAccTencentCloudWafDomainPostActionResource_basic(t *testing.T) { +func TestAccTencentCloudWafDomainPostActionConfigResource_basic(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -19,23 +19,23 @@ func TestAccTencentCloudWafDomainPostActionResource_basic(t *testing.T) { { Config: testAccWafDomainPostAction, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("tencentcloud_waf_domain_post_action.example", "id"), - resource.TestCheckResourceAttrSet("tencentcloud_waf_domain_post_action.example", "domain"), - resource.TestCheckResourceAttrSet("tencentcloud_waf_domain_post_action.example", "post_cls_action"), - resource.TestCheckResourceAttrSet("tencentcloud_waf_domain_post_action.example", "post_ckafka_action"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_domain_post_action_config.example", "id"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_domain_post_action_config.example", "domain"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_domain_post_action_config.example", "post_cls_action"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_domain_post_action_config.example", "post_ckafka_action"), ), }, { Config: testAccWafDomainPostActionUpdate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("tencentcloud_waf_domain_post_action.example", "id"), - resource.TestCheckResourceAttrSet("tencentcloud_waf_domain_post_action.example", "domain"), - resource.TestCheckResourceAttrSet("tencentcloud_waf_domain_post_action.example", "post_cls_action"), - resource.TestCheckResourceAttrSet("tencentcloud_waf_domain_post_action.example", "post_ckafka_action"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_domain_post_action_config.example", "id"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_domain_post_action_config.example", "domain"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_domain_post_action_config.example", "post_cls_action"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_domain_post_action_config.example", "post_ckafka_action"), ), }, { - ResourceName: "tencentcloud_waf_domain_post_action.example", + ResourceName: "tencentcloud_waf_domain_post_action_config.example", ImportState: true, ImportStateVerify: true, }, @@ -44,7 +44,7 @@ func TestAccTencentCloudWafDomainPostActionResource_basic(t *testing.T) { } const testAccWafDomainPostAction = ` -resource "tencentcloud_waf_domain_post_action" "example" { +resource "tencentcloud_waf_domain_post_action_config" "example" { domain = "example.com" post_cls_action = 1 post_ckafka_action = 0 @@ -52,7 +52,7 @@ resource "tencentcloud_waf_domain_post_action" "example" { ` const testAccWafDomainPostActionUpdate = ` -resource "tencentcloud_waf_domain_post_action" "example" { +resource "tencentcloud_waf_domain_post_action_config" "example" { domain = "example.com" post_cls_action = 0 post_ckafka_action = 1 diff --git a/tencentcloud/services/waf/resource_tc_waf_instance_attack_log_post.md b/tencentcloud/services/waf/resource_tc_waf_instance_attack_log_post.md deleted file mode 100644 index 248af60221..0000000000 --- a/tencentcloud/services/waf/resource_tc_waf_instance_attack_log_post.md +++ /dev/null @@ -1,20 +0,0 @@ -Provides a resource to create a WAF instance attack log post - -~> **NOTE:** Only enterprise version and above are supported for activation - -Example Usage - -```hcl -resource "tencentcloud_waf_instance_attack_log_post" "example" { - instance_id = "waf_2kxtlbky11b4wcrb" - attack_log_post = 1 -} -``` - -Import - -WAF instance attack log post can be imported using the id, e.g. - -``` -terraform import tencentcloud_waf_instance_attack_log_post.example waf_2kxtlbky11b4wcrb -``` diff --git a/tencentcloud/services/waf/resource_tc_waf_instance_attack_log_post.go b/tencentcloud/services/waf/resource_tc_waf_instance_attack_log_post_config.go similarity index 69% rename from tencentcloud/services/waf/resource_tc_waf_instance_attack_log_post.go rename to tencentcloud/services/waf/resource_tc_waf_instance_attack_log_post_config.go index e40503aeb3..22c0903a49 100644 --- a/tencentcloud/services/waf/resource_tc_waf_instance_attack_log_post.go +++ b/tencentcloud/services/waf/resource_tc_waf_instance_attack_log_post_config.go @@ -12,12 +12,12 @@ import ( "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" ) -func ResourceTencentCloudWafInstanceAttackLogPost() *schema.Resource { +func ResourceTencentCloudWafInstanceAttackLogPostConfig() *schema.Resource { return &schema.Resource{ - Create: resourceTencentCloudWafInstanceAttackLogPostCreate, - Read: resourceTencentCloudWafInstanceAttackLogPostRead, - Update: resourceTencentCloudWafInstanceAttackLogPostUpdate, - Delete: resourceTencentCloudWafInstanceAttackLogPostDelete, + Create: resourceTencentCloudWafInstanceAttackLogPostConfigCreate, + Read: resourceTencentCloudWafInstanceAttackLogPostConfigRead, + Update: resourceTencentCloudWafInstanceAttackLogPostConfigUpdate, + Delete: resourceTencentCloudWafInstanceAttackLogPostConfigDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -39,8 +39,8 @@ func ResourceTencentCloudWafInstanceAttackLogPost() *schema.Resource { } } -func resourceTencentCloudWafInstanceAttackLogPostCreate(d *schema.ResourceData, meta interface{}) error { - defer tccommon.LogElapsed("resource.tencentcloud_waf_instance_attack_log_post.create")() +func resourceTencentCloudWafInstanceAttackLogPostConfigCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_waf_instance_attack_log_post_config.create")() defer tccommon.InconsistentCheck(d, meta)() var instanceId string @@ -50,11 +50,11 @@ func resourceTencentCloudWafInstanceAttackLogPostCreate(d *schema.ResourceData, d.SetId(instanceId) - return resourceTencentCloudWafInstanceAttackLogPostUpdate(d, meta) + return resourceTencentCloudWafInstanceAttackLogPostConfigUpdate(d, meta) } -func resourceTencentCloudWafInstanceAttackLogPostRead(d *schema.ResourceData, meta interface{}) error { - defer tccommon.LogElapsed("resource.tencentcloud_waf_instance_attack_log_post.read")() +func resourceTencentCloudWafInstanceAttackLogPostConfigRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_waf_instance_attack_log_post_config.read")() defer tccommon.InconsistentCheck(d, meta)() var ( @@ -71,7 +71,7 @@ func resourceTencentCloudWafInstanceAttackLogPostRead(d *schema.ResourceData, me if respData == nil { d.SetId("") - log.Printf("[WARN]%s resource `waf_instance_attack_log_post` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + log.Printf("[WARN]%s resource `waf_instance_attack_log_post_config` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) return nil } @@ -84,8 +84,8 @@ func resourceTencentCloudWafInstanceAttackLogPostRead(d *schema.ResourceData, me return nil } -func resourceTencentCloudWafInstanceAttackLogPostUpdate(d *schema.ResourceData, meta interface{}) error { - defer tccommon.LogElapsed("resource.tencentcloud_waf_instance_attack_log_post.update")() +func resourceTencentCloudWafInstanceAttackLogPostConfigUpdate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_waf_instance_attack_log_post_config.update")() defer tccommon.InconsistentCheck(d, meta)() var ( @@ -112,15 +112,15 @@ func resourceTencentCloudWafInstanceAttackLogPostUpdate(d *schema.ResourceData, }) if reqErr != nil { - log.Printf("[CRITAL]%s update waf instance attack log_post failed, reason:%+v", logId, reqErr) + log.Printf("[CRITAL]%s update waf instance attack log post config failed, reason:%+v", logId, reqErr) return reqErr } - return resourceTencentCloudWafInstanceAttackLogPostRead(d, meta) + return resourceTencentCloudWafInstanceAttackLogPostConfigRead(d, meta) } -func resourceTencentCloudWafInstanceAttackLogPostDelete(d *schema.ResourceData, meta interface{}) error { - defer tccommon.LogElapsed("resource.tencentcloud_waf_instance_attack_log_post.delete")() +func resourceTencentCloudWafInstanceAttackLogPostConfigDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_waf_instance_attack_log_post_config.delete")() defer tccommon.InconsistentCheck(d, meta)() return nil diff --git a/tencentcloud/services/waf/resource_tc_waf_instance_attack_log_post_config.md b/tencentcloud/services/waf/resource_tc_waf_instance_attack_log_post_config.md new file mode 100644 index 0000000000..6ebfe56a69 --- /dev/null +++ b/tencentcloud/services/waf/resource_tc_waf_instance_attack_log_post_config.md @@ -0,0 +1,20 @@ +Provides a resource to create a WAF instance attack log post config + +~> **NOTE:** Only enterprise version and above are supported for activation + +Example Usage + +```hcl +resource "tencentcloud_waf_instance_attack_log_post_config" "example" { + instance_id = "waf_2kxtlbky11b4wcrb" + attack_log_post = 1 +} +``` + +Import + +WAF instance attack log post config can be imported using the id, e.g. + +``` +terraform import tencentcloud_waf_instance_attack_log_post_config.example waf_2kxtlbky11b4wcrb +``` diff --git a/tencentcloud/services/waf/resource_tc_waf_instance_attack_log_post_test.go b/tencentcloud/services/waf/resource_tc_waf_instance_attack_log_post_config_test.go similarity index 71% rename from tencentcloud/services/waf/resource_tc_waf_instance_attack_log_post_test.go rename to tencentcloud/services/waf/resource_tc_waf_instance_attack_log_post_config_test.go index da62c2eeb8..29a5985ffe 100644 --- a/tencentcloud/services/waf/resource_tc_waf_instance_attack_log_post_test.go +++ b/tencentcloud/services/waf/resource_tc_waf_instance_attack_log_post_config_test.go @@ -8,7 +8,7 @@ import ( tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" ) -func TestAccTencentCloudWafInstanceAttackLogPostResource_basic(t *testing.T) { +func TestAccTencentCloudWafInstanceAttackLogPostConfigResource_basic(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -19,21 +19,21 @@ func TestAccTencentCloudWafInstanceAttackLogPostResource_basic(t *testing.T) { { Config: testAccWafInstanceAttackLogPost, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("tencentcloud_waf_instance_attack_log_post.example", "id"), - resource.TestCheckResourceAttrSet("tencentcloud_waf_instance_attack_log_post.example", "instance_id"), - resource.TestCheckResourceAttrSet("tencentcloud_waf_instance_attack_log_post.example", "attack_log_post"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_instance_attack_log_post_config.example", "id"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_instance_attack_log_post_config.example", "instance_id"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_instance_attack_log_post_config.example", "attack_log_post"), ), }, { Config: testAccWafInstanceAttackLogPostUpdate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("tencentcloud_waf_instance_attack_log_post.example", "id"), - resource.TestCheckResourceAttrSet("tencentcloud_waf_instance_attack_log_post.example", "instance_id"), - resource.TestCheckResourceAttrSet("tencentcloud_waf_instance_attack_log_post.example", "attack_log_post"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_instance_attack_log_post_config.example", "id"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_instance_attack_log_post_config.example", "instance_id"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_instance_attack_log_post_config.example", "attack_log_post"), ), }, { - ResourceName: "tencentcloud_waf_instance_attack_log_post.example", + ResourceName: "tencentcloud_waf_instance_attack_log_post_config.example", ImportState: true, ImportStateVerify: true, }, @@ -42,14 +42,14 @@ func TestAccTencentCloudWafInstanceAttackLogPostResource_basic(t *testing.T) { } const testAccWafInstanceAttackLogPost = ` -resource "tencentcloud_waf_instance_attack_log_post" "example" { +resource "tencentcloud_waf_instance_attack_log_post_config" "example" { instance_id = "waf_2kxtlbky11b4wcrb" attack_log_post = 1 } ` const testAccWafInstanceAttackLogPostUpdate = ` -resource "tencentcloud_waf_instance_attack_log_post" "example" { +resource "tencentcloud_waf_instance_attack_log_post_config" "example" { instance_id = "waf_2kxtlbky11b4wcrb" attack_log_post = 0 } diff --git a/tencentcloud/services/waf/resource_tc_waf_waf_bot_scene_ucb_rule.go b/tencentcloud/services/waf/resource_tc_waf_waf_bot_scene_ucb_rule.go new file mode 100644 index 0000000000..175c237f32 --- /dev/null +++ b/tencentcloud/services/waf/resource_tc_waf_waf_bot_scene_ucb_rule.go @@ -0,0 +1,1315 @@ +package waf + +import ( + "context" + "fmt" + "log" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + waf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf/v20180125" + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func ResourceTencentCloudWafBotSceneUCBRule() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudWafBotSceneUCBRuleCreate, + Read: resourceTencentCloudWafBotSceneUCBRuleRead, + Update: resourceTencentCloudWafBotSceneUCBRuleUpdate, + Delete: resourceTencentCloudWafBotSceneUCBRuleDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "domain": { + Required: true, + ForceNew: true, + Type: schema.TypeString, + Description: "Domain.", + }, + + "scene_id": { + Required: true, + ForceNew: true, + Type: schema.TypeString, + Description: "When calling at the BOT global whitelist, pass `global`; When configuring BOT scenarios, transmit the specific scenario ID.", + }, + + "rule": { + Optional: true, + Type: schema.TypeList, + MaxItems: 1, + Description: "Rule content, add encoding SceneId information. When calling at the BOT global whitelist, SceneId is set to `global` and RuleType is passed as 10, Action is `permit`; When configuring BOT scenarios, SceneId is the scenario ID.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "domain": { + Type: schema.TypeString, + Required: true, + Description: "Domain.", + }, + + "name": { + Type: schema.TypeString, + Required: true, + Description: "Rule name.", + }, + + "rule": { + Type: schema.TypeList, + Required: true, + Description: "Specific rule items of UCB.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "key": { + Type: schema.TypeString, + Optional: true, + Description: "Key.", + }, + + "op": { + Type: schema.TypeString, + Optional: true, + Description: "Operator.", + }, + + "value": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "Value.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "basic_value": { + Type: schema.TypeString, + Optional: true, + Description: "String type value.", + }, + + "logic_value": { + Type: schema.TypeBool, + Optional: true, + Description: "Bool type value.", + }, + + "belong_value": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Optional: true, + Description: "String array type value.", + }, + + "valid_key": { + Type: schema.TypeString, + Optional: true, + Description: "Indicate valid fields.", + }, + + "multi_value": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Optional: true, + Description: "String array type value.", + }, + }, + }, + }, + + "op_op": { + Type: schema.TypeString, + Optional: true, + Description: "Optional Supplementary Operators.", + }, + + "op_arg": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Optional: true, + Description: "Optional supplementary parameters.", + }, + + "op_value": { + Type: schema.TypeFloat, + Optional: true, + Description: "Optional supplementary values.", + }, + + "name": { + Type: schema.TypeString, + Optional: true, + Description: "When using header parameter values.", + }, + + "areas": { + Type: schema.TypeList, + Optional: true, + Description: "Regional selection.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "country": { + Type: schema.TypeString, + Required: true, + Description: "In addition to standard countries, the country also supports two special identifiers: domestic and foreign.", + }, + + "region": { + Type: schema.TypeString, + Optional: true, + Description: "Province.", + }, + + "city": { + Type: schema.TypeString, + Optional: true, + Description: "City.", + }, + }, + }, + }, + + "lang": { + Type: schema.TypeString, + Optional: true, + Description: "Language environment.", + }, + }, + }, + }, + + "action": { + Type: schema.TypeString, + Required: true, + Description: "Disposal action.", + }, + + "on_off": { + Type: schema.TypeString, + Required: true, + Description: "Rule switch.", + }, + + "rule_type": { + Type: schema.TypeInt, + Required: true, + Description: "Rule type.", + }, + + "prior": { + Type: schema.TypeInt, + Required: true, + Description: "Rule priority.", + }, + + "timestamp": { + Type: schema.TypeInt, + Required: true, + Description: "Modifying timestamps.", + }, + + "label": { + Type: schema.TypeString, + Required: true, + Description: "Label.", + }, + + "id": { + Type: schema.TypeString, + Optional: true, + Description: "Entry ID.", + }, + + "scene_id": { + Type: schema.TypeString, + Optional: true, + Description: "Scene ID.", + }, + + "valid_time": { + Type: schema.TypeInt, + Optional: true, + Description: "Valid time.", + }, + + "appid": { + Type: schema.TypeInt, + Optional: true, + Description: "Appid.", + }, + "addition_arg": { + Type: schema.TypeString, + Optional: true, + Description: "Additional parameters.", + }, + + "desc": { + Type: schema.TypeString, + Optional: true, + Description: "Rule description.", + }, + + "rule_id": { + Type: schema.TypeString, + Optional: true, + Description: "Rule ID.", + }, + + "pre_define": { + Type: schema.TypeBool, + Optional: true, + Description: "True - System preset rules False - Custom rules.", + }, + + "job_type": { + Type: schema.TypeString, + Optional: true, + Description: "Scheduled task type.", + }, + + "job_date_time": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "Scheduled task configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "timed": { + Type: schema.TypeList, + Optional: true, + Description: "Time parameter for timed execution.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "start_date_time": { + Type: schema.TypeInt, + Optional: true, + Description: "Start timestamp, in seconds.", + }, + + "end_date_time": { + Type: schema.TypeInt, + Optional: true, + Description: "End timestamp, in seconds.", + }, + }, + }, + }, + + "cron": { + Type: schema.TypeList, + Optional: true, + Description: "Time parameter for cycle execution.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "days": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Optional: true, + Description: "On what day of each month is it executed.", + }, + + "w_days": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Optional: true, + Description: "What day of the week is executed each week.", + }, + + "start_time": { + Type: schema.TypeString, + Optional: true, + Description: "Start time.", + }, + "end_time": { + Type: schema.TypeString, + Optional: true, + Description: "End time.", + }, + }, + }, + }, + + "time_t_zone": { + Type: schema.TypeString, + Optional: true, + Description: "Time zone.", + }, + }, + }, + }, + + "expire_time": { + Type: schema.TypeInt, + Optional: true, + Description: "Effective deadline.", + }, + + "valid_status": { + Type: schema.TypeInt, + Optional: true, + Description: "Effective -1, Invalid -0.", + }, + + "block_page_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Customize interception page ID.", + }, + + "action_list": { + Type: schema.TypeList, + Optional: true, + Description: "When Action=intercept, this field is mandatory.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "action": { + Type: schema.TypeString, + Optional: true, + Description: "Action.", + }, + + "proportion": { + Type: schema.TypeFloat, + Optional: true, + Description: "Proportion.", + }, + }, + }, + }, + }, + }, + }, + }, + } +} + +func resourceTencentCloudWafBotSceneUCBRuleCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_waf_bot_scene_ucb_rule.create")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + request = waf.NewModifyBotSceneUCBRuleRequest() + response = waf.NewModifyBotSceneUCBRuleResponse() + domain string + sceneId string + ) + + if v, ok := d.GetOk("domain"); ok { + request.Domain = helper.String(v.(string)) + domain = v.(string) + } + + if v, ok := d.GetOk("scene_id"); ok { + request.SceneId = helper.String(v.(string)) + sceneId = v.(string) + } + + if dMap, ok := helper.InterfacesHeadMap(d, "rule"); ok { + inOutputBotUCBRule := waf.InOutputBotUCBRule{} + if v, ok := dMap["domain"]; ok { + inOutputBotUCBRule.Domain = helper.String(v.(string)) + } + + if v, ok := dMap["name"]; ok { + inOutputBotUCBRule.Name = helper.String(v.(string)) + } + + if v, ok := dMap["rule"]; ok { + for _, item := range v.([]interface{}) { + if ruleMap, ok := item.(map[string]interface{}); ok && ruleMap != nil { + inOutputUCBRuleEntry := waf.InOutputUCBRuleEntry{} + if v, ok := ruleMap["key"]; ok { + inOutputUCBRuleEntry.Key = helper.String(v.(string)) + } + + if v, ok := ruleMap["op"]; ok { + inOutputUCBRuleEntry.Op = helper.String(v.(string)) + } + + if valueMap, ok := helper.InterfaceToMap(ruleMap, "value"); ok { + uCBEntryValue := waf.UCBEntryValue{} + if v, ok := valueMap["basic_value"]; ok { + uCBEntryValue.BasicValue = helper.String(v.(string)) + } + + if v, ok := valueMap["logic_value"]; ok { + uCBEntryValue.LogicValue = helper.Bool(v.(bool)) + } + + if v, ok := valueMap["belong_value"]; ok { + belongValueSet := v.(*schema.Set).List() + for i := range belongValueSet { + if belongValueSet[i] != nil { + belongValue := belongValueSet[i].(string) + uCBEntryValue.BelongValue = append(uCBEntryValue.BelongValue, &belongValue) + } + } + } + + if v, ok := valueMap["valid_key"]; ok { + uCBEntryValue.ValidKey = helper.String(v.(string)) + } + + if v, ok := valueMap["multi_value"]; ok { + multiValueSet := v.(*schema.Set).List() + for i := range multiValueSet { + if multiValueSet[i] != nil { + multiValue := multiValueSet[i].(string) + uCBEntryValue.MultiValue = append(uCBEntryValue.MultiValue, &multiValue) + } + } + } + + inOutputUCBRuleEntry.Value = &uCBEntryValue + } + + if v, ok := ruleMap["op_op"]; ok { + inOutputUCBRuleEntry.OpOp = helper.String(v.(string)) + } + + if v, ok := ruleMap["op_arg"]; ok { + opArgSet := v.(*schema.Set).List() + for i := range opArgSet { + if opArgSet[i] != nil { + opArg := opArgSet[i].(string) + inOutputUCBRuleEntry.OpArg = append(inOutputUCBRuleEntry.OpArg, &opArg) + } + } + } + + if v, ok := ruleMap["op_value"]; ok { + inOutputUCBRuleEntry.OpValue = helper.Float64(v.(float64)) + } + + if v, ok := ruleMap["name"]; ok { + inOutputUCBRuleEntry.Name = helper.String(v.(string)) + } + + if v, ok := ruleMap["areas"]; ok { + for _, item := range v.([]interface{}) { + areasMap := item.(map[string]interface{}) + area := waf.Area{} + if v, ok := areasMap["country"]; ok { + area.Country = helper.String(v.(string)) + } + + if v, ok := areasMap["region"]; ok { + area.Region = helper.String(v.(string)) + } + + if v, ok := areasMap["city"]; ok { + area.City = helper.String(v.(string)) + } + + inOutputUCBRuleEntry.Areas = append(inOutputUCBRuleEntry.Areas, &area) + } + } + + if v, ok := ruleMap["lang"]; ok { + inOutputUCBRuleEntry.Lang = helper.String(v.(string)) + } + + inOutputBotUCBRule.Rule = append(inOutputBotUCBRule.Rule, &inOutputUCBRuleEntry) + } + } + } + + if v, ok := dMap["action"]; ok { + inOutputBotUCBRule.Action = helper.String(v.(string)) + } + + if v, ok := dMap["on_off"]; ok { + inOutputBotUCBRule.OnOff = helper.String(v.(string)) + } + + if v, ok := dMap["rule_type"]; ok { + inOutputBotUCBRule.RuleType = helper.IntInt64(v.(int)) + } + + if v, ok := dMap["prior"]; ok { + inOutputBotUCBRule.Prior = helper.IntInt64(v.(int)) + } + + if v, ok := dMap["timestamp"]; ok { + inOutputBotUCBRule.Timestamp = helper.IntInt64(v.(int)) + } + + if v, ok := dMap["label"]; ok { + inOutputBotUCBRule.Label = helper.String(v.(string)) + } + + if v, ok := dMap["id"]; ok { + inOutputBotUCBRule.Id = helper.String(v.(string)) + } + + if v, ok := dMap["scene_id"]; ok { + inOutputBotUCBRule.SceneId = helper.String(v.(string)) + } + + if v, ok := dMap["valid_time"]; ok { + inOutputBotUCBRule.ValidTime = helper.IntInt64(v.(int)) + } + + if v, ok := dMap["appid"]; ok { + inOutputBotUCBRule.Appid = helper.IntUint64(v.(int)) + } + + if v, ok := dMap["addition_arg"]; ok { + inOutputBotUCBRule.AdditionArg = helper.String(v.(string)) + } + + if v, ok := dMap["desc"]; ok { + inOutputBotUCBRule.Desc = helper.String(v.(string)) + } + + if v, ok := dMap["rule_id"]; ok { + inOutputBotUCBRule.RuleId = helper.String(v.(string)) + } + + if v, ok := dMap["pre_define"]; ok { + inOutputBotUCBRule.PreDefine = helper.Bool(v.(bool)) + } + + if v, ok := dMap["job_type"]; ok { + inOutputBotUCBRule.JobType = helper.String(v.(string)) + } + + if jobDateTimeMap, ok := helper.InterfaceToMap(dMap, "job_date_time"); ok { + jobDateTime := waf.JobDateTime{} + if v, ok := jobDateTimeMap["timed"]; ok { + for _, item := range v.([]interface{}) { + if timedMap, ok := item.(map[string]interface{}); ok && timedMap != nil { + timedJob := waf.TimedJob{} + if v, ok := timedMap["start_date_time"]; ok { + timedJob.StartDateTime = helper.IntUint64(v.(int)) + } + + if v, ok := timedMap["end_date_time"]; ok { + timedJob.EndDateTime = helper.IntUint64(v.(int)) + } + + jobDateTime.Timed = append(jobDateTime.Timed, &timedJob) + } + } + } + + if v, ok := jobDateTimeMap["cron"]; ok { + for _, item := range v.([]interface{}) { + if cronMap, ok := item.(map[string]interface{}); ok && cronMap != nil { + cronJob := waf.CronJob{} + if v, ok := cronMap["days"]; ok { + daysSet := v.(*schema.Set).List() + for i := range daysSet { + days := daysSet[i].(int) + cronJob.Days = append(cronJob.Days, helper.IntUint64(days)) + } + } + + if v, ok := cronMap["w_days"]; ok { + wDaysSet := v.(*schema.Set).List() + for i := range wDaysSet { + wDays := wDaysSet[i].(int) + cronJob.WDays = append(cronJob.WDays, helper.IntUint64(wDays)) + } + } + + if v, ok := cronMap["start_time"]; ok { + cronJob.StartTime = helper.String(v.(string)) + } + + if v, ok := cronMap["end_time"]; ok { + cronJob.EndTime = helper.String(v.(string)) + } + + jobDateTime.Cron = append(jobDateTime.Cron, &cronJob) + } + } + } + + if v, ok := jobDateTimeMap["time_t_zone"]; ok { + jobDateTime.TimeTZone = helper.String(v.(string)) + } + + inOutputBotUCBRule.JobDateTime = &jobDateTime + } + + if v, ok := dMap["expire_time"]; ok { + inOutputBotUCBRule.ExpireTime = helper.IntUint64(v.(int)) + } + + if v, ok := dMap["valid_status"]; ok { + inOutputBotUCBRule.ValidStatus = helper.IntInt64(v.(int)) + } + + if v, ok := dMap["block_page_id"]; ok { + inOutputBotUCBRule.BlockPageId = helper.IntUint64(v.(int)) + } + + if v, ok := dMap["action_list"]; ok { + for _, item := range v.([]interface{}) { + if actionListMap, ok := item.(map[string]interface{}); ok && actionListMap != nil { + uCBActionProportion := waf.UCBActionProportion{} + if v, ok := actionListMap["action"]; ok { + uCBActionProportion.Action = helper.String(v.(string)) + } + + if v, ok := actionListMap["proportion"]; ok { + uCBActionProportion.Proportion = helper.Float64(v.(float64)) + } + + inOutputBotUCBRule.ActionList = append(inOutputBotUCBRule.ActionList, &uCBActionProportion) + } + } + } + + request.Rule = &inOutputBotUCBRule + } + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseWafV20180125Client().ModifyBotSceneUCBRule(request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + if result == nil || result.Response == nil { + return resource.NonRetryableError(fmt.Errorf("Create waf bot scene ucb rule failed, Response is nil.")) + } + + response = result + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s create waf bot scene ucb rule failed, reason:%+v", logId, err) + return err + } + + _ = response + ruleId := "" + d.SetId(strings.Join([]string{domain, sceneId, ruleId}, tccommon.FILED_SP)) + + return resourceTencentCloudWafBotSceneUCBRuleRead(d, meta) +} + +func resourceTencentCloudWafBotSceneUCBRuleRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_waf_bot_scene_ucb_rule.read")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + service = WafService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + ) + + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) != 3 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + + domain := idSplit[0] + sceneId := idSplit[1] + ruleId := idSplit[2] + + respData, err := service.DescribeWafBotSceneUCBRuleById(ctx, domain, sceneId, ruleId) + if err != nil { + return err + } + + if respData == nil { + d.SetId("") + log.Printf("[WARN]%s resource `WafBotSceneUCBRule` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + return nil + } + + if respData.Domain != nil { + _ = d.Set("domain", respData.Domain) + } + + if respData.SceneId != nil { + _ = d.Set("scene_id", respData.SceneId) + } + + // if waf_bot_scene_ucb_rule.Rule != nil { + // ruleMap := map[string]interface{}{} + + // if waf_bot_scene_ucb_rule.Rule.Domain != nil { + // ruleMap["domain"] = waf_bot_scene_ucb_rule.Rule.Domain + // } + + // if waf_bot_scene_ucb_rule.Rule.Name != nil { + // ruleMap["name"] = waf_bot_scene_ucb_rule.Rule.Name + // } + + // if waf_bot_scene_ucb_rule.Rule.Rule != nil { + // ruleList := []interface{}{} + // for _, rule := range waf_bot_scene_ucb_rule.Rule.Rule { + // ruleMap := map[string]interface{}{} + + // if rule.Key != nil { + // ruleMap["key"] = rule.Key + // } + + // if rule.Op != nil { + // ruleMap["op"] = rule.Op + // } + + // if rule.Value != nil { + // valueMap := map[string]interface{}{} + + // if rule.Value.BasicValue != nil { + // valueMap["basic_value"] = rule.Value.BasicValue + // } + + // if rule.Value.LogicValue != nil { + // valueMap["logic_value"] = rule.Value.LogicValue + // } + + // if rule.Value.BelongValue != nil { + // valueMap["belong_value"] = rule.Value.BelongValue + // } + + // if rule.Value.ValidKey != nil { + // valueMap["valid_key"] = rule.Value.ValidKey + // } + + // if rule.Value.MultiValue != nil { + // valueMap["multi_value"] = rule.Value.MultiValue + // } + + // ruleMap["value"] = []interface{}{valueMap} + // } + + // if rule.OpOp != nil { + // ruleMap["op_op"] = rule.OpOp + // } + + // if rule.OpArg != nil { + // ruleMap["op_arg"] = rule.OpArg + // } + + // if rule.OpValue != nil { + // ruleMap["op_value"] = rule.OpValue + // } + + // if rule.Name != nil { + // ruleMap["name"] = rule.Name + // } + + // if rule.Areas != nil { + // areasList := []interface{}{} + // for _, areas := range rule.Areas { + // areasMap := map[string]interface{}{} + + // if areas.Country != nil { + // areasMap["country"] = areas.Country + // } + + // if areas.Region != nil { + // areasMap["region"] = areas.Region + // } + + // if areas.City != nil { + // areasMap["city"] = areas.City + // } + + // areasList = append(areasList, areasMap) + // } + + // ruleMap["areas"] = areasList + // } + + // if rule.Lang != nil { + // ruleMap["lang"] = rule.Lang + // } + + // ruleList = append(ruleList, ruleMap) + // } + + // ruleMap["rule"] = ruleList + // } + + // if waf_bot_scene_ucb_rule.Rule.Action != nil { + // ruleMap["action"] = waf_bot_scene_ucb_rule.Rule.Action + // } + + // if waf_bot_scene_ucb_rule.Rule.OnOff != nil { + // ruleMap["on_off"] = waf_bot_scene_ucb_rule.Rule.OnOff + // } + + // if waf_bot_scene_ucb_rule.Rule.RuleType != nil { + // ruleMap["rule_type"] = waf_bot_scene_ucb_rule.Rule.RuleType + // } + + // if waf_bot_scene_ucb_rule.Rule.Prior != nil { + // ruleMap["prior"] = waf_bot_scene_ucb_rule.Rule.Prior + // } + + // if waf_bot_scene_ucb_rule.Rule.Timestamp != nil { + // ruleMap["timestamp"] = waf_bot_scene_ucb_rule.Rule.Timestamp + // } + + // if waf_bot_scene_ucb_rule.Rule.Label != nil { + // ruleMap["label"] = waf_bot_scene_ucb_rule.Rule.Label + // } + + // if waf_bot_scene_ucb_rule.Rule.Id != nil { + // ruleMap["id"] = waf_bot_scene_ucb_rule.Rule.Id + // } + + // if waf_bot_scene_ucb_rule.Rule.SceneId != nil { + // ruleMap["scene_id"] = waf_bot_scene_ucb_rule.Rule.SceneId + // } + + // if waf_bot_scene_ucb_rule.Rule.ValidTime != nil { + // ruleMap["valid_time"] = waf_bot_scene_ucb_rule.Rule.ValidTime + // } + + // if waf_bot_scene_ucb_rule.Rule.Appid != nil { + // ruleMap["appid"] = waf_bot_scene_ucb_rule.Rule.Appid + // } + + // if waf_bot_scene_ucb_rule.Rule.AdditionArg != nil { + // ruleMap["addition_arg"] = waf_bot_scene_ucb_rule.Rule.AdditionArg + // } + + // if waf_bot_scene_ucb_rule.Rule.Desc != nil { + // ruleMap["desc"] = waf_bot_scene_ucb_rule.Rule.Desc + // } + + // if waf_bot_scene_ucb_rule.Rule.RuleId != nil { + // ruleMap["rule_id"] = waf_bot_scene_ucb_rule.Rule.RuleId + // } + + // if waf_bot_scene_ucb_rule.Rule.PreDefine != nil { + // ruleMap["pre_define"] = waf_bot_scene_ucb_rule.Rule.PreDefine + // } + + // if waf_bot_scene_ucb_rule.Rule.JobType != nil { + // ruleMap["job_type"] = waf_bot_scene_ucb_rule.Rule.JobType + // } + + // if waf_bot_scene_ucb_rule.Rule.JobDateTime != nil { + // jobDateTimeMap := map[string]interface{}{} + + // if waf_bot_scene_ucb_rule.Rule.JobDateTime.Timed != nil { + // timedList := []interface{}{} + // for _, timed := range waf_bot_scene_ucb_rule.Rule.JobDateTime.Timed { + // timedMap := map[string]interface{}{} + + // if timed.StartDateTime != nil { + // timedMap["start_date_time"] = timed.StartDateTime + // } + + // if timed.EndDateTime != nil { + // timedMap["end_date_time"] = timed.EndDateTime + // } + + // timedList = append(timedList, timedMap) + // } + + // jobDateTimeMap["timed"] = timedList + // } + + // if waf_bot_scene_ucb_rule.Rule.JobDateTime.Cron != nil { + // cronList := []interface{}{} + // for _, cron := range waf_bot_scene_ucb_rule.Rule.JobDateTime.Cron { + // cronMap := map[string]interface{}{} + + // if cron.Days != nil { + // cronMap["days"] = cron.Days + // } + + // if cron.WDays != nil { + // cronMap["w_days"] = cron.WDays + // } + + // if cron.StartTime != nil { + // cronMap["start_time"] = cron.StartTime + // } + + // if cron.EndTime != nil { + // cronMap["end_time"] = cron.EndTime + // } + + // cronList = append(cronList, cronMap) + // } + + // jobDateTimeMap["cron"] = cronList + // } + + // if waf_bot_scene_ucb_rule.Rule.JobDateTime.TimeTZone != nil { + // jobDateTimeMap["time_t_zone"] = waf_bot_scene_ucb_rule.Rule.JobDateTime.TimeTZone + // } + + // ruleMap["job_date_time"] = []interface{}{jobDateTimeMap} + // } + + // if waf_bot_scene_ucb_rule.Rule.ExpireTime != nil { + // ruleMap["expire_time"] = waf_bot_scene_ucb_rule.Rule.ExpireTime + // } + + // if waf_bot_scene_ucb_rule.Rule.ValidStatus != nil { + // ruleMap["valid_status"] = waf_bot_scene_ucb_rule.Rule.ValidStatus + // } + + // if waf_bot_scene_ucb_rule.Rule.BlockPageId != nil { + // ruleMap["block_page_id"] = waf_bot_scene_ucb_rule.Rule.BlockPageId + // } + + // if waf_bot_scene_ucb_rule.Rule.ActionList != nil { + // actionListList := []interface{}{} + // for _, actionList := range waf_bot_scene_ucb_rule.Rule.ActionList { + // actionListMap := map[string]interface{}{} + + // if actionList.Action != nil { + // actionListMap["action"] = actionList.Action + // } + + // if actionList.Proportion != nil { + // actionListMap["proportion"] = actionList.Proportion + // } + + // actionListList = append(actionListList, actionListMap) + // } + + // ruleMap["action_list"] = actionListList + // } + + // _ = d.Set("rule", []interface{}{ruleMap}) + // } + + return nil +} + +func resourceTencentCloudWafBotSceneUCBRuleUpdate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_waf_bot_scene_ucb_rule.update")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + request = waf.NewModifyBotSceneUCBRuleRequest() + ) + + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) != 3 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + + domain := idSplit[0] + sceneId := idSplit[1] + ruleId := idSplit[2] + + request.Domain = &domain + request.SceneId = &sceneId + + if dMap, ok := helper.InterfacesHeadMap(d, "rule"); ok { + inOutputBotUCBRule := waf.InOutputBotUCBRule{} + if v, ok := dMap["domain"]; ok { + inOutputBotUCBRule.Domain = helper.String(v.(string)) + } + + if v, ok := dMap["name"]; ok { + inOutputBotUCBRule.Name = helper.String(v.(string)) + } + + if v, ok := dMap["rule"]; ok { + for _, item := range v.([]interface{}) { + ruleMap := item.(map[string]interface{}) + inOutputUCBRuleEntry := waf.InOutputUCBRuleEntry{} + if v, ok := ruleMap["key"]; ok { + inOutputUCBRuleEntry.Key = helper.String(v.(string)) + } + + if v, ok := ruleMap["op"]; ok { + inOutputUCBRuleEntry.Op = helper.String(v.(string)) + } + + if valueMap, ok := helper.InterfaceToMap(ruleMap, "value"); ok { + uCBEntryValue := waf.UCBEntryValue{} + if v, ok := valueMap["basic_value"]; ok { + uCBEntryValue.BasicValue = helper.String(v.(string)) + } + + if v, ok := valueMap["logic_value"]; ok { + uCBEntryValue.LogicValue = helper.Bool(v.(bool)) + } + + if v, ok := valueMap["belong_value"]; ok { + belongValueSet := v.(*schema.Set).List() + for i := range belongValueSet { + if belongValueSet[i] != nil { + belongValue := belongValueSet[i].(string) + uCBEntryValue.BelongValue = append(uCBEntryValue.BelongValue, &belongValue) + } + } + } + + if v, ok := valueMap["valid_key"]; ok { + uCBEntryValue.ValidKey = helper.String(v.(string)) + } + + if v, ok := valueMap["multi_value"]; ok { + multiValueSet := v.(*schema.Set).List() + for i := range multiValueSet { + if multiValueSet[i] != nil { + multiValue := multiValueSet[i].(string) + uCBEntryValue.MultiValue = append(uCBEntryValue.MultiValue, &multiValue) + } + } + } + + inOutputUCBRuleEntry.Value = &uCBEntryValue + } + + if v, ok := ruleMap["op_op"]; ok { + inOutputUCBRuleEntry.OpOp = helper.String(v.(string)) + } + + if v, ok := ruleMap["op_arg"]; ok { + opArgSet := v.(*schema.Set).List() + for i := range opArgSet { + if opArgSet[i] != nil { + opArg := opArgSet[i].(string) + inOutputUCBRuleEntry.OpArg = append(inOutputUCBRuleEntry.OpArg, &opArg) + } + } + } + + if v, ok := ruleMap["op_value"]; ok { + inOutputUCBRuleEntry.OpValue = helper.Float64(v.(float64)) + } + + if v, ok := ruleMap["name"]; ok { + inOutputUCBRuleEntry.Name = helper.String(v.(string)) + } + + if v, ok := ruleMap["areas"]; ok { + for _, item := range v.([]interface{}) { + areasMap := item.(map[string]interface{}) + area := waf.Area{} + if v, ok := areasMap["country"]; ok { + area.Country = helper.String(v.(string)) + } + + if v, ok := areasMap["region"]; ok { + area.Region = helper.String(v.(string)) + } + + if v, ok := areasMap["city"]; ok { + area.City = helper.String(v.(string)) + } + + inOutputUCBRuleEntry.Areas = append(inOutputUCBRuleEntry.Areas, &area) + } + } + + if v, ok := ruleMap["lang"]; ok { + inOutputUCBRuleEntry.Lang = helper.String(v.(string)) + } + + inOutputBotUCBRule.Rule = append(inOutputBotUCBRule.Rule, &inOutputUCBRuleEntry) + } + } + + if v, ok := dMap["action"]; ok { + inOutputBotUCBRule.Action = helper.String(v.(string)) + } + + if v, ok := dMap["on_off"]; ok { + inOutputBotUCBRule.OnOff = helper.String(v.(string)) + } + + if v, ok := dMap["rule_type"]; ok { + inOutputBotUCBRule.RuleType = helper.IntInt64(v.(int)) + } + + if v, ok := dMap["prior"]; ok { + inOutputBotUCBRule.Prior = helper.IntInt64(v.(int)) + } + + if v, ok := dMap["timestamp"]; ok { + inOutputBotUCBRule.Timestamp = helper.IntInt64(v.(int)) + } + + if v, ok := dMap["label"]; ok { + inOutputBotUCBRule.Label = helper.String(v.(string)) + } + + if v, ok := dMap["id"]; ok { + inOutputBotUCBRule.Id = helper.String(v.(string)) + } + + if v, ok := dMap["scene_id"]; ok { + inOutputBotUCBRule.SceneId = helper.String(v.(string)) + } + + if v, ok := dMap["valid_time"]; ok { + inOutputBotUCBRule.ValidTime = helper.IntInt64(v.(int)) + } + + if v, ok := dMap["appid"]; ok { + inOutputBotUCBRule.Appid = helper.IntUint64(v.(int)) + } + + if v, ok := dMap["addition_arg"]; ok { + inOutputBotUCBRule.AdditionArg = helper.String(v.(string)) + } + + if v, ok := dMap["desc"]; ok { + inOutputBotUCBRule.Desc = helper.String(v.(string)) + } + + inOutputBotUCBRule.RuleId = &ruleId + + if v, ok := dMap["pre_define"]; ok { + inOutputBotUCBRule.PreDefine = helper.Bool(v.(bool)) + } + + if v, ok := dMap["job_type"]; ok { + inOutputBotUCBRule.JobType = helper.String(v.(string)) + } + + if jobDateTimeMap, ok := helper.InterfaceToMap(dMap, "job_date_time"); ok { + jobDateTime := waf.JobDateTime{} + if v, ok := jobDateTimeMap["timed"]; ok { + for _, item := range v.([]interface{}) { + timedMap := item.(map[string]interface{}) + timedJob := waf.TimedJob{} + if v, ok := timedMap["start_date_time"]; ok { + timedJob.StartDateTime = helper.IntUint64(v.(int)) + } + + if v, ok := timedMap["end_date_time"]; ok { + timedJob.EndDateTime = helper.IntUint64(v.(int)) + } + + jobDateTime.Timed = append(jobDateTime.Timed, &timedJob) + } + } + + if v, ok := jobDateTimeMap["cron"]; ok { + for _, item := range v.([]interface{}) { + cronMap := item.(map[string]interface{}) + cronJob := waf.CronJob{} + if v, ok := cronMap["days"]; ok { + daysSet := v.(*schema.Set).List() + for i := range daysSet { + days := daysSet[i].(int) + cronJob.Days = append(cronJob.Days, helper.IntUint64(days)) + } + } + + if v, ok := cronMap["w_days"]; ok { + wDaysSet := v.(*schema.Set).List() + for i := range wDaysSet { + wDays := wDaysSet[i].(int) + cronJob.WDays = append(cronJob.WDays, helper.IntUint64(wDays)) + } + } + + if v, ok := cronMap["start_time"]; ok { + cronJob.StartTime = helper.String(v.(string)) + } + + if v, ok := cronMap["end_time"]; ok { + cronJob.EndTime = helper.String(v.(string)) + } + + jobDateTime.Cron = append(jobDateTime.Cron, &cronJob) + } + } + + if v, ok := jobDateTimeMap["time_t_zone"]; ok { + jobDateTime.TimeTZone = helper.String(v.(string)) + } + + inOutputBotUCBRule.JobDateTime = &jobDateTime + } + + if v, ok := dMap["expire_time"]; ok { + inOutputBotUCBRule.ExpireTime = helper.IntUint64(v.(int)) + } + + if v, ok := dMap["valid_status"]; ok { + inOutputBotUCBRule.ValidStatus = helper.IntInt64(v.(int)) + } + + if v, ok := dMap["block_page_id"]; ok { + inOutputBotUCBRule.BlockPageId = helper.IntUint64(v.(int)) + } + + if v, ok := dMap["action_list"]; ok { + for _, item := range v.([]interface{}) { + actionListMap := item.(map[string]interface{}) + uCBActionProportion := waf.UCBActionProportion{} + if v, ok := actionListMap["action"]; ok { + uCBActionProportion.Action = helper.String(v.(string)) + } + + if v, ok := actionListMap["proportion"]; ok { + uCBActionProportion.Proportion = helper.Float64(v.(float64)) + } + + inOutputBotUCBRule.ActionList = append(inOutputBotUCBRule.ActionList, &uCBActionProportion) + } + } + + request.Rule = &inOutputBotUCBRule + } + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseWafV20180125Client().ModifyBotSceneUCBRule(request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s update waf bot scene ucb rule failed, reason:%+v", logId, err) + return err + } + + return resourceTencentCloudWafBotSceneUCBRuleRead(d, meta) +} + +func resourceTencentCloudWafBotSceneUCBRuleDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_waf_bot_scene_ucb_rule.delete")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + service = WafService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + ) + + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) != 3 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + + domain := idSplit[0] + sceneId := idSplit[1] + ruleId := idSplit[2] + + if err := service.DeleteWafBotSceneUCBRuleById(ctx, domain, sceneId, ruleId); err != nil { + return err + } + + return nil +} diff --git a/tencentcloud/services/waf/service_tencentcloud_waf.go b/tencentcloud/services/waf/service_tencentcloud_waf.go index 771607ab98..ecb87a97a7 100644 --- a/tencentcloud/services/waf/service_tencentcloud_waf.go +++ b/tencentcloud/services/waf/service_tencentcloud_waf.go @@ -1698,3 +1698,198 @@ func (me *WafService) DescribeWafDomainPostActionById(ctx context.Context, domai return } + +func (me *WafService) DescribeWafBotSceneStatusConfigById(ctx context.Context, domain string, sceneId string) (ret *waf.BotSceneInfo, errRet error) { + logId := tccommon.GetLogId(ctx) + + request := waf.NewDescribeBotSceneListRequest() + response := waf.NewDescribeBotSceneListResponse() + request.Domain = helper.String(domain) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error()) + } + }() + + var ( + BotSceneList []*waf.BotSceneInfo + offset int64 = 0 + limit int64 = 20 + ) + + for { + request.Offset = &offset + request.Limit = &limit + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + ratelimit.Check(request.GetAction()) + result, e := me.client.UseWafV20180125Client().DescribeBotSceneList(request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + response = result + return nil + }) + + if err != nil { + errRet = err + return + } + + if response == nil || len(response.Response.BotSceneList) < 1 { + break + } + + BotSceneList = append(BotSceneList, response.Response.BotSceneList...) + if len(response.Response.BotSceneList) < int(limit) { + break + } + + offset += limit + } + + for _, item := range BotSceneList { + if *item.SceneId == sceneId { + ret = item + return + } + } + + return +} + +func (me *WafService) DescribeWafBotStatusConfigById(ctx context.Context, domain string) (ret *waf.DescribeBotSceneOverviewResponseParams, errRet error) { + logId := tccommon.GetLogId(ctx) + + request := waf.NewDescribeBotSceneOverviewRequest() + response := waf.NewDescribeBotSceneOverviewResponse() + request.Domain = helper.String(domain) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error()) + } + }() + + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + ratelimit.Check(request.GetAction()) + result, e := me.client.UseWafV20180125Client().DescribeBotSceneOverview(request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + response = result + return nil + }) + + if err != nil { + errRet = err + return + } + + ret = response.Response + return +} + +func (me *WafService) DescribeWafBotSceneUCBRuleById(ctx context.Context, domain, sceneId, ruleId string) (ret *waf.InOutputBotUCBRule, errRet error) { + logId := tccommon.GetLogId(ctx) + + request := waf.NewDescribeBotSceneUCBRuleRequest() + response := waf.NewDescribeBotSceneUCBRuleResponse() + request.Domain = helper.String(domain) + request.SceneId = helper.String(sceneId) + request.Sort = helper.String("desc") + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error()) + } + }() + + var ( + BotSceneUCBRuleList []*waf.InOutputBotUCBRule + skip uint64 = 0 + limit uint64 = 20 + ) + + for { + request.Skip = &skip + request.Limit = &limit + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + ratelimit.Check(request.GetAction()) + result, e := me.client.UseWafV20180125Client().DescribeBotSceneUCBRule(request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + response = result + return nil + }) + + if err != nil { + errRet = err + return + } + + if response == nil || response.Response == nil || response.Response.Data == nil || len(response.Response.Data.Res) < 1 { + break + } + + BotSceneUCBRuleList = append(BotSceneUCBRuleList, response.Response.Data.Res...) + if len(response.Response.Data.Res) < int(limit) { + break + } + + limit += skip + } + + for _, item := range BotSceneUCBRuleList { + if *item.SceneId == sceneId { + ret = item + return + } + } + + return +} + +func (me *WafService) DeleteWafBotSceneUCBRuleById(ctx context.Context, domain, sceneId, ruleId string) (errRet error) { + logId := tccommon.GetLogId(ctx) + + request := waf.NewDeleteBotSceneUCBRuleRequest() + request.Domain = helper.String(domain) + request.SceneId = helper.String(sceneId) + request.RuleId = helper.String(ruleId) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error()) + } + }() + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + ratelimit.Check(request.GetAction()) + result, e := me.client.UseWafV20180125Client().DeleteBotSceneUCBRule(request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + return nil + }) + + if err != nil { + errRet = err + return + } + + return +} diff --git a/website/docs/r/waf_bot_scene_status_config.html.markdown b/website/docs/r/waf_bot_scene_status_config.html.markdown new file mode 100644 index 0000000000..fd9a15a8ca --- /dev/null +++ b/website/docs/r/waf_bot_scene_status_config.html.markdown @@ -0,0 +1,49 @@ +--- +subcategory: "Web Application Firewall(WAF)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_waf_bot_scene_status_config" +sidebar_current: "docs-tencentcloud-resource-waf_bot_scene_status_config" +description: |- + Provides a resource to create a WAF bot scene status config +--- + +# tencentcloud_waf_bot_scene_status_config + +Provides a resource to create a WAF bot scene status config + +## Example Usage + +```hcl +resource "tencentcloud_waf_bot_scene_status_config" "example" { + domain = "example.com" + scene_id = "3024324123" + status = true +} +``` + +## Argument Reference + +The following arguments are supported: + +* `domain` - (Required, String, ForceNew) Domain. +* `scene_id` - (Required, String, ForceNew) Scene ID. +* `status` - (Required, Bool) Bot status. true - enable; false - disable. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. +* `priority` - Priority. +* `scene_name` - Scene name. +* `type` - Scene type, default: Default scenario, custom: Non default scenario. + + +## Import + +WAF bot scene status config can be imported using the id, e.g. + +``` +terraform import tencentcloud_waf_bot_scene_status_config.example example.com#3024324123 +``` + diff --git a/website/docs/r/waf_bot_status_config.html.markdown b/website/docs/r/waf_bot_status_config.html.markdown new file mode 100644 index 0000000000..8f0f21b8ec --- /dev/null +++ b/website/docs/r/waf_bot_status_config.html.markdown @@ -0,0 +1,55 @@ +--- +subcategory: "Web Application Firewall(WAF)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_waf_bot_status_config" +sidebar_current: "docs-tencentcloud-resource-waf_bot_status_config" +description: |- + Provides a resource to create a WAF bot status config +--- + +# tencentcloud_waf_bot_status_config + +Provides a resource to create a WAF bot status config + +## Example Usage + +```hcl +resource "tencentcloud_waf_bot_status_config" "example" { + domain = "example.com" + status = "1" +} +``` + +### Or + +```hcl +resource "tencentcloud_waf_bot_status_config" "example" { + domain = "example.com" + status = "0" + instance_id = "waf_2kxtlbky11bbcr4b" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `domain` - (Required, String, ForceNew) Domain. +* `status` - (Required, String) Bot status. 1 - enable; 0 - disable. +* `instance_id` - (Optional, String) Instance ID. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. +* `current_global_scene` - The currently enabled scenario with a global matching range and the highest priority. + * `priority` - Priority. + * `scene_id` - Scene ID. + * `scene_name` - Scene name. + * `update_time` - Update time. +* `custom_rule_nums` - Total number of custom rules, excluding BOT whitelist. +* `scene_count` - Scene total count. +* `valid_scene_count` - Number of effective scenarios. + + diff --git a/website/docs/r/waf_domain_post_action_config.html.markdown b/website/docs/r/waf_domain_post_action_config.html.markdown new file mode 100644 index 0000000000..6c57add789 --- /dev/null +++ b/website/docs/r/waf_domain_post_action_config.html.markdown @@ -0,0 +1,47 @@ +--- +subcategory: "Web Application Firewall(WAF)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_waf_domain_post_action_config" +sidebar_current: "docs-tencentcloud-resource-waf_domain_post_action_config" +description: |- + Provides a resource to create a WAF domain post action config +--- + +# tencentcloud_waf_domain_post_action_config + +Provides a resource to create a WAF domain post action config + +## Example Usage + +```hcl +resource "tencentcloud_waf_domain_post_action_config" "example" { + domain = "example.com" + post_cls_action = 1 + post_ckafka_action = 0 +} +``` + +## Argument Reference + +The following arguments are supported: + +* `domain` - (Required, String, ForceNew) Domain. +* `post_ckafka_action` - (Required, Int) 0- Disable shipping, 1- Enable shipping. +* `post_cls_action` - (Required, Int) 0- Disable shipping, 1- Enable shipping. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. + + + +## Import + +WAF domain post action config can be imported using the id, e.g. + +``` +terraform import tencentcloud_waf_domain_post_action_config.example example.com +``` + diff --git a/website/docs/r/waf_instance_attack_log_post_config.html.markdown b/website/docs/r/waf_instance_attack_log_post_config.html.markdown new file mode 100644 index 0000000000..c088e72ed6 --- /dev/null +++ b/website/docs/r/waf_instance_attack_log_post_config.html.markdown @@ -0,0 +1,47 @@ +--- +subcategory: "Web Application Firewall(WAF)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_waf_instance_attack_log_post_config" +sidebar_current: "docs-tencentcloud-resource-waf_instance_attack_log_post_config" +description: |- + Provides a resource to create a WAF instance attack log post config +--- + +# tencentcloud_waf_instance_attack_log_post_config + +Provides a resource to create a WAF instance attack log post config + +~> **NOTE:** Only enterprise version and above are supported for activation + +## Example Usage + +```hcl +resource "tencentcloud_waf_instance_attack_log_post_config" "example" { + instance_id = "waf_2kxtlbky11b4wcrb" + attack_log_post = 1 +} +``` + +## Argument Reference + +The following arguments are supported: + +* `attack_log_post` - (Required, Int) Attack log delivery switch. 0- Disable, 1- Enable. +* `instance_id` - (Required, String, ForceNew) Waf instance ID. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. + + + +## Import + +WAF instance attack log post config can be imported using the id, e.g. + +``` +terraform import tencentcloud_waf_instance_attack_log_post_config.example waf_2kxtlbky11b4wcrb +``` + diff --git a/website/tencentcloud.erb b/website/tencentcloud.erb index e273c4f190..fccd1f0e2e 100644 --- a/website/tencentcloud.erb +++ b/website/tencentcloud.erb @@ -6829,6 +6829,12 @@
  • tencentcloud_waf_auto_deny_rules
  • +
  • + tencentcloud_waf_bot_scene_status_config +
  • +
  • + tencentcloud_waf_bot_status_config +
  • tencentcloud_waf_cc
  • @@ -6851,10 +6857,10 @@ tencentcloud_waf_custom_white_rule
  • - tencentcloud_waf_domain_post_action + tencentcloud_waf_domain_post_action_config
  • - tencentcloud_waf_instance_attack_log_post + tencentcloud_waf_instance_attack_log_post_config
  • tencentcloud_waf_ip_access_control From 1b48be19d6b2876389212241162c37488a127fa2 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Tue, 13 May 2025 11:19:45 +0800 Subject: [PATCH 2/6] add --- .changelog/3355.txt | 7 +++ .../r/waf_domain_post_action.html.markdown | 47 ------------------- ...waf_instance_attack_log_post.html.markdown | 47 ------------------- 3 files changed, 7 insertions(+), 94 deletions(-) create mode 100644 .changelog/3355.txt delete mode 100644 website/docs/r/waf_domain_post_action.html.markdown delete mode 100644 website/docs/r/waf_instance_attack_log_post.html.markdown diff --git a/.changelog/3355.txt b/.changelog/3355.txt new file mode 100644 index 0000000000..e0461be382 --- /dev/null +++ b/.changelog/3355.txt @@ -0,0 +1,7 @@ +```release-note:new-resource +tencentcloud_waf_bot_scene_status_config +``` + +```release-note:new-resource +tencentcloud_waf_bot_status_config +``` diff --git a/website/docs/r/waf_domain_post_action.html.markdown b/website/docs/r/waf_domain_post_action.html.markdown deleted file mode 100644 index 3197a9e9ed..0000000000 --- a/website/docs/r/waf_domain_post_action.html.markdown +++ /dev/null @@ -1,47 +0,0 @@ ---- -subcategory: "Web Application Firewall(WAF)" -layout: "tencentcloud" -page_title: "TencentCloud: tencentcloud_waf_domain_post_action" -sidebar_current: "docs-tencentcloud-resource-waf_domain_post_action" -description: |- - Provides a resource to create a WAF domain post action ---- - -# tencentcloud_waf_domain_post_action - -Provides a resource to create a WAF domain post action - -## Example Usage - -```hcl -resource "tencentcloud_waf_domain_post_action" "example" { - domain = "example.com" - post_cls_action = 1 - post_ckafka_action = 0 -} -``` - -## Argument Reference - -The following arguments are supported: - -* `domain` - (Required, String, ForceNew) Domain. -* `post_ckafka_action` - (Required, Int) 0- Disable shipping, 1- Enable shipping. -* `post_cls_action` - (Required, Int) 0- Disable shipping, 1- Enable shipping. - -## Attributes Reference - -In addition to all arguments above, the following attributes are exported: - -* `id` - ID of the resource. - - - -## Import - -WAF domain post action can be imported using the id, e.g. - -``` -terraform import tencentcloud_waf_domain_post_action.example example.com -``` - diff --git a/website/docs/r/waf_instance_attack_log_post.html.markdown b/website/docs/r/waf_instance_attack_log_post.html.markdown deleted file mode 100644 index fd6a45ac13..0000000000 --- a/website/docs/r/waf_instance_attack_log_post.html.markdown +++ /dev/null @@ -1,47 +0,0 @@ ---- -subcategory: "Web Application Firewall(WAF)" -layout: "tencentcloud" -page_title: "TencentCloud: tencentcloud_waf_instance_attack_log_post" -sidebar_current: "docs-tencentcloud-resource-waf_instance_attack_log_post" -description: |- - Provides a resource to create a WAF instance attack log post ---- - -# tencentcloud_waf_instance_attack_log_post - -Provides a resource to create a WAF instance attack log post - -~> **NOTE:** Only enterprise version and above are supported for activation - -## Example Usage - -```hcl -resource "tencentcloud_waf_instance_attack_log_post" "example" { - instance_id = "waf_2kxtlbky11b4wcrb" - attack_log_post = 1 -} -``` - -## Argument Reference - -The following arguments are supported: - -* `attack_log_post` - (Required, Int) Attack log delivery switch. 0- Disable, 1- Enable. -* `instance_id` - (Required, String, ForceNew) Waf instance ID. - -## Attributes Reference - -In addition to all arguments above, the following attributes are exported: - -* `id` - ID of the resource. - - - -## Import - -WAF instance attack log post can be imported using the id, e.g. - -``` -terraform import tencentcloud_waf_instance_attack_log_post.example waf_2kxtlbky11b4wcrb -``` - From 69fe235c4254dab55c7dbeab41c241ebcf567048 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Tue, 13 May 2025 17:15:38 +0800 Subject: [PATCH 3/6] add --- ...resource_tc_waf_bot_scene_status_config.go | 2 +- .../waf/resource_tc_waf_bot_status_config.go | 51 +++++++++++++++---- .../waf/resource_tc_waf_bot_status_config.md | 17 +++---- .../resource_tc_waf_bot_status_config_test.go | 8 ++- .../services/waf/service_tencentcloud_waf.go | 3 ++ .../r/waf_bot_status_config.html.markdown | 21 ++++---- 6 files changed, 68 insertions(+), 34 deletions(-) diff --git a/tencentcloud/services/waf/resource_tc_waf_bot_scene_status_config.go b/tencentcloud/services/waf/resource_tc_waf_bot_scene_status_config.go index 9aa2060b04..9c6ad305e5 100644 --- a/tencentcloud/services/waf/resource_tc_waf_bot_scene_status_config.go +++ b/tencentcloud/services/waf/resource_tc_waf_bot_scene_status_config.go @@ -79,7 +79,7 @@ func resourceTencentCloudWafBotSceneStatusConfigCreate(d *schema.ResourceData, m } if v, ok := d.GetOk("scene_id"); ok { - domain = v.(string) + sceneId = v.(string) } d.SetId(strings.Join([]string{domain, sceneId}, tccommon.FILED_SP)) diff --git a/tencentcloud/services/waf/resource_tc_waf_bot_status_config.go b/tencentcloud/services/waf/resource_tc_waf_bot_status_config.go index 69225dc07f..a3e6753001 100644 --- a/tencentcloud/services/waf/resource_tc_waf_bot_status_config.go +++ b/tencentcloud/services/waf/resource_tc_waf_bot_status_config.go @@ -2,7 +2,9 @@ package waf import ( "context" + "fmt" "log" + "strings" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -18,6 +20,9 @@ func ResourceTencentCloudWafBotStatusConfig() *schema.Resource { Read: resourceTencentCloudWafBotStatusConfigRead, Update: resourceTencentCloudWafBotStatusConfigUpdate, Delete: resourceTencentCloudWafBotStatusConfigDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "status": { Type: schema.TypeString, @@ -34,7 +39,8 @@ func ResourceTencentCloudWafBotStatusConfig() *schema.Resource { "instance_id": { Type: schema.TypeString, - Optional: true, + Required: true, + ForceNew: true, Description: "Instance ID.", }, @@ -93,13 +99,20 @@ func resourceTencentCloudWafBotStatusConfigCreate(d *schema.ResourceData, meta i defer tccommon.LogElapsed("resource.tencentcloud_waf_bot_status_config.create")() defer tccommon.InconsistentCheck(d, meta)() - var domain string + var ( + instanceId string + domain string + ) + + if v, ok := d.GetOk("instance_id"); ok { + instanceId = v.(string) + } if v, ok := d.GetOk("domain"); ok { domain = v.(string) } - d.SetId(domain) + d.SetId(strings.Join([]string{instanceId, domain}, tccommon.FILED_SP)) return resourceTencentCloudWafBotStatusConfigUpdate(d, meta) } @@ -112,9 +125,16 @@ func resourceTencentCloudWafBotStatusConfigRead(d *schema.ResourceData, meta int logId = tccommon.GetLogId(tccommon.ContextNil) ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) service = WafService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} - domain = d.Id() ) + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + + instanceId := idSplit[0] + domain := idSplit[1] + respData, err := service.DescribeWafBotStatusConfigById(ctx, domain) if err != nil { return err @@ -127,9 +147,14 @@ func resourceTencentCloudWafBotStatusConfigRead(d *schema.ResourceData, meta int } _ = d.Set("domain", domain) + _ = d.Set("instance_id", instanceId) if respData.Status != nil { - _ = d.Set("status", respData.Status) + if *respData.Status == true { + _ = d.Set("status", "1") + } else { + _ = d.Set("status", "0") + } } if respData.SceneCount != nil { @@ -178,18 +203,22 @@ func resourceTencentCloudWafBotStatusConfigUpdate(d *schema.ResourceData, meta i logId = tccommon.GetLogId(tccommon.ContextNil) ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) request = wafv20180125.NewModifyBotStatusRequest() - domain = d.Id() ) - if v, ok := d.GetOk("status"); ok { - request.Status = helper.String(v.(string)) + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) } - if v, ok := d.GetOk("instance_id"); ok { - request.InstanceID = helper.String(v.(string)) + instanceId := idSplit[0] + domain := idSplit[1] + + if v, ok := d.GetOk("status"); ok { + request.Status = helper.String(v.(string)) } - request.Domain = helper.String(domain) + request.InstanceID = &instanceId + request.Domain = &domain request.Category = helper.String("bot") request.IsVersionFour = helper.Bool(true) request.BotVersion = helper.String("4.1.0") diff --git a/tencentcloud/services/waf/resource_tc_waf_bot_status_config.md b/tencentcloud/services/waf/resource_tc_waf_bot_status_config.md index 220c0061ea..4e86050594 100644 --- a/tencentcloud/services/waf/resource_tc_waf_bot_status_config.md +++ b/tencentcloud/services/waf/resource_tc_waf_bot_status_config.md @@ -4,17 +4,16 @@ Example Usage ```hcl resource "tencentcloud_waf_bot_status_config" "example" { - domain = "example.com" - status = "1" + instance_id = "waf_2kxtlbky11bbcr4b" + domain = "example.com" + status = "0" } ``` -Or +Import -```hcl -resource "tencentcloud_waf_bot_status_config" "example" { - domain = "example.com" - status = "0" - instance_id = "waf_2kxtlbky11bbcr4b" -} +WAF bot status config can be imported using the id, e.g. + +``` +terraform import tencentcloud_waf_bot_status_config.example waf_2kw1ente05223fcr#example.com ``` diff --git a/tencentcloud/services/waf/resource_tc_waf_bot_status_config_test.go b/tencentcloud/services/waf/resource_tc_waf_bot_status_config_test.go index d5f8193690..71d0809355 100644 --- a/tencentcloud/services/waf/resource_tc_waf_bot_status_config_test.go +++ b/tencentcloud/services/waf/resource_tc_waf_bot_status_config_test.go @@ -20,6 +20,7 @@ func TestAccTencentCloudWafBotStatusConfigResource_basic(t *testing.T) { Config: testAccWafBotStatusConfig, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "id"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "instance_id"), resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "domain"), resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "status"), ), @@ -28,6 +29,7 @@ func TestAccTencentCloudWafBotStatusConfigResource_basic(t *testing.T) { Config: testAccWafBotStatusConfigUpdate, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "id"), + resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "instance_id"), resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "domain"), resource.TestCheckResourceAttrSet("tencentcloud_waf_bot_status_config.example", "status"), ), @@ -43,14 +45,16 @@ func TestAccTencentCloudWafBotStatusConfigResource_basic(t *testing.T) { const testAccWafBotStatusConfig = ` resource "tencentcloud_waf_bot_status_config" "example" { + instance_id = "waf_2kxtlbky11bbcr4b" domain = "example.com" - status = "1" + status = "0" } ` const testAccWafBotStatusConfigUpdate = ` resource "tencentcloud_waf_bot_status_config" "example" { + instance_id = "waf_2kxtlbky11bbcr4b" domain = "example.com" - status = "0" + status = "1" } ` diff --git a/tencentcloud/services/waf/service_tencentcloud_waf.go b/tencentcloud/services/waf/service_tencentcloud_waf.go index ecb87a97a7..c78b048dfd 100644 --- a/tencentcloud/services/waf/service_tencentcloud_waf.go +++ b/tencentcloud/services/waf/service_tencentcloud_waf.go @@ -1705,6 +1705,9 @@ func (me *WafService) DescribeWafBotSceneStatusConfigById(ctx context.Context, d request := waf.NewDescribeBotSceneListRequest() response := waf.NewDescribeBotSceneListResponse() request.Domain = helper.String(domain) + // wait waf sdk update + // request.BusinessType = common.StringPtrs([]string{"all"}) + request.BusinessType = common.StringPtrs([]string{"login", "seckill", "crawl", "scan", "key-protect", "click-farming", "junk-mail", "social-media", "auto-download", "custom"}) defer func() { if errRet != nil { diff --git a/website/docs/r/waf_bot_status_config.html.markdown b/website/docs/r/waf_bot_status_config.html.markdown index 8f0f21b8ec..a4a2ec634c 100644 --- a/website/docs/r/waf_bot_status_config.html.markdown +++ b/website/docs/r/waf_bot_status_config.html.markdown @@ -15,18 +15,9 @@ Provides a resource to create a WAF bot status config ```hcl resource "tencentcloud_waf_bot_status_config" "example" { - domain = "example.com" - status = "1" -} -``` - -### Or - -```hcl -resource "tencentcloud_waf_bot_status_config" "example" { + instance_id = "waf_2kxtlbky11bbcr4b" domain = "example.com" status = "0" - instance_id = "waf_2kxtlbky11bbcr4b" } ``` @@ -35,8 +26,8 @@ resource "tencentcloud_waf_bot_status_config" "example" { The following arguments are supported: * `domain` - (Required, String, ForceNew) Domain. +* `instance_id` - (Required, String, ForceNew) Instance ID. * `status` - (Required, String) Bot status. 1 - enable; 0 - disable. -* `instance_id` - (Optional, String) Instance ID. ## Attributes Reference @@ -53,3 +44,11 @@ In addition to all arguments above, the following attributes are exported: * `valid_scene_count` - Number of effective scenarios. +## Import + +WAF bot status config can be imported using the id, e.g. + +``` +terraform import tencentcloud_waf_bot_status_config.example waf_2kw1ente05223fcr#example.com +``` + From a092f82c4983302aca4539e94131f870a5391eb7 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Tue, 13 May 2025 17:32:06 +0800 Subject: [PATCH 4/6] add --- tencentcloud/services/waf/resource_tc_waf_bot_status_config.md | 2 +- website/docs/r/waf_bot_status_config.html.markdown | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tencentcloud/services/waf/resource_tc_waf_bot_status_config.md b/tencentcloud/services/waf/resource_tc_waf_bot_status_config.md index 4e86050594..aa0f427f7a 100644 --- a/tencentcloud/services/waf/resource_tc_waf_bot_status_config.md +++ b/tencentcloud/services/waf/resource_tc_waf_bot_status_config.md @@ -15,5 +15,5 @@ Import WAF bot status config can be imported using the id, e.g. ``` -terraform import tencentcloud_waf_bot_status_config.example waf_2kw1ente05223fcr#example.com +terraform import tencentcloud_waf_bot_status_config.example waf_2kxtlbky11bbcr4b#example.com ``` diff --git a/website/docs/r/waf_bot_status_config.html.markdown b/website/docs/r/waf_bot_status_config.html.markdown index a4a2ec634c..bb91b69a09 100644 --- a/website/docs/r/waf_bot_status_config.html.markdown +++ b/website/docs/r/waf_bot_status_config.html.markdown @@ -49,6 +49,6 @@ In addition to all arguments above, the following attributes are exported: WAF bot status config can be imported using the id, e.g. ``` -terraform import tencentcloud_waf_bot_status_config.example waf_2kw1ente05223fcr#example.com +terraform import tencentcloud_waf_bot_status_config.example waf_2kxtlbky11bbcr4b#example.com ``` From dedbfaec81d8470b51f4f2f06dbde7805342ccb2 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Tue, 13 May 2025 19:50:33 +0800 Subject: [PATCH 5/6] add --- .../waf/resource_tc_waf_bot_status_config.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tencentcloud/services/waf/resource_tc_waf_bot_status_config.go b/tencentcloud/services/waf/resource_tc_waf_bot_status_config.go index a3e6753001..ce93bd4ba0 100644 --- a/tencentcloud/services/waf/resource_tc_waf_bot_status_config.go +++ b/tencentcloud/services/waf/resource_tc_waf_bot_status_config.go @@ -24,12 +24,6 @@ func ResourceTencentCloudWafBotStatusConfig() *schema.Resource { State: schema.ImportStatePassthrough, }, Schema: map[string]*schema.Schema{ - "status": { - Type: schema.TypeString, - Required: true, - Description: "Bot status. 1 - enable; 0 - disable.", - }, - "domain": { Type: schema.TypeString, Required: true, @@ -44,6 +38,12 @@ func ResourceTencentCloudWafBotStatusConfig() *schema.Resource { Description: "Instance ID.", }, + "status": { + Type: schema.TypeString, + Required: true, + Description: "Bot status. 1 - enable; 0 - disable.", + }, + "scene_count": { Type: schema.TypeInt, Computed: true, From 4379a88146bac7c5023b5acf9ae48efc6553df08 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Tue, 13 May 2025 19:52:18 +0800 Subject: [PATCH 6/6] add --- .../services/waf/resource_tc_waf_bot_status_config.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tencentcloud/services/waf/resource_tc_waf_bot_status_config.go b/tencentcloud/services/waf/resource_tc_waf_bot_status_config.go index ce93bd4ba0..3a37ee7776 100644 --- a/tencentcloud/services/waf/resource_tc_waf_bot_status_config.go +++ b/tencentcloud/services/waf/resource_tc_waf_bot_status_config.go @@ -24,18 +24,18 @@ func ResourceTencentCloudWafBotStatusConfig() *schema.Resource { State: schema.ImportStatePassthrough, }, Schema: map[string]*schema.Schema{ - "domain": { + "instance_id": { Type: schema.TypeString, Required: true, ForceNew: true, - Description: "Domain.", + Description: "Instance ID.", }, - "instance_id": { + "domain": { Type: schema.TypeString, Required: true, ForceNew: true, - Description: "Instance ID.", + Description: "Domain.", }, "status": {