{"id":27010423,"url":"https://github.com/lumitech-co/lumitech-terraform-template","last_synced_at":"2026-05-06T22:11:01.183Z","repository":{"id":284369793,"uuid":"936604353","full_name":"lumitech-co/lumitech-terraform-template","owner":"lumitech-co","description":"Automated deployment of a Node.js server and PostgreSQL database on GCP using Terraform for consistent configuration across envs.","archived":false,"fork":false,"pushed_at":"2025-08-16T16:41:01.000Z","size":76,"stargazers_count":17,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-16T18:26:54.410Z","etag":null,"topics":["google-cloud","nodejs","postgresql","templates","terraform"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lumitech-co.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-02-21T11:20:57.000Z","updated_at":"2025-08-04T08:57:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"8c9fb54b-b16c-403f-8c2b-164fda1bc4d0","html_url":"https://github.com/lumitech-co/lumitech-terraform-template","commit_stats":null,"previous_names":["lumitech-co/lumitech-terraform-template"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lumitech-co/lumitech-terraform-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lumitech-co%2Flumitech-terraform-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lumitech-co%2Flumitech-terraform-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lumitech-co%2Flumitech-terraform-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lumitech-co%2Flumitech-terraform-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lumitech-co","download_url":"https://codeload.github.com/lumitech-co/lumitech-terraform-template/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lumitech-co%2Flumitech-terraform-template/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32713942,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-06T19:35:05.142Z","status":"ssl_error","status_checked_at":"2026-05-06T19:35:03.996Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["google-cloud","nodejs","postgresql","templates","terraform"],"created_at":"2025-04-04T11:05:02.226Z","updated_at":"2026-05-06T22:11:01.178Z","avatar_url":"https://github.com/lumitech-co.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n \u003cimg width=\"374\" src=\"https://github.com/user-attachments/assets/2ab91ccf-ce8e-4f2e-94a8-347e53746e5b\" /\u003e\n\u003c/div\u003e\n\n# Lumitech Terraform Template \nThis template offers a solution for deploying a Node.js server and a PostgreSQL database on Google Cloud Platform (GCP) using Terraform, an infrastructure as code tool. By leveraging Terraform's language (HCL), the infrastructure can be deployed across different environments like development, production, staging ensuring that the correct configuration is preserved.\n\n### About Lumitech\n[Lumitech](https://lumitech.co/) is a custom software development company providing professional services worldwide. We partner with technology businesses globally helping them to build successful engineering teams and create innovative software products. We’re a global team of software engineers, AI and ML specialists, product managers, and technology experts who have achieved a 600% growth rate since 2022. When a rocket launches toward the moon, it doesn’t stop halfway. Neither do we.\n\n## ⚙ Infrastructure Overview\n\nThe infrastructure includes the following components:\n\n1. **VPC Network**: A Virtual Private Cloud network to securely connect your resources.\n2. **Cloud Run**: A fully managed environment for deploying and scaling containerized applications.\n3. **Cloud SQL**: A fully managed relational database service for PostgreSQL.\n4. **IAM Roles**: Identity and Access Management roles for handling migrations, deployment, and secrets access.\n5. **CI/CD**: Prisma database migration and deployment configurations triggered on branch updates.\n\n## 📝 Prerequisites\n\nBefore you begin, ensure you have the following prerequisites:\n\n- **Terraform CLI**: Install Terraform by following the [installation guide](https://developer.hashicorp.com/terraform/install).\n- **gcloud CLI**: Install the Google Cloud SDK by following the [installation guide](https://cloud.google.com/sdk/docs/install).\n- **Basic Knowledge of Terraform**: Familiarize yourself with Terraform by following [this tutorial](https://developer.hashicorp.com/terraform/tutorials/docker-get-started).\n- **GCP Project**: Create a Google Cloud Platform project with billing enabled. Follow the [creation guide](https://developers.google.com/workspace/guides/create-project#project) and [billing setup guide](https://developers.google.com/workspace/guides/create-project#billing).\n\n## 🚀 Deployment Steps\n\n1. **IAM Roles**: Ensure your IAM Principal has the following roles:\n    - Cloud Run Admin\n    - Editor\n    - Project IAM Admin\n    - Secret Manager Admin\n    - Service Account Admin\n    - Service Networking Admin\n2. **gcloud Authentication**: Authenticate to the _gcloud_ CLI in your terminal - `gcloud auth login`. A detailed guide you can find [here](https://cloud.google.com/docs/authentication/gcloud#local).\n3. **GitHub Repository Connection**: Connect your GitHub repository to GCP Cloud Build. Follow [this guide](https://cloud.google.com/build/docs/automating-builds/github/connect-repo-github?generation=1st-gen#connecting_a_github_repository).\n4. **Copy Template Files**:  Copy the files from the template to your project directory. The following files are required:\n    - `migration-cloudbuild.yaml` and `cloudbuild.yaml`.\n    - `tf` directory files with `dev` and `modules` folders.\n    - `.gitignore` with necessary files to be ignored from Terraform.\n5. **Input Variables**: Update the `terraform.tfvars` file inside the `tf/dev` directory. Update the mock data with your project variables.\n    - In this file, you provide the variables of the infrastructure to be created — service name, database name, GitHub repository, etc.\n    - If you are using VSCode, you can install the [Terraform extension](https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform). \n6. **Infrastructure Creation**: Go to `tf/dev` directory in your terminal and apply the following commands:\n    1. `terraform init` - Initialize the dependencies of your project.\n    2. `terraform apply` - Create the infrastructure on GCP. You will be prompted to confirm the changes. This step takes approximately 20 minutes.\n    3. `terraform init -migrate-state` - Migrate the state to GCP after the infrastructure creation. The state will be stored on Google Cloud Storage instead of in local files.\n7. **Save Changes**: Push the changes to your GitHub repository with `git push`. This step will trigger first deployment and migration actions on Cloud Build.\n8. **Unset Temporary Image**: Set the Cloud Run dummy image variable to false after the first successful deployment. You do not need to run terraform apply again, as the new image is already in use.\n\n## ➡️ Further Setup\n### Adding Environment Variables\nTo provide a new secret environment variable to the Cloud Run container, proceed with the following steps:\n1. Create a new secret variable in the Secret Manager. You can follow the steps in the [Secret Manager documentation](https://cloud.google.com/secret-manager/docs/creating-and-accessing-secrets#create-a-secret).\n    - Add an environment prefix if the variable will be used only for the current environment. e.g. `dev-secret-name`\n2. Copy the secret ID from the secret details page. Secret ID example: `projects/123456789101/secrets/dev-secret-name`.\n3. Create a Terraform variable with the secret ID as its value.\n```terraform\n# tf/dev/variables.tf\nvariable \"example_secret_for_cloud_run\" {\n  type = string\n}\n# ... other variable declarations\n```\n```terraform\n# tf/dev/terraform.tfvars\nexample_secret_for_cloud_run = \"projects/123456789102/secrets/dev-some-secret\"\n# ... other variables\n```\n4. Pass the secret ID variable to the Cloud Run module.\n```terraform\n# tf/dev/main.tf\nmodule \"cloud_run\" {\n...\n  secret_vars = {\n    SECRET_NAME = var.example_secret_for_cloud_run\n  }\n...\n}\n```\n5. Update the infrastructure on GCP - `terraform apply` and confirm the changes.\n    - This step passes the variables to the Cloud Run instance and creates an IAM role with access to the secret ID.\n\n### Creating Different Environments\nEach environment is defined as a root module with the same reusable submodules.\nTo create another environment (production, staging, etc.), complete the following steps:\n1. Copy the `tf/dev` directory with the desired environment name (e.g., `tf/prod` or `tf/staging`).\n2. Update the environment variables in `terraform.tfvars` to match the environment.\n3. Proceed from **step 6** in the **Deployment Steps** section.\n\n\n## 📂 Template Structure\n\nThis Terraform template is split into a **root module** (in `tf/dev`) and **submodules** (in `tf/modules`). By separating environment-specific settings from reusable infrastructure modules, you can quickly replicate environments (e.g., `tf/prod`, `tf/staging`) while keeping the same core logic in the submodules.\n\n### `tf/dev` (Root Module)\n\n- Holds environment-level configurations and the main `.tfvars` file for variables specific to this environment.\n- References the submodules to provision resources for your chosen environment.\n- You can copy this entire directory to create another environment (e.g., `tf/prod`).\n\n### `tf/modules` (Submodules)\n\nEach directory within `tf/modules` defines a reusable component of the infrastructure:\n\n- `cloud-run/` – Provisions and configures Cloud Run services.  \n- `cloud-sql/` – Manages a Cloud SQL PostgreSQL instance.  \n- `network/` – Sets up a VPC network.  \n- `project-api/` – Enables project-level APIs.\n- `secret/` – Generate secrets in Secret Manager.\n\n```\n.\n├── cloudbuild.yaml\n├── Dockerfile\n├── LICENSE\n├── migration-cloudbuild.yaml\n├── README.md\n└── tf\n    ├── dev\n    │   ├── main.tf\n    │   ├── outputs.tf\n    │   ├── terraform.tfvars\n    │   └── variables.tf\n    └── modules\n        ├── cloud-run\n        │   ├── iam.tf\n        │   ├── main.tf\n        │   ├── outputs.tf\n        │   └── variables.tf\n        ├── cloud-sql\n        │   ├── iam.tf\n        │   ├── main.tf\n        │   ├── migration.tf\n        │   ├── outputs.tf\n        │   ├── secrets.tf\n        │   └── variables.tf\n        ├── network\n        │   ├── main.tf\n        │   ├── outputs.tf\n        │   └── variables.tf\n        ├── project-api\n        │   └── main.tf\n        └── secret\n            ├── main.tf\n            └── variables.tf\n\n```\n\n## ✨ Related Documentation\n- [General style and structure guidelines](https://cloud.google.com/docs/terraform/best-practices/general-style-structure) - Google Cloud best practices for Terraform configurations.\n- [Root modules](https://cloud.google.com/docs/terraform/best-practices/root-modules) - Google Cloud best practices for Root modules and Terraform structure.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flumitech-co%2Flumitech-terraform-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flumitech-co%2Flumitech-terraform-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flumitech-co%2Flumitech-terraform-template/lists"}