首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Packer ec2-ami部署上的标记格式

Packer ec2-ami部署上的标记格式
EN

Stack Overflow用户
提问于 2021-07-05 08:28:34
回答 1查看 1.1K关注 0票数 1

我正在尝试第一次使用Hashicorp创建一个amazon,但是在创建标记时遇到了这个失败,我已经尝试了一些格式的尝试和错误测试,但是仍然是不吉利的。

代码语言:javascript
复制
[ec2-boy-oh-boy@ip-172-168-99-23 pogi]$ packer init .
Error: Missing item separator

  on variables.pkr.hcl line 28, in variable "tags":
  27:   default = [
  28:    "environment"    : "testing"

Expected a comma to mark the beginning of the next item. 

我的代码ec2.pkr.hcl如下所示:

代码语言:javascript
复制
[ec2-boy-oh-boy@ip-172-168-99-23 pogi]$ cat ec2.pkr.hcl 
packer {
  required_plugins {
    amazon = {
      version = ">= 0.0.2"
      source  = "github.com/hashicorp/amazon"
    }
  }
}

source "amazon-ebs" "ec2" {
  ami_name      = "${var.ami_prefix}-${local.timestamp}"
  instance_type = "t2.micro"
  region        = "us-east-1"
  vpc_id        = "${var.vpc}"
  subnet_id     = "${var.subnet}"
  security_group_ids = ["${var.sg}"]
  ssh_username = "ec2-boy-oh-boy"
  source_ami_filter {
    filters = {
      name                = "amzn2-ami-hvm-2.0*"
      root-device-type    = "ebs"
      virtualization-type = "hvm"
    }
    most_recent = true
    owners      = ["12345567896"]
  }
  launch_block_device_mappings = [
    {
        "device_name": "/dev/xvda",
        "delete_on_termination": true
        "volume_size": 10
        "volume_type": "gp2"
    }
   ]
  run_tags = "${var.tags}"
  run_volume_tags = "${var.tags}"
}

build {
  sources = [
    "source.amazon-ebs.ec2"
  ]
}
[ec2-boy-oh-boy@ip-172-168-99-23 pogi]$ 

然后我的代码variables.pkr.hcl如下所示:

代码语言:javascript
复制
 [ec2-boy-oh-boy@ip-172-168-99-23 pogi]$ cat variables.pkr.hcl 
locals {
  timestamp = regex_replace(timestamp(), "[- TZ:]", "")
}

variable "ami_prefix" {
  type    = string
  default = "ec2-boy-oh-boy"
}

variable "vpc" {
  type    = string
  default = "vpc-asd957d"
}

variable "subnet" {
  type    = string
  default = "subnet-asd957d"
}

variable "sg" {
  type    = string
  default = "sg-asd957d"
}

variable "tags" {
  type = map
  default = [
    environment        = "testing"
    type               = "none"
    production         = "later"
  ]
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-06 17:24:19

tags变量的默认值为list(string)类型。标签标签指令都期望类型为map[string]string

我对变量文件进行了以下更改,并成功地运行了packer init

代码语言:javascript
复制
variable "tags" {
  default = {
    environment = "testing"
    type        = "none"
    production  = "later"
  }

  type = map(string)
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68252936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档