A Terraform module uses as a template to start new module.
It includes all the automation (versioning, providers update, lint, security) and best practices from HashiCorp.
- Pre-commit: enforce checks on the module before commit
- Semantic Release: automate the release and version process
- Reviewdog: automate the review process with per code line comments (TFLint & TFSec checks)
- Renovate: automate the dependency management (update provider version, etc.)
- ShiftLeft SCAN: security audit tool to detect security flaws in application and infrastructure code
gcloud auth application-default login
Go to the Google Cloud Platform Console and activate the following APIs:
- compute.googleapis.com
If you want to use this module inside your project, you can use the following code (change the tag to match the latest version):
module "module-template" {
source = "git::https://github.com/timoa/terraform-google-module-example.git?ref=tags/0.0.2"
# Required
project_id = "my-project-id"
# Optional
namespace = "my-project"
stage = "prod"
region = "us-east1"
}
terraform init
terraform plan
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# module.project_factory_project_services.google_project_service.project_services["cloudresourcemanager.googleapis.com"] will be created
+ resource "google_project_service" "project_services" {
+ disable_dependent_services = true
+ disable_on_destroy = false
+ id = (known after apply)
+ project = "my-project-id"
+ service = "cloudresourcemanager.googleapis.com"
}
# module.project_factory_project_services.google_project_service.project_services["compute.googleapis.com"] will be created
+ resource "google_project_service" "project_services" {
+ disable_dependent_services = true
+ disable_on_destroy = false
+ id = (known after apply)
+ project = "my-project-id"
+ service = "compute.googleapis.com"
}
Plan: 2 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ available_zones = [
+ "us-east1-b",
+ "us-east1-c",
+ "us-east1-d",
]