From d658b576b94acb0f13a62171845acc492f799b67 Mon Sep 17 00:00:00 2001 From: miguelpuiggarcia Date: Wed, 11 Sep 2024 18:14:04 +0100 Subject: [PATCH] Tests --- test/README.md | 57 ++++++++++++++++++++++++++++++++++++------- test/gcp/main.tf | 4 +++ test/gcp/variables.tf | 10 ++++++++ 3 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 test/gcp/variables.tf diff --git a/test/README.md b/test/README.md index 49b8146..9264b19 100644 --- a/test/README.md +++ b/test/README.md @@ -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. diff --git a/test/gcp/main.tf b/test/gcp/main.tf index e69de29..bd33538 100644 --- a/test/gcp/main.tf +++ b/test/gcp/main.tf @@ -0,0 +1,4 @@ +provider "google" { + project = var.gcp_project + region = var.gcp_region +} \ No newline at end of file diff --git a/test/gcp/variables.tf b/test/gcp/variables.tf new file mode 100644 index 0000000..6e389ca --- /dev/null +++ b/test/gcp/variables.tf @@ -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 +}