Skip to content

Commit 81b669c

Browse files
Santosh SahuSantosh Sahu
authored andcommitted
assume roles
1 parent 2d441d6 commit 81b669c

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

examples/default/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ terraform {
99
provider "lambdabased" {
1010
region = "us-east-1"
1111
# account = "123456789012" # Optional: AWS account ID to assume role in
12-
# assume_role_name = "OrganizationAccountAccessRole" # Optional: Role name to assume (defaults to OrganizationAccountAccessRole)
12+
# assume_role_name = "MyRoleName" # Required when account is specified
1313
}
1414

1515
locals {

provider/provider.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ func createProvider(configureContextFunc schema.ConfigureContextFunc) *schema.Pr
3939
"assume_role_name": {
4040
Type: schema.TypeString,
4141
Optional: true,
42-
Default: "OrganizationAccountAccessRole",
43-
Description: "Name of the IAM role to assume in the target account. Defaults to OrganizationAccountAccessRole.",
42+
Default: "",
43+
Description: "Name of the IAM role to assume in the target account. Required when account is specified.",
4444
},
4545
"assume_role": {
4646
Type: schema.TypeList,
@@ -75,9 +75,10 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
7575
return nil, diag.FromErr(err)
7676
}
7777

78-
// If account is specified, assume role in that account
79-
if account := d.Get("account").(string); account != "" {
80-
roleName := d.Get("assume_role_name").(string)
78+
// If account and assume_role_name are specified, assume role in that account
79+
account := d.Get("account").(string)
80+
roleName := d.Get("assume_role_name").(string)
81+
if account != "" && roleName != "" {
8182
roleArn := fmt.Sprintf("arn:aws:iam::%s:role/%s", account, roleName)
8283
stsSvc := sts.NewFromConfig(cfg)
8384
creds := stscreds.NewAssumeRoleProvider(stsSvc, roleArn)

0 commit comments

Comments
 (0)