Skip to content

Instantly share code, notes, and snippets.

@atsaki
Last active August 29, 2015 14:18
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 atsaki/18310bebef990d5fa712 to your computer and use it in GitHub Desktop.
Save atsaki/18310bebef990d5fa712 to your computer and use it in GitHub Desktop.
Terraformの出力を別のTerraformで利用する ref: http://qiita.com/atsaki/items/d4678c1d62093fef47ec
$ mkdir -p ~/terraform-remote/repo1
$ cd ~/terraform-remote/repo1
$ cat << EOS > repo1.tf
output "repo1_output" {
value = "Output from repo1"
}
EOS
$ terraform remote config -backend consul -backend-config="path=repo1"
Initialized blank state with remote state enabled!
Remote state configured and pulled.
$ terraform apply
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
repo1_output = Output from repo1
$ mkdir -p ~/terraform-remote/repo2
$ cd ~/terraform-remote/repo2
$ cat << EOS > repo2.tf
resource "terraform_remote_state" "repo1" {
backend = "consul"
config {
path = "repo1"
}
}
output "repo1_output" {
value = "\${terraform_remote_state.repo1.output.repo1_output}"
}
EOS
$ terraform apply
terraform_remote_state.repo1: Creating...
backend: "" => "consul"
config.#: "" => "1"
config.path: "" => "repo1"
output.#: "" => "<computed>"
terraform_remote_state.repo1: Creation complete
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.
State path: terraform.tfstate
Outputs:
repo1_output = Output from repo1
$ cd ~/terraform-remote/repo1
$ cat << EOS > repo1.tf
output "repo1_output" {
value = "Modified output from repo1"
}
EOS
$ terraform apply
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
repo1_output = Modified output from repo1
$ cd ~/terraform-remote/repo2
$ terraform apply
terraform_remote_state.repo1: Refreshing state... (ID: 2015-04-04 10:34:03.745421914 +0000 UTC)
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
repo1_output = Modified output from repo1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment