terraform变量声明错误

terraform变量声明错误,terraform,Terraform,我在terraform 0.11.14上,我有一个aws_cloudformation_堆栈资源,如下所示: resource "aws_cloudformation_stack" "ingress_sg" { name = "bastion-${var.accountName}-ingressIntuitIPs" lifecycle { prevent_destroy = true } parameters { VpcId = "${var.default_

我在terraform 0.11.14上,我有一个aws_cloudformation_堆栈资源,如下所示:

resource "aws_cloudformation_stack" "ingress_sg" {
  name = "bastion-${var.accountName}-ingressIntuitIPs"

  lifecycle {
    prevent_destroy = true
  }

  parameters {
    VpcId = "${var.default_vpc_id}"
    Port = 22
    Name = "bastion-${var.accountName}-ingressIntuitIPs"
    GroupName = "true"
  }
  }```

when i run terraform, its throwing this error:

```Error: module.swimlane.module.bastion.aws_cloudformation_stack.ingress_sg: 1 error occurred:
    * module.swimlane.module.bastion.aws_cloudformation_stack.ingress_sg: invalid variable syntax: "VpcId". Did you mean 'var.VpcId'? If this is part of inline `template` parameter
then you must escape the interpolation with two dollar signs. For
example: ${a} becomes $${a}.

感谢您的帮助。提前感谢。

错误消息准确地解释了您需要执行的操作:

"you must escape the interpolation with two dollar signs. For
example: ${a} becomes $${a}."
意味着

VpcId = "${var.default_vpc_id}" 
变成

VpcId = "$${var.default_vpc_id}"

在模板正文中添加额外的美元符号,如下所示修复了该问题:


template\u body=
注意:如果将模板指定为文字字符串而不是加载文件,则内联模板必须使用双美元符号(如$${hello}),以防止Terraform将配置中的值插入字符串。这是因为template_文件创建了自己的插值系统实例,其值由其嵌套的vars块提供,而不是由配置的周围范围提供
@ChrisFNZ:我应该提到,我确实尝试过使用您提到的双美元符号,但没有用。遇到了同样的错误