Skip to content

Commit 0e14f05

Browse files
WeiMengXSWeiMengXS
andauthored
Feat/organiztion update member (#2206)
* feat: add datasource * feat: add datasource * feat: changelog * feat: support update * feat: support update --------- Co-authored-by: WeiMengXS <nickcchen@tencent.com>
1 parent 2ee8ca9 commit 0e14f05

12 files changed

+776
-31
lines changed

.changelog/2206.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_month
3+
```
4+
5+
```release-note:new-data-source
6+
tencentcloud_organization_org_financial_by_product
7+
```
8+
9+
```release-note:enhancement
10+
tencentcloud_organization_org_member: support api `UpdateOrganizationMember`
11+
```
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/*
2+
Use this data source to query detailed information of organization org_financial_by_month
3+
4+
Example Usage
5+
6+
```hcl
7+
8+
data "tencentcloud_organization_org_financial_by_month" "org_financial_by_month" {
9+
end_month = "2023-05"
10+
member_uins = [100026517717]
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 dataSourceTencentCloudOrganizationOrgFinancialByMonth() *schema.Resource {
26+
return &schema.Resource{
27+
Read: dataSourceTencentCloudOrganizationOrgFinancialByMonthRead,
28+
Schema: map[string]*schema.Schema{
29+
"end_month": {
30+
Optional: true,
31+
Type: schema.TypeString,
32+
Description: "Query for the end month. Format:yyyy-mm, for example:2021-01.",
33+
},
34+
35+
"member_uins": {
36+
Optional: true,
37+
Type: schema.TypeSet,
38+
Elem: &schema.Schema{
39+
Type: schema.TypeInt,
40+
},
41+
Description: "Member uin list. Up to 100.",
42+
},
43+
44+
"product_codes": {
45+
Optional: true,
46+
Type: schema.TypeSet,
47+
Elem: &schema.Schema{
48+
Type: schema.TypeString,
49+
},
50+
Description: "Product code list. Up to 100.",
51+
},
52+
53+
"items": {
54+
Computed: true,
55+
Type: schema.TypeList,
56+
Description: "Organization financial info by month.",
57+
Elem: &schema.Resource{
58+
Schema: map[string]*schema.Schema{
59+
"id": {
60+
Type: schema.TypeInt,
61+
Computed: true,
62+
Description: "Record ID.",
63+
},
64+
"month": {
65+
Type: schema.TypeString,
66+
Computed: true,
67+
Description: "Month.",
68+
},
69+
"total_cost": {
70+
Type: schema.TypeFloat,
71+
Computed: true,
72+
Description: "Total cost of the month.",
73+
},
74+
"growth_rate": {
75+
Type: schema.TypeString,
76+
Computed: true,
77+
Description: "Growth rate compared to last month.",
78+
},
79+
},
80+
},
81+
},
82+
83+
"result_output_file": {
84+
Type: schema.TypeString,
85+
Optional: true,
86+
Description: "Used to save results.",
87+
},
88+
},
89+
}
90+
}
91+
92+
func dataSourceTencentCloudOrganizationOrgFinancialByMonthRead(d *schema.ResourceData, meta interface{}) error {
93+
defer logElapsed("data_source.tencentcloud_organization_org_financial_by_month.read")()
94+
defer inconsistentCheck(d, meta)()
95+
96+
logId := getLogId(contextNil)
97+
98+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
99+
100+
paramMap := make(map[string]interface{})
101+
if v, ok := d.GetOk("end_month"); ok {
102+
paramMap["EndMonth"] = helper.String(v.(string))
103+
}
104+
105+
if v, ok := d.GetOk("member_uins"); ok {
106+
memberUinsSet := v.(*schema.Set).List()
107+
paramMap["MemberUins"] = helper.InterfacesIntInt64Point(memberUinsSet)
108+
}
109+
110+
if v, ok := d.GetOk("product_codes"); ok {
111+
productCodesSet := v.(*schema.Set).List()
112+
paramMap["ProductCodes"] = helper.InterfacesStringsPoint(productCodesSet)
113+
}
114+
115+
service := OrganizationService{client: meta.(*TencentCloudClient).apiV3Conn}
116+
117+
var items []*organization.OrgFinancialByMonth
118+
119+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
120+
result, e := service.DescribeOrganizationOrgFinancialByMonthByFilter(ctx, paramMap)
121+
if e != nil {
122+
return retryError(e)
123+
}
124+
items = result
125+
return nil
126+
})
127+
if err != nil {
128+
return err
129+
}
130+
131+
ids := make([]string, 0, len(items))
132+
tmpList := make([]map[string]interface{}, 0, len(items))
133+
134+
if items != nil {
135+
for _, orgFinancialByMonth := range items {
136+
orgFinancialByMonthMap := map[string]interface{}{}
137+
138+
if orgFinancialByMonth.Id != nil {
139+
orgFinancialByMonthMap["id"] = orgFinancialByMonth.Id
140+
}
141+
142+
if orgFinancialByMonth.Month != nil {
143+
orgFinancialByMonthMap["month"] = orgFinancialByMonth.Month
144+
}
145+
146+
if orgFinancialByMonth.TotalCost != nil {
147+
orgFinancialByMonthMap["total_cost"] = orgFinancialByMonth.TotalCost
148+
}
149+
150+
if orgFinancialByMonth.GrowthRate != nil {
151+
orgFinancialByMonthMap["growth_rate"] = orgFinancialByMonth.GrowthRate
152+
}
153+
154+
ids = append(ids, *orgFinancialByMonth.Month)
155+
tmpList = append(tmpList, orgFinancialByMonthMap)
156+
}
157+
158+
_ = d.Set("items", tmpList)
159+
}
160+
161+
d.SetId(helper.DataResourceIdsHash(ids))
162+
output, ok := d.GetOk("result_output_file")
163+
if ok && output.(string) != "" {
164+
if e := writeToFile(output.(string), tmpList); e != nil {
165+
return e
166+
}
167+
}
168+
return nil
169+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudOrganizationOrgFinancialByMonthDataSource_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: testAccOrganizationOrgFinancialByMonthDataSource,
19+
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_organization_org_financial_by_month.org_financial_by_month"),
20+
resource.TestCheckResourceAttr("data.tencentcloud_organization_org_financial_by_month.org_financial_by_month", "end_month", "2023-05"),
21+
resource.TestCheckResourceAttrSet("data.tencentcloud_organization_org_financial_by_month.org_financial_by_month", "member_uins.#"),
22+
resource.TestCheckResourceAttr("data.tencentcloud_organization_org_financial_by_month.org_financial_by_month", "member_uins.0", "100026517717"),
23+
),
24+
},
25+
},
26+
})
27+
}
28+
29+
const testAccOrganizationOrgFinancialByMonthDataSource = `
30+
31+
data "tencentcloud_organization_org_financial_by_month" "org_financial_by_month" {
32+
end_month = "2023-05"
33+
member_uins = [100026517717]
34+
}
35+
36+
`

0 commit comments

Comments
 (0)