Last active
August 29, 2015 14:18
-
-
Save atsaki/18310bebef990d5fa712 to your computer and use it in GitHub Desktop.
Terraformの出力を別のTerraformで利用する ref: http://qiita.com/atsaki/items/d4678c1d62093fef47ec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mkdir -p ~/terraform-remote/repo1 | |
$ cd ~/terraform-remote/repo1 | |
$ cat << EOS > repo1.tf | |
output "repo1_output" { | |
value = "Output from repo1" | |
} | |
EOS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ terraform remote config -backend consul -backend-config="path=repo1" | |
Initialized blank state with remote state enabled! | |
Remote state configured and pulled. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ terraform apply | |
Apply complete! Resources: 0 added, 0 changed, 0 destroyed. | |
Outputs: | |
repo1_output = Output from repo1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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