Skip to content

Commit 030aee9

Browse files
committed
add
1 parent a4bfdce commit 030aee9

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

tencentcloud/provider.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ const (
137137
PROVIDER_ASSUME_ROLE_SAML_ASSERTION = "TENCENTCLOUD_ASSUME_ROLE_SAML_ASSERTION"
138138
PROVIDER_ASSUME_ROLE_PRINCIPAL_ARN = "TENCENTCLOUD_ASSUME_ROLE_PRINCIPAL_ARN"
139139
PROVIDER_ASSUME_ROLE_WEB_IDENTITY_TOKEN = "TENCENTCLOUD_ASSUME_ROLE_WEB_IDENTITY_TOKEN"
140+
PROVIDER_ASSUME_ROLE_PROVIDER_ID = "TENCENTCLOUD_ASSUME_ROLE_PROVIDER_ID"
140141
PROVIDER_SHARED_CREDENTIALS_DIR = "TENCENTCLOUD_SHARED_CREDENTIALS_DIR"
141142
PROVIDER_PROFILE = "TENCENTCLOUD_PROFILE"
142143
PROVIDER_CAM_ROLE_NAME = "TENCENTCLOUD_CAM_ROLE_NAME"
@@ -321,6 +322,12 @@ func Provider() *schema.Provider {
321322
Description: "The `assume_role_with_web_identity` block. If provided, terraform will attempt to assume this role using the supplied credentials.",
322323
Elem: &schema.Resource{
323324
Schema: map[string]*schema.Schema{
325+
"provider_id": {
326+
Type: schema.TypeString,
327+
Optional: true,
328+
DefaultFunc: schema.EnvDefaultFunc(PROVIDER_ASSUME_ROLE_PROVIDER_ID, nil),
329+
Description: "Identity provider name. It can be sourced from the `TENCENTCLOUD_ASSUME_ROLE_PROVIDER_ID`, Default is OIDC.",
330+
},
324331
"web_identity_token": {
325332
Type: schema.TypeString,
326333
Required: true,
@@ -2399,6 +2406,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
23992406
envPrincipalArn := os.Getenv(PROVIDER_ASSUME_ROLE_PRINCIPAL_ARN)
24002407
// get assume role with web identity from env
24012408
envWebIdentityToken := os.Getenv(PROVIDER_ASSUME_ROLE_WEB_IDENTITY_TOKEN)
2409+
assumeRoleProviderId := os.Getenv(PROVIDER_ASSUME_ROLE_PROVIDER_ID)
24022410

24032411
if envSamlAssertion == "" && envPrincipalArn == "" && envWebIdentityToken == "" {
24042412
// use assume role
@@ -2418,7 +2426,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
24182426
needSecret = false
24192427
} else if envWebIdentityToken != "" {
24202428
// use assume role with oidc
2421-
err = genClientWithOidcSTS(&tcClient, envRoleArn, envSessionName, assumeRoleSessionDuration, envWebIdentityToken)
2429+
err = genClientWithOidcSTS(&tcClient, envRoleArn, envSessionName, assumeRoleSessionDuration, envWebIdentityToken, assumeRoleProviderId)
24222430
if err != nil {
24232431
return nil, fmt.Errorf("Get auth from assume role with OIDC by env failed. Reason: %s", err.Error())
24242432
}
@@ -2457,6 +2465,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
24572465
assumeRoleSamlAssertion string
24582466
assumeRolePrincipalArn string
24592467
assumeRoleWebIdentityToken string
2468+
assumeRoleProviderId string
24602469
)
24612470

24622471
// get assume role with saml from tf
@@ -2488,8 +2497,8 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
24882497
assumeRoleArn = assumeRoleWithWebIdentity["role_arn"].(string)
24892498
assumeRoleSessionName = assumeRoleWithWebIdentity["session_name"].(string)
24902499
assumeRoleSessionDuration = assumeRoleWithWebIdentity["session_duration"].(int)
2491-
2492-
err = genClientWithOidcSTS(&tcClient, assumeRoleArn, assumeRoleSessionName, assumeRoleSessionDuration, assumeRoleWebIdentityToken)
2500+
assumeRoleProviderId = assumeRoleWithWebIdentity["provider_id"].(string)
2501+
err = genClientWithOidcSTS(&tcClient, assumeRoleArn, assumeRoleSessionName, assumeRoleSessionDuration, assumeRoleWebIdentityToken, assumeRoleProviderId)
24932502
if err != nil {
24942503
return nil, fmt.Errorf("Get auth from assume role with OIDC failed. Reason: %s", err.Error())
24952504
}
@@ -2654,15 +2663,18 @@ func genClientWithSamlSTS(tcClient *TencentCloudClient, assumeRoleArn, assumeRol
26542663
return nil
26552664
}
26562665

2657-
func genClientWithOidcSTS(tcClient *TencentCloudClient, assumeRoleArn, assumeRoleSessionName string, assumeRoleSessionDuration int, assumeRolePolicy string) error {
2666+
func genClientWithOidcSTS(tcClient *TencentCloudClient, assumeRoleArn, assumeRoleSessionName string, assumeRoleSessionDuration int, assumeRolePolicy, assumeRoleProviderId string) error {
26582667
// applying STS credentials
26592668
request := sdksts.NewAssumeRoleWithWebIdentityRequest()
26602669
response := sdksts.NewAssumeRoleWithWebIdentityResponse()
2661-
request.ProviderId = helper.String("OIDC")
2670+
if assumeRoleProviderId == "" {
2671+
assumeRoleProviderId = "OIDC"
2672+
}
26622673
request.RoleArn = helper.String(assumeRoleArn)
26632674
request.RoleSessionName = helper.String(assumeRoleSessionName)
26642675
request.DurationSeconds = helper.IntInt64(assumeRoleSessionDuration)
26652676
request.WebIdentityToken = helper.String(assumeRolePolicy)
2677+
request.ProviderId = helper.String(assumeRoleProviderId)
26662678
var stsExtInfo connectivity.StsExtInfo
26672679
stsExtInfo.Authorization = "SKIP"
26682680
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {

website/docs/index.html.markdown

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ Usage:
240240
```hcl
241241
provider "tencentcloud" {
242242
assume_role_with_web_identity {
243+
provider_id = "OIDC"
243244
role_arn = "my-role-arn"
244245
session_name = "my-session-name"
245246
session_duration = 3600
@@ -248,7 +249,7 @@ provider "tencentcloud" {
248249
}
249250
```
250251

251-
The `role_arn`, `session_name`, `session_duration`, `web_identity_token` can also provided via `TENCENTCLOUD_ASSUME_ROLE_ARN`, `TENCENTCLOUD_ASSUME_ROLE_SESSION_NAME`, `TENCENTCLOUD_ASSUME_ROLE_SESSION_DURATION` and `TENCENTCLOUD_ASSUME_ROLE_WEB_IDENTITY_TOKEN` environment variables.
252+
The `provider_id`, `role_arn`, `session_name`, `session_duration`, `web_identity_token` can also provided via `TENCENTCLOUD_ASSUME_ROLE_PROVIDER_ID`, `TENCENTCLOUD_ASSUME_ROLE_ARN`, `TENCENTCLOUD_ASSUME_ROLE_SESSION_NAME`, `TENCENTCLOUD_ASSUME_ROLE_SESSION_DURATION` and `TENCENTCLOUD_ASSUME_ROLE_WEB_IDENTITY_TOKEN` environment variables.
252253

253254
Usage:
254255

@@ -257,6 +258,7 @@ $ export TENCENTCLOUD_SECRET_ID="my-secret-id"
257258
$ export TENCENTCLOUD_SECRET_KEY="my-secret-key"
258259
$ export TENCENTCLOUD_ASSUME_ROLE_SESSION_DURATION=3600
259260
$ export TENCENTCLOUD_ASSUME_ROLE_WEB_IDENTITY_TOKEN="my-web-identity-token"
261+
$ export TENCENTCLOUD_ASSUME_ROLE_PROVIDER_ID="OIDC"
260262
$ terraform plan
261263
```
262264

@@ -322,8 +324,8 @@ locals {
322324
323325
provider "tencentcloud" {
324326
region = local.region
325-
secret_id = "xxxxxx"
326-
secret_key = "xxxxxx"
327+
secret_id = "my-secret-id"
328+
secret_key = "my-secret-key"
327329
cos_domain = "https://${local.cdc_id}.cos-cdc.${local.region}.myqcloud.com/"
328330
}
329331
```
@@ -399,6 +401,7 @@ The nested `assume_role_with_saml` block supports the following:
399401
* `principal_arn` - (Required) Player Access Description Name. It can be sourced from the `TENCENTCLOUD_ASSUME_ROLE_PRINCIPAL_ARN`.
400402

401403
The nested `assume_role_with_web_identity` block supports the following:
404+
* `provider_id` - (Optional) Identity provider name. It can be sourced from the `TENCENTCLOUD_ASSUME_ROLE_PROVIDER_ID`, Default is OIDC.
402405
* `role_arn` - (Required) The ARN of the role to assume. It can also be sourced from the `TENCENTCLOUD_ASSUME_ROLE_ARN` environment variable.
403406
* `session_name` - (Required) The session name to use when making the AssumeRole call. It can also be sourced from the `TENCENTCLOUD_ASSUME_ROLE_SESSION_NAME` environment variable.
404407
* `session_duration` - (Required) The duration of the session when making the AssumeRole call. Its value ranges from 0 to 43200(seconds), and default is 7200 seconds. It can also be sourced from the `TENCENTCLOUD_ASSUME_ROLE_SESSION_DURATION` environment variable.

0 commit comments

Comments
 (0)