Skip to content

Instantly share code, notes, and snippets.

@rk295
Created October 25, 2018 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rk295/9d6490d58216e1792b3fc1c4be346a3e to your computer and use it in GitHub Desktop.
Save rk295/9d6490d58216e1792b3fc1c4be346a3e to your computer and use it in GitHub Desktop.
Terraform Remote State quick explanation

Cross Referencing resources

To reference the resources created by this stack in other stacks you need to define a data resource pointing to the S3 bucket and key defined in `remote-state.tf.

Your data definition should look something like this:

data "terraform_remote_state" "vpc" {
    backend = "s3"
    config {
        bucket = "terraform-state.example.com"
        key = "eu-west-1/vpc-1"
        region = "eu-west-1"
    }
}

In your code, if you wanted (for example) to reference the vpc_id created by this stack you would do something like this:

vpc_id = "${data.terraform_remote_state.vpc.vpc_id}"
  • The .vpc. section in the variable name must match the name of the data resource you define.
  • The .vpc_id is the name of the variable from this (the source stack). Must be one of those listed in outputs.tf.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment