Skip to content

Commit 5df751c

Browse files
WeiMengXSWeiMengXS
andauthored
Feat/orgiaztion 2 (#2198)
* feat: organization inc * feat: organization email * feat: organization email * feat: organization email * feat: organization email * fix: test --------- Co-authored-by: WeiMengXS <nickcchen@tencent.com>
1 parent a81c9ed commit 5df751c

17 files changed

+1266
-5
lines changed

.changelog/2198.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```release-note:new-data-source
2+
tencentcloud_organization_org_financial_by_member
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_organization_instance
7+
```
8+
9+
```release-note:new-resource
10+
tencentcloud_organization_org_member_email
11+
```

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ require (
4545
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.693
4646
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
4747
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.711
48-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.762
48+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.763
4949
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624
5050
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
5151
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.692
@@ -68,7 +68,7 @@ require (
6868
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mongodb v1.0.651
6969
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor v1.0.734
7070
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mps v1.0.758
71-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.0.762
71+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.0.763
7272
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.676
7373
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/privatedns v1.0.751
7474
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/pts v1.0.533

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.762 h1:ixDQ
895895
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.762/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
896896
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.762 h1:ixDQofTbSDKpIwNI+yUgEUrUBH18m2Jb+ZQjFnTnAcU=
897897
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.762/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
898+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.763 h1:N+/GDFRlTSgufNGIotPcPRe1+tF0H94K0z11cleqhDg=
899+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.763/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
898900
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624 h1:nEZqsoqt1pEoaP9JjkHQy3/H00suCfzlHW1qOm2nYD8=
899901
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624/go.mod h1:+TXSVyeKwt1IhZRqKPbTREteBcP+K07Q846/ilNzLWA=
900902
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.589 h1:LZihgirMH0vsaGScYexxwY0fTss9vHaSZs/YOQUVESg=
@@ -953,6 +955,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.0.540 h
953955
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.0.540/go.mod h1:jHcHwlsdNL9ycLwNtqYZVjLKJILA1xuODMeMDMOxCrA=
954956
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.0.762 h1:WtI21wvdpyvyjC6cdqduQpxngsvo7irGd+2VzMhlOqk=
955957
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.0.762/go.mod h1:OT/tFn3z36vkvTkFOQOvYixU1z5A75ihJu6yUd5UJiM=
958+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.0.763 h1:Qfsu2gRG+rguebyfKqoBrfxBkzxazQymQtdf4Azl9ow=
959+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.0.763/go.mod h1:bR3aAS3kvCEJXgjWpMOocxMNDGoD+7Aue6BWN8TKZ40=
956960
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.676 h1:KDt87M2b8j/Xo/9o+kaVtJ46fOtPctCpMDa1CJpSlkY=
957961
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.676/go.mod h1:mXbqv53QFAhvyYqainXSAMdoCui5GudorFhKufJxITc=
958962
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/privatedns v1.0.751 h1:D2tcvMV9G8dWIoTybLeZoO3Xwz3tFa0A/cN1+glbMG4=
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/*
2+
Use this data source to query detailed information of organization org_financial_by_member
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_organization_org_financial_by_member" "org_financial_by_member" {
8+
month = "2023-05"
9+
end_month = "2023-10"
10+
member_uins = [100015591986,100029796005]
11+
}
12+
```
13+
*/
14+
package tencentcloud
15+
16+
import (
17+
"context"
18+
19+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
20+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
21+
organization "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization/v20210331"
22+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
23+
)
24+
25+
func dataSourceTencentCloudOrganizationOrgFinancialByMember() *schema.Resource {
26+
return &schema.Resource{
27+
Read: dataSourceTencentCloudOrganizationOrgFinancialByMemberRead,
28+
Schema: map[string]*schema.Schema{
29+
"month": {
30+
Required: true,
31+
Type: schema.TypeString,
32+
Description: "Query for the start month. Format:yyyy-mm, for example:2021-01.",
33+
},
34+
35+
"end_month": {
36+
Optional: true,
37+
Type: schema.TypeString,
38+
Description: "Query for the end month. Format:yyyy-mm, for example:2021-01.The default value is the `Month`.",
39+
},
40+
41+
"member_uins": {
42+
Optional: true,
43+
Type: schema.TypeSet,
44+
Elem: &schema.Schema{
45+
Type: schema.TypeInt,
46+
},
47+
Description: "Member uin list. Up to 100.",
48+
},
49+
50+
"product_codes": {
51+
Optional: true,
52+
Type: schema.TypeSet,
53+
Elem: &schema.Schema{
54+
Type: schema.TypeString,
55+
},
56+
Description: "Product code list. Up to 100.",
57+
},
58+
59+
"total_cost": {
60+
Computed: true,
61+
Type: schema.TypeFloat,
62+
Description: "Total cost of the member.",
63+
},
64+
65+
"items": {
66+
Computed: true,
67+
Type: schema.TypeList,
68+
Description: "Member financial detail.",
69+
Elem: &schema.Resource{
70+
Schema: map[string]*schema.Schema{
71+
"member_uin": {
72+
Type: schema.TypeInt,
73+
Computed: true,
74+
Description: "Member uin.",
75+
},
76+
"member_name": {
77+
Type: schema.TypeString,
78+
Computed: true,
79+
Description: "Member name.",
80+
},
81+
"total_cost": {
82+
Type: schema.TypeFloat,
83+
Computed: true,
84+
Description: "Total cost of the member.",
85+
},
86+
"ratio": {
87+
Type: schema.TypeString,
88+
Computed: true,
89+
Description: "The percentage of the organization total cost that is accounted for by the member.",
90+
},
91+
},
92+
},
93+
},
94+
95+
"result_output_file": {
96+
Type: schema.TypeString,
97+
Optional: true,
98+
Description: "Used to save results.",
99+
},
100+
},
101+
}
102+
}
103+
104+
func dataSourceTencentCloudOrganizationOrgFinancialByMemberRead(d *schema.ResourceData, meta interface{}) error {
105+
defer logElapsed("data_source.tencentcloud_organization_org_financial_by_member.read")()
106+
defer inconsistentCheck(d, meta)()
107+
108+
logId := getLogId(contextNil)
109+
110+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
111+
112+
paramMap := make(map[string]interface{})
113+
if v, ok := d.GetOk("month"); ok {
114+
paramMap["Month"] = helper.String(v.(string))
115+
}
116+
117+
if v, ok := d.GetOk("end_month"); ok {
118+
paramMap["EndMonth"] = helper.String(v.(string))
119+
}
120+
121+
if v, ok := d.GetOk("member_uins"); ok {
122+
memberUinsSet := v.(*schema.Set).List()
123+
paramMap["MemberUins"] = helper.InterfacesIntInt64Point(memberUinsSet)
124+
}
125+
126+
if v, ok := d.GetOk("product_codes"); ok {
127+
productCodesSet := v.(*schema.Set).List()
128+
paramMap["ProductCodes"] = helper.InterfacesStringsPoint(productCodesSet)
129+
}
130+
131+
service := OrganizationService{client: meta.(*TencentCloudClient).apiV3Conn}
132+
var response *organization.DescribeOrganizationFinancialByMemberResponseParams
133+
134+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
135+
result, e := service.DescribeOrganizationOrgFinancialByMemberByFilter(ctx, paramMap)
136+
if e != nil {
137+
return retryError(e)
138+
}
139+
response = result
140+
return nil
141+
})
142+
if err != nil {
143+
return err
144+
}
145+
146+
ids := make([]string, 0, len(response.Items))
147+
tmpList := make([]map[string]interface{}, 0, len(response.Items))
148+
if response.TotalCost != nil {
149+
_ = d.Set("total_cost", response.TotalCost)
150+
}
151+
152+
if response.Items != nil {
153+
for _, orgMemberFinancial := range response.Items {
154+
orgMemberFinancialMap := map[string]interface{}{}
155+
156+
if orgMemberFinancial.MemberUin != nil {
157+
orgMemberFinancialMap["member_uin"] = orgMemberFinancial.MemberUin
158+
}
159+
160+
if orgMemberFinancial.MemberName != nil {
161+
orgMemberFinancialMap["member_name"] = orgMemberFinancial.MemberName
162+
}
163+
164+
if orgMemberFinancial.TotalCost != nil {
165+
orgMemberFinancialMap["total_cost"] = orgMemberFinancial.TotalCost
166+
}
167+
168+
if orgMemberFinancial.Ratio != nil {
169+
orgMemberFinancialMap["ratio"] = orgMemberFinancial.Ratio
170+
}
171+
172+
ids = append(ids, helper.Int64ToStr(*orgMemberFinancial.MemberUin))
173+
tmpList = append(tmpList, orgMemberFinancialMap)
174+
}
175+
176+
_ = d.Set("items", tmpList)
177+
}
178+
179+
d.SetId(helper.DataResourceIdsHash(ids))
180+
output, ok := d.GetOk("result_output_file")
181+
if ok && output.(string) != "" {
182+
if e := writeToFile(output.(string), tmpList); e != nil {
183+
return e
184+
}
185+
}
186+
return nil
187+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudOrganizationOrgFinancialByMemberDataSource_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: testAccOrganizationOrgFinancialByMemberDataSource,
19+
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_organization_org_financial_by_member.org_financial_by_member")),
20+
},
21+
},
22+
})
23+
}
24+
25+
const testAccOrganizationOrgFinancialByMemberDataSource = `
26+
27+
data "tencentcloud_organization_org_financial_by_member" "org_financial_by_member" {
28+
month = "2023-05"
29+
end_month = "2023-10"
30+
member_uins = [100015591986,100029796005]
31+
}
32+
33+
`

tencentcloud/provider.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,11 +1387,14 @@ TencentCloud Automation Tools(TAT)
13871387
Tencent Cloud Organization (TCO)
13881388
Data Source
13891389
tencentcloud_organization_org_auth_node
1390+
tencentcloud_organization_org_financial_by_member
13901391
Resource
13911392
tencentcloud_organization_org_node
13921393
tencentcloud_organization_org_member
1393-
tencentcloud_organization_policy_sub_account_attachment
1394+
tencentcloud_organization_instance
1395+
tencentcloud_organization_org_member_email
13941396
tencentcloud_organization_org_member_auth_identity_attachment
1397+
tencentcloud_organization_policy_sub_account_attachment
13951398
13961399
TDSQL-C for PostgreSQL(TDCPG)
13971400
Data Source
@@ -2452,6 +2455,7 @@ func Provider() *schema.Provider {
24522455
"tencentcloud_ses_black_email_address": dataSourceTencentCloudSesBlackEmailAddress(),
24532456
"tencentcloud_ses_statistics_report": dataSourceTencentCloudSesStatisticsReport(),
24542457
"tencentcloud_ses_send_email_status": dataSourceTencentCloudSesSendEmailStatus(),
2458+
"tencentcloud_organization_org_financial_by_member": dataSourceTencentCloudOrganizationOrgFinancialByMember(),
24552459
"tencentcloud_organization_org_auth_node": dataSourceTencentCloudOrganizationOrgAuthNode(),
24562460
},
24572461

@@ -3030,6 +3034,8 @@ func Provider() *schema.Provider {
30303034
"tencentcloud_tat_invocation_command_attachment": resourceTencentCloudTatInvocationCommandAttachment(),
30313035
"tencentcloud_organization_org_node": resourceTencentCloudOrganizationOrgNode(),
30323036
"tencentcloud_organization_org_member": resourceTencentCloudOrganizationOrgMember(),
3037+
"tencentcloud_organization_org_member_email": resourceTencentCloudOrganizationOrgMemberEmail(),
3038+
"tencentcloud_organization_instance": resourceTencentCloudOrganizationOrganization(),
30333039
"tencentcloud_organization_policy_sub_account_attachment": resourceTencentCloudOrganizationPolicySubAccountAttachment(),
30343040
"tencentcloud_organization_org_member_auth_identity_attachment": resourceTencentCloudOrganizationOrgMemberAuthIdentityAttachment(),
30353041
"tencentcloud_dbbrain_sql_filter": resourceTencentCloudDbbrainSqlFilter(),

0 commit comments

Comments
 (0)