Terraform: how to refer tfstate in other directory

Created on 5 Sep 2016  ยท  3Comments  ยท  Source: hashicorp/terraform

like:

- folderA
  - vpcA.tf
  - peering_connection.tf
  - terraform.tfstate
- folderB
  - vpcB.tf
  - terraform.tfstate

I need vpc id of vpcB to set in peering_connection in folderA, Now I
can only just hard coding vpcB id in that file. How to solve this situation?

Thank you for your time.

Most helpful comment

data "terraform_remote_state" "folderB" {
    backend = "local"
    config {
        path = "${path.module}/../folderB/terraform.tfstate"
    }
}

you can now reference like this: data.terraform_remote_state.folderB.vpc_id

Ensure you output the vpc_id

All 3 comments

data "terraform_remote_state" "folderB" {
    backend = "local"
    config {
        path = "${path.module}/../folderB/terraform.tfstate"
    }
}

you can now reference like this: data.terraform_remote_state.folderB.vpc_id

Ensure you output the vpc_id

Oh, awesome, thank you very much

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.

Was this page helpful?
0 / 5 - 0 ratings