Tagging AMI with the source AMI ID

1,370 views
Skip to first unread message

Matt Brewster

unread,
Jul 12, 2017, 9:38:32 AM7/12/17
to Packer
Hi all,

Most of my builders look up an AMI based on a source_ami_filter. I'd like to tag the created AMI with the source AMI ID so there's an audit of the hierarchy. The documentation states:

tags (object of key/value strings) - Tags applied to the AMI and relevant snapshots. This is a template engine where the SourceAMI variable is replaced with the source AMI ID and BuildRegion variable is replaced with the value of region.

So far I have tried:

{
"variables": {
"SourceAMI": ""
},
"builders": [
{
"type": "amazon-ebs",
"region": "eu-west-2",
"instance_type": "t2.small",
"ssh_username": "ec2-user",
"ami_name": "root-{{timestamp}}",
"source_ami": "ami-11130775",
"tags": {
"based_on_ami": "{{user `SourceAMI`}}"
}
}
]
}


{
"builders": [
{
"type": "amazon-ebs",
"region": "eu-west-2",
"instance_type": "t2.small",
"ssh_username": "ec2-user",
"ami_name": "root-{{timestamp}}",
"source_ami": "ami-11130775",
"tags": {
"based_on_ami": "{{user `SourceAMI`}}"
}
}
]
}


{
"builders": [
{
"type": "amazon-ebs",
"region": "eu-west-2",
"instance_type": "t2.small",
"ssh_username": "ec2-user",
"ami_name": "root-{{timestamp}}",
"source_ami": "ami-11130775",
"tags": {
"based_on_ami": "{{`SourceAMI`}}"
}
}
]
}


{
"builders": [
{
"type": "amazon-ebs",
"region": "eu-west-2",
"instance_type": "t2.small",
"ssh_username": "ec2-user",
"ami_name": "root-{{timestamp}}",
"source_ami": "ami-11130775",
"tags": {
"based_on_ami": "{{`.SourceAMI`}}"
}
}
]
}


So far none of these have worked. Can someone point me in the right direction please..?

Thanks
Matt

Rickard von Essen

unread,
Jul 12, 2017, 10:11:21 AM7/12/17
to packe...@googlegroups.com
This should work:

"tags": {
"based_on_ami": "{{.SourceAMI}}"
}

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/3b7d907b-2fc2-40f6-9e73-2ed00b501c6b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matt Brewster

unread,
Jul 12, 2017, 11:55:20 AM7/12/17
to Packer
That doesn't work I'm afraid, it creates the tag but the value is "<no value>".
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.

Rickard von Essen

unread,
Jul 12, 2017, 12:37:40 PM7/12/17
to packe...@googlegroups.com
Which version of Packer? 

To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/07a2373f-3a0a-47da-8a9b-6c046c49ac1a%40googlegroups.com.

Matt Brewster

unread,
Jul 13, 2017, 12:10:24 PM7/13/17
to Packer
It turns out to be a really old version! I've updated to the latest and it's working now, thanks.
Which version of Packer? 

Reply all
Reply to author
Forward
0 new messages