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

question: terraform remote state #11682

Closed
xsellier opened this issue Feb 3, 2017 · 6 comments
Closed

question: terraform remote state #11682

xsellier opened this issue Feb 3, 2017 · 6 comments

Comments

@xsellier
Copy link

xsellier commented Feb 3, 2017

Hi there,

Terraform Version

Terraform v0.9.0-dev (24c5d59)

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 ?

@apparentlymart
Copy link
Contributor

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.

@zbikmarc
Copy link
Contributor

zbikmarc commented Feb 7, 2017

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.

@xsellier
Copy link
Author

xsellier commented Feb 7, 2017

@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 ?

@hartzell
Copy link
Contributor

I'm seeing the same thing that @zbikmarc sees, variables do not seem to be expanded inside the terraform { backend {} } block.

@svanzoest
Copy link
Contributor

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.

@ghost
Copy link

ghost commented Apr 3, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants