Hi!
I’m excited to use HCL2 styled configs since HCL2: allow calling env as input var default value by azr · Pull Request #10240 · hashicorp/packer · GitHub, I’m using environment variables like his in the HCL config
–
variable “aws_az” {
type = string
default = env(“AWZ_AZ”)
}
variable “aws_profile” {
type = string
default = env(“AWS_PROFILE”)
}
variable “aws_region” {
type = string
default = env(“AWS_REGION”)
}
The variables aren’t being set and used and I’m getting
–
Error: NoCredentialProviders: no valid providers in chain. Deprecated.
For verbose messaging see aws.Config.CredentialsChainVerboseErrors
If I hard code these three variables, it obviously works
Am I setting something/using the variables incorrectly?
Note : packer inspect returns an empty string for these variables but if I run
echo $AWS_REGION, I get the correct value, eg: ‘us-east-1’
Packer version : 1.7.0
macos : 10.13
the environment variables are set, I’m using the standard shell
And then I’m using the variables within the source block as
profile = “${var.aws_profile}”
Which returns the profile isn’t set and there aren’t no credentials
Very strange. I can’t reproduce. The following works for me:
source "null" "example" {
communicator = "none"
}
variable "myvar" {
default = env("MYVAR")
}
build {
name = "mybuild"
sources = [
"source.null.example"
]
provisioner "shell-local" {
inline = ["echo myvar is ${var.myvar}"]
}
}
1 Like
Hey, apologies I was away for a computer for two weeks, I tried this to no avail - see I don’t get anything here, do you think it has to do w my os ver?
cat tes.pkr.hcl
source "null" "example" {
communicator = "none"
}
variable "myvar" {
default = env("MYVAR")
}
build {
name = "mybuild"
sources = [
"source.null.example"
]
provisioner "shell-local" {
inline = ["echo myvar is ${var.myvar}"]
}
}
echo $MYVAR
123
packer --version
1.7.0
packer build tes.pkr.hcl
mybuild.null.example: output will be in this color.
==> mybuild.null.example: Running local shell script: /var/folders/81/pgbj934n0kg56bv_fc8qnf2j06sxf5/T/packer-shell667017858
mybuild.null.example: myvar is
Build 'mybuild.null.example' finished after 42 milliseconds 3 microseconds.
==> Wait completed after 42 milliseconds 181 microseconds
==> Builds finished. The artifacts of successful builds are:
--> mybuild.null.example: Did not export anything. This is the null builder
had a colleague test this on macos 10.15.6 and it’s the same behavior for them
nevermind, this was us being silly cause we’re not used to zsh, my variables were not really “environment” variables, those weren’t being listed as a part of env
, I exported them out and things are working like a charm!
muchas gracias! ( apologies for the confusion )