Skip to content

Commit 7d7a134

Browse files
authored
feat(tco): [126756602] add new resource (#3492)
* add * add * add * add
1 parent 037bb8c commit 7d7a134

19 files changed

+1033
-348
lines changed

.changelog/3492.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
tencentcloud_organization_member_auth_policy_attachment
3+
```

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ require (
4646
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1107
4747
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033
4848
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1148
49-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.13
49+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.14
5050
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1206
5151
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
5252
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.1161
@@ -69,7 +69,7 @@ require (
6969
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mongodb v1.0.1096
7070
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor v1.0.1149
7171
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mps v1.0.853
72-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.1.8
72+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.1.14
7373
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.1156
7474
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/privatedns v1.0.1038
7575
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/pts v1.0.762

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.8 h1:Qxwajp
955955
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.8/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
956956
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.13 h1:xQc87gs85w3Rj7rhT83YvoLpVRzsmUHNmm05ti6cVKI=
957957
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.13/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
958+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.14 h1:+I+n8wDpnG95yLnV3rtT4MUs8gdwgbpuZEVKQhSxqxs=
959+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.14/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
958960
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993 h1:WlPgXldQCxt7qi5Xrc6j6zTrsXWzN5BcOGs7Irq7fwQ=
959961
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993/go.mod h1:Z9U8zNtyuyKhjS0698wqsrG/kLx1TQ5CEixXBwVe7xY=
960962
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860 h1:F3esKBIT3HW9+7Gt8cVgf8X06VdGIczpgLBUECzSEzU=
@@ -1024,6 +1026,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.1.0 h1:
10241026
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.1.0/go.mod h1:aJQSSfZOC9JLE19cH0ypZuipGaTQLMazzf6BGyqCl+0=
10251027
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.1.8 h1:8jEpC3Oa4s3B94ME97URLw4Qufwv1x8WS284nZAWNoI=
10261028
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.1.8/go.mod h1:5j1DRgOuOlxM54zVCDtiLM8WMYvFyhOuQM/PzWugUqA=
1029+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.1.14 h1:vmvzSrR90cbhhxYkfJNs+OLJigfnPCW8cQtmOk8CZ1M=
1030+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.1.14/go.mod h1:KI5v7d+FJCm06dmIqJJInxluDS0W5hV/GesQn4YiJYM=
10271031
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.1156 h1:zf/4a8G7E7RlVaGCVyjVkljX5P4gjNJymQkHoEzhjs4=
10281032
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.1156/go.mod h1:B1+7f2z0qF8G2EjFzPXtqHK3tPbzqb2y725eW1wIkaM=
10291033
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/privatedns v1.0.1038 h1:4rzyVxkDB27v73jDXPr5eGAwjN859R7SsqniCt+46XE=

tencentcloud/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,6 +2020,7 @@ func Provider() *schema.Provider {
20202020
"tencentcloud_identity_center_scim_credential": tco.ResourceTencentCloudIdentityCenterScimCredential(),
20212021
"tencentcloud_identity_center_scim_synchronization_status": tco.ResourceTencentCloudIdentityCenterScimSynchronizationStatus(),
20222022
"tencentcloud_provision_role_configuration_operation": tco.ResourceTencentCloudProvisionRoleConfigurationOperation(),
2023+
"tencentcloud_organization_member_auth_policy_attachment": tco.ResourceTencentCloudOrganizationMemberAuthPolicyAttachment(),
20232024
"tencentcloud_dbbrain_sql_filter": dbbrain.ResourceTencentCloudDbbrainSqlFilter(),
20242025
"tencentcloud_dbbrain_security_audit_log_export_task": dbbrain.ResourceTencentCloudDbbrainSecurityAuditLogExportTask(),
20252026
"tencentcloud_dbbrain_db_diag_report_task": dbbrain.ResourceTencentCloudDbbrainDbDiagReportTask(),

tencentcloud/provider.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,7 @@ tencentcloud_organization_org_share_unit_resource
17991799
tencentcloud_accept_join_share_unit_invitation_operation
18001800
tencentcloud_reject_join_share_unit_invitation_operation
18011801
tencentcloud_provision_role_configuration_operation
1802+
tencentcloud_organization_member_auth_policy_attachment
18021803

18031804
TDSQL-C for PostgreSQL(TDCPG)
18041805
Data Source
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
package tco
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"log"
7+
"strings"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
11+
organizationv20210331 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization/v20210331"
12+
13+
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
14+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
15+
)
16+
17+
func ResourceTencentCloudOrganizationMemberAuthPolicyAttachment() *schema.Resource {
18+
return &schema.Resource{
19+
Create: resourceTencentCloudOrganizationMemberAuthPolicyAttachmentCreate,
20+
Read: resourceTencentCloudOrganizationMemberAuthPolicyAttachmentRead,
21+
Delete: resourceTencentCloudOrganizationMemberAuthPolicyAttachmentDelete,
22+
Importer: &schema.ResourceImporter{
23+
State: schema.ImportStatePassthrough,
24+
},
25+
Schema: map[string]*schema.Schema{
26+
"policy_id": {
27+
Type: schema.TypeInt,
28+
Required: true,
29+
ForceNew: true,
30+
Description: "Pilicy ID.",
31+
},
32+
33+
"org_sub_account_uin": {
34+
Type: schema.TypeInt,
35+
Required: true,
36+
ForceNew: true,
37+
Description: "Organization administrator sub-account Uin.",
38+
},
39+
40+
// computed
41+
"identity_id": {
42+
Type: schema.TypeInt,
43+
Computed: true,
44+
Description: "Identity ID.",
45+
},
46+
47+
"identity_role_name": {
48+
Type: schema.TypeString,
49+
Computed: true,
50+
Description: "Identity role name.",
51+
},
52+
53+
"identity_role_alias_name": {
54+
Type: schema.TypeString,
55+
Computed: true,
56+
Description: "Identity role alias name.",
57+
},
58+
59+
"create_time": {
60+
Type: schema.TypeString,
61+
Computed: true,
62+
Description: "Create time.",
63+
},
64+
65+
"policy_name": {
66+
Type: schema.TypeString,
67+
Computed: true,
68+
Description: "Policy name.",
69+
},
70+
71+
"member_uin": {
72+
Type: schema.TypeInt,
73+
Computed: true,
74+
Description: "Member UIN.",
75+
},
76+
77+
"member_name": {
78+
Type: schema.TypeString,
79+
Computed: true,
80+
Description: "Member name.",
81+
},
82+
83+
"org_sub_account_name": {
84+
Type: schema.TypeString,
85+
Computed: true,
86+
Description: "Org sub account name.",
87+
},
88+
89+
"bind_type": {
90+
Type: schema.TypeInt,
91+
Computed: true,
92+
Description: "Bind type. 1-Subaccount, 2-User Group.",
93+
},
94+
},
95+
}
96+
}
97+
98+
func resourceTencentCloudOrganizationMemberAuthPolicyAttachmentCreate(d *schema.ResourceData, meta interface{}) error {
99+
defer tccommon.LogElapsed("resource.tencentcloud_organization_member_auth_policy_attachment.create")()
100+
defer tccommon.InconsistentCheck(d, meta)()
101+
102+
var (
103+
logId = tccommon.GetLogId(tccommon.ContextNil)
104+
ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)
105+
request = organizationv20210331.NewBindOrganizationPolicySubAccountRequest()
106+
policyId string
107+
orgSubAccountUin string
108+
)
109+
110+
if v, ok := d.GetOkExists("policy_id"); ok {
111+
request.PolicyId = helper.IntInt64(v.(int))
112+
policyId = helper.IntToStr(v.(int))
113+
}
114+
115+
if v, ok := d.GetOkExists("org_sub_account_uin"); ok {
116+
request.OrgSubAccountUins = append(request.OrgSubAccountUins, helper.IntInt64(v.(int)))
117+
orgSubAccountUin = helper.IntToStr(v.(int))
118+
}
119+
120+
reqErr := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
121+
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseOrganizationClient().BindOrganizationPolicySubAccountWithContext(ctx, request)
122+
if e != nil {
123+
return tccommon.RetryError(e)
124+
} else {
125+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
126+
}
127+
128+
return nil
129+
})
130+
131+
if reqErr != nil {
132+
log.Printf("[CRITAL]%s create organization members auth policy attachment failed, reason:%+v", logId, reqErr)
133+
return reqErr
134+
}
135+
136+
d.SetId(strings.Join([]string{policyId, orgSubAccountUin}, tccommon.FILED_SP))
137+
return resourceTencentCloudOrganizationMemberAuthPolicyAttachmentRead(d, meta)
138+
}
139+
140+
func resourceTencentCloudOrganizationMemberAuthPolicyAttachmentRead(d *schema.ResourceData, meta interface{}) error {
141+
defer tccommon.LogElapsed("resource.tencentcloud_organization_member_auth_policy_attachment.read")()
142+
defer tccommon.InconsistentCheck(d, meta)()
143+
144+
var (
145+
logId = tccommon.GetLogId(tccommon.ContextNil)
146+
ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)
147+
service = OrganizationService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
148+
)
149+
150+
idSplit := strings.Split(d.Id(), tccommon.FILED_SP)
151+
if len(idSplit) != 2 {
152+
return fmt.Errorf("id is broken,%s", d.Id())
153+
}
154+
155+
policyId := idSplit[0]
156+
orgSubAccountUin := idSplit[1]
157+
158+
respData, err := service.DescribeOrganizationMembersAuthPolicyAttachmentById(ctx, policyId, orgSubAccountUin)
159+
if err != nil {
160+
return err
161+
}
162+
163+
if respData == nil {
164+
log.Printf("[WARN]%s resource `tencentcloud_organization_member_auth_policy_attachment` [%s] not found, please check if it has been deleted.\n", logId, d.Id())
165+
d.SetId("")
166+
return nil
167+
}
168+
169+
if len(respData) != 1 {
170+
return fmt.Errorf("Query organization members auth policy attachment by id return more than one.")
171+
}
172+
173+
for _, item := range respData {
174+
if item.PolicyId != nil {
175+
_ = d.Set("policy_id", item.PolicyId)
176+
}
177+
178+
if item.OrgSubAccountUin != nil {
179+
_ = d.Set("org_sub_account_uin", item.OrgSubAccountUin)
180+
}
181+
182+
if item.IdentityId != nil {
183+
_ = d.Set("identity_id", item.IdentityId)
184+
}
185+
186+
if item.IdentityRoleName != nil {
187+
_ = d.Set("identity_role_name", item.IdentityRoleName)
188+
}
189+
190+
if item.IdentityRoleAliasName != nil {
191+
_ = d.Set("identity_role_alias_name", item.IdentityRoleAliasName)
192+
}
193+
194+
if item.CreateTime != nil {
195+
_ = d.Set("create_time", item.CreateTime)
196+
}
197+
198+
if item.PolicyName != nil {
199+
_ = d.Set("policy_name", item.PolicyName)
200+
}
201+
202+
if item.MemberUin != nil {
203+
_ = d.Set("member_uin", item.MemberUin)
204+
}
205+
206+
if item.MemberName != nil {
207+
_ = d.Set("member_name", item.MemberName)
208+
}
209+
210+
if item.OrgSubAccountName != nil {
211+
_ = d.Set("org_sub_account_name", item.OrgSubAccountName)
212+
}
213+
214+
if item.BindType != nil {
215+
_ = d.Set("bind_type", item.BindType)
216+
}
217+
}
218+
219+
return nil
220+
}
221+
222+
func resourceTencentCloudOrganizationMemberAuthPolicyAttachmentDelete(d *schema.ResourceData, meta interface{}) error {
223+
defer tccommon.LogElapsed("resource.tencentcloud_organization_member_auth_policy_attachment.delete")()
224+
defer tccommon.InconsistentCheck(d, meta)()
225+
226+
var (
227+
logId = tccommon.GetLogId(tccommon.ContextNil)
228+
ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)
229+
request = organizationv20210331.NewCancelOrganizationPolicySubAccountRequest()
230+
)
231+
232+
idSplit := strings.Split(d.Id(), tccommon.FILED_SP)
233+
if len(idSplit) != 2 {
234+
return fmt.Errorf("id is broken,%s", d.Id())
235+
}
236+
237+
policyId := idSplit[0]
238+
orgSubAccountUin := idSplit[1]
239+
240+
request.PolicyId = helper.StrToInt64Point(policyId)
241+
request.OrgSubAccountUins = append(request.OrgSubAccountUins, helper.StrToInt64Point(orgSubAccountUin))
242+
reqErr := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
243+
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseOrganizationClient().CancelOrganizationPolicySubAccountWithContext(ctx, request)
244+
if e != nil {
245+
return tccommon.RetryError(e)
246+
} else {
247+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
248+
}
249+
250+
return nil
251+
})
252+
253+
if reqErr != nil {
254+
log.Printf("[CRITAL]%s delete organization members auth policy attachment failed, reason:%+v", logId, reqErr)
255+
return reqErr
256+
}
257+
258+
return nil
259+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Provides a resource to create a Organization member auth policy attachment
2+
3+
Example Usage
4+
5+
```hcl
6+
resource "tencentcloud_organization_member_auth_policy_attachment" "example" {
7+
policy_id = 252421751
8+
org_sub_account_uin = 100037718939
9+
}
10+
```
11+
12+
Import
13+
14+
Organization member auth policy attachment can be imported using the id, e.g.
15+
16+
```
17+
terraform import tencentcloud_organization_member_auth_policy_attachment.example 252421751#100037718939
18+
```
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package tco_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
8+
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
9+
)
10+
11+
func TestAccTencentCloudOrganizationMemberAuthPolicyAttachmentResource_basic(t *testing.T) {
12+
t.Parallel()
13+
resource.Test(t, resource.TestCase{
14+
PreCheck: func() {
15+
tcacctest.AccPreCheck(t)
16+
},
17+
Providers: tcacctest.AccProviders,
18+
Steps: []resource.TestStep{
19+
{
20+
Config: testAccOrganizationMemberAuthPolicyAttachment,
21+
Check: resource.ComposeTestCheckFunc(
22+
resource.TestCheckResourceAttrSet("tencentcloud_organization_member_auth_policy_attachment.example", "id"),
23+
resource.TestCheckResourceAttrSet("tencentcloud_organization_member_auth_policy_attachment.example", "policy_id"),
24+
resource.TestCheckResourceAttrSet("tencentcloud_organization_member_auth_policy_attachment.example", "org_sub_account_uin"),
25+
),
26+
},
27+
{
28+
ResourceName: "tencentcloud_organization_member_auth_policy_attachment.example",
29+
ImportState: true,
30+
ImportStateVerify: true,
31+
},
32+
},
33+
})
34+
}
35+
36+
const testAccOrganizationMemberAuthPolicyAttachment = `
37+
resource "tencentcloud_organization_member_auth_policy_attachment" "example" {
38+
policy_id = 250021751
39+
org_sub_account_uin = 100037718139
40+
}
41+
`

0 commit comments

Comments
 (0)