-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f40fbf
commit d658b57
Showing
3 changed files
with
62 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,56 @@ | ||
# Module Testing | ||
Here's an improved version of your README file that includes instructions for running Terraform plans for the entire configuration as well as specific modules with dynamic variables: | ||
|
||
Use this folder to run locally the testing of the modules | ||
## **Module Testing** | ||
|
||
**Run** | ||
Use this folder to run local testing of the modules. | ||
|
||
`cd gcp` | ||
### **Setup** | ||
|
||
`terraform init` | ||
1. **Navigate to the GCP Directory:** | ||
|
||
`terraform validate` | ||
```bash | ||
cd gcp | ||
``` | ||
|
||
`terraform plan` | ||
2. **Initialize Terraform:** | ||
|
||
If all green, all good to go. | ||
Initialize the Terraform working directory. This step downloads the necessary provider plugins. | ||
|
||
TODO: Add this in CI to actually build the module examples on its own project | ||
```bash | ||
terraform init | ||
``` | ||
|
||
3. **Validate Configuration:** | ||
|
||
Validate the Terraform files to ensure the configuration is syntactically valid and internally consistent. | ||
|
||
```bash | ||
terraform validate | ||
``` | ||
|
||
### **Run Terraform Plan** | ||
|
||
#### **Whole Plan** | ||
|
||
To generate an execution plan for the entire configuration, run: | ||
|
||
```bash | ||
terraform plan | ||
``` | ||
|
||
#### **Specific Modules** | ||
|
||
To generate an execution plan targeting a specific module, use the `-target` option along with dynamic variable values: | ||
|
||
```bash | ||
terraform plan --target="module.cloud-cloudbuild-trigger" -var "gcp_project=infra-dev-migue-93b99628" -var "gcp_region=europe-west2" | ||
``` | ||
|
||
### **Notes** | ||
|
||
- Ensure that the `gcp_project` and `gcp_region` variables are set appropriately for your environment. These can be passed directly in the command line as shown above, or set in a `terraform.tfvars` file. | ||
- If all validations and plans are successful, the configuration is ready to be applied. | ||
|
||
### **Future Improvements** | ||
|
||
- **CI Integration:** Plan to integrate this process into a Continuous Integration (CI) pipeline to automatically build and test the module examples in a dedicated project environment. |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
provider "google" { | ||
project = var.gcp_project | ||
region = var.gcp_region | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
variable "gcp_project" { | ||
description = "The GCP project ID" | ||
type = string | ||
} | ||
|
||
variable "gcp_region" { | ||
description = "The GCP region" | ||
type = string | ||
default = "europe-west2" # You can set a default value if desired | ||
} |