hands-on lab

Enforcing Tagging Governance with Git Pre-commit Hooks and CloudFormation Guard

Difficulty: Beginner
Duration: Up to 30 minutes
Students: 8
On average, students complete this lab in25m
Get guided in a real environmentPractice with a step-by-step scenario in a real, provisioned environment.
Learn and validateUse validations to check your solutions every step of the way.
See resultsTrack your knowledge and monitor your progress.

Description

Amazon CloudFormation Guard (cfn-guard) is an open-source policy-as-code tool that validates infrastructure-as-code templates against rules written in its own domain-specific language, helping teams enforce standards before resources are ever deployed.

Git pre-commit hooks run automatically before a commit is finalized and can reject it outright if a check fails, giving teams a way to catch issues at the earliest point in the development workflow. The open-source pre-commit framework makes these checks easy to share and maintain across a team's repositories.

In this lab, you will configure a pre-commit hook that pulls centrally maintained tagging rules from Amazon S3, write a cfn-guard rule enforcing required tags, and apply that enforcement to both a CloudFormation template and a Terraform configuration, catching missing or invalid tags before either ever reaches a deploy.

Learning objectives

Upon completion of this beginner-level lab, you will be able to:

  • Explain how commit-time tagging enforcement fits alongside org-level governance tools such as AWS Tag Policies and CloudFormation Hooks
  • Write cfn-guard rules that enforce required tags and allowed tag values, and wire it into a Git pre-commit hook
  • Apply the tagging enforcement pattern to a AWS CloudFormation template and a Terraform plan

Intended audience

  • Cloud Engineers
  • DevOps Engineers
  • FinOps Engineers

Prerequisites

Familiarity with the following will be beneficial but is not required:

  • Git and the pre-commit framework
  • AWS CloudFormation
  • Terraform

The following content can be used to fulfill the prerequisites:

Environment before

Environment after

Covered topics

Hands-on Lab UUID

Lab steps

0 of 3 steps completed.Use arrow keys to navigate between steps. Press Enter to go to a step if available.
  1. Pulling Centralized Tagging Rules from Amazon S3
  2. Enforcing Tagging Governance on CloudFormation Templates
  3. Extending Tagging Governance to Terraform Plans