-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow SGTM to be setup with Terraform Cloud (#164)
SGTM has only used the s3-backed terraform backend with terragrunt for a while. Asana is moving to using just Terraform Cloud so we want to enable SGTM to move to TFC as well. Changes: * Created a new generate block with conditionals depending on which remote backend wants to use. This should generate a well-formatted `backend.tf` * Still kept the old pathway for s3 remote backend * Added 3 new TF vars to define the backend configuration * Updated docs and instructions for deployment Pull Request synchronized with [Asana task](https://app.asana.com/0/0/1206682923832152)
- Loading branch information
1 parent
55f1359
commit 973b8b8
Showing
3 changed files
with
60 additions
and
22 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
# Should be able to use vars directly in main.tf, but can't | ||
# in backend configuration, so we use terragrunt for now. | ||
# See: https://github.com/hashicorp/terraform/issues/13022 | ||
remote_state { | ||
backend = "s3" | ||
|
||
generate = { | ||
path = "backend.tf" | ||
if_exists = "overwrite_terragrunt" | ||
generate "backend" { | ||
path = "backend.tf" | ||
if_exists = "overwrite_terragrunt" | ||
contents = <<EOF | ||
terraform { | ||
%{ if get_env("TF_VAR_terraform_backend_use_tfc", false) } | ||
backend "remote" { | ||
organization = "${get_env("TF_VAR_terraform_backend_organization_name")}" | ||
workspaces { | ||
name = "${get_env("TF_VAR_terraform_backend_workspace_name")}" | ||
} | ||
} | ||
|
||
config = { | ||
%{ else } | ||
backend "s3" { | ||
bucket = "${get_env("TF_VAR_terraform_backend_s3_bucket_name")}" | ||
dynamodb_table = "sgtm_terraform_state_lock" | ||
region = "us-east-1" | ||
key = "${path_relative_to_include()}/terraform.tfstate" | ||
} | ||
%{ endif } | ||
} | ||
EOF | ||
} |
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