(Please note: after receiving initial answers, this issue seems to not be just an issue with passing the variables, but with modularizing my configurations, note at the bottom where I hardcode the values yet the UI prompts me to provide the values)
I've got a project I've broken into the following directory structure
master.tf
variables.tfvars
- providers/
-- digital_ocean/
--- digital_ocean.tf
--- variables.tf
-- cloud_flare/
--- cloud_flare.tf
--- variables.tf
- management/
-- jenkins/
--- jenkins-master.tf
I'm attempting to pass my Digital Ocean and Cloudflare tokens as variables, to their respective modules. Everything below the root directory is loaded into master.tf
as a module.
I have the following in my varaibles.tfvars file:
cloudflare_email ="[email protected]"
cloudflare_token ="TOKEN_STRING"
do_token ="${DO_PAT}"
The following lines appear in my master.tf
variable "do_token" {}
module "digital_ocean" {
source = "./providers/digital_ocean"
token = "${var.do_token}"
}
variable "cloudflare_email" {}
variable "cloudflare_token" {}
module "cloud_flare" {
source = "./providers/cloud_flare"
email = "${var.cloudflare_email}"
token = "${var.cloudflare_token}"
}
My digital_ocean module looks like
variable "token" {}
provider "digitalocean" {
token = "${var.token}"
}
and the cloudflare provider looks like
variable "email" {}
variable "token" {}
provider "CloudFlare" {
email = "${var.email}"
token = "${var.token}"
}
Setting up my jenkins master server on DO
resource "digitalocean_droplet" "jenkins-master" {
...
}
From the command line I'm running terraform apply -var-file="variables.tfvars"
or I've also tried passing them via the CLI like so..
terraform apply \
-var "[email protected]" \
-var "cloudflare_token=TOKEN_STRING" \
-var "do_token=${DO_PAT}"
With the above declarations, it will send me into UI mode and prompt me for those variables rather than reading them automatically. I've replicated this behavior on both Terraform v0.9.8 and v0.9.10.
Before I started breaking everything out into separate modules, passing in variables presented no issues.
I've tried pulling the provider declarations into master.tf
to see if there were any weird behaviors with modularizing them, with the same behavior.
I also tried hard coding the values into the provider declarations and am experiencing the same behaviors.
terraform init
properly? – Ornithineterraform apply \ -var cloudflare_email="[email protected]" \ -var cloudflare_token="TOKEN_STRING" \ -var do_token="${DO_PAT}"
– Bolitho