Skip to content

Commit 2f09790

Browse files
committed
feat(tco): add resource_tc_organization_org_manage_policy_config
feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config feat(tco): add resource_tc_organization_org_manage_policy_config
1 parent 1deb86a commit 2f09790

12 files changed

+747
-7
lines changed

.changelog/2603.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

.changelog/2604.txt

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

.github/workflows/golangci-lint.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ jobs:
1818
# This workflow contains a single job called "build"
1919
golangci-lint:
2020
# The type of runner that the job will run on
21-
runs-on: macos-latest
22-
21+
runs-on: macos-12
22+
2323
# Steps represent a sequence of tasks that will be executed as part of the job
2424
steps:
2525
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
@@ -32,7 +32,7 @@ jobs:
3232
with:
3333
go-version-file: .go-version
3434
#go-version: '1.21'
35-
cache: false
35+
cache: false
3636

3737
# Runs a set of commands using the runners shell
3838
- name: golangci-lint
@@ -42,4 +42,4 @@ jobs:
4242
#version: v1.54
4343
working-directory: ./tencentcloud
4444
args: --new-from-rev=origin/master -v
45-
#args: --enable-all --max-same-issues=0 --max-issues-per-linter=0 --new-from-rev=origin/master -v
45+
#args: --enable-all --max-same-issues=0 --max-issues-per-linter=0 --new-from-rev=origin/master -v

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,8 @@ func Provider() *schema.Provider {
16511651
"tencentcloud_organization_org_member_auth_identity_attachment": tco.ResourceTencentCloudOrganizationOrgMemberAuthIdentityAttachment(),
16521652
"tencentcloud_organization_org_member_policy_attachment": tco.ResourceTencentCloudOrganizationOrgMemberPolicyAttachment(),
16531653
"tencentcloud_organization_org_manage_policy_config": tco.ResourceTencentCloudOrganizationOrgManagePolicyConfig(),
1654+
"tencentcloud_organization_org_manage_policy": tco.ResourceTencentCloudOrganizationOrgManagePolicy(),
1655+
"tencentcloud_organization_org_manage_policy_target": tco.ResourceTencentCloudOrganizationOrgManagePolicyTarget(),
16541656
"tencentcloud_dbbrain_sql_filter": dbbrain.ResourceTencentCloudDbbrainSqlFilter(),
16551657
"tencentcloud_dbbrain_security_audit_log_export_task": dbbrain.ResourceTencentCloudDbbrainSecurityAuditLogExportTask(),
16561658
"tencentcloud_dbbrain_db_diag_report_task": dbbrain.ResourceTencentCloudDbbrainDbDiagReportTask(),

tencentcloud/services/tco/extension_tco.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,12 @@ const (
66

77
ServiceControlPolicyCode = 0
88
TagPolicyCode = 1
9+
10+
PAGE_ITEM = 200
11+
12+
TargetTypeNode = "NODE"
13+
TargetTypeMember = "MEMBER"
14+
15+
DescribeTargetTypeNode = "Node"
16+
DescribeTargetTypeMember = "User"
917
)
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
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+
organization "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 ResourceTencentCloudOrganizationOrgManagePolicy() *schema.Resource {
18+
return &schema.Resource{
19+
Create: resourceTencentCloudOrganizationOrgManagePolicyCreate,
20+
Read: resourceTencentCloudOrganizationOrgManagePolicyRead,
21+
Update: resourceTencentCloudOrganizationOrgManagePolicyUpdate,
22+
Delete: resourceTencentCloudOrganizationOrgManagePolicyDelete,
23+
Importer: &schema.ResourceImporter{
24+
State: schema.ImportStatePassthrough,
25+
},
26+
Schema: map[string]*schema.Schema{
27+
"name": {
28+
Required: true,
29+
Type: schema.TypeString,
30+
Description: "Policy name.\nThe length is 1~128 characters, which can include Chinese characters, English letters, numbers, and underscores.",
31+
},
32+
33+
"content": {
34+
Required: true,
35+
Type: schema.TypeString,
36+
Description: "Policy content. Refer to the CAM policy syntax.",
37+
},
38+
39+
"type": {
40+
Optional: true,
41+
Default: ServiceControlPolicyType,
42+
Type: schema.TypeString,
43+
Description: "Policy type. Default value is SERVICE_CONTROL_POLICY.\nValid values:\n - `SERVICE_CONTROL_POLICY`: Service control policy.\n - `TAG_POLICY`: Tag policy.",
44+
},
45+
46+
"description": {
47+
Optional: true,
48+
Type: schema.TypeString,
49+
Description: "Policy description.",
50+
},
51+
52+
"policy_id": {
53+
Computed: true,
54+
Type: schema.TypeString,
55+
Description: "Policy Id.",
56+
},
57+
},
58+
}
59+
}
60+
61+
func resourceTencentCloudOrganizationOrgManagePolicyCreate(d *schema.ResourceData, meta interface{}) error {
62+
defer tccommon.LogElapsed("resource.tencentcloud_organization_org_manage_policy.create")()
63+
defer tccommon.InconsistentCheck(d, meta)()
64+
65+
logId := tccommon.GetLogId(tccommon.ContextNil)
66+
67+
var (
68+
policyType string
69+
request = organization.NewCreatePolicyRequest()
70+
response = organization.NewCreatePolicyResponse()
71+
)
72+
if v, ok := d.GetOk("name"); ok {
73+
request.Name = helper.String(v.(string))
74+
}
75+
76+
if v, ok := d.GetOk("content"); ok {
77+
request.Content = helper.String(v.(string))
78+
}
79+
80+
if v, ok := d.GetOk("type"); ok {
81+
policyType = v.(string)
82+
request.Type = helper.String(v.(string))
83+
}
84+
85+
if v, ok := d.GetOk("description"); ok {
86+
request.Description = helper.String(v.(string))
87+
}
88+
89+
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
90+
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseOrganizationClient().CreatePolicy(request)
91+
if e != nil {
92+
return tccommon.RetryError(e)
93+
} else {
94+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
95+
}
96+
response = result
97+
return nil
98+
})
99+
if err != nil {
100+
log.Printf("[CRITAL]%s create organization OrgManagePolicy failed, reason:%+v", logId, err)
101+
return err
102+
}
103+
104+
d.SetId(strings.Join([]string{helper.UInt64ToStr(*response.Response.PolicyId), policyType}, tccommon.FILED_SP))
105+
return resourceTencentCloudOrganizationOrgManagePolicyRead(d, meta)
106+
}
107+
108+
func resourceTencentCloudOrganizationOrgManagePolicyRead(d *schema.ResourceData, meta interface{}) error {
109+
defer tccommon.LogElapsed("resource.tencentcloud_organization_org_manage_policy.read")()
110+
defer tccommon.InconsistentCheck(d, meta)()
111+
112+
logId := tccommon.GetLogId(tccommon.ContextNil)
113+
114+
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
115+
116+
service := OrganizationService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
117+
118+
idSplit := strings.Split(d.Id(), tccommon.FILED_SP)
119+
if len(idSplit) != 2 {
120+
return fmt.Errorf("id is broken,%s", d.Id())
121+
}
122+
policyId := idSplit[0]
123+
policyType := idSplit[1]
124+
125+
OrgManagePolicy, err := service.DescribeOrganizationOrgManagePolicyById(ctx, policyId, policyType)
126+
if err != nil {
127+
return err
128+
}
129+
130+
if OrgManagePolicy == nil {
131+
d.SetId("")
132+
log.Printf("[WARN]%s resource `OrganizationOrgManagePolicy` [%s] not found, please check if it has been deleted.\n", logId, d.Id())
133+
return nil
134+
}
135+
136+
if OrgManagePolicy.PolicyName != nil {
137+
_ = d.Set("name", OrgManagePolicy.PolicyName)
138+
}
139+
140+
if OrgManagePolicy.PolicyDocument != nil {
141+
_ = d.Set("content", OrgManagePolicy.PolicyDocument)
142+
}
143+
144+
if OrgManagePolicy.Type != nil {
145+
_ = d.Set("type", policyType)
146+
}
147+
148+
if OrgManagePolicy.Description != nil {
149+
_ = d.Set("description", OrgManagePolicy.Description)
150+
}
151+
_ = d.Set("policy_id", policyId)
152+
153+
return nil
154+
}
155+
156+
func resourceTencentCloudOrganizationOrgManagePolicyUpdate(d *schema.ResourceData, meta interface{}) error {
157+
defer tccommon.LogElapsed("resource.tencentcloud_organization_org_manage_policy.update")()
158+
defer tccommon.InconsistentCheck(d, meta)()
159+
160+
logId := tccommon.GetLogId(tccommon.ContextNil)
161+
162+
request := organization.NewUpdatePolicyRequest()
163+
164+
idSplit := strings.Split(d.Id(), tccommon.FILED_SP)
165+
if len(idSplit) != 2 {
166+
return fmt.Errorf("id is broken,%s", d.Id())
167+
}
168+
policyId := idSplit[0]
169+
170+
request.PolicyId = helper.StrToInt64Point(policyId)
171+
172+
needChange := false
173+
mutableArgs := []string{"name", "content", "type", "description"}
174+
for _, v := range mutableArgs {
175+
if d.HasChange(v) {
176+
needChange = true
177+
break
178+
}
179+
}
180+
181+
if needChange {
182+
if v, ok := d.GetOk("name"); ok {
183+
request.Name = helper.String(v.(string))
184+
}
185+
if v, ok := d.GetOk("content"); ok {
186+
request.Content = helper.String(v.(string))
187+
}
188+
if v, ok := d.GetOk("type"); ok {
189+
request.Type = helper.String(v.(string))
190+
}
191+
if v, ok := d.GetOk("description"); ok {
192+
request.Description = helper.String(v.(string))
193+
}
194+
195+
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
196+
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseOrganizationClient().UpdatePolicy(request)
197+
if e != nil {
198+
return tccommon.RetryError(e)
199+
} else {
200+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
201+
}
202+
return nil
203+
})
204+
if err != nil {
205+
log.Printf("[CRITAL]%s update organization OrgManagePolicy failed, reason:%+v", logId, err)
206+
return err
207+
}
208+
209+
}
210+
return resourceTencentCloudOrganizationOrgManagePolicyRead(d, meta)
211+
}
212+
213+
func resourceTencentCloudOrganizationOrgManagePolicyDelete(d *schema.ResourceData, meta interface{}) error {
214+
defer tccommon.LogElapsed("resource.tencentcloud_organization_org_manage_policy.delete")()
215+
defer tccommon.InconsistentCheck(d, meta)()
216+
217+
logId := tccommon.GetLogId(tccommon.ContextNil)
218+
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
219+
220+
service := OrganizationService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
221+
idSplit := strings.Split(d.Id(), tccommon.FILED_SP)
222+
if len(idSplit) != 2 {
223+
return fmt.Errorf("id is broken,%s", d.Id())
224+
}
225+
policyId := idSplit[0]
226+
policyType := idSplit[1]
227+
228+
if err := service.DeleteOrganizationOrgManagePolicyById(ctx, policyId, policyType); err != nil {
229+
return err
230+
}
231+
232+
return nil
233+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Provides a resource to create a organization org_manage_policy
2+
3+
Example Usage
4+
5+
```hcl
6+
resource "tencentcloud_organization_org_manage_policy" "org_manage_policy" {
7+
name = "FullAccessPolicy"
8+
content = "{\"version\":\"2.0\",\"statement\":[{\"effect\":\"allow\",\"action\":\"*\",\"resource\":\"*\"}]}"
9+
type = "SERVICE_CONTROL_POLICY"
10+
description = "Full access policy"
11+
}
12+
```
13+
14+
Import
15+
16+
organization org_manage_policy can be imported using the id, e.g.
17+
18+
```
19+
terraform import tencentcloud_organization_org_manage_policy.org_manage_policy policy_id#type
20+
```

0 commit comments

Comments
 (0)