Skip to content

feat(teo): [124357710]support teo_bind_security_template #3393

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3393.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
tencentcloud_teo_bind_security_template
```
1 change: 1 addition & 0 deletions tencentcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1872,6 +1872,7 @@ func Provider() *schema.Provider {
"tencentcloud_teo_function_runtime_environment": teo.ResourceTencentCloudTeoFunctionRuntimeEnvironment(),
"tencentcloud_teo_security_policy_config": teo.ResourceTencentCloudTeoSecurityPolicyConfig(),
"tencentcloud_teo_dns_record": teo.ResourceTencentCloudTeoDnsRecord(),
"tencentcloud_teo_bind_security_template": teo.ResourceTencentCloudTeoBindSecurityTemplate(),
"tencentcloud_tcm_mesh": tcm.ResourceTencentCloudTcmMesh(),
"tencentcloud_tcm_cluster_attachment": tcm.ResourceTencentCloudTcmClusterAttachment(),
"tencentcloud_tcm_prometheus_attachment": tcm.ResourceTencentCloudTcmPrometheusAttachment(),
Expand Down
1 change: 1 addition & 0 deletions tencentcloud/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,7 @@ tencentcloud_teo_l7_acc_setting
tencentcloud_teo_security_ip_group
tencentcloud_teo_security_policy_config
tencentcloud_teo_dns_record
tencentcloud_teo_bind_security_template

TencentCloud ServiceMesh(TCM)
Data Source
Expand Down
210 changes: 210 additions & 0 deletions tencentcloud/services/teo/resource_tc_teo_bind_security_template.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Provides a resource to create a teo bind_security_template

~> **NOTE:** If the domain name you input has been bound to a policy template (including site-level protection policies), the default value is to replace the template currently bound to the domain name.
~> **NOTE:** The current resource can only bind/unbind the template and domain name belonging to the same site.

Example Usage

```hcl
resource "tencentcloud_teo_bind_security_template" "teo_bind_security_template" {
}

```
Import

teo application_proxy_rule can be imported using the zoneId#templateId, e.g.
```
terraform import tencentcloud_teo_bind_security_template.teo_bind_security_template zone-2983wizgxqvm#templateId
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package teo

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
teov20220901 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220901"
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
)

func resourceTeoBindSecurityTemplateUpdateStateRefreshFunc_0_0(ctx context.Context, zoneId string, templateId string, entity string) resource.StateRefreshFunc {
var req *teov20220901.DescribeSecurityTemplateBindingsRequest
return func() (interface{}, string, error) {
meta := tccommon.ProviderMetaFromContext(ctx)

service := TeoService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
if meta == nil {
return nil, "", fmt.Errorf("resource data can not be nil")
}
if req == nil {
d := tccommon.ResourceDataFromContext(ctx)
if d == nil {
return nil, "", fmt.Errorf("resource data can not be nil")
}
_ = d
req = teov20220901.NewDescribeSecurityTemplateBindingsRequest()
}
resp, err := service.DescribeTeoBindSecurityTemplateById(ctx, zoneId, templateId, entity)
if err != nil {
return nil, "", err
}
if resp == nil {
return nil, "", nil
}
return resp, *resp.Status, nil
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package teo_test

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
)

func TestAccTencentCloudTeoBindSecurityTemplateResource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
tcacctest.AccPreCheck(t)
},
Providers: tcacctest.AccProviders,
Steps: []resource.TestStep{
{
Config: testAccTeoBindSecurityTemplate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("tencentcloud_teo_bind_security_template.teo_bind_security_template", "zone_id", "zone-39quuimqg8r6"),
resource.TestCheckResourceAttr("tencentcloud_teo_bind_security_template.teo_bind_security_template", "template_id", "temp-7dr7dm78"),
resource.TestCheckResourceAttr("tencentcloud_teo_bind_security_template.teo_bind_security_template", "entity", "aaa.makn.cn"),
resource.TestCheckResourceAttr("tencentcloud_teo_bind_security_template.teo_bind_security_template", "operate", "bind"),
resource.TestCheckResourceAttr("tencentcloud_teo_bind_security_template.teo_bind_security_template", "status", "online"),
),
},
{
ResourceName: "tencentcloud_teo_bind_security_template.teo_bind_security_template",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

const testAccTeoBindSecurityTemplate = `

resource "tencentcloud_teo_bind_security_template" "teo_bind_security_template" {
operate = "bind"
template_id = "temp-7dr7dm78"
zone_id = "zone-39quuimqg8r6"
entity = "aaa.makn.cn"
}

`
38 changes: 38 additions & 0 deletions tencentcloud/services/teo/service_tencentcloud_teo.go
Original file line number Diff line number Diff line change
Expand Up @@ -1819,3 +1819,41 @@ func (me *TeoService) DescribeTeoDnsRecordById(ctx context.Context, zoneId, reco
}
return
}

func (me *TeoService) DescribeTeoBindSecurityTemplateById(ctx context.Context, zoneId string, templateId string, entity string) (ret *teov20220901.EntityStatus, errRet error) {
logId := tccommon.GetLogId(ctx)

request := teov20220901.NewDescribeSecurityTemplateBindingsRequest()
request.ZoneId = helper.String(zoneId)
request.TemplateId = []*string{helper.String(templateId)}

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())
}
}()

ratelimit.Check(request.GetAction())

response, err := me.client.UseTeoV20220901Client().DescribeSecurityTemplateBindings(request)
if err != nil {
errRet = err
return
}
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
if response != nil && response.Response != nil {
if response.Response.SecurityTemplate != nil && len(response.Response.SecurityTemplate) > 0 {
if response.Response.SecurityTemplate[0] != nil && response.Response.SecurityTemplate[0].TemplateScope != nil && len(response.Response.SecurityTemplate[0].TemplateScope) > 0 {
if response.Response.SecurityTemplate[0].TemplateScope[0] != nil && len(response.Response.SecurityTemplate[0].TemplateScope[0].EntityStatus) > 0 {
for _, v := range response.Response.SecurityTemplate[0].TemplateScope[0].EntityStatus {
if v != nil && *v.Entity == entity {
ret = v
return
}
}
}
}
}
}
return
}
Loading
Loading