我是新的地形使用vs代码和" terraform“扩展从Mikael。
在可以使用ctrl+space (intellisense)和使用资源引用的地方,我学会了使用字符串内插。但是,我不确定这是否总是必需的(在我的*.tf文件中引用资源)?如果我不需要插值,而只需要引用一个资源,那么使用“字符串内插方式”真的很麻烦。
假设我有一个名为static的azurerm_storage_account资源。我可以这样做,vs代码说一切都好。
name = "${azurerm_storage_account.static-site.name}"
或者我可以这么做
name = azurerm_storage_account.static-site.name
我得到了一个错误的unexpected token while parsing list: IDENT
相比之下,如果我环顾官方文档站点,显然有些情况下没有使用引号,例如,参见本节on-explicit-resource-dependencies中的示例
resource "aws_iam_role_policy" "example" {
name = "example"
role = aws_iam_role.example.name
policy = jsonencode({
"Statement" = [{
# This policy allows software running on the EC2 instance to
# access the S3 API.
"Action" = "s3:*",
"Effect" = "Allow",
}],
})
}
resource "aws_instance" "example" {
ami = "ami-a1b2c3d4"
instance_type = "t2.micro"
iam_instance_profile = aws_iam_instance_profile.example <--------------- !!!
# However, if software running in this EC2 instance needs access
# to the S3 API in order to boot properly, there is also a "hidden"
# dependency on the aws_iam_role_policy that Terraform cannot
# automatically infer, so it must be declared explicitly:
depends_on = [
aws_iam_role_policy.example,
]
}
这会给我带来错误。或者这是我使用的蔚蓝资源特别需要的吗?上面的例子是关于aws的。
干杯
发布于 2019-07-25 15:32:19
我相信JSON encode Function的问题,而不是插值系统的问题。要克服这个错误,您可以heredoc syantx。可以使用heredoc语法提供多行字符串值。
resource "aws_iam_role_policy" "example" {
name = "example"
role = "${aws_iam_role.example.name}"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement" = [
{
"Sid": "VisualEditor5",
"Effect": "Allow",
"Action": "s3:*",
"Resource": "*"
}
]
}
EOF
}要验证这个问题,只需注释掉role = "${aws_iam_role.example.name}"。

当问题消失时,请使用heredoc语法。

这个错误背后的原因是插件提供者仍然不能提供“Terraform0.12支持”。

https://stackoverflow.com/questions/57205037
复制相似问题