Hi there,
Terraform v0.9.0-dev (24c5d59f5ceabc639cff80da28b5cc350463df77)
It is a question about the upcoming terraform version.
Before 0.9.x I used to have a remote terraform state, and it was configured as following
resource "aws_s3_bucket" "bucket" {
bucket = "some-${var.name}-${var.environment}-terraform-state"
acl = "private"
tags {
Name = "${var.name}"
Environment = "${var.environment}"
Stack = "${var.environment}"
}
}
data "terraform_remote_state" "remote_state" {
backend = "s3"
config {
bucket = "${aws_s3_bucket.bucket.id}"
key = "${var.environment}/terraform.tfstate"
region = "${var.region}"
}
}
But with terraform 0.9.x it does not work anymore, and I cannot figure out how to make it work. I tried something like this:
terraform {
backend "s3" {
bucket = "some-develop-terraform-state"
key = "develop/terraform.tfstate"
region = "us-east-1"
}
}
But, it does not pull the remote state locally. May I have some help please ?
Hi @xsellier,
I will start by disclaiming that I've not actually used the 0.9 dev stuff much yet so I'm guessing here, but with that said:
The data "terraform_remote_state" block is for retrieving the state of a separate Terraform configuration to incorporate its results into the current. On the other hand, I believe the backend "s3" block under terraform is for defining where the current module should write its state.
So these two constructs achieve different things. You should be able to keep your data "terraform_remote_state" block as-is when upgrading to 0.9.
If you were previously running terraform remote config ... commands to get remote state set up, that is what the backend "s3" block is replacing. In 0.9 you put the arguments that were previously passed to terraform remote config instead into the backend block, and run terraform init to get things started.
I think my question is related to this. Is interpolation supported in terraform {} block? I tried to pass ${var.something} but in generated .terraform/terraform.tfstate file it was still ${var.something} instead of its actual value.
@apparentlymart In version 0.9 terraform remote does not exists anymore. Meaning configuration is done via terraform init.
@zbikmarc I have the exact same question. How to inject variable in terraform {} block ?
I'm seeing the same thing that @zbikmarc sees, variables do not seem to be expanded inside the terraform { backend {} } block.
This seems to be similar to #12067, I am wondering if there is a way to leverage the new environments to manage different state backends per environment.
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.
Most helpful comment
I think my question is related to this. Is interpolation supported in
terraform {}block? I tried to pass${var.something}but in generated.terraform/terraform.tfstatefile it was still${var.something}instead of its actual value.