-
Notifications
You must be signed in to change notification settings - Fork 123
docs: document safe local backend usage for terraform integration tests #5440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+78
−94
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # Terraform for Integration Test Resources | ||
|
|
||
| This directory contains Terraform configurations to set up the resources needed | ||
| for integration tests (Firestore, KMS, Buckets, etc.). | ||
|
|
||
| ## Safe Usage for Personal Test Projects | ||
|
|
||
| By default, this configuration uses a remote GCS backend which tracks the state | ||
| of the shared `rust-sdk-testing` project. **Do not run `terraform apply` | ||
| directly with the remote backend if you are targeting a personal test project, | ||
| as it may interfere with the shared state or disable services in the shared | ||
| project.** | ||
|
|
||
| To safely use these Terraform scripts to set up resources in your personal test | ||
| project: | ||
|
|
||
| 1. **Set your project variable**: | ||
|
|
||
| ```bash | ||
| PROJECT=$(gcloud config get project) | ||
| ``` | ||
|
|
||
| 1. **Override the backend to use local state**: Create a `backend_override.tf` | ||
| file. This tells Terraform to store the state locally on your machine instead | ||
| of the shared GCS bucket. | ||
|
|
||
| ```bash | ||
| cat > backend_override.tf <<EOF | ||
| terraform { | ||
| backend "local" { | ||
| path = "${HOME}/${PROJECT}-rust-sdk.tfstate" | ||
| } | ||
| } | ||
| EOF | ||
| ``` | ||
|
|
||
| 1. **Initialize Terraform**: | ||
|
|
||
| ```bash | ||
| terraform init -reconfigure | ||
| ``` | ||
|
|
||
| 1. **Plan and Apply**: | ||
|
|
||
| ### Option A: For Local Testing (Recommended) | ||
|
|
||
| If you only need the resources for running tests locally (and do not need to | ||
| set up GCB triggers), target only the `services` and `resources` modules. | ||
| This avoids the need to create CI-specific service accounts: | ||
|
|
||
| ```bash | ||
| terraform plan -var="project=${PROJECT}" -target=module.services -target=module.resources -out="/tmp/builds.plan" | ||
| terraform apply "/tmp/builds.plan" | ||
| ``` | ||
|
|
||
| ## Known Issues | ||
|
|
||
| - **Services not enabled error**: If Terraform fails with an error that services | ||
| like Firestore or KMS are not enabled, you may need to enable them manually | ||
| using | ||
| `gcloud services enable firestore.googleapis.com cloudkms.googleapis.com` and | ||
| retry. This can happen because Terraform checks if the service is active | ||
| before the enablement has fully propagated in the Google Cloud backend. | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like we should be able to prevent accidental deletion of / creation of things.
Maybe we can have some kind of sigil resource that must exist (and is created outside terraform) before anything runs? Or maybe something with the
prevent_destroyflag?Or maybe we just don't have permissions to delete these things, and only a robot can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created #5462 to track that idea.