Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add Support for assumeRoles with enforced MFA #3885

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"
Expand Down Expand Up @@ -94,6 +95,7 @@ import (
type Config struct {
AccessKey string
SecretKey string
MFA bool
CredsFilename string
Profile string
Token string
Expand Down Expand Up @@ -307,6 +309,11 @@ func (c *Config) Client() (interface{}, error) {
}
}

if c.MFA {
// add StdinTokenProvider for MFA
opt.AssumeRoleTokenProvider = stscreds.StdinTokenProvider
}

// create base session with no retries. MaxRetries will be set later
sess, err := session.NewSessionWithOptions(opt)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ func Provider() terraform.ResourceProvider {
Description: descriptions["secret_key"],
},

"mfa": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: descriptions["mfa"],
},

"profile": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -599,6 +606,9 @@ func init() {
"secret_key": "The secret key for API operations. You can retrieve this\n" +
"from the 'Security & Credentials' section of the AWS console.",

"mfa": "Explicitly configure the provider to use MFA. If omitted," +
"default value is `false`",

"profile": "The profile for API operations. If not set, the default profile\n" +
"created with `aws configure` will be used.",

Expand Down Expand Up @@ -689,6 +699,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config := Config{
AccessKey: d.Get("access_key").(string),
SecretKey: d.Get("secret_key").(string),
MFA: d.Get("mfa").(bool),
Profile: d.Get("profile").(string),
Token: d.Get("token").(string),
Region: d.Get("region").(string),
Expand Down