Skip to content

Commit 9c10dab

Browse files
WeiMengXSWeiMengXS
andauthored
Feat/cam account (#2225)
* feat: doc * feat: set version config * feat: Cam account * feat: doc * feat: doc * feat: changelog * feat: fix getOkExists --------- Co-authored-by: WeiMengXS <[email protected]>
1 parent 1c7166d commit 9c10dab

18 files changed

+1170
-5
lines changed

.changelog/2225.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
```release-note:new-resource
2+
tencentcloud_cam_set_policy_version_config
3+
```
4+
5+
```release-note:new-data-source
6+
tencentcloud_cam_account_summary
7+
```
8+
9+
```release-note:new-data-source
10+
tencentcloud_cam_policy_granting_service_access
11+
```
12+
13+
```release-note:new-data-source
14+
tencentcloud_cam_secret_last_used_time
15+
```
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
Use this data source to query detailed information of cam account_summary
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_cam_account_summary" "account_summary" {
8+
}
9+
```
10+
*/
11+
package tencentcloud
12+
13+
import (
14+
"context"
15+
16+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
17+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
18+
cam "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam/v20190116"
19+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
20+
)
21+
22+
func dataSourceTencentCloudCamAccountSummary() *schema.Resource {
23+
return &schema.Resource{
24+
Read: dataSourceTencentCloudCamAccountSummaryRead,
25+
Schema: map[string]*schema.Schema{
26+
"policies": {
27+
Computed: true,
28+
Type: schema.TypeInt,
29+
Description: "The number of policy.",
30+
},
31+
32+
"roles": {
33+
Computed: true,
34+
Type: schema.TypeInt,
35+
Description: "The number of role.",
36+
},
37+
38+
"user": {
39+
Computed: true,
40+
Type: schema.TypeInt,
41+
Description: "The number of Sub-user.",
42+
},
43+
44+
"group": {
45+
Computed: true,
46+
Type: schema.TypeInt,
47+
Description: "The number of Group.",
48+
},
49+
50+
"member": {
51+
Computed: true,
52+
Type: schema.TypeInt,
53+
Description: "The number of grouped users.",
54+
},
55+
56+
"identity_providers": {
57+
Computed: true,
58+
Type: schema.TypeInt,
59+
Description: "The number of identity provider.",
60+
},
61+
62+
"result_output_file": {
63+
Type: schema.TypeString,
64+
Optional: true,
65+
Description: "Used to save results.",
66+
},
67+
},
68+
}
69+
}
70+
71+
func dataSourceTencentCloudCamAccountSummaryRead(d *schema.ResourceData, meta interface{}) error {
72+
defer logElapsed("data_source.tencentcloud_cam_account_summary.read")()
73+
defer inconsistentCheck(d, meta)()
74+
75+
logId := getLogId(contextNil)
76+
77+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
78+
79+
service := CamService{client: meta.(*TencentCloudClient).apiV3Conn}
80+
AccountData := &cam.GetAccountSummaryResponseParams{}
81+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
82+
result, e := service.DescribeCamAccountSummaryByFilter(ctx)
83+
if e != nil {
84+
return retryError(e)
85+
}
86+
AccountData = result
87+
return nil
88+
})
89+
if err != nil {
90+
return err
91+
}
92+
template := make(map[string]interface{}, 0)
93+
94+
if AccountData.Policies != nil {
95+
_ = d.Set("policies", AccountData.Policies)
96+
template["policies"] = AccountData.Policies
97+
}
98+
99+
if AccountData.Roles != nil {
100+
_ = d.Set("roles", AccountData.Roles)
101+
template["roles"] = AccountData.Roles
102+
}
103+
104+
if AccountData.User != nil {
105+
_ = d.Set("user", AccountData.User)
106+
template["user"] = AccountData.User
107+
}
108+
109+
if AccountData.Group != nil {
110+
_ = d.Set("group", AccountData.Group)
111+
template["group"] = AccountData.Group
112+
}
113+
114+
if AccountData.Member != nil {
115+
_ = d.Set("member", AccountData.Member)
116+
template["member"] = AccountData.Member
117+
}
118+
119+
if AccountData.IdentityProviders != nil {
120+
_ = d.Set("identity_providers", AccountData.IdentityProviders)
121+
template["identity_providers"] = AccountData.IdentityProviders
122+
}
123+
d.SetId(helper.BuildToken())
124+
output, ok := d.GetOk("result_output_file")
125+
if ok && output.(string) != "" {
126+
if e := writeToFile(output.(string), template); e != nil {
127+
return e
128+
}
129+
}
130+
return nil
131+
}
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 TestAccTencentCloudCamAccountSummaryDataSource_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: testAccCamAccountSummaryDataSource,
19+
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_cam_account_summary.account_summary")),
20+
},
21+
},
22+
})
23+
}
24+
25+
const testAccCamAccountSummaryDataSource = `
26+
27+
data "tencentcloud_cam_account_summary" "account_summary" {
28+
}
29+
30+
`

tencentcloud/data_source_tc_cam_list_attached_user_policy.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ func dataSourceTencentCloudCamListAttachedUserPolicyRead(d *schema.ResourceData,
139139
ctx := context.WithValue(context.TODO(), logIdKey, logId)
140140

141141
paramMap := make(map[string]interface{})
142-
if v, _ := d.GetOk("target_uin"); v != nil {
142+
if v, _ := d.GetOkExists("target_uin"); v != nil {
143143
paramMap["TargetUin"] = helper.IntUint64(v.(int))
144144
}
145145

146-
if v, _ := d.GetOk("attach_type"); v != nil {
146+
if v, _ := d.GetOkExists("attach_type"); v != nil {
147147
paramMap["AttachType"] = helper.IntUint64(v.(int))
148148
}
149149

150-
if v, _ := d.GetOk("strategy_type"); v != nil {
150+
if v, _ := d.GetOkExists("strategy_type"); v != nil {
151151
paramMap["StrategyType"] = helper.IntUint64(v.(int))
152152
}
153153

tencentcloud/data_source_tc_cam_list_entities_for_policy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ func dataSourceTencentCloudCamListEntitiesForPolicyRead(d *schema.ResourceData,
9696
ctx := context.WithValue(context.TODO(), logIdKey, logId)
9797

9898
paramMap := make(map[string]interface{})
99-
if v, _ := d.GetOk("policy_id"); v != nil {
99+
if v, _ := d.GetOkExists("policy_id"); v != nil {
100100
paramMap["PolicyId"] = helper.IntUint64(v.(int))
101101
}
102102

103-
if v, _ := d.GetOk("rp"); v != nil {
103+
if v, _ := d.GetOkExists("rp"); v != nil {
104104
paramMap["Rp"] = helper.IntUint64(v.(int))
105105
}
106106

0 commit comments

Comments
 (0)