Skip to content

Commit 8b798f5

Browse files
committed
feat(teo): [124357710]support teo_bind_security_template
1 parent 6718194 commit 8b798f5

7 files changed

+352
-0
lines changed

tencentcloud/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,6 +1872,7 @@ func Provider() *schema.Provider {
18721872
"tencentcloud_teo_function_runtime_environment": teo.ResourceTencentCloudTeoFunctionRuntimeEnvironment(),
18731873
"tencentcloud_teo_security_policy_config": teo.ResourceTencentCloudTeoSecurityPolicyConfig(),
18741874
"tencentcloud_teo_dns_record": teo.ResourceTencentCloudTeoDnsRecord(),
1875+
"tencentcloud_teo_bind_security_template": teo.ResourceTencentCloudTeoBindSecurityTemplate(),
18751876
"tencentcloud_tcm_mesh": tcm.ResourceTencentCloudTcmMesh(),
18761877
"tencentcloud_tcm_cluster_attachment": tcm.ResourceTencentCloudTcmClusterAttachment(),
18771878
"tencentcloud_tcm_prometheus_attachment": tcm.ResourceTencentCloudTcmPrometheusAttachment(),

tencentcloud/provider.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,7 @@ tencentcloud_teo_l7_acc_setting
15111511
tencentcloud_teo_security_ip_group
15121512
tencentcloud_teo_security_policy_config
15131513
tencentcloud_teo_dns_record
1514+
tencentcloud_teo_bind_security_template
15141515

15151516
TencentCloud ServiceMesh(TCM)
15161517
Data Source

tencentcloud/services/teo/resource_tc_teo_bind_security_template.go

Lines changed: 210 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Provides a resource to create a teo bind_security_template
2+
3+
~> **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.
4+
~> **NOTE:** The current resource can only bind/unbind the template and domain name belonging to the same site.
5+
6+
Example Usage
7+
8+
```hcl
9+
resource "tencentcloud_teo_bind_security_template" "teo_bind_security_template" {
10+
}
11+
12+
```
13+
Import
14+
15+
teo application_proxy_rule can be imported using the zoneId#templateId, e.g.
16+
```
17+
terraform import tencentcloud_teo_bind_security_template.teo_bind_security_template zone-2983wizgxqvm#templateId
18+
```
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package teo
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8+
teov20220901 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220901"
9+
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
10+
)
11+
12+
func resourceTeoBindSecurityTemplateUpdateStateRefreshFunc_0_0(ctx context.Context, zoneId string, templateId string, entity string) resource.StateRefreshFunc {
13+
var req *teov20220901.DescribeSecurityTemplateBindingsRequest
14+
return func() (interface{}, string, error) {
15+
meta := tccommon.ProviderMetaFromContext(ctx)
16+
17+
service := TeoService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
18+
if meta == nil {
19+
return nil, "", fmt.Errorf("resource data can not be nil")
20+
}
21+
if req == nil {
22+
d := tccommon.ResourceDataFromContext(ctx)
23+
if d == nil {
24+
return nil, "", fmt.Errorf("resource data can not be nil")
25+
}
26+
_ = d
27+
req = teov20220901.NewDescribeSecurityTemplateBindingsRequest()
28+
}
29+
resp, err := service.DescribeTeoBindSecurityTemplateById(ctx, zoneId, templateId, entity)
30+
if err != nil {
31+
return nil, "", err
32+
}
33+
if resp == nil {
34+
return nil, "", nil
35+
}
36+
return resp, *resp.Status, nil
37+
}
38+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package teo_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
8+
)
9+
10+
func TestAccTencentCloudTeoBindSecurityTemplateResource_basic(t *testing.T) {
11+
t.Parallel()
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() {
14+
tcacctest.AccPreCheck(t)
15+
},
16+
Providers: tcacctest.AccProviders,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccTeoBindSecurityTemplate,
20+
Check: resource.ComposeTestCheckFunc(
21+
resource.TestCheckResourceAttr("tencentcloud_teo_bind_security_template.teo_bind_security_template", "zone_id", "zone-39quuimqg8r6"),
22+
resource.TestCheckResourceAttr("tencentcloud_teo_bind_security_template.teo_bind_security_template", "template_id", "temp-7dr7dm78"),
23+
resource.TestCheckResourceAttr("tencentcloud_teo_bind_security_template.teo_bind_security_template", "entity", "aaa.makn.cn"),
24+
resource.TestCheckResourceAttr("tencentcloud_teo_bind_security_template.teo_bind_security_template", "operate", "bind"),
25+
resource.TestCheckResourceAttr("tencentcloud_teo_bind_security_template.teo_bind_security_template", "status", "online"),
26+
),
27+
},
28+
{
29+
ResourceName: "tencentcloud_teo_bind_security_template.teo_bind_security_template",
30+
ImportState: true,
31+
ImportStateVerify: true,
32+
},
33+
},
34+
})
35+
}
36+
37+
const testAccTeoBindSecurityTemplate = `
38+
39+
resource "tencentcloud_teo_bind_security_template" "teo_bind_security_template" {
40+
operate = "bind"
41+
template_id = "temp-7dr7dm78"
42+
zone_id = "zone-39quuimqg8r6"
43+
entity = "aaa.makn.cn"
44+
}
45+
46+
`

tencentcloud/services/teo/service_tencentcloud_teo.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,3 +1819,41 @@ func (me *TeoService) DescribeTeoDnsRecordById(ctx context.Context, zoneId, reco
18191819
}
18201820
return
18211821
}
1822+
1823+
func (me *TeoService) DescribeTeoBindSecurityTemplateById(ctx context.Context, zoneId string, templateId string, entity string) (ret *teov20220901.EntityStatus, errRet error) {
1824+
logId := tccommon.GetLogId(ctx)
1825+
1826+
request := teov20220901.NewDescribeSecurityTemplateBindingsRequest()
1827+
request.ZoneId = helper.String(zoneId)
1828+
request.TemplateId = []*string{helper.String(templateId)}
1829+
1830+
defer func() {
1831+
if errRet != nil {
1832+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
1833+
}
1834+
}()
1835+
1836+
ratelimit.Check(request.GetAction())
1837+
1838+
response, err := me.client.UseTeoV20220901Client().DescribeSecurityTemplateBindings(request)
1839+
if err != nil {
1840+
errRet = err
1841+
return
1842+
}
1843+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
1844+
if response != nil && response.Response != nil {
1845+
if response.Response.SecurityTemplate != nil && len(response.Response.SecurityTemplate) > 0 {
1846+
if response.Response.SecurityTemplate[0] != nil && response.Response.SecurityTemplate[0].TemplateScope != nil && len(response.Response.SecurityTemplate[0].TemplateScope) > 0 {
1847+
if response.Response.SecurityTemplate[0].TemplateScope[0] != nil && len(response.Response.SecurityTemplate[0].TemplateScope[0].EntityStatus) > 0 {
1848+
for _, v := range response.Response.SecurityTemplate[0].TemplateScope[0].EntityStatus {
1849+
if v != nil && *v.Entity == entity {
1850+
ret = v
1851+
return
1852+
}
1853+
}
1854+
}
1855+
}
1856+
}
1857+
}
1858+
return
1859+
}

0 commit comments

Comments
 (0)