{"id":21264575,"url":"https://github.com/psimakov/gcp-mig-simple","last_synced_at":"2025-04-14T06:09:27.033Z","repository":{"id":149535464,"uuid":"564959226","full_name":"psimakov/gcp-mig-simple","owner":"psimakov","description":"Zero-Downtime Blue/Green VM Deployments with Managed Instance Groups, Cloud Build \u0026 Terraform -- a Google Cloud Platform Demo","archived":false,"fork":false,"pushed_at":"2023-01-31T23:07:22.000Z","size":7542,"stargazers_count":3,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T06:09:20.650Z","etag":null,"topics":["cloud-build","google-cloud-platform","managed-instance-groups","terraform"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/psimakov.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}},"created_at":"2022-11-11T23:12:59.000Z","updated_at":"2025-02-04T16:01:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"f487b939-0b0d-4de3-a1f6-314710942974","html_url":"https://github.com/psimakov/gcp-mig-simple","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psimakov%2Fgcp-mig-simple","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psimakov%2Fgcp-mig-simple/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psimakov%2Fgcp-mig-simple/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psimakov%2Fgcp-mig-simple/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/psimakov","download_url":"https://codeload.github.com/psimakov/gcp-mig-simple/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248830395,"owners_count":21168272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["cloud-build","google-cloud-platform","managed-instance-groups","terraform"],"created_at":"2024-11-21T05:01:49.727Z","updated_at":"2025-04-14T06:09:26.998Z","avatar_url":"https://github.com/psimakov.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zero-Downtime Blue/Green VM Deployments with Managed Instance Groups, Cloud Build \u0026 Terraform\u003cbr\u003e\u003csub\u003e*a Google Cloud Platform Demo*\u003c/sub\u003e\n\n## Summary\n\nThis repository provides source code for zero-downtime blue/green VM deployments using Cloud Build and Terraform.\n\nIt configures multiple regional external HTTP(S) load balancers and deploys a demo application to Compute Engine VMs in managed instance groups (MIGs). It adds Cloud Build triggers to start deployment automatically when configuration file changes in Source Code Repository.\n\nYou can watch the video of this demo running and follow the code walkthrough. You can also run this demo in your own project.\n\n## Video: Live Demo \u0026 Code Walkthrough\n\n[\u003cimg src=\"img/video.png\" width=\"100%\"\u003e](https://youtu.be/7-jO5OGPUxM)\n\n## Do It Yourself\n\n\u003e **Warning**\n\u003e\n\u003e This project is for **advanced** Google Cloud Platform infrastructure developers and SRE. If you decide to clone and run any code from this repository, **you will be billed** for the real infrastructure it creates. We rely on unattended automation, which can make it difficult for you to manage your project manually. We use custom VPCs with public IP addresses, which can make your project **vulnerable to attacks**. If you are a novice GCP user and just want to learn -- watch the video above instead.\n\n\u003e **Note**\n\u003e\n\u003e Take a pause here if you are a developer in a large enterprise company that already uses Google Cloud Platform. Remember that all your projects are subject to foundational setup of your organization and its landing zones ([link](https://cloud.google.com/architecture/landing-zones)). There maybe org policy restrictions (for example: on using regions or external IP addresses) that will break this demo. Reach out to the team that manages GCP in your organization to discuss where and how you can run this demo following their policies.\n\nAnyone can run this demo on their own. Here is how:\n\n* create new Google Cloud Platform project\n* enable billing, which is required\n* install `gcloud` CLI ([link](https://cloud.google.com/sdk/docs/install)) or use your project Cloud Shell\n* set SDK default project, by executing\n  ```\n  gcloud config set project \u003cYOUR_PROJECT_ID\u003e\n  ```\n* execute setup script\n  * run it directly from our GitHub repo:\n    ```\n    bash \u003c(curl https://raw.githubusercontent.com/psimakov/gcp-mig-simple/main/setup.sh)\n    ```\n  * or, fetch, review, and then run it:\n    ```\n    curl https://raw.githubusercontent.com/psimakov/gcp-mig-simple/main/setup.sh -o setup.sh\n    bash ./setup.sh\n    ```\n* follow on-screen instructions\n* trigger deployment by committing configuration change\n  ```\n  mkdir ~/work\n  cd ~/work\n  gcloud source repos clone copy-of-gcp-mig-simple\n  cd ./copy-of-gcp-mig-simple\n\n  nano infra/main.tfvars\n\n  git add .\n  git commit -m \"Promote green\"\n  git push\n  ```\n* visit Cloud Build History page to see progress of execution\n* review Cloud Build apply pipeline logs for deployment IP addresses\n* at the end, delete all created resources\n  ```\n  bash \u003c(curl https://raw.githubusercontent.com/psimakov/gcp-mig-simple/main/teardown.sh)\n  ```\n\nGood luck!\n\n## Slides\n\n\u003cimg src=\"img/title.png\" width=\"100%\"\u003e\n\n### Technical Architecture\n\n#### High level architecture of generic blue/green deployment\n\u003cimg src=\"img/bg.png\" width=\"100%\"\u003e\n\n#### Detailed architecture of regional external HTTP(S) load balancer with managed instance group (MIG) backend ([link](https://cloud.google.com/load-balancing/docs/https/setting-up-reg-ext-https-lb))\n\n\u003cimg src=\"img/mig.png\" width=\"100%\"\u003e\n\n#### Detailed architecture of DevOps workflow\n\u003cimg src=\"img/devops.png\" width=\"100%\"\u003e\n\n### Bootstrapping\n\n#### Setup shell script is executed by developer\n\u003cimg src=\"img/setup.png\" width=\"100%\"\u003e\n\n#### Bootstrap Cloud Build is executed\n\u003cimg src=\"img/boot.png\" width=\"100%\"\u003e\n\n#### Cloud Source Repository is created\n\u003cimg src=\"img/csr.png\" width=\"100%\"\u003e\n\n#### Cloud Build triggers are created\n\u003cimg src=\"img/cloud-build-triggers.png\" width=\"100%\"\u003e\n\n### GitOps Deployment\n\n#### Deployment is triggered when developer commits configuration change\n\u003cimg src=\"img/gitops.png\" width=\"100%\"\u003e\n\n#### Cloud Build applies Terraform plan\n\u003cimg src=\"img/pipeline-apply.png\" width=\"100%\"\u003e\n\n#### All application serving components including three load balancers, blue and green MIGs and their VMs are now live\n\u003cimg src=\"img/live.png\" width=\"100%\"\u003e\n\n#### Managed instance groups (MIGs) were created\n\u003cimg src=\"img/migs.png\" width=\"100%\"\u003e\n\n#### Virtual machine instances (VMs) have started\n\u003cimg src=\"img/vms.png\" width=\"100%\"\u003e\n\n#### External IP addresses were assigned\n\u003cimg src=\"img/ips.png\" width=\"100%\"\u003e\n\n### Clean Up\n\n#### Cloud Build destroys Terraform plan when developer triggers it manually\n\u003cimg src=\"img/pipeline-destroy.png\" width=\"100%\"\u003e\n\n#### All resources managed by Terraform are destroyed, but Cloud Build execution history is preserved\n\u003cimg src=\"img/cloud-build-history.png\" width=\"100%\"\u003e\n\n#### Teardown shell script is executed by developer, deleting Cloud Source Repository and Cloud Build triggers\n\u003cimg src=\"img/teardown.png\" width=\"100%\"\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpsimakov%2Fgcp-mig-simple","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpsimakov%2Fgcp-mig-simple","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpsimakov%2Fgcp-mig-simple/lists"}