Packer: boolean to make run_tags the same as tags

Created on 5 Feb 2020  路  3Comments  路  Source: hashicorp/packer

Please search the existing issues for relevant feature requests, and use the
reaction feature
(https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/)
to add upvotes to pre-existing requests.

Feature Description

I'd like to make run_tags the same as tags using a boolean like "tags_same" = true, or similar which can make all tagging the same as what is defined in tags.

Use Case(s)

Tired of adding new tags to one but not the other. I'd like to keep things DRY as much as possible.

buildeamazon enhancement hcl2

All 3 comments

Hello @nitrocode, thanks for opening. We recently merged #8588 that allows to use variables in HCL2. I would like to talk about the feasibility of this in Packer HCL2 and how I think it should/will proably work ( we are not quite there yet ):

1/ I think we should add the possibility to define the tag field instead of tags, to be defined like this:

source "amazon-ebs" "example-source" {
  tag {
    key                 = "Name"
    value               = "example-asg-name"
    propagate_at_launch = false
  }
  //...

I think this would solve one issue here.

2/ from there we will need to introduce the dynamic block from Terraform

locals {
  standard_tags = {
    Component   = "user-service"
    Environment = "production"
  }
}

source "amazon-ebs" "example-source" {
  // same as before
  dynamic "tag" {
    for_each = local.standard_tags

    content {
      key                 = tag.key
      value               = tag.value
      propagate_at_launch = true
    }
}

Here are the places where that could be handy:


Builders:
https://github.com/hashicorp/packer/blob/ecaec1ac584895dd8588ba3ffa4e74afad2be20b/builder/alicloud/ecs/image_config.go#L194

https://github.com/hashicorp/packer/blob/d084cd1895ab1c39272a435e6367c96abb9e9982/builder/amazon/common/ami_config.go#L107

https://github.com/hashicorp/packer/blob/6655f93b599ce12e4fe454f6604b60d125aad2b2/builder/amazon/common/run_config.go#L200

https://github.com/hashicorp/packer/blob/6655f93b599ce12e4fe454f6604b60d125aad2b2/builder/amazon/common/run_config.go#L284

https://github.com/hashicorp/packer/blob/d084cd1895ab1c39272a435e6367c96abb9e9982/builder/amazon/common/ami_config.go#L52

https://github.com/hashicorp/packer/blob/239f97471ccc55fcd070db1a145bb1bd701186ae/builder/amazon/ebsvolume/block_device.go#L16

https://github.com/hashicorp/packer/blob/0785c2f6fca9c22bf25528e0176042799dd79df9/builder/cloudstack/config.go#L164

https://github.com/hashicorp/packer/blob/0785c2f6fca9c22bf25528e0176042799dd79df9/builder/docker/config.go#L80

https://github.com/hashicorp/packer/blob/0785c2f6fca9c22bf25528e0176042799dd79df9/builder/googlecompute/config.go#L83

https://github.com/hashicorp/packer/blob/0785c2f6fca9c22bf25528e0176042799dd79df9/builder/googlecompute/config.go#L83

https://github.com/hashicorp/packer/blob/0785c2f6fca9c22bf25528e0176042799dd79df9/builder/googlecompute/config.go#L94

https://github.com/hashicorp/packer/blob/0785c2f6fca9c22bf25528e0176042799dd79df9/builder/googlecompute/config.go#L96

https://github.com/hashicorp/packer/blob/0785c2f6fca9c22bf25528e0176042799dd79df9/builder/hcloud/config.go#L38

https://github.com/hashicorp/packer/blob/0785c2f6fca9c22bf25528e0176042799dd79df9/builder/hyperone/config.go#L65

https://github.com/hashicorp/packer/blob/0785c2f6fca9c22bf25528e0176042799dd79df9/builder/hyperone/config.go#L74

https://github.com/hashicorp/packer/blob/0785c2f6fca9c22bf25528e0176042799dd79df9/builder/lxd/config.go#L38

https://github.com/hashicorp/packer/blob/0785c2f6fca9c22bf25528e0176042799dd79df9/builder/lxd/config.go#L41

https://github.com/hashicorp/packer/blob/6305c555dfcac9c79b7c029b6565ae06e8e9cd20/builder/openstack/image_config.go#L18

https://github.com/hashicorp/packer/blob/5da5b00e1c98a1aafd53ef14533acb80d33aeaaa/builder/openstack/run_config.go#L140

https://github.com/hashicorp/packer/blob/5da5b00e1c98a1aafd53ef14533acb80d33aeaaa/builder/openstack/run_config.go#L192

https://github.com/hashicorp/packer/blob/0785c2f6fca9c22bf25528e0176042799dd79df9/builder/oracle/oci/config.go#L68

https://github.com/hashicorp/packer/blob/80dadaf3f156af775cb406027379627c6c8afed7/builder/osc/bsuvolume/block_device.go#L10

https://github.com/hashicorp/packer/blob/793b3f1990ce4090cd9ea381ddc78307df1526b2/builder/osc/common/omi_config.go#L20

https://github.com/hashicorp/packer/blob/6fb8988d088160935495d1518b4f1b77e6a5d885/builder/tencentcloud/cvm/run_config.go#L85

https://github.com/hashicorp/packer/blob/078ba7c8c38d30f988709a1b3d0d06d735a9d1c1/builder/triton/source_machine_config.go#L54-L57

https://github.com/hashicorp/packer/blob/43996843729a9585cf30f2b26b916dc895047d70/builder/triton/target_image_config.go#L38

https://github.com/hashicorp/packer/blob/43996843729a9585cf30f2b26b916dc895047d70/builder/vmware/common/vmx_config.go#L13-L17

https://github.com/hashicorp/packer/blob/073eda76aae664eba5e1f212bac2f66881748f5d/builder/vsphere/common/step_config_params.go#L16

https://github.com/hashicorp/packer/blob/0785c2f6fca9c22bf25528e0176042799dd79df9/builder/yandex/config.go#L60

https://github.com/hashicorp/packer/blob/0785c2f6fca9c22bf25528e0176042799dd79df9/builder/yandex/config.go#L76

https://github.com/hashicorp/packer/blob/0785c2f6fca9c22bf25528e0176042799dd79df9/builder/yandex/config.go#L82-L84

There are also post-processors where that could be used.

Note that this wouldn't necessarily be a breaking change as a new tag/property field would be introduced. We would have to sort of deprecate tags/properties fields and may be come up with a way to help users fix their templates, ( or don't, and not deprecate anything ).

Hey there, yesterday I opened #8720 that adds support for dynamic blocks. Up next we will need to add that new tag specific type.

Was this page helpful?
0 / 5 - 0 ratings