Skip to content

Commit 4501be7

Browse files
authored
backend/remote-state: Add support for assume role extensions to s3 backend (#13236)
Fixes: #13234 This now matches the AWS provider for the Assume Role support
1 parent 4450f99 commit 4501be7

File tree

1 file changed

+44
-20
lines changed

1 file changed

+44
-20
lines changed

backend/remote-state/s3/backend.go

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,101 +21,122 @@ import (
2121
func New() backend.Backend {
2222
s := &schema.Backend{
2323
Schema: map[string]*schema.Schema{
24-
"bucket": &schema.Schema{
24+
"bucket": {
2525
Type: schema.TypeString,
2626
Required: true,
2727
Description: "The name of the S3 bucket",
2828
},
2929

30-
"key": &schema.Schema{
30+
"key": {
3131
Type: schema.TypeString,
3232
Required: true,
3333
Description: "The path to the state file inside the bucket",
3434
},
3535

36-
"region": &schema.Schema{
36+
"region": {
3737
Type: schema.TypeString,
3838
Required: true,
3939
Description: "The region of the S3 bucket.",
4040
DefaultFunc: schema.EnvDefaultFunc("AWS_DEFAULT_REGION", nil),
4141
},
4242

43-
"endpoint": &schema.Schema{
43+
"endpoint": {
4444
Type: schema.TypeString,
4545
Optional: true,
4646
Description: "A custom endpoint for the S3 API",
4747
DefaultFunc: schema.EnvDefaultFunc("AWS_S3_ENDPOINT", ""),
4848
},
4949

50-
"encrypt": &schema.Schema{
50+
"encrypt": {
5151
Type: schema.TypeBool,
5252
Optional: true,
5353
Description: "Whether to enable server side encryption of the state file",
5454
Default: false,
5555
},
5656

57-
"acl": &schema.Schema{
57+
"acl": {
5858
Type: schema.TypeString,
5959
Optional: true,
6060
Description: "Canned ACL to be applied to the state file",
6161
Default: "",
6262
},
6363

64-
"access_key": &schema.Schema{
64+
"access_key": {
6565
Type: schema.TypeString,
6666
Optional: true,
6767
Description: "AWS access key",
6868
Default: "",
6969
},
7070

71-
"secret_key": &schema.Schema{
71+
"secret_key": {
7272
Type: schema.TypeString,
7373
Optional: true,
7474
Description: "AWS secret key",
7575
Default: "",
7676
},
7777

78-
"kms_key_id": &schema.Schema{
78+
"kms_key_id": {
7979
Type: schema.TypeString,
8080
Optional: true,
8181
Description: "The ARN of a KMS Key to use for encrypting the state",
8282
Default: "",
8383
},
8484

85-
"lock_table": &schema.Schema{
85+
"lock_table": {
8686
Type: schema.TypeString,
8787
Optional: true,
8888
Description: "DynamoDB table for state locking",
8989
Default: "",
9090
},
9191

92-
"profile": &schema.Schema{
92+
"profile": {
9393
Type: schema.TypeString,
9494
Optional: true,
9595
Description: "AWS profile name",
9696
Default: "",
9797
},
9898

99-
"shared_credentials_file": &schema.Schema{
99+
"shared_credentials_file": {
100100
Type: schema.TypeString,
101101
Optional: true,
102102
Description: "Path to a shared credentials file",
103103
Default: "",
104104
},
105105

106-
"token": &schema.Schema{
106+
"token": {
107107
Type: schema.TypeString,
108108
Optional: true,
109109
Description: "MFA token",
110110
Default: "",
111111
},
112112

113-
"role_arn": &schema.Schema{
113+
"role_arn": {
114114
Type: schema.TypeString,
115115
Optional: true,
116116
Description: "The role to be assumed",
117117
Default: "",
118118
},
119+
120+
"session_name": {
121+
Type: schema.TypeString,
122+
Optional: true,
123+
Description: "The session name to use when assuming the role.",
124+
Default: "",
125+
},
126+
127+
"external_id": {
128+
Type: schema.TypeString,
129+
Optional: true,
130+
Description: "The external ID to use when assuming the role",
131+
Default: "",
132+
},
133+
134+
"assume_role_policy": {
135+
Type: schema.TypeString,
136+
Optional: true,
137+
Description: "The permissions applied when assuming a role.",
138+
Default: "",
139+
},
119140
},
120141
}
121142

@@ -156,12 +177,15 @@ func (b *Backend) configure(ctx context.Context) error {
156177

157178
var errs []error
158179
creds, err := terraformAWS.GetCredentials(&terraformAWS.Config{
159-
AccessKey: data.Get("access_key").(string),
160-
SecretKey: data.Get("secret_key").(string),
161-
Token: data.Get("token").(string),
162-
Profile: data.Get("profile").(string),
163-
CredsFilename: data.Get("shared_credentials_file").(string),
164-
AssumeRoleARN: data.Get("role_arn").(string),
180+
AccessKey: data.Get("access_key").(string),
181+
SecretKey: data.Get("secret_key").(string),
182+
Token: data.Get("token").(string),
183+
Profile: data.Get("profile").(string),
184+
CredsFilename: data.Get("shared_credentials_file").(string),
185+
AssumeRoleARN: data.Get("role_arn").(string),
186+
AssumeRoleSessionName: data.Get("session_name").(string),
187+
AssumeRoleExternalID: data.Get("external_id").(string),
188+
AssumeRolePolicy: data.Get("assume_role_policy").(string),
165189
})
166190
if err != nil {
167191
return err

0 commit comments

Comments
 (0)