Skip to content

Instantly share code, notes, and snippets.

@Erouan50
Created June 20, 2022 21:51
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 Erouan50/e0aa4d091e069d977bb95629bcf6101e to your computer and use it in GitHub Desktop.
Save Erouan50/e0aa4d091e069d977bb95629bcf6101e to your computer and use it in GitHub Desktop.
tfc_ouptputs vs terraform_remote_state
variable "github_organization" {}
variable "tfc_organization" {}
variable "oauth_token_id" {}
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]
}
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