Terraform remote state w/ vars

193 views
Skip to first unread message

gerardo...@renlearn.com

unread,
Oct 16, 2016, 9:34:21 PM10/16/16
to Terraform
I have the below code block in my main.tf file to enable remote state storage.

data "terraform_remote_state" "redshift-demo" {
    backend = "s3"
    config {
        bucket = "${var.s3}"
        key = "${var.s3_key}/${var.env}-state.tfstate"
        region = "${var.aws_region}"
    }
}

 I have a separate dev.tfvars file that has the variables defined as below.

# S3 Remote State Config
s3 = "my-bucket"
s3_key = "folder-name"
env = "dev"
aws_region = "us-west-2"

When I execute a terraform plan -var-file="dev.tfvars" I get the error below stating the variables are not defined. But I have defined them in the dev.tfvars files so not sure exactly whats missing.

 resource 'data.terraform_remote_state.redshift-test' config: unknown variable referenced: 's3'. define it with 'variable' blocks
* resource 'data.terraform_remote_state.redshift-test' config: unknown variable referenced: 's3_key'. define it with 'variable' blocks
* resource 'data.terraform_remote_state.redshift-test' config: unknown variable referenced: 'env'. define it with 'variable' blocks
* resource 'data.terraform_remote_state.redshift-test' config: unknown variable referenced: 'aws_region'. define it with 'variable' blocks

Thanks..

James Turnbull

unread,
Oct 16, 2016, 10:34:31 PM10/16/16
to terrafo...@googlegroups.com
Even if you have the variables in tfvars you still need to create
`variable` definitions for them:

variable s3 {}
variable s3_key {}
etc

Kind Regards

James Turnbull

--
* The Terraform Book (https://terraformbook.com)
* The Art of Monitoring (https://artofmonitoring.com)
* The Docker Book (https://dockerbook.com)
* The Logstash Book (https://logstashbook.com)

gerardo...@renlearn.com

unread,
Oct 17, 2016, 9:36:59 AM10/17/16
to Terraform
Thanks that worked..
Reply all
Reply to author
Forward
0 new messages