@@ -198,7 +198,7 @@ func Provider() *schema.Provider {
198
198
//internal version: replace enableBpass begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
199
199
//internal version: replace enableBpass end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
200
200
"assume_role" : {
201
- Type : schema .TypeSet ,
201
+ Type : schema .TypeList ,
202
202
Optional : true ,
203
203
MaxItems : 1 ,
204
204
Description : "The `assume_role` block. If provided, terraform will attempt to assume this role using the supplied credentials." ,
@@ -237,23 +237,23 @@ func Provider() *schema.Provider {
237
237
Type : schema .TypeString ,
238
238
Optional : true ,
239
239
DefaultFunc : schema .EnvDefaultFunc (PROVIDER_ASSUME_ROLE_SAML_ASSERTION , nil ),
240
- ConflictsWith : []string {"web_identity_token" },
241
- RequiredWith : []string {"principal_arn" },
240
+ ConflictsWith : []string {"assume_role.0. web_identity_token" },
241
+ RequiredWith : []string {"assume_role.0. principal_arn" },
242
242
Description : "SAML assertion information encoded in base64. And it can't be used with `web_identity_token` together." ,
243
243
},
244
244
"principal_arn" : {
245
245
Type : schema .TypeString ,
246
246
Optional : true ,
247
247
DefaultFunc : schema .EnvDefaultFunc (PROVIDER_ASSUME_ROLE_PRINCIPAL_ARN , nil ),
248
- ConflictsWith : []string {"web_identity_token" },
249
- RequiredWith : []string {"saml_assertion" },
248
+ ConflictsWith : []string {"assume_role.0. web_identity_token" },
249
+ RequiredWith : []string {"assume_role.0. saml_assertion" },
250
250
Description : "Player Access Description Name. And it can't be used with `web_identity_token` together." ,
251
251
},
252
252
"web_identity_token" : {
253
253
Type : schema .TypeString ,
254
254
Optional : true ,
255
255
DefaultFunc : schema .EnvDefaultFunc (PROVIDER_ASSUME_ROLE_WEB_IDENTITY_TOKEN , nil ),
256
- ConflictsWith : []string {"saml_assertion" , "principal_arn" },
256
+ ConflictsWith : []string {"assume_role.0. saml_assertion" , "assume_role.0. principal_arn" },
257
257
Description : "OIDC token issued by IdP. And it can't be used with `saml_assertion` or `principal_arn` together." ,
258
258
},
259
259
},
@@ -2128,12 +2128,27 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
2128
2128
assumeRoleSessionDuration = 7200
2129
2129
}
2130
2130
2131
- _ = genClientWithSTS (& tcClient , envRoleArn , envSessionName , assumeRoleSessionDuration , "" )
2131
+ envSamlAssertion := os .Getenv (PROVIDER_ASSUME_ROLE_SAML_ASSERTION )
2132
+ envPrincipalArn := os .Getenv (PROVIDER_ASSUME_ROLE_PRINCIPAL_ARN )
2133
+ envWebIdentityToken := os .Getenv (PROVIDER_ASSUME_ROLE_WEB_IDENTITY_TOKEN )
2134
+
2135
+ if envSamlAssertion == "" && envPrincipalArn == "" && envWebIdentityToken == "" {
2136
+ // use assume role
2137
+ _ = genClientWithSTS (& tcClient , envRoleArn , envSessionName , assumeRoleSessionDuration , "" )
2138
+ } else if envSamlAssertion != "" && envPrincipalArn != "" {
2139
+ // use assume role with saml
2140
+ _ = genClientWithSamlSTS (& tcClient , envRoleArn , envSessionName , assumeRoleSessionDuration , envSamlAssertion , envPrincipalArn )
2141
+ } else if envWebIdentityToken != "" {
2142
+ // use assume role with oidc
2143
+ _ = genClientWithOidcSTS (& tcClient , envRoleArn , envSessionName , assumeRoleSessionDuration , envWebIdentityToken )
2144
+ } else {
2145
+ return nil , fmt .Errorf ("get `assume_role` from env error.\n " )
2146
+ }
2132
2147
}
2133
2148
2134
2149
// get assume role from tf
2135
2150
if v , ok := d .GetOk ("assume_role" ); ok {
2136
- assumeRoleList := v .(* schema. Set ). List ( )
2151
+ assumeRoleList := v .([] interface {} )
2137
2152
if len (assumeRoleList ) == 1 {
2138
2153
// assume role
2139
2154
assumeRole := assumeRoleList [0 ].(map [string ]interface {})
@@ -2157,13 +2172,13 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
2157
2172
// use assume role with oidc
2158
2173
_ = genClientWithOidcSTS (& tcClient , assumeRoleArn , assumeRoleSessionName , assumeRoleSessionDuration , assumeRoleWebIdentityToken )
2159
2174
} else {
2160
- return nil , fmt .Errorf ("`assume_role` params error." )
2175
+ return nil , fmt .Errorf ("get `assume_role` params error.\n " )
2161
2176
}
2162
2177
}
2163
2178
}
2164
2179
2165
2180
if secretId == "" || secretKey == "" {
2166
- return nil , fmt .Errorf ("Please set your `secret_id` and `secret_key`." )
2181
+ return nil , fmt .Errorf ("Please set your `secret_id` and `secret_key`.\n " )
2167
2182
}
2168
2183
2169
2184
return & tcClient , nil
0 commit comments