Skip to content

Commit 274fbe2

Browse files
authored
Merge pull request #683 from tencentcloudstack/fix/tke-auth-option-update
Fix/tke auth option update
2 parents 1326800 + 854b74a commit 274fbe2

File tree

4 files changed

+43
-32
lines changed

4 files changed

+43
-32
lines changed

tencentcloud/data_source_tc_cam_user_policy_attachments.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ func dataSourceTencentCloudCamUserPolicyAttachments() *schema.Resource {
3535

3636
Schema: map[string]*schema.Schema{
3737
"user_id": {
38-
Type: schema.TypeString,
39-
Optional: true,
38+
Type: schema.TypeString,
39+
Optional: true,
4040
AtLeastOneOf: []string{"user_id", "user_name"},
41-
Deprecated: "It has been deprecated from version 1.59.6. Use `user_name` instead.",
42-
Description: "ID of the attached CAM user to be queried.",
41+
Deprecated: "It has been deprecated from version 1.59.6. Use `user_name` instead.",
42+
Description: "ID of the attached CAM user to be queried.",
4343
},
4444
"user_name": {
45-
Type: schema.TypeString,
46-
Optional: true,
45+
Type: schema.TypeString,
46+
Optional: true,
4747
AtLeastOneOf: []string{"user_id", "user_name"},
48-
Description: "Name of the attached CAM user as unique key to be queried.",
48+
Description: "Name of the attached CAM user as unique key to be queried.",
4949
},
5050
"policy_id": {
5151
Type: schema.TypeString,
@@ -78,7 +78,7 @@ func dataSourceTencentCloudCamUserPolicyAttachments() *schema.Resource {
7878
"user_id": {
7979
Type: schema.TypeString,
8080
Computed: true,
81-
Deprecated: "It has been deprecated from version 1.59.6. Use `user_name` instead.",
81+
Deprecated: "It has been deprecated from version 1.59.6. Use `user_name` instead.",
8282
Description: "ID of CAM user.",
8383
},
8484
"user_name": {
@@ -164,7 +164,7 @@ func dataSourceTencentCloudCamUserPolicyAttachmentsRead(d *schema.ResourceData,
164164
ids := make([]string, 0, len(policyOfUsers))
165165
for _, policy := range policyOfUsers {
166166
mapping := map[string]interface{}{
167-
"user_id": userId,
167+
"user_id": userId,
168168
"user_name": userId,
169169
"policy_id": strconv.Itoa(int(*policy.PolicyId)),
170170
"create_time": *policy.AddTime,

tencentcloud/resource_tc_kubernetes_cluster.go

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,21 +1125,20 @@ func resourceTencentCloudTkeCluster() *schema.Resource {
11251125
Elem: &schema.Resource{
11261126
Schema: map[string]*schema.Schema{
11271127
"jwks_uri": {
1128-
Type: schema.TypeString,
1129-
Optional: true,
1128+
Type: schema.TypeString,
1129+
Optional: true,
11301130
Description: "Specify service-account-jwks-uri.",
11311131
},
11321132
"issuer": {
1133-
Type: schema.TypeString,
1134-
Optional: true,
1133+
Type: schema.TypeString,
1134+
Optional: true,
11351135
Description: "Specify service-account-issuer.",
11361136
},
11371137
"auto_create_discovery_anonymous_auth": {
1138-
Type: schema.TypeBool,
1139-
Optional: true,
1138+
Type: schema.TypeBool,
1139+
Optional: true,
11401140
Description: "If set to `true`, the rbac rule will be created automatically which allow anonymous user to access '/.well-known/openid-configuration' and '/openid/v1/jwks'.",
11411141
},
1142-
11431142
},
11441143
},
11451144
Description: "Specify cluster authentication configuration. Only available for managed cluster and `cluster_version` >= 1.20.",
@@ -1544,26 +1543,28 @@ func tkeGetNodePoolGlobalConfig(d *schema.ResourceData) *tke.ModifyClusterAsGrou
15441543
return request
15451544
}
15461545

1547-
func tkeGetAuthOptions (d *schema.ResourceData) *tke.ModifyClusterAuthenticationOptionsRequest {
1546+
func tkeGetAuthOptions(d *schema.ResourceData) *tke.ModifyClusterAuthenticationOptionsRequest {
15481547
raw, ok := d.GetOk("auth_options")
15491548
options := raw.([]interface{})
15501549

1551-
if !ok || len(options) == 0 {
1552-
return nil
1553-
}
1554-
1555-
option := options[0].(map[string]interface{})
15561550
request := tke.NewModifyClusterAuthenticationOptionsRequest()
15571551
request.ClusterId = helper.String(d.Id())
1558-
15591552
request.ServiceAccounts = &tke.ServiceAccountAuthenticationOptions{
15601553
AutoCreateDiscoveryAnonymousAuth: helper.Bool(false),
1554+
Issuer: helper.String(""),
1555+
JWKSURI: helper.String(""),
1556+
}
1557+
1558+
if !ok || len(options) == 0 {
1559+
return request
15611560
}
15621561

1562+
option := options[0].(map[string]interface{})
1563+
15631564
if v, ok := option["auto_create_discovery_anonymous_auth"]; ok {
15641565
request.ServiceAccounts.AutoCreateDiscoveryAnonymousAuth = helper.Bool(v.(bool))
15651566
}
1566-
1567+
15671568
if v, ok := option["issuer"]; ok {
15681569
request.ServiceAccounts.Issuer = helper.String(v.(string))
15691570
}
@@ -2065,6 +2066,13 @@ func resourceTencentCloudTkeClusterCreate(d *schema.ResourceData, meta interface
20652066
}
20662067
}
20672068

2069+
if _, ok := d.GetOk("auth_options"); ok {
2070+
request := tkeGetAuthOptions(d)
2071+
if err := service.ModifyClusterAuthenticationOptions(ctx, request); err != nil {
2072+
return err
2073+
}
2074+
}
2075+
20682076
if err = resourceTencentCloudTkeClusterRead(d, meta); err != nil {
20692077
log.Printf("[WARN]%s resource.kubernetes_cluster.read after create fail , %s", logId, err.Error())
20702078
return err

tencentcloud/resource_tc_kubernetes_node_pool.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -904,11 +904,11 @@ func resourceKubernetesNodePoolUpdate(d *schema.ResourceData, meta interface{})
904904
}
905905

906906
var (
907-
scalingGroupId = *nodePool.AutoscalingGroupId
908-
name = d.Get("scaling_group_name").(string)
909-
projectId = d.Get("scaling_group_project_id").(int)
910-
defaultCooldown = d.Get("default_cooldown").(int)
911-
zones []*string
907+
scalingGroupId = *nodePool.AutoscalingGroupId
908+
name = d.Get("scaling_group_name").(string)
909+
projectId = d.Get("scaling_group_project_id").(int)
910+
defaultCooldown = d.Get("default_cooldown").(int)
911+
zones []*string
912912
terminationPolicies []*string
913913
)
914914

tencentcloud/service_tencentcloud_tke.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,6 @@ func (me *TkeService) DescribeClusterAuthenticationOptions(ctx context.Context,
14081408
return
14091409
}
14101410

1411-
14121411
func (me *TkeService) ModifyClusterAuthenticationOptions(ctx context.Context, request *tke.ModifyClusterAuthenticationOptionsRequest) (errRet error) {
14131412
logId := getLogId(ctx)
14141413
defer func() {
@@ -1418,9 +1417,13 @@ func (me *TkeService) ModifyClusterAuthenticationOptions(ctx context.Context, re
14181417
}()
14191418

14201419
ratelimit.Check(request.GetAction())
1421-
_, err := me.client.UseTkeClient().ModifyClusterAuthenticationOptions(request)
1420+
response, err := me.client.UseTkeClient().ModifyClusterAuthenticationOptions(request)
14221421
if err != nil {
14231422
errRet = err
14241423
}
1424+
1425+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
1426+
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
1427+
14251428
return
1426-
}
1429+
}

0 commit comments

Comments
 (0)