【问题标题】:Cannot include the given value in a string template: string required不能在字符串模板中包含给定值:需要字符串
【发布时间】:2022-02-09 19:48:12
【问题描述】:

有人有使用 Terraform 构建 Packer ec2 的经验并且可以帮助我吗? 基本上,对于代表 Packer 的“null_resource”,我收到此错误

   │ Error: Invalid template interpolation value
│
│   on asg.tf line 14, in resource "null_resource" "packer":
│    7:     command = <<EOF
│    8: packer build \
│    9:   -var region=${var.region} \
│   10:   -var vpc_id=${module.vpc.vpc_id} \
│   11:   -var subnet_id="${module.vpc.private_subnets[0]}" \
│   12:   -var instance_type=${var.instance_type} \
│   13:   -var ami_name=${var.ami_name} \
│   14:   -var source_ami=${data.aws_ami.search} \
│   15:   -var image_path=${local.image_complete_path} \
│   16:   template.json
│   17: EOF
│     ├────────────────
│     │ data.aws_ami.search is object with 34 attributes
│
│ Cannot include the given value in a string template: string required.

希望能得到一些帮助,谢谢大家!

【问题讨论】:

    标签: amazon-web-services terraform amazon-ami packer


    【解决方案1】:

    错误信息非常有表现力:

    data.aws_ami.search 是具有 34 个属性的对象

    你需要一个单一的值,所以你需要一种过滤属性的方法。

    根据 aws_ami 数据源 [1] 的 Terraform 文档,您可能需要 name 属性,因此您应该寻找的值是:

    data.aws_ami.search.name
    

    如果您需要 AMI ID,那么您应该使用:

    data.aws_ami.search.id
    

    这与使用data.aws_ami.search.image_id [2] 相同。


    [1]https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami#name

    [2]https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami#image_id

    【讨论】:

      猜你喜欢
      • 2021-03-22
      • 2020-03-18
      • 1970-01-01
      • 1970-01-01
      • 2011-03-18
      • 2018-05-15
      • 2021-01-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多