Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variables not recognized #8681

Closed
tbanyai opened this issue Feb 1, 2020 · 5 comments · Fixed by #8588
Closed

Variables not recognized #8681

tbanyai opened this issue Feb 1, 2020 · 5 comments · Fixed by #8588

Comments

@tbanyai
Copy link

tbanyai commented Feb 1, 2020

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
Copy link
Contributor

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?

@azr azr added bug and removed bug labels Feb 3, 2020
@kevinbirch
Copy link

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
Copy link
Contributor

I believe that currently, no functions are working in HCL2 templates -- we have a PR open implementing functions, here: #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
Copy link
Author

tbanyai commented Feb 4, 2020

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.

@tbanyai tbanyai closed this as completed Feb 4, 2020
@ghost
Copy link

ghost commented Apr 1, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants