hashicorp / terraform-provider-terraform

Terraform terraform provider
https://www.terraform.io/docs/providers/terraform/
Mozilla Public License 2.0
24 stars 22 forks source link

Interpolations not supported in terraform_remote_state data resource in some modules but not others #12

Open hashibot opened 7 years ago

hashibot commented 7 years ago

This issue was originally opened by @ChienHuey as hashicorp/terraform#16101. It was migrated here as a result of the provider split. The original body of the issue is below.


Terraform Version

v0.10.2

Terraform Configuration Files

>>>>start main.tf<<<<<
module "global" {
  source = "s3::https://s3.amazonaws.com/my-module-bucket/one.zip"
}

module "k8s" {
  source = "s3::https://s3.amazonaws.com/my-module-bucket/two.zip"
}

# partial configuration
terraform {
  backend "s3" {
  }
}
>>>>end main.tf<<<<

>>>>start global.tf<<<<
variable tfstate_bucket_key {}
variable tfstate_bucket_name {}
variable tfstate_bucket_region {}

data "terraform_remote_state" "global_state" {
 backend = "s3"
 config {
   key = "${var.tfstate_bucket_key}"
   bucket = "${var.tfstate_bucket_name}"
   region = "${var.tfstate_bucket_region}"
  }
}
>>>>end global.tf<<<<

>>>>start k8s.tf<<<<
variable tfstate_bucket_key {}
variable tfstate_bucket_name {}
variable tfstate_bucket_region {}

data "terraform_remote_state" "k8s_state" {
 backend = "s3"
 config {
   key = "${var.tfstate_bucket_key}"
   bucket = "${var.tfstate_bucket_name}"
   region = "${var.tfstate_bucket_region}"
  }
}
>>>>end k8s.tf<<<<

Debug Output

terraform get --update=true

Runs successfully.

when running

terraform init -backend=true -backend-config="key=my_bucket_key" -backend-config="region=us-east-1" -backend-config="bucket=my_bucket"

[output] https://gist.github.com/ChienHuey/2eaa7839f797bd647a30a5d4575517ff

Crash Output

If the console output indicates that Terraform crashed, please share a link to a GitHub Gist containing the output of the crash.log file.

Expected Behavior

What should have happened?

Terraform should have initialized without issue.

Actual Behavior

What actually happened?

Terraform failed to initialize and complained the interpolations are not supported in the global module

Initializing the backend...
Error getting plugins: module root:
    module global: required variable "key" not set
    module global: required variable "bucket" not set
    module global: required variable "region" not set
  module global.root: 1 error(s) occurred:

* terraform.backend: configuration cannot contain interpolations

Steps to Reproduce

  1. terraform get --update=true
  2. terraform init -backend=true -backend-config="key=my_bucket_key" -backend-config="region=us-east-1" -backend-config="bucket=my_bucket"

Important Factoids

What's strange is that when I go into the global module and remove the interpolations. Replace them with hard-coded values for bucket, key and region. Re-run. Terraform initializes without issue. Even though there are interpolations for the data terraform_remote_state in the k8s module.

References

casank25 commented 6 years ago

I'm also having the same issue.

main.tf

module "streams" {
    source = "./streams"
}

streams/main.tf

data "terraform_remote_state" "streams" {
    backend = "s3"
    config {
        bucket = "${var.aws_bucket}"
        key = "streams/master-stack.tfstate"
        region = "${var.aws_region}"
    }
}

streams/env_vars.tf

variable "aws_region" {}
variable "aws_bucket" {}

and then i use ENV vars TF_VAR_aws_bucket and TF_VAR_aws_region and i get same errors as above. Is there any work around for this now?