Skip to content

Commit

Permalink
chore: Add docs and fix testdata
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenthsh committed May 21, 2024
1 parent f7ff0c9 commit 3789e29
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
28 changes: 22 additions & 6 deletions config/v2/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,20 +810,36 @@ func resolveGenericProvider(
if p.Enabled != nil {
enabled = *p.Enabled
}
// special assume role config block handling
assumeRoleBlock := make(map[string]string)
setAssumeRoleBlock := false
for key, value := range p.Config {
if value == nil {
delete(config, key)
} else {
// specially for AWS associate assume role
if key == "assume_role" {
tmp := fmt.Sprintf("arn:aws:iam::%s:role/%s", *awsConfig.AccountID, value)
config["assume_role"] = map[string]string{"role_arn": tmp}
config["region"] = *awsConfig.Region
} else {
switch key {
case "assume_role":
setAssumeRoleBlock = true
// build assume_role_block
// ref: https://registry.terraform.io/providers/hashicorp/awscc/latest/docs#assume-role
// ValidateAWSProvider should ensure AccountID is not nil
assumeRoleBlock["role_arn"] = fmt.Sprintf("arn:aws:iam::%s:role/%s", *awsConfig.AccountID, value)
// TODO: is it ok that these are ignored unless `assume_role` key is defined?
case "session_name":
fallthrough
case "external_id":
assumeRoleBlock[key] = value.(string)
default:
config[key] = value
}
}
}
if setAssumeRoleBlock {
// inherit resolved awsConfig region and accountID
// TODO: handle additionalRegions/additionalProvider configuration?
config["region"] = *awsConfig.Region
config["assume_role"] = assumeRoleBlock
}
return source, customProvider, version, enabled
}

Expand Down
3 changes: 2 additions & 1 deletion testdata/generic_providers_yaml/fogg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ envs:
custom_provider: false
config:
baz_token: prod_token_arn
aws_assume_role: "TerraformExecutionRole"
assume_role: "TerraformExecutionRole"
session_name: "foo"
components:
network: {}
stg:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3789e29

Please sign in to comment.