This repository defines and provisions all cloud infrastructure for the Cognicare platform using Terraform.
It is designed to create a secure, scalable, and productionβready environment in Google Cloud Platform (GCP) and integrates seamlessly with the Cognicare application GitOps deployment pipeline.
- Overview
- Architecture
- Infrastructure Components
- Repository Structure
- Technology Stack
- Modules Explained
- CI/CD with Terraform
- Security Considerations
- Getting Started
- Running Locally
- Integration with Application Deployment
- Helpful Links
- License
This repository provisions:
- π VPC network & subnetwork for Cognicare services.
- β Google Kubernetes Engine (GKE) cluster (Standard or Autopilot mode).
- π¦ Google Artifact Registry (GAR) repositories for container images.
- π Networking configuration for service-to-service communication.
- π GitHub Actions workflow for automated infrastructure provisioning.
The Cognicare platform (from academiay4/cognicare-app) runs on top of this infrastructure, using GitOps via ArgoCD for continuous deployment.
graph TD
subgraph "Terraform Infra Repo"
A[Terraform Modules]
A1[Network Module]
A2[GKE Module]
A3[Artifact Registry Module]
end
subgraph "Google Cloud"
B[VPC Network & Subnetwork]
C[GKE Cluster]
D[Artifact Registry]
end
subgraph "Application Repo (GitOps)"
E[Cognicare Microservices]
F[ArgoCD]
end
A --> B
A --> C
A --> D
E --> F
F --> C
| Component | Purpose |
|---|---|
| VPC & Subnetwork | Provides an isolated, private network for Cognicare services. |
| GKE Standard Cluster | Runs Cognicareβs Kubernetes workloads with configurable node pools. |
| GKE Autopilot (Optional) | Alternative managed mode (commented out in current config). |
| Artifact Registry | Stores Docker images for Cognicare microservices. |
| GitHub Actions Terraform Workflow | Automates provisioning and updating of infrastructure. |
academiay4-cognicare-infra/
βββ backend.tf # Remote Terraform state backend (GCS)
βββ main.tf # Main module calls
βββ outputs.tf # Exported values (kubeconfig command, cluster name, etc.)
βββ provider.tf # Google provider configuration
βββ variables.tf # Input variables
βββ modules/ # Reusable Terraform modules
β βββ network/ # VPC + subnetwork
β βββ gke_standard/ # Standard GKE cluster + node pool
β βββ gke_autopilot/ # Autopilot GKE cluster
β βββ gar/ # Google Artifact Registry
βββ .github/workflows/ # CI/CD workflows
β βββ terraform.yaml # Automated provisioning pipeline
βββ .terraform.lock.hcl # Provider dependency lock
| Tool / Service | Purpose |
|---|---|
| Terraform | Infrastructure as Code (IaC) |
| Google Cloud Platform (GCP) | Hosting provider |
| GKE (Google Kubernetes Engine) | Managed Kubernetes cluster |
| Google Artifact Registry (GAR) | Container image storage |
| Google Cloud VPC | Private network for workloads |
| GitHub Actions | CI/CD automation |
| GCS (Google Cloud Storage) | Remote Terraform state backend |
Creates:
- VPC network (
google_compute_network) - Subnetwork (
google_compute_subnetwork) with a custom CIDR range - Private IP access for Google APIs
Inputs:
network_name,subnetwork_name,ip_cidr_range,project_id,region
Outputs:
network_id,subnetwork_id,network_name,subnetwork_name
Creates:
- Standard GKE cluster (VPC Native)
- Configurable node pool (machine type, disk type, node count)
Inputs:
cluster_name,zone,node_count,machine_type,disk_type,disk_size_gb
Outputs:
cluster_name,endpoint,ca_certificate
- Fully managed GKE cluster (autopilot mode).
- Currently commented out in
main.tfbut available for future use.
Creates:
-
Multiple Docker repositories for Cognicare services.
-
Example repos:
admin-portal-servicemri-servicegateway-serviceprogress-tracking-servicetreatment-planning-service
The .github/workflows/terraform.yaml workflow automates infrastructure changes:
- Trigger β Runs on push to
masterbranch. - Checkout β Clones repo into GitHub Actions runner.
- Authenticate β Uses
google-github-actions/auth@v2with a GCP service account key (GCP_SA_KEY). - Terraform Init β Initializes Terraform backend (GCS bucket for remote state).
- Terraform Plan β Generates execution plan and uploads as artifact.
- Terraform Apply β Applies infrastructure changes without manual approval (
-auto-approve).
| Secret | Purpose |
|---|---|
PROJECT_ID |
GCP Project ID |
REGION |
GCP Region |
ZONE |
GCP Zone |
CLUSTER_NAME |
GKE cluster name |
NETWORK_NAME |
VPC network name |
SUBNETWORK_NAME |
Subnetwork name |
IP_CIDR_RANGE |
Subnetwork CIDR block |
NODE_COUNT |
Number of GKE nodes |
MACHINE_TYPE |
GCP VM type |
DISK_TYPE |
GKE node disk type |
DISK_SIZE_GB |
GKE node disk size |
TF_BUCKET |
GCS bucket for Terraform state |
GCP_SA_KEY |
Base64βencoded GCP service account key JSON |
- State file β Stored in GCS bucket (remote backend) to avoid local state corruption.
- Service account β Has least privilege required for provisioning.
- Secrets β Stored in GitHub Actions Secrets.
- Private networking β GKE cluster is deployed in a private VPC.
gcloud auth application-default loginEither:
- Set them in
.tfvarsfile - Or pass them as CLI args:
terraform apply \
-var="project_id=your-project" \
-var="region=us-central1" \
-var="zone=us-central1-a" \
...terraform init -backend-config="bucket=YOUR_TF_STATE_BUCKET"
terraform plan
terraform applyThis infra repo is the first step in Cognicareβs deployment pipeline:
-
This repo provisions:
- VPC
- GKE cluster
- Artifact Registry
-
Application repo builds & pushes Docker images to GAR.
-
Manifest repo (GitOps) updates Helm chart image tags.
-
ArgoCD syncs manifests to the GKE cluster.
- Terraform GCP Provider Docs
- GKE Documentation
- Google Artifact Registry Docs
- Terraform Best Practices
Licensed under the MIT License. See the LICENSE file.