Skip to content

Commit 81dc716

Browse files
authored
add vpc other datasourcce (#1862)
* add vpc other datasourcce * add vpc other datasourcce * add vpc other datasourcce
1 parent 582142f commit 81dc716

28 files changed

+2503
-0
lines changed

.changelog/1862.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
```release-note:new-data-source
2+
tencentcloud_vpc_security_group_limits
3+
```
4+
5+
```release-note:new-data-source
6+
tencentcloud_vpc_security_group_references
7+
```
8+
9+
```release-note:new-data-source
10+
tencentcloud_vpc_sg_snapshot_file_content
11+
```
12+
13+
```release-note:new-data-source
14+
tencentcloud_vpc_snapshot_files
15+
```
16+
17+
```release-note:new-data-source
18+
tencentcloud_vpc_subnet_resource_dashboard
19+
```
20+
21+
```release-note:new-data-source
22+
tencentcloud_vpc_template_limits
23+
```
24+
25+
```release-note:new-data-source
26+
tencentcloud_vpc_used_ip_address
27+
```
28+
29+
```release-note:new-data-source
30+
tencentcloud_vpc_limits
31+
```
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
Use this data source to query detailed information of vpc limits
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_vpc_limits" "limits" {
8+
limit_types = ["appid-max-vpcs", "vpc-max-subnets"]
9+
}
10+
```
11+
*/
12+
package tencentcloud
13+
14+
import (
15+
"context"
16+
17+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
18+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
19+
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
20+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
21+
)
22+
23+
func dataSourceTencentCloudVpcLimits() *schema.Resource {
24+
return &schema.Resource{
25+
Read: dataSourceTencentCloudVpcLimitsRead,
26+
Schema: map[string]*schema.Schema{
27+
"limit_types": {
28+
Required: true,
29+
Type: schema.TypeSet,
30+
Elem: &schema.Schema{
31+
Type: schema.TypeString,
32+
},
33+
Description: "Quota name. A maximum of 100 quota types can be queried each time.",
34+
},
35+
36+
"vpc_limit_set": {
37+
Computed: true,
38+
Type: schema.TypeList,
39+
Description: "vpc limit.",
40+
Elem: &schema.Resource{
41+
Schema: map[string]*schema.Schema{
42+
"limit_type": {
43+
Type: schema.TypeString,
44+
Computed: true,
45+
Description: "type of vpc limit.",
46+
},
47+
"limit_value": {
48+
Type: schema.TypeInt,
49+
Computed: true,
50+
Description: "value of vpc limit.",
51+
},
52+
},
53+
},
54+
},
55+
56+
"result_output_file": {
57+
Type: schema.TypeString,
58+
Optional: true,
59+
Description: "Used to save results.",
60+
},
61+
},
62+
}
63+
}
64+
65+
func dataSourceTencentCloudVpcLimitsRead(d *schema.ResourceData, meta interface{}) error {
66+
defer logElapsed("data_source.tencentcloud_vpc_limits.read")()
67+
defer inconsistentCheck(d, meta)()
68+
69+
logId := getLogId(contextNil)
70+
71+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
72+
73+
paramMap := make(map[string]interface{})
74+
if v, ok := d.GetOk("limit_types"); ok {
75+
limitTypesSet := v.(*schema.Set).List()
76+
paramMap["LimitTypes"] = helper.InterfacesStringsPoint(limitTypesSet)
77+
}
78+
79+
service := VpcService{client: meta.(*TencentCloudClient).apiV3Conn}
80+
81+
var vpcLimitSet []*vpc.VpcLimit
82+
83+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
84+
result, e := service.DescribeVpcLimitsByFilter(ctx, paramMap)
85+
if e != nil {
86+
return retryError(e)
87+
}
88+
vpcLimitSet = result
89+
return nil
90+
})
91+
if err != nil {
92+
return err
93+
}
94+
95+
ids := make([]string, 0, len(vpcLimitSet))
96+
tmpList := make([]map[string]interface{}, 0, len(vpcLimitSet))
97+
98+
if vpcLimitSet != nil {
99+
for _, vpcLimit := range vpcLimitSet {
100+
vpcLimitMap := map[string]interface{}{}
101+
102+
if vpcLimit.LimitType != nil {
103+
vpcLimitMap["limit_type"] = vpcLimit.LimitType
104+
}
105+
106+
if vpcLimit.LimitValue != nil {
107+
vpcLimitMap["limit_value"] = vpcLimit.LimitValue
108+
}
109+
110+
ids = append(ids, *vpcLimit.LimitType)
111+
tmpList = append(tmpList, vpcLimitMap)
112+
}
113+
114+
_ = d.Set("vpc_limit_set", tmpList)
115+
}
116+
117+
d.SetId(helper.DataResourceIdsHash(ids))
118+
output, ok := d.GetOk("result_output_file")
119+
if ok && output.(string) != "" {
120+
if e := writeToFile(output.(string), tmpList); e != nil {
121+
return e
122+
}
123+
}
124+
return nil
125+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudVpcLimitsDataSource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheck(t)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccVpcLimitsDataSource,
19+
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_vpc_limits.limits")),
20+
},
21+
},
22+
})
23+
}
24+
25+
const testAccVpcLimitsDataSource = `
26+
27+
data "tencentcloud_vpc_limits" "limits" {
28+
limit_types = ["appid-max-vpcs", "vpc-max-subnets"]
29+
}
30+
`
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
Use this data source to query detailed information of vpc security_group_limits
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_vpc_security_group_limits" "security_group_limits" {}
8+
```
9+
*/
10+
package tencentcloud
11+
12+
import (
13+
"context"
14+
15+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
16+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
17+
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
18+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
19+
)
20+
21+
func dataSourceTencentCloudVpcSecurityGroupLimits() *schema.Resource {
22+
return &schema.Resource{
23+
Read: dataSourceTencentCloudVpcSecurityGroupLimitsRead,
24+
Schema: map[string]*schema.Schema{
25+
"security_group_limit_set": {
26+
Computed: true,
27+
Type: schema.TypeList,
28+
Description: "sg limit set.",
29+
Elem: &schema.Resource{
30+
Schema: map[string]*schema.Schema{
31+
"security_group_limit": {
32+
Type: schema.TypeInt,
33+
Computed: true,
34+
Description: "number of sg can be created.",
35+
},
36+
"security_group_policy_limit": {
37+
Type: schema.TypeInt,
38+
Computed: true,
39+
Description: "number of sg polciy can be created.",
40+
},
41+
"referred_security_group_limit": {
42+
Type: schema.TypeInt,
43+
Computed: true,
44+
Description: "number of sg can be referred.",
45+
},
46+
"security_group_instance_limit": {
47+
Type: schema.TypeInt,
48+
Computed: true,
49+
Description: "number of sg associated instances.",
50+
},
51+
"instance_security_group_limit": {
52+
Type: schema.TypeInt,
53+
Computed: true,
54+
Description: "number of instances associated sg.",
55+
},
56+
"security_group_extended_policy_limit": {
57+
Type: schema.TypeInt,
58+
Computed: true,
59+
Description: "number of sg extended policy.",
60+
},
61+
"security_group_referred_cvm_and_eni_limit": {
62+
Type: schema.TypeInt,
63+
Computed: true,
64+
Description: "number of eni and cvm can be referred.",
65+
},
66+
"security_group_referred_svc_limit": {
67+
Type: schema.TypeInt,
68+
Computed: true,
69+
Description: "number of svc can be referred.",
70+
},
71+
},
72+
},
73+
},
74+
75+
"result_output_file": {
76+
Type: schema.TypeString,
77+
Optional: true,
78+
Description: "Used to save results.",
79+
},
80+
},
81+
}
82+
}
83+
84+
func dataSourceTencentCloudVpcSecurityGroupLimitsRead(d *schema.ResourceData, meta interface{}) error {
85+
defer logElapsed("data_source.tencentcloud_vpc_security_group_limits.read")()
86+
defer inconsistentCheck(d, meta)()
87+
88+
logId := getLogId(contextNil)
89+
90+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
91+
92+
paramMap := make(map[string]interface{})
93+
service := VpcService{client: meta.(*TencentCloudClient).apiV3Conn}
94+
95+
var securityGroupLimitSet *vpc.SecurityGroupLimitSet
96+
97+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
98+
result, e := service.DescribeVpcSecurityGroupLimits(ctx, paramMap)
99+
if e != nil {
100+
return retryError(e)
101+
}
102+
securityGroupLimitSet = result
103+
return nil
104+
})
105+
if err != nil {
106+
return err
107+
}
108+
109+
ids := make([]string, 0)
110+
securityGroupLimitSetMap := map[string]interface{}{}
111+
112+
if securityGroupLimitSet != nil {
113+
if securityGroupLimitSet.SecurityGroupLimit != nil {
114+
securityGroupLimitSetMap["security_group_limit"] = securityGroupLimitSet.SecurityGroupLimit
115+
}
116+
117+
if securityGroupLimitSet.SecurityGroupPolicyLimit != nil {
118+
securityGroupLimitSetMap["security_group_policy_limit"] = securityGroupLimitSet.SecurityGroupPolicyLimit
119+
}
120+
121+
if securityGroupLimitSet.ReferedSecurityGroupLimit != nil {
122+
securityGroupLimitSetMap["referred_security_group_limit"] = securityGroupLimitSet.ReferedSecurityGroupLimit
123+
}
124+
125+
if securityGroupLimitSet.SecurityGroupInstanceLimit != nil {
126+
securityGroupLimitSetMap["security_group_instance_limit"] = securityGroupLimitSet.SecurityGroupInstanceLimit
127+
}
128+
129+
if securityGroupLimitSet.InstanceSecurityGroupLimit != nil {
130+
securityGroupLimitSetMap["instance_security_group_limit"] = securityGroupLimitSet.InstanceSecurityGroupLimit
131+
}
132+
133+
if securityGroupLimitSet.SecurityGroupExtendedPolicyLimit != nil {
134+
securityGroupLimitSetMap["security_group_extended_policy_limit"] = securityGroupLimitSet.SecurityGroupExtendedPolicyLimit
135+
}
136+
137+
if securityGroupLimitSet.SecurityGroupReferedCvmAndEniLimit != nil {
138+
securityGroupLimitSetMap["security_group_referred_cvm_and_eni_limit"] = securityGroupLimitSet.SecurityGroupReferedCvmAndEniLimit
139+
}
140+
141+
if securityGroupLimitSet.SecurityGroupReferedSvcLimit != nil {
142+
securityGroupLimitSetMap["security_group_referred_svc_limit"] = securityGroupLimitSet.SecurityGroupReferedSvcLimit
143+
}
144+
145+
ids = append(ids, helper.UInt64ToStr(*securityGroupLimitSet.SecurityGroupLimit))
146+
_ = d.Set("security_group_limit_set", []interface{}{securityGroupLimitSetMap})
147+
}
148+
149+
d.SetId(helper.DataResourceIdsHash(ids))
150+
output, ok := d.GetOk("result_output_file")
151+
if ok && output.(string) != "" {
152+
if e := writeToFile(output.(string), securityGroupLimitSetMap); e != nil {
153+
return e
154+
}
155+
}
156+
return nil
157+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudVpcSecurityGroupLimitsDataSource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheck(t)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccVpcSecurityGroupLimitsDataSource,
19+
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_vpc_security_group_limits.security_group_limits")),
20+
},
21+
},
22+
})
23+
}
24+
25+
const testAccVpcSecurityGroupLimitsDataSource = `
26+
27+
data "tencentcloud_vpc_security_group_limits" "security_group_limits" {}
28+
29+
`

0 commit comments

Comments
 (0)