hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.
http://www.packer.io
Other
14.99k stars 3.32k forks source link

Variables not recognized #8681

Closed tbanyai closed 4 years ago

tbanyai commented 4 years ago

I am trying to migrate my docker builds to Packer 1.5/HCL2 (in the hope so I can split up the single monolithic scripts and share the provisioners between my other scripts building ami images). However the user variables do not seem to work, for example running this simple case:

variables { source_image= "centos:7.3.1611" username= "blahblahuser" }
source "docker" "base_setup"{ image= "{{user source_image}}" commit= true } build { sources = [ "docker.base_setup" ] provisioner "shell" { inline= [ "useradd -m -s /bin/bash -G wheel {{user username}}", ] } }

ends up in this error:

Error: render 'image': template: root:1:2: executing "root" at <user source_image>: error calling user: test in:

{{user source_image}}

on spark_image_docker_1.pkr.hcl line 7, in source "docker" "base_setup": 7: source "docker" "base_setup"{ ==> Builds finished but no artifacts were created.

Any ideas?

sylviamoss commented 4 years ago

Hi @tbanyai! Thanks for reaching out. Unfortunately, {{user ...}} is one one of the function that is not currently working on HCL2 templates. We are currently working on making this one and other functions available to it and should be out soon. Until then, could you use this values straight forward in your HCL2 templates?

kevinbirch commented 4 years ago

Unfortunately, {{user ...}} is one one of the function that is not currently working on HCL2 templates. We are currently working on making this one and other functions available to it and should be out soon.

@sylviamoss Is there a list of functions that currently work (or don't work) for HCL2?

Until then, could you use this values straight forward in your HCL2 templates?

By this do you mean use the values as literals instead of variables or something else?

SwampDragons commented 4 years ago

I believe that currently, no functions are working in HCL2 templates -- we have a PR open implementing functions, here: https://github.com/hashicorp/packer/pull/8588. If you scroll to the store_artifacts build, you can click through and pull a binary testing that behavior out, or you can wait until the v1.5.2 release which should contain that PR :)

Yes, I believe Moss was suggesting hardcoding instead of using variables in the meantime.

tbanyai commented 4 years ago

OK, thanks for the clarification. In this case I will delay upgrading until 1.5.2 comes out because my real scripts uses variables extensively.

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.