Terraform: Error from provider defined in module "unknown variable accessed: var.access_key", TF 0.8.0

Created on 14 Dec 2016  ·  8Comments  ·  Source: hashicorp/terraform

Terraform Version

Error under Terraform v0.8.0, worked as expected under v0.7.13

Affected Resource(s)

Appears when defining a provider inside a module. Works as expected if provider is defined outside the module.

Terraform Configuration Files

fixtures/module/module.tf

variable "access_key" {}
variable "secret_key" {}
variable "region" {
    default = "us-east-1"
}
variable "bucket" {}

module "test_module" {
  source = "../aws"

  access_key = "${var.access_key}"
  secret_key = "${var.secret_key}"
  region = "${var.region}"

  bucket = "${var.bucket}"
}

fixtures/aws/example.tf

variable "access_key" {}
variable "secret_key" {}
variable "region" {
    default = "us-east-1"
}
variable "bucket" {}

provider "aws" {
  access_key = "${var.access_key}"
  secret_key = "${var.secret_key}"
  region     = "${var.region}"
}

resource "aws_s3_bucket_object" "s3_object" {
  bucket     = "${var.bucket}"
  key        = "foo"
  content    = "foo"
}

Debug Output

When running apply or plan, it returns the following error (sometimes says secret_key is unknown instead):

Error running plan: 1 error(s) occurred:

* 1:3: unknown variable accessed: var.access_key in:

${var.access_key}

Debug output from 0.8.0 (busted): https://gist.github.com/ljfranklin/9a22219aea0097047e187456680cce61
Debug output from 0.7.13 (working): https://gist.github.com/ljfranklin/4da85c6c60d13119a9437ceb430b9eb5

Expected Behavior

Expected plan or apply to succeed against the above module: terraform plan fixtures/module/. This worked as expected under v0.7.13.

Actual Behavior

Terraform returns the above error.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Create the two files listed above.
  2. terraform plan fixtures/module/
  3. Verify "unknown variable accessed" error appears

Important Factoids

If provider is defined in module.tf rather than inside the module source (example.tf) then the plan succeeds as expected.

bug core

Most helpful comment

@mitchellh I think this is only partially fixed as I can see unknown variable accessed messages when applying one resource using -target

All 8 comments

Reproduced, working on it. In the mean time, you can workaround it by specifying -Xlegacy-graph on the CLI.

Also, thanks for the great bug report and reproduction case.

Fix is in reference PR, will be fixed in 0.8.1. Thank you!

I want to note that this only happens if a module variable is used _only_ by a provider. If it is also referenced by anything else (output, resource) then this works. This can be used by a workaround if -Xlegacy-graph can't be used since you're using new TF 0.8 features.

I am also facing same issue with terraform 08.what is the workaround?

Regards,
Ashwini

This is fixed in 0.8.1 which we just released!

On Dec 15, 2016, 3:35 AM -0800, Ashwini_Mhatre notifications@github.com, wrote:
>

I am also facing same issue with terraform 08.what is the workaround?

Regards,
Ashwini


You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub (https://github.com/hashicorp/terraform/issues/10711#issuecomment-267306792), or mute the thread (https://github.com/notifications/unsubscribe-auth/AAAFE973ueWSypcWo5q4uO4RbvvuNh9Rks5rISXrgaJpZM4LMV5t).

@mitchellh I think this is only partially fixed as I can see unknown variable accessed messages when applying one resource using -target

@mcanevet This was also reported here: #10911

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.

Was this page helpful?
0 / 5 - 0 ratings