ошибки объявления переменных terraform - PullRequest
0 голосов
/ 07 ноября 2019

Я нахожусь на terraform 0.11.14, у меня есть ресурс aws_cloudformation_stack, как показано ниже:

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}.

Любая помощь приветствуется. заранее спасибо.

Ответы [ 2 ]

0 голосов
/ 08 ноября 2019

добавление дополнительного знака доллара в тело шаблона, как показано ниже, устраняет проблему:

template_body = <<STACK ..Outputs: SecurityGroupId: Condition: CreateSecurityGroup Export: Name: !Sub $${VpcId}:$${Name}-tcp-$${Port}:id Value: !Ref SecurityGroup STACK }

0 голосов
/ 07 ноября 2019

Сообщение об ошибке объясняет, что именно вам нужно сделать:

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

Означает, что

VpcId = "${var.default_vpc_id}" 

становится

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