i want my terraform command plan to have some additional variable override according to if some variables are setted up prior in the bash script.
that is to say: the usual terraform plan
i want to expand to terraform plan -var="foo=bar"
if some variable is set up.
i tried up
terraform plan "${_TERRAFORM_DOCKER_IMAGE_OPTION:-}"
but this fails due to the terraform error:
Too many command line arguments. Configuration path expected.
is there a way to do a dynamic plan command for terraform?
the bash script is a slight modification of the bash SIMPLE boilerplate by alphabetum. https://github.com/alphabetum/bash-boilerplate/blob/master/bash-simple
with a couple of conditionals to create the -var
strings.
if [[ -n "${_DOCKER_IMAGE}" ]]
then
_TERRAFORM_DOCKER_IMAGE_OPTION="-var=\"app_image=${_DOCKER_IMAGE}\""
fi
after the variable strings are setted up, i try to use them in the terraform plan command as:
terraform plan "${_TERRAFORM_DOCKER_IMAGE_OPTION}" "${_TERRAFORM_APPLICATION_COUNT_OPTION}"
what i expect is the terraform plan to work without parameters when the vars are unset, or use the respective -var strings when they are setted up
_TERRAFORM_DOCKER_IMAGE_OPTION
? Note that${_TERRAFORM_DOCKER_IMAGE_OPTION:-}
will produce a null if the variable is not set. Usually, that syntax is used like${_TERRAFORM_DOCKER_IMAGE_OPTION:-myDefaultValue}
. Sorry, no experience with terraform. Good luck! – shellter