I discovered a handy trick to get the account id of the given profile/account. The key is to use a new data source object and pass it the provider. See the code below.
provider "aws" {
alias = "env_e1"
profile = "seclab-sso"
region = "us-east-1"
}
data "aws_caller_identity" "sec" {
provider = aws.env_e1
}
output "sec-account-id" {
value = data.aws_caller_identity.sec.account_id
}
So no need to ever put account ids in terraform code again? I’m good with that.
Happy building,
D
Don’t add account id to your Terraform code