-
-
Save Erouan50/e0aa4d091e069d977bb95629bcf6101e to your computer and use it in GitHub Desktop.
tfc_ouptputs vs terraform_remote_state
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
variable "github_organization" {} | |
variable "tfc_organization" {} | |
variable "oauth_token_id" {} |
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
resource "github_repository" "workspace_a" { | |
name = "workspace-a" | |
auto_init = true | |
} | |
resource "github_repository_file" "workspace_a" { | |
repository = github_repository.workspace_a.name | |
content = <<EOF | |
output "my_secret" { | |
value = "my-super-secret" | |
# Mark as insensitive due to https://github.com/hashicorp/terraform-provider-tfe/issues/449 | |
# sensitive = true | |
} | |
EOF | |
file = "main.tf" | |
} | |
resource "tfe_workspace" "workspace_a" { | |
name = "workspace-a" | |
organization = var.tfc_organization | |
auto_apply = true | |
vcs_repo { | |
identifier = "${var.github_organization}/${github_repository.workspace_a.name}" | |
oauth_token_id = var.oauth_token_id | |
} | |
depends_on = [github_repository_file.workspace_a] | |
} |
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
resource "github_repository" "workspace_b" { | |
name = "workspace-b" | |
auto_init = true | |
} | |
resource "github_repository_file" "workspace_b" { | |
repository = github_repository.workspace_b.name | |
content = <<EOF | |
data "tfe_outputs" "workspace_a" { | |
organization = "${var.tfc_organization}" | |
workspace = "workspace-a" | |
} | |
resource "null_resource" "test" { | |
provisioner "local-exec" { | |
command = "echo $${data.tfe_outputs.workspace_a.values.my_secret}" | |
} | |
} | |
EOF | |
file = "main.tf" | |
} | |
resource "tfe_workspace" "workspace_b" { | |
name = "workspace-b" | |
organization = var.tfc_organization | |
auto_apply = true | |
vcs_repo { | |
identifier = "${var.github_organization}/${github_repository.workspace_b.name}" | |
oauth_token_id = var.oauth_token_id | |
branch = "master" | |
} | |
depends_on = [ | |
github_repository.workspace_b, | |
time_sleep.this | |
] | |
} | |
// Let's wait for the workspace a to apply | |
resource "time_sleep" "this" { | |
create_duration = "30s" | |
depends_on = [tfe_workspace.workspace_a] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment