Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelpuiggarcia committed Sep 11, 2024
1 parent 0f40fbf commit d658b57
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 9 deletions.
57 changes: 48 additions & 9 deletions test/README.md
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.
4 changes: 4 additions & 0 deletions test/gcp/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
provider "google" {
project = var.gcp_project
region = var.gcp_region
}
10 changes: 10 additions & 0 deletions test/gcp/variables.tf
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
}

0 comments on commit d658b57

Please sign in to comment.