Skip to content

Instantly share code, notes, and snippets.

@tamsky
Created September 16, 2023 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamsky/1df5198c44e9b475785373e2e532647e to your computer and use it in GitHub Desktop.
Save tamsky/1df5198c44e9b475785373e2e532647e to your computer and use it in GitHub Desktop.
locals {
# Replace a terraform-aws-provider sts assumed role with the equivalent iam role, i.e:
# arn:aws:sts::<account-id>:assumed-role/<role-name>/<numeric-session-id>
# =>
# arn:aws:iam::<account-id>:role/<role-name>
# This allows a user to simply pass `role_arn = "${data.aws_caller_identity.this.arn}"`
role_arn = replace(
var.role_arn,
"/(.*):sts:(.*):assumed-role/(.*)/[0-9]*$/",
"$1:iam:$2:role/$3",
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment