Skip to content

tzehon/iis-gitops

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Managing infrastructure as code with Terraform, Cloud Build, and GitOps

This repo explains how to manage infrastructure as code with Terraform and Cloud Build using GitOps.

Configuring Terraform to store state in a Cloud Storage bucket

  1. In Cloud Shell, create the Cloud Storage bucket:

     PROJECT_ID=$(gcloud config get-value project)
     gsutil mb gs://${PROJECT_ID}-tfstate
    
  2. Enable Object Versioning to keep the history of your deployments:

     gsutil versioning set on gs://${PROJECT_ID}-tfstate
    

Trigger Cloud Build to build a new image with each commit

  1. Connect your repository to Cloud Build
  2. Create a trigger

Enforcing Cloud Build execution success before merging branches

To make sure merges can be applied only when respective Cloud Build executions are successful, proceed with the following steps:

  1. On GitHub, navigate to the main page of your forked repository.
  2. Under your repository name, click Settings.
  3. In the left menu, click Branches.
  4. Under Branch protection rules, click Add rule.
  5. In Branch name pattern, select dev.
  6. In Rule settings, select Require status checks to pass before merging, and then in Status checks found in the last week for this repository, click Build.
  7. Click Create.
  8. Repeat steps 5–8, setting Branch name pattern to prod.

This configuration is important to protect both the dev and prod branches. Meaning, commits must first be pushed to another branch, and only then they can be merged to the protected branch. In this tutorial, the protection requires that the Cloud Build execution be successful for the merge to be allowed.

Promoting your environment to production

Once you have tested your app, you can promote your configuration to production by merging the dev branch to prod.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HCL 100.0%