-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy pathdata_source_tc_cam_account_summary.go
124 lines (103 loc) · 3.2 KB
/
data_source_tc_cam_account_summary.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package cam
import (
"context"
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
cam "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam/v20190116"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)
func DataSourceTencentCloudCamAccountSummary() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudCamAccountSummaryRead,
Schema: map[string]*schema.Schema{
"policies": {
Computed: true,
Type: schema.TypeInt,
Description: "The number of policy.",
},
"roles": {
Computed: true,
Type: schema.TypeInt,
Description: "The number of role.",
},
"user": {
Computed: true,
Type: schema.TypeInt,
Description: "The number of Sub-user.",
},
"group": {
Computed: true,
Type: schema.TypeInt,
Description: "The number of Group.",
},
"member": {
Computed: true,
Type: schema.TypeInt,
Description: "The number of grouped users.",
},
"identity_providers": {
Computed: true,
Type: schema.TypeInt,
Description: "The number of identity provider.",
},
"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},
},
}
}
func dataSourceTencentCloudCamAccountSummaryRead(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("data_source.tencentcloud_cam_account_summary.read")()
defer tccommon.InconsistentCheck(d, meta)()
logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
service := CamService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
AccountData := &cam.GetAccountSummaryResponseParams{}
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeCamAccountSummaryByFilter(ctx)
if e != nil {
return tccommon.RetryError(e)
}
AccountData = result
return nil
})
if err != nil {
return err
}
template := make(map[string]interface{}, 0)
if AccountData.Policies != nil {
_ = d.Set("policies", AccountData.Policies)
template["policies"] = AccountData.Policies
}
if AccountData.Roles != nil {
_ = d.Set("roles", AccountData.Roles)
template["roles"] = AccountData.Roles
}
if AccountData.User != nil {
_ = d.Set("user", AccountData.User)
template["user"] = AccountData.User
}
if AccountData.Group != nil {
_ = d.Set("group", AccountData.Group)
template["group"] = AccountData.Group
}
if AccountData.Member != nil {
_ = d.Set("member", AccountData.Member)
template["member"] = AccountData.Member
}
if AccountData.IdentityProviders != nil {
_ = d.Set("identity_providers", AccountData.IdentityProviders)
template["identity_providers"] = AccountData.IdentityProviders
}
d.SetId(helper.BuildToken())
output, ok := d.GetOk("result_output_file")
if ok && output.(string) != "" {
if e := tccommon.WriteToFile(output.(string), template); e != nil {
return e
}
}
return nil
}