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

Provider blocks unaware of externally given variables #124

Closed
esmevane opened this issue Jul 30, 2014 · 2 comments
Closed

Provider blocks unaware of externally given variables #124

esmevane opened this issue Jul 30, 2014 · 2 comments
Labels

Comments

@esmevane
Copy link

When given the two files:

# terraform.tfvars
digital_ocean_token = "12345"
size = "512mb"

# terraform.tf
provider "digitalocean" {
  token = "${var.digital_ocean_token}"
}

resource "digitalocean_droplet" "web" {
  image = "ubuntu1404"
  name = "web-1"
  region = "nyc2"
  size = "${var.size}"
}

We get this error:

$ terraform plan
Error validating config: 1 error(s) occurred:

* provider config 'digitalocean': unknown variable referenced: digital_ocean_token

${var.size} seems to work fine.

Changing the configuration to this:

# terraform.tfvars
do_token = "12345"
size = "512mb"

# terraform.tf
variable "digital_ocean_token" {
  default = "${var.do_token}"
}

provider "digitalocean" {
  token = "${var.digital_ocean_token}"
}

resource "digitalocean_droplet" "web" {
  image = "ubuntu1404"
  name = "web-1"
  region = "nyc2"
  size = "${var.size}"
}

Seems to remove the error.

Similarly, just passing things in over the command line with -var or specifically invoking the -var-file argument produces the same behavior outlined above, where directly referencing the given arguments results in an error, but adding an indirect variable block fixes it.

It seems like the provider block is not accessing externally given variables. I'm able to produce this with the aws provider as well.

@pearkes pearkes added the bug label Jul 30, 2014
@mitchellh
Copy link
Contributor

The provider should be seeing this. Are these both your complete files? I don't see a declaration of digital_ocean_token anywhere. (I see you setting it in tfvars but it needs to be declared with a variable block somewhere). Is that in another file?

Can you paste all of your exact files (properly censored)?

@esmevane
Copy link
Author

Oops! I was definitely missing the previous variable declaration. Also variables.tf (don't know how I missed that).

I did a little more digging and I think the provider block is seeing things just fine, and I have just duplicated this issue. Provider blocks seem to be working fine, no distinction from any other block.

FWIW, Here it is as I have it now:

# variables.tf
variable "digital_ocean_token" { }

# terraform.tfvars
digital_ocean_token = "12345"

# terraform.tf
provider "digitalocean" {
  token = "${var.digital_ocean_token}"
}

resource "digitalocean_droplet" "web" {
  image = "ubuntu-14-04-x64"
  name = "web-1"
  region = "nyc2"
  size = "512mb"
}

With things like this, terraform plan results in:

There are warnings and/or errors related to your configuration. Please
fix these before continuing.

Errors:

  * Required variable not set: digital_ocean_token

When I run terraform plan -var-file terraform.tfvars:

Refreshing Terraform state prior to plan...


The Terraform execution plan has been generated and is shown below.
Resources are shown in alphabetical order for quick scanning. Green resources
will be created (or destroyed and then created if an existing resource
exists), yellow resources are being changed in-place, and red resources
will be destroyed.

Your plan was also saved to the path below. Call the "apply" subcommand
with this plan file and Terraform will exactly execute this execution
plan.

Path: terraforming.out

+ digitalocean_droplet.web
    backups:            "" => "<computed>"
    image:              "" => "ubuntu-14-04-x64"
    ipv4_address:       "" => "<computed>"
    ipv6:               "" => "<computed>"
    ipv6_address:       "" => "<computed>"
    locked:             "" => "<computed>"
    name:               "" => "web-1"
    private_networking: "" => "<computed>"
    region:             "" => "nyc2"
    size:               "" => "512mb"
    status:             "" => "<computed>"

Sorry for the misdirection!

catsby pushed a commit that referenced this issue Nov 9, 2015
Updates the docs and clarifies the usage of `do_token` variable.

I was experiencing an issue mentioned here #124 and so adding more docs should be helpful.
dpetzold pushed a commit to clearcare/terraform that referenced this issue Nov 12, 2015
Updates the docs and clarifies the usage of `do_token` variable.

I was experiencing an issue mentioned here hashicorp#124 and so adding more docs should be helpful.
grubernaut pushed a commit to digitalocean/terraform-provider-digitalocean that referenced this issue Jun 9, 2017
Updates the docs and clarifies the usage of `do_token` variable.

I was experiencing an issue mentioned here hashicorp/terraform#124 and so adding more docs should be helpful.
@ghost ghost locked and limited conversation to collaborators May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants