Skip to content

Commit 03f6d98

Browse files
authored
Merge pull request #677 from tencentcloudstack/fix/cam-role-data-and-node-asg
fix - policy attach data username and node_pool argument mistake
2 parents 442d78c + 646d7ab commit 03f6d98

7 files changed

+49
-19
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 1.59.6 (September 28, 2021)
2+
3+
BUGFIXES:
4+
5+
* Resource `resource_tc_kubernetes_node_pool_test.go` fix termination_policies argument mistake
6+
7+
DEPRECATED:
8+
9+
* DataSource `data_source_tc_cam_user_policy_attachments.go` deprecate `user_id` and replaced by `user_name`
10+
111
## 1.59.5 (September 28, 2021)
212

313
ENHANCEMENTS:

examples/tencentcloud-cam/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ resource "tencentcloud_cam_role" "example" {
3030

3131
resource "tencentcloud_cam_group_membership" "example" {
3232
group_id = tencentcloud_cam_group.example.id
33-
user_ids = [tencentcloud_cam_user.example.id]
33+
user_names = [tencentcloud_cam_user.example.name]
3434
}
3535

3636
resource "tencentcloud_cam_role_policy_attachment" "example" {
@@ -39,7 +39,7 @@ resource "tencentcloud_cam_role_policy_attachment" "example" {
3939
}
4040

4141
resource "tencentcloud_cam_user_policy_attachment" "example" {
42-
user_id = tencentcloud_cam_user.example.id
42+
user_name = tencentcloud_cam_user.example.name
4343
policy_id = tencentcloud_cam_policy.example.id
4444
}
4545

@@ -75,7 +75,7 @@ data "tencentcloud_cam_group_memberships" "memberships" {
7575
}
7676

7777
data "tencentcloud_cam_user_policy_attachments" "user_policy_attachments" {
78-
user_id = tencentcloud_cam_user_policy_attachment.example.user_id
78+
user_name = tencentcloud_cam_user_policy_attachment.example.user_name
7979
}
8080

8181
data "tencentcloud_cam_role_policy_attachments" "role_policy_attachments" {

tencentcloud/data_source_tc_cam_user_policy_attachments.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,17 @@ func dataSourceTencentCloudCamUserPolicyAttachments() *schema.Resource {
3636
Schema: map[string]*schema.Schema{
3737
"user_id": {
3838
Type: schema.TypeString,
39-
Required: true,
39+
Optional: true,
40+
AtLeastOneOf: []string{"user_id", "user_name"},
41+
Deprecated: "It has been deprecated from version 1.59.6. Use `user_name` instead.",
4042
Description: "ID of the attached CAM user to be queried.",
4143
},
44+
"user_name": {
45+
Type: schema.TypeString,
46+
Optional: true,
47+
AtLeastOneOf: []string{"user_id", "user_name"},
48+
Description: "Name of the attached CAM user as unique key to be queried.",
49+
},
4250
"policy_id": {
4351
Type: schema.TypeString,
4452
Optional: true,
@@ -70,8 +78,14 @@ func dataSourceTencentCloudCamUserPolicyAttachments() *schema.Resource {
7078
"user_id": {
7179
Type: schema.TypeString,
7280
Computed: true,
81+
Deprecated: "It has been deprecated from version 1.59.6. Use `user_name` instead.",
7382
Description: "ID of CAM user.",
7483
},
84+
"user_name": {
85+
Type: schema.TypeString,
86+
Computed: true,
87+
Description: "Name of CAM user as unique key.",
88+
},
7589
"policy_id": {
7690
Type: schema.TypeString,
7791
Computed: true,
@@ -111,7 +125,10 @@ func dataSourceTencentCloudCamUserPolicyAttachmentsRead(d *schema.ResourceData,
111125
ctx := context.WithValue(context.TODO(), logIdKey, logId)
112126

113127
params := make(map[string]interface{})
114-
userId := d.Get("user_id").(string)
128+
userId, _, err := getUserId(d)
129+
if err != nil {
130+
return err
131+
}
115132
params["user_id"] = userId
116133
if v, ok := d.GetOk("policy_id"); ok {
117134
policyId, err := strconv.Atoi(v.(string))
@@ -131,7 +148,7 @@ func dataSourceTencentCloudCamUserPolicyAttachmentsRead(d *schema.ResourceData,
131148
client: meta.(*TencentCloudClient).apiV3Conn,
132149
}
133150
var policyOfUsers []*cam.AttachPolicyInfo
134-
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
151+
err = resource.Retry(readRetryTimeout, func() *resource.RetryError {
135152
results, e := camService.DescribeUserPolicyAttachmentsByFilter(ctx, params)
136153
if e != nil {
137154
return retryError(e)
@@ -147,7 +164,8 @@ func dataSourceTencentCloudCamUserPolicyAttachmentsRead(d *schema.ResourceData,
147164
ids := make([]string, 0, len(policyOfUsers))
148165
for _, policy := range policyOfUsers {
149166
mapping := map[string]interface{}{
150-
"user_id": userId,
167+
"user_id": userId,
168+
"user_name": userId,
151169
"policy_id": strconv.Itoa(int(*policy.PolicyId)),
152170
"create_time": *policy.AddTime,
153171
"create_mode": *policy.CreateMode,

tencentcloud/data_source_tc_cam_user_policy_attachments_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestAccTencentCloudCamUserPolicyAttachmentsDataSource_basic(t *testing.T) {
1717
Check: resource.ComposeAggregateTestCheckFunc(
1818
testAccCheckCamUserPolicyAttachmentExists("tencentcloud_cam_user_policy_attachment.user_policy_attachment"),
1919
resource.TestCheckResourceAttr("data.tencentcloud_cam_user_policy_attachments.user_policy_attachments", "user_policy_attachment_list.#", "1"),
20-
resource.TestCheckResourceAttrSet("data.tencentcloud_cam_user_policy_attachments.user_policy_attachments", "user_policy_attachment_list.0.user_id"),
20+
resource.TestCheckResourceAttrSet("data.tencentcloud_cam_user_policy_attachments.user_policy_attachments", "user_policy_attachment_list.0.user_name"),
2121
resource.TestCheckResourceAttrSet("data.tencentcloud_cam_user_policy_attachments.user_policy_attachments", "user_policy_attachment_list.0.policy_id"),
2222
resource.TestCheckResourceAttrSet("data.tencentcloud_cam_user_policy_attachments.user_policy_attachments", "user_policy_attachment_list.0.policy_name"),
2323
resource.TestCheckResourceAttrSet("data.tencentcloud_cam_user_policy_attachments.user_policy_attachments", "user_policy_attachment_list.0.create_mode"),
@@ -48,11 +48,11 @@ resource "tencentcloud_cam_policy" "policy" {
4848
}
4949
5050
resource "tencentcloud_cam_user_policy_attachment" "user_policy_attachment" {
51-
user_id = tencentcloud_cam_user.user.id
51+
user_name = tencentcloud_cam_user.user.name
5252
policy_id = tencentcloud_cam_policy.policy.id
5353
}
5454
5555
data "tencentcloud_cam_user_policy_attachments" "user_policy_attachments" {
56-
user_id = tencentcloud_cam_user_policy_attachment.user_policy_attachment.user_id
56+
user_name = tencentcloud_cam_user_policy_attachment.user_policy_attachment.user_name
5757
}
5858
`

tencentcloud/resource_tc_kubernetes_node_pool.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
909909
projectId = d.Get("scaling_group_project_id").(int)
910910
defaultCooldown = d.Get("default_cooldown").(int)
911911
zones []*string
912-
terminationPolicy []*string
912+
terminationPolicies []*string
913913
)
914914

915915
if v, ok := d.GetOk("zones"); ok {
@@ -918,14 +918,14 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
918918
}
919919
}
920920

921-
if v, ok := d.GetOk("termination_policy"); ok {
921+
if v, ok := d.GetOk("termination_policies"); ok {
922922
for _, policy := range v.([]interface{}) {
923-
terminationPolicy = append(terminationPolicy, helper.String(policy.(string)))
923+
terminationPolicies = append(terminationPolicies, helper.String(policy.(string)))
924924
}
925925
}
926926

927927
err = resource.Retry(writeRetryTimeout, func() *resource.RetryError {
928-
errRet := asService.ModifyScalingGroup(ctx, scalingGroupId, name, projectId, defaultCooldown, zones, terminationPolicy)
928+
errRet := asService.ModifyScalingGroup(ctx, scalingGroupId, name, projectId, defaultCooldown, zones, terminationPolicies)
929929
if errRet != nil {
930930
return retryError(errRet)
931931
}

tencentcloud/service_tencentcloud_as.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ func (me *AsService) DescribeScheduledActionById(ctx context.Context, scheduledA
440440
return
441441
}
442442

443-
func (me *AsService) ModifyScalingGroup(ctx context.Context, id string, name string, projectId int, cooldown int, zones []*string, terminatePolicy []*string) error {
443+
func (me *AsService) ModifyScalingGroup(ctx context.Context, id string, name string, projectId int, cooldown int, zones []*string, terminationPolicies []*string) error {
444444
logId := getLogId(ctx)
445445
request := as.NewModifyAutoScalingGroupRequest()
446446

@@ -462,8 +462,8 @@ func (me *AsService) ModifyScalingGroup(ctx context.Context, id string, name str
462462
request.Zones = zones
463463
}
464464

465-
if len(terminatePolicy) != 0 {
466-
request.TerminationPolicies = terminatePolicy[:1]
465+
if len(terminationPolicies) != 0 {
466+
request.TerminationPolicies = terminationPolicies
467467
}
468468

469469
ratelimit.Check(request.GetAction())

website/docs/d/cam_user_policy_attachments.html.markdown

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ data "tencentcloud_cam_user_policy_attachments" "bar" {
3030

3131
The following arguments are supported:
3232

33-
* `user_id` - (Required) ID of the attached CAM user to be queried.
3433
* `create_mode` - (Optional) Mode of Creation of the CAM user policy attachment. `1` means the CAM policy attachment is created by production, and the others indicate syntax strategy ways.
3534
* `policy_id` - (Optional) ID of CAM policy to be queried.
3635
* `policy_type` - (Optional) Type of the policy strategy. 'User' means customer strategy and 'QCS' means preset strategy.
3736
* `result_output_file` - (Optional) Used to save results.
37+
* `user_id` - (Optional, **Deprecated**) It has been deprecated from version 1.59.6. Use `user_name` instead. ID of the attached CAM user to be queried.
38+
* `user_name` - (Optional) Name of the attached CAM user as unique key to be queried.
3839

3940
## Attributes Reference
4041

@@ -46,6 +47,7 @@ In addition to all arguments above, the following attributes are exported:
4647
* `policy_id` - Name of CAM user.
4748
* `policy_name` - The name of the policy.
4849
* `policy_type` - Type of the policy strategy. 'User' means customer strategy and 'QCS' means preset strategy.
49-
* `user_id` - ID of CAM user.
50+
* `user_id` - (**Deprecated**) It has been deprecated from version 1.59.6. Use `user_name` instead. ID of CAM user.
51+
* `user_name` - Name of CAM user as unique key.
5052

5153

0 commit comments

Comments
 (0)