tags - Packer ec2-ami 部署上的标签格式
问题描述
我正在尝试第一次使用 Hashicorp Packer 创建一个亚马逊 ec2 ami,但是在创建标签时遇到了这个失败,我已经尝试了一些格式的试错测试,但仍然不走运
[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 如下所示:
[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 看起来像这样:
[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"
]
}
解决方案
您的变量默认值为tags
type list(string)
。run_tags和run_volume_tags指令都需要type 。map[string]string
我能够对您的变量文件进行以下更改并packer init
成功运行:
variable "tags" {
default = {
environment = "testing"
type = "none"
production = "later"
}
type = map(string)
}
推荐阅读
- javascript - jQuery延迟并获取php变量
- angular - 调用 ComponentFactoryResolver 时出现错误未找到具有延迟加载的组件的组件工厂
- android - Firebase 性能监控库与作为签名 jar 分发的库不兼容
- nosql - 通过包含在 MarkLogic 中包含 XQuery 结果
- firebase - 如何使用新的存储 URL 扩展 Firebase App 对象
- node.js - CORS 预检通道未成功,React to Express
- json - 如何使用 Google Apps 脚本将 JSON 文件保存到 Google Drive?
- javascript - D3.js 缩放 translateTo 问题
- c# - 在 xUnit 中跳过集合相等性中的类型检查
- php - 在 PHP 中按对象值的总和对多维数组进行排序