Skip to content

Commit dbd3d6e

Browse files
authored
add tke oidc (#2227)
* add tke oidc * add changelog * update
1 parent 9c10dab commit dbd3d6e

9 files changed

+402
-16
lines changed

.changelog/2227.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_kubernetes_auth_attachment: Support OIDC config.
3+
```
4+
5+
```release-note:new-data-source
6+
tencentcloud_cam_oidc_config
7+
```
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
Use this data source to query detailed information of cam oidc_config
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_cam_oidc_config" "oidc_config" {
8+
name = "cls-kzilgv5m"
9+
}
10+
11+
output "identity_key" {
12+
value = data.tencentcloud_cam_oidc_config.oidc_config.identity_key
13+
}
14+
15+
output "identity_url" {
16+
value = data.tencentcloud_cam_oidc_config.oidc_config.identity_url
17+
}
18+
19+
```
20+
*/
21+
package tencentcloud
22+
23+
import (
24+
"log"
25+
26+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
27+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
28+
cam "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam/v20190116"
29+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
30+
)
31+
32+
func dataSourceTencentCloudCamOidcConfig() *schema.Resource {
33+
return &schema.Resource{
34+
Read: dataSourceTencentCloudCamOidcConfigRead,
35+
Schema: map[string]*schema.Schema{
36+
"name": {
37+
Required: true,
38+
Type: schema.TypeString,
39+
Description: "Name.",
40+
},
41+
42+
"provider_type": {
43+
Computed: true,
44+
Type: schema.TypeInt,
45+
Description: "IdP type. 11: Role IdP.",
46+
},
47+
48+
"identity_url": {
49+
Computed: true,
50+
Type: schema.TypeString,
51+
Description: "IdP URL.",
52+
},
53+
54+
"identity_key": {
55+
Computed: true,
56+
Type: schema.TypeString,
57+
Description: "Public key for signature.",
58+
},
59+
60+
"client_id": {
61+
Computed: true,
62+
Type: schema.TypeSet,
63+
Elem: &schema.Schema{
64+
Type: schema.TypeString,
65+
},
66+
Description: "Client ID.",
67+
},
68+
69+
"status": {
70+
Computed: true,
71+
Type: schema.TypeInt,
72+
Description: "Status. 0: Not set; 2: Disabled; 11: Enabled.",
73+
},
74+
75+
"description": {
76+
Computed: true,
77+
Type: schema.TypeString,
78+
Description: "Description.",
79+
},
80+
81+
"result_output_file": {
82+
Type: schema.TypeString,
83+
Optional: true,
84+
Description: "Used to save results.",
85+
},
86+
},
87+
}
88+
}
89+
90+
func dataSourceTencentCloudCamOidcConfigRead(d *schema.ResourceData, meta interface{}) error {
91+
defer logElapsed("data_source.tencentcloud_cam_oidc_config.read")()
92+
defer inconsistentCheck(d, meta)()
93+
94+
logId := getLogId(contextNil)
95+
var name string
96+
result := make(map[string]interface{})
97+
98+
request := cam.NewDescribeOIDCConfigRequest()
99+
100+
if v, ok := d.GetOk("name"); ok {
101+
name = v.(string)
102+
request.Name = helper.String(v.(string))
103+
}
104+
105+
var response *cam.DescribeOIDCConfigResponse
106+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
107+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseCamClient().DescribeOIDCConfig(request)
108+
if e != nil {
109+
return retryError(e)
110+
}
111+
response = result
112+
return nil
113+
})
114+
if err != nil {
115+
log.Printf("[CRITAL]%s read CAM role SSO failed, reason:%s\n", logId, err.Error())
116+
return err
117+
}
118+
119+
if response.Response.ProviderType != nil {
120+
_ = d.Set("provider_type", response.Response.ProviderType)
121+
result["provider_type"] = response.Response.ProviderType
122+
}
123+
124+
if response.Response.IdentityUrl != nil {
125+
_ = d.Set("identity_url", response.Response.IdentityUrl)
126+
result["identity_url"] = response.Response.IdentityUrl
127+
}
128+
129+
if response.Response.IdentityKey != nil {
130+
_ = d.Set("identity_key", response.Response.IdentityKey)
131+
result["identity_key"] = response.Response.IdentityKey
132+
}
133+
134+
if response.Response.ClientId != nil {
135+
_ = d.Set("client_id", response.Response.ClientId)
136+
result["client_id"] = response.Response.ClientId
137+
}
138+
139+
if response.Response.Status != nil {
140+
_ = d.Set("status", response.Response.Status)
141+
result["status"] = response.Response.Status
142+
}
143+
144+
if response.Response.Description != nil {
145+
_ = d.Set("description", response.Response.Description)
146+
result["description"] = response.Response.Description
147+
}
148+
149+
d.SetId(name)
150+
output, ok := d.GetOk("result_output_file")
151+
if ok && output.(string) != "" {
152+
if e := writeToFile(output.(string), result); e != nil {
153+
return e
154+
}
155+
}
156+
return nil
157+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudCamOidcConfigDataSource_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: testAccCamOidcConfigDataSource,
19+
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_cam_oidc_config.oidc_config")),
20+
},
21+
},
22+
})
23+
}
24+
25+
const testAccCamOidcConfigDataSource = `
26+
27+
data "tencentcloud_cam_oidc_config" "oidc_config" {
28+
name = "cls-kzilgv5m"
29+
}
30+
31+
output "identity_key" {
32+
value = data.tencentcloud_cam_oidc_config.oidc_config.identity_key
33+
}
34+
35+
output "identity_url" {
36+
value = data.tencentcloud_cam_oidc_config.oidc_config.identity_url
37+
}
38+
`

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ Cloud Access Management(CAM)
227227
tencentcloud_cam_secret_last_used_time
228228
tencentcloud_cam_account_summary
229229
tencentcloud_cam_policy_granting_service_access
230+
tencentcloud_cam_oidc_config
230231
231232
Resource
232233
tencentcloud_cam_role
@@ -2194,6 +2195,7 @@ func Provider() *schema.Provider {
21942195
"tencentcloud_cam_saml_providers": dataSourceTencentCloudCamSAMLProviders(),
21952196
"tencentcloud_cam_list_entities_for_policy": dataSourceTencentCloudCamListEntitiesForPolicy(),
21962197
"tencentcloud_cam_account_summary": dataSourceTencentCloudCamAccountSummary(),
2198+
"tencentcloud_cam_oidc_config": dataSourceTencentCloudCamOidcConfig(),
21972199
"tencentcloud_user_info": datasourceTencentCloudUserInfo(),
21982200
"tencentcloud_cdn_domains": dataSourceTencentCloudCdnDomains(),
21992201
"tencentcloud_cdn_domain_verifier": dataSourceTencentCloudCdnDomainVerifyRecord(),

0 commit comments

Comments
 (0)