Last active
April 9, 2024 08:53
-
-
Save mhmdio/fc0ba674ae1059f7422cc21dec335526 to your computer and use it in GitHub Desktop.
terraform data account_id and region
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data "aws_caller_identity" "current" {} # data.aws_caller_identity.current.account_id | |
data "aws_region" "current" {} # data.aws_region.current.name | |
output "account_id" { | |
description = "Selected AWS Account ID" | |
value = data.aws_caller_identity.current.account_id | |
} | |
output "region" { | |
description = "Details about selected AWS region" | |
value = data.aws_region.current.name | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data "aws_default_tags" "current" {} | |
# The attribute `${data.aws_caller_identity.current.account_id}` will be current account number. | |
data "aws_caller_identity" "current" {} | |
# The attribue `${data.aws_iam_account_alias.current.account_alias}` will be current account alias | |
data "aws_iam_account_alias" "current" {} | |
# The attribute `${data.aws_region.current.name}` will be current region | |
data "aws_region" "current" {} | |
# The attribute `${data.aws_partition.current.partition}` will be current partition | |
data "aws_partition" "current" {} | |
# Set as [local values](https://www.terraform.io/docs/configuration/locals.html) | |
locals { | |
account_id = data.aws_caller_identity.current.account_id | |
account_alias = data.aws_iam_account_alias.current.account_alias | |
region = data.aws_region.current.name | |
partition = data.aws_partition.current.partition | |
default_tags = data.aws_default_tags.current.tags | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment