繁体   English   中英

是否可以将标签添加到使用 Packer 创建的包含过滤后的 source_ami 名称的 AWS AMI?

[英]Is it possible to add a tag to AWS AMI created with Packer containing name of filtered source_ami?

我正在使用Packer构建 AWS AMI。 源图像由过滤器source_ami_filter定义,源块看起来像

source "amazon-ebs" "test-image" {
  ami_name      = "Some AMI Name"
  instance_type = "t2.micro"
  region        = "eu-central-1"
  source_ami_filter {
    filters = {
      name                = "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"
      root-device-type    = "ebs"
      virtualization-type = "hvm"
    }
    most_recent = true
    owners      = ["099720109477"]
  }
  tags = {
//    source_ami_name = ...  # how to get it?
  }
  ssh_username = "ubuntu"
}

如何从规范中获取使用的源 AMI 的名称?

有一些共享信息变量,例如SourceAMIName

这意味着您可以通过执行以下操作获取源 AMI 名称并将其用作标签:

source_ami_name = "{{ .SourceAMIName }}"

这是一个完整的例子: https://www.packer.io/docs/builders/amazon/ebs#tag-example

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM