Skip to content

Commit

Permalink
Implement AWS EXTERNAL ID feature (#142)
Browse files Browse the repository at this point in the history
* Implement AWS EXTERNAL ID feature

* Fix null externalid issue
  • Loading branch information
alemuro committed Feb 27, 2021
1 parent d4da387 commit 695ab95
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ The precedence of configurations is as described below.
|`--dynamodb-table` | `AWS_DYNAMODB_TABLE` | `aws.dynamodb-table` | AWS DynamoDB table for locks | - |
|`--s3-bucket` | `AWS_BUCKET` | `aws.bucket` | AWS S3 bucket | - |
|`--app-role-arn` | `APP_ROLE_ARN` | `aws.app-role-arn` | Role ARN to Assume | - |
|`--aws-external-id` | `AWS_EXTERNAL_ID` | `aws.external-id` | External ID to use when assuming role | - |
|`--key-prefix` | `AWS_KEY_PREFIX` | `aws.key-prefix` | AWS Key Prefix | - |
|`--file-extension` | `AWS_FILE_EXTENSION` | `aws.file-extension` | File extension(s) of state files. Use multiple CLI flags or a comma separated list ENV variable | .tfstate |
|`--base-url` | `TERRABOARD_BASE_URL` | `web.base-url` | Base URL | / |
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type AWSConfig struct {
Endpoint string `long:"aws-endpoint" env:"AWS_ENDPOINT" yaml:"endpoint" description:"AWS endpoint."`
Region string `long:"aws-region" env:"AWS_REGION" yaml:"region" description:"AWS region."`
APPRoleArn string `long:"aws-role-arn" env:"APP_ROLE_ARN" yaml:"app-role-arn" description:"Role ARN to Assume."`
ExternalID string `long:"aws-external-id" env:"AWS_EXTERNAL_ID" yaml:"external-id" description:"External ID to use when assuming role."`
}

// TFEConfig stores the Terraform Enterprise configuration
Expand Down
6 changes: 5 additions & 1 deletion state/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ func NewAWS(c *config.Config) AWS {

if len(c.AWS.APPRoleArn) > 0 {
log.Debugf("Using %s role", c.AWS.APPRoleArn)
creds := stscreds.NewCredentials(sess, c.AWS.APPRoleArn)
creds := stscreds.NewCredentials(sess, c.AWS.APPRoleArn, func(p *stscreds.AssumeRoleProvider) {
if c.AWS.ExternalID != "" {
p.ExternalID = aws_sdk.String(c.AWS.ExternalID)
}
})
awsConfig.WithCredentials(creds)
}

Expand Down

0 comments on commit 695ab95

Please sign in to comment.