【发布时间】:2021-09-24 14:34:25
【问题描述】:
我想在 terraform 中访问我的 AWS 账户 ID。我可以通过aws_caller_identity 每the documentation 来解决它。然后如何使用我创建的变量?在以下情况下,我尝试在 S3 存储桶名称中使用它:
data "aws_caller_identity" "current" {}
output "account_id" {
value = data.aws_caller_identity.current.account_id
}
resource "aws_s3_bucket" "test-bucket" {
bucket = "test-bucket-${account_id}"
}
尝试以这种方式使用account_id 变量会给我错误A reference to a resource type must be followed by at least one attribute access, specifying the resource name. 我希望我没有正确调用它?
【问题讨论】:
-
"test-bucket-${account_id}"应该是"test-bucket-${data.aws_caller_identity.current.account_id}"- 或者定义一个具有相同值的locals。 -
我希望有办法不必一遍又一遍地重复
ata.aws_caller_identity.current.account_id。知道如何定义分配给 account_id 的本地人吗?
标签: amazon-web-services amazon-s3 terraform