Skip to content

Commit 92d67fd

Browse files
authored
Merge branch 'master' into master
2 parents 7dedc33 + 602b127 commit 92d67fd

File tree

47 files changed

+3462
-55
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3462
-55
lines changed

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
## 1.49.2 (Unreleased)
1+
## 1.50.0 (Unreleased)
2+
3+
FEATURES:
4+
5+
* **New Resource**: `tencentcloud_address_template`
6+
* **New Resource**: `tencentcloud_address_template_group`
7+
* **New Resource**: `tencentcloud_protocol_template`
8+
* **New Resource**: `tencentcloud_protocol_template_group`
9+
* **New Data Source**: `tencentcloud_address_templates`
10+
* **New Data Source**: `tencentcloud_address_template_groups`
11+
* **New Data Source**: `tencentcloud_protocol_templates`
12+
* **New Data Source**: `tencentcloud_protocol_template_groups`
13+
14+
ENHANCEMENTS:
15+
16+
* Resource `tencentcloud_sercurity_group_rule` add `address_template` and `protocol_template` to support building new security group rule with resource `tencentcloud_address_template` and `tencentcloud_protocol_template`.
217

318
BUG FIXES:
419

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
resource "tencentcloud_address_template" "example" {
2+
name = "example"
3+
addresses = ["10.0.0.0/24", "1.1.1.1", "1.0.0.1-1.0.0.100"]
4+
}
5+
6+
resource "tencentcloud_address_template_group" "example" {
7+
name = "example"
8+
template_ids = [tencentcloud_address_template.example.id]
9+
}
10+
11+
data "tencentcloud_address_templates" "example" {
12+
id = tencentcloud_address_template.example.id
13+
}
14+
15+
data "tencentcloud_address_template_groups" "example" {
16+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
terraform {
2+
required_version = ">= 0.12"
3+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
resource "tencentcloud_protocol_template" "example" {
2+
name = "example"
3+
protocols = ["udp:all", "tcp:90,110", "icmp", "tcp:1110-1120"]
4+
}
5+
6+
resource "tencentcloud_protocol_template_group" "example" {
7+
name = "example"
8+
template_ids = [tencentcloud_protocol_template.example.id]
9+
}
10+
11+
data "tencentcloud_protocol_templates" "example" {
12+
id = tencentcloud_protocol_template.example.id
13+
}
14+
15+
data "tencentcloud_protocol_template_groups" "example" {
16+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
terraform {
2+
required_version = ">= 0.12"
3+
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ require (
1919
github.com/yangwenmai/ratelimit v0.0.0-20180104140304-44221c2292e1
2020
github.com/zclconf/go-cty v1.4.2 // indirect
2121
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect
22+
golang.org/x/tools v0.0.0-20200502202811-ed308ab3e770
2223
)
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
Use this data source to query detailed information of address template groups.
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_address_template_groups" "name" {
8+
name = "test"
9+
}
10+
```
11+
*/
12+
package tencentcloud
13+
14+
import (
15+
"context"
16+
"log"
17+
18+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
19+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
20+
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
21+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
22+
)
23+
24+
func dataSourceTencentCloudAddressTemplateGroups() *schema.Resource {
25+
return &schema.Resource{
26+
Read: dataSourceTencentCloudAddressTemplateGroupsRead,
27+
28+
Schema: map[string]*schema.Schema{
29+
"name": {
30+
Type: schema.TypeString,
31+
Optional: true,
32+
Description: "Name of the address template group to query.",
33+
},
34+
"id": {
35+
Type: schema.TypeString,
36+
Optional: true,
37+
Description: "Id of the address template group to query.",
38+
},
39+
"result_output_file": {
40+
Type: schema.TypeString,
41+
Optional: true,
42+
Description: "Used to save results.",
43+
},
44+
45+
// Computed values
46+
"group_list": {
47+
Type: schema.TypeList,
48+
Computed: true,
49+
Description: "Information list of the dedicated address template groups.",
50+
Elem: &schema.Resource{
51+
Schema: map[string]*schema.Schema{
52+
"id": {
53+
Type: schema.TypeString,
54+
Computed: true,
55+
Description: "Id of the address template group.",
56+
},
57+
"name": {
58+
Type: schema.TypeString,
59+
Computed: true,
60+
Description: "Name of address template group.",
61+
},
62+
"template_ids": {
63+
Type: schema.TypeList,
64+
Elem: &schema.Schema{
65+
Type: schema.TypeString,
66+
},
67+
Computed: true,
68+
Description: "ID set of the address template.",
69+
},
70+
},
71+
},
72+
},
73+
},
74+
}
75+
}
76+
77+
func dataSourceTencentCloudAddressTemplateGroupsRead(d *schema.ResourceData, meta interface{}) error {
78+
defer logElapsed("data_source.tencentcloud_address_template_groups.read")()
79+
80+
logId := getLogId(contextNil)
81+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
82+
83+
var name, templateId string
84+
var filters = make([]*vpc.Filter, 0)
85+
if v, ok := d.GetOk("name"); ok {
86+
name = v.(string)
87+
filters = append(filters, &vpc.Filter{Name: helper.String("address-template-group-name"), Values: []*string{&name}})
88+
}
89+
90+
if v, ok := d.GetOk("id"); ok {
91+
templateId = v.(string)
92+
filters = append(filters, &vpc.Filter{Name: helper.String("address-template-group-id"), Values: []*string{&templateId}})
93+
}
94+
95+
vpcService := VpcService{client: meta.(*TencentCloudClient).apiV3Conn}
96+
var outErr, inErr error
97+
groups, outErr := vpcService.DescribeAddressTemplateGroups(ctx, filters)
98+
if outErr != nil {
99+
outErr = resource.Retry(readRetryTimeout, func() *resource.RetryError {
100+
groups, inErr = vpcService.DescribeAddressTemplateGroups(ctx, filters)
101+
if inErr != nil {
102+
return retryError(inErr)
103+
}
104+
return nil
105+
})
106+
}
107+
108+
if outErr != nil {
109+
return outErr
110+
}
111+
112+
ids := make([]string, 0, len(groups))
113+
templateGroupList := make([]map[string]interface{}, 0, len(groups))
114+
for _, ins := range groups {
115+
mapping := map[string]interface{}{
116+
"id": ins.AddressTemplateGroupId,
117+
"name": ins.AddressTemplateGroupName,
118+
"template_ids": ins.AddressTemplateIdSet,
119+
}
120+
templateGroupList = append(templateGroupList, mapping)
121+
ids = append(ids, *ins.AddressTemplateGroupId)
122+
}
123+
d.SetId(helper.DataResourceIdsHash(ids))
124+
if e := d.Set("group_list", templateGroupList); e != nil {
125+
log.Printf("[CRITAL]%s provider set address template group list fail, reason:%s\n", logId, e)
126+
return e
127+
}
128+
129+
output, ok := d.GetOk("result_output_file")
130+
if ok && output.(string) != "" {
131+
if e := writeToFile(output.(string), templateGroupList); e != nil {
132+
return e
133+
}
134+
}
135+
136+
return nil
137+
138+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
7+
)
8+
9+
var testDataAddressTemplateGroupsNameAll = "data.tencentcloud_address_template_groups.all_test"
10+
11+
func TestAccTencentCloudDataAddressTemplateGroups(t *testing.T) {
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() { testAccPreCheck(t) },
14+
Providers: testAccProviders,
15+
CheckDestroy: testAccCheckAddressTemplateGroupDestroy,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccTencentCloudDataAddressTemplateGroupsBasic,
19+
Check: resource.ComposeAggregateTestCheckFunc(
20+
testAccCheckAddressTemplateGroupExists("tencentcloud_address_template_group.mygroup"),
21+
resource.TestCheckResourceAttrSet(testDataAddressTemplateGroupsNameAll, "group_list.0.id"),
22+
resource.TestCheckResourceAttr(testDataAddressTemplateGroupsNameAll, "group_list.0.name", "mygroup"),
23+
resource.TestCheckResourceAttr(testDataAddressTemplateGroupsNameAll, "group_list.0.template_ids.#", "1"),
24+
),
25+
},
26+
},
27+
})
28+
}
29+
30+
const testAccTencentCloudDataAddressTemplateGroupsBasic = `
31+
resource "tencentcloud_address_template" "myaddress_template" {
32+
name = "testacctcrtemplate"
33+
addresses = ["1.1.1.1"]
34+
}
35+
36+
resource "tencentcloud_address_template_group" "mygroup" {
37+
name = "mygroup"
38+
template_ids = [tencentcloud_address_template.myaddress_template.id]
39+
}
40+
41+
data "tencentcloud_address_template_groups" "all_test" {
42+
name = tencentcloud_address_template_group.mygroup.name
43+
id = tencentcloud_address_template_group.mygroup.id
44+
}
45+
46+
`
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
Use this data source to query detailed information of address templates.
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_address_templates" "name" {
8+
name = "test"
9+
}
10+
```
11+
*/
12+
package tencentcloud
13+
14+
import (
15+
"context"
16+
"log"
17+
18+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
19+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
20+
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
21+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
22+
)
23+
24+
func dataSourceTencentCloudAddressTemplates() *schema.Resource {
25+
return &schema.Resource{
26+
Read: dataSourceTencentCloudAddressTemplatesRead,
27+
28+
Schema: map[string]*schema.Schema{
29+
"name": {
30+
Type: schema.TypeString,
31+
Optional: true,
32+
Description: "Name of the address template to query.",
33+
},
34+
"id": {
35+
Type: schema.TypeString,
36+
Optional: true,
37+
Description: "Id of the address template to query.",
38+
},
39+
"result_output_file": {
40+
Type: schema.TypeString,
41+
Optional: true,
42+
Description: "Used to save results.",
43+
},
44+
45+
// Computed values
46+
"template_list": {
47+
Type: schema.TypeList,
48+
Computed: true,
49+
Description: "Information list of the dedicated address templates.",
50+
Elem: &schema.Resource{
51+
Schema: map[string]*schema.Schema{
52+
"id": {
53+
Type: schema.TypeString,
54+
Computed: true,
55+
Description: "Id of the address template.",
56+
},
57+
"name": {
58+
Type: schema.TypeString,
59+
Computed: true,
60+
Description: "Name of address template.",
61+
},
62+
"addresses": {
63+
Type: schema.TypeList,
64+
Elem: &schema.Schema{
65+
Type: schema.TypeString,
66+
},
67+
Computed: true,
68+
Description: "Set of the addresses.",
69+
},
70+
},
71+
},
72+
},
73+
},
74+
}
75+
}
76+
77+
func dataSourceTencentCloudAddressTemplatesRead(d *schema.ResourceData, meta interface{}) error {
78+
defer logElapsed("data_source.tencentcloud_address_templates.read")()
79+
80+
logId := getLogId(contextNil)
81+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
82+
83+
var name, templateId string
84+
var filters = make([]*vpc.Filter, 0)
85+
if v, ok := d.GetOk("name"); ok {
86+
name = v.(string)
87+
filters = append(filters, &vpc.Filter{Name: helper.String("address-template-name"), Values: []*string{&name}})
88+
}
89+
90+
if v, ok := d.GetOk("id"); ok {
91+
templateId = v.(string)
92+
filters = append(filters, &vpc.Filter{Name: helper.String("address-template-id"), Values: []*string{&templateId}})
93+
}
94+
95+
vpcService := VpcService{client: meta.(*TencentCloudClient).apiV3Conn}
96+
var outErr, inErr error
97+
templates, outErr := vpcService.DescribeAddressTemplates(ctx, filters)
98+
if outErr != nil {
99+
outErr = resource.Retry(readRetryTimeout, func() *resource.RetryError {
100+
templates, inErr = vpcService.DescribeAddressTemplates(ctx, filters)
101+
if inErr != nil {
102+
return retryError(inErr)
103+
}
104+
return nil
105+
})
106+
}
107+
108+
if outErr != nil {
109+
return outErr
110+
}
111+
112+
ids := make([]string, 0, len(templates))
113+
templateList := make([]map[string]interface{}, 0, len(templates))
114+
for _, ins := range templates {
115+
mapping := map[string]interface{}{
116+
"id": ins.AddressTemplateId,
117+
"name": ins.AddressTemplateName,
118+
"addresses": ins.AddressSet,
119+
}
120+
templateList = append(templateList, mapping)
121+
ids = append(ids, *ins.AddressTemplateId)
122+
}
123+
d.SetId(helper.DataResourceIdsHash(ids))
124+
if e := d.Set("template_list", templateList); e != nil {
125+
log.Printf("[CRITAL]%s provider set address template list fail, reason:%s\n", logId, e)
126+
return e
127+
}
128+
129+
output, ok := d.GetOk("result_output_file")
130+
if ok && output.(string) != "" {
131+
if e := writeToFile(output.(string), templateList); e != nil {
132+
return e
133+
}
134+
}
135+
136+
return nil
137+
138+
}

0 commit comments

Comments
 (0)