CLI tool to validate and enforce AWS tags for resources deployed using Terraform. Targeted for CI/CD pipelines and CLI environments.
Project description
tf-tagguard
tf-tagguard is a CLI tool to validate and enforce AWS tags on resources deployed via Terraform. It is designed for CI/CD pipelines and local CLI environments, ensuring all resources meet your organization's tagging policies.
Features
- Validate presence of required tags.
- Validate tag values (exact match, list of values, or regex patterns).
- Tabular summary of missing or invalid tags using
tabulate. - Fail-fast behavior for duplicate tag declarations.
- Easy integration into CI/CD pipelines.
- Modular design for future extensions.
Installation
pip install tf-tagguard
CLI Usage
validatetags-tf PLAN_FILE [OPTIONS]
| Option | Description | Example |
|---|---|---|
-r, --required-tags |
Comma-separated list of required tags (presence only). | --required-tags Name,Environment |
-v, --value-tags |
List of tags with expected values. Supports: - Exact value → key=value - List of allowed values → key=[v1,v2,v3] - Regex pattern → key=^regex$ |
Environment=dev Team=[dev,ops,qa] Owner=^user.*$ |
Examples
- Validate only tag presence
validatetags-tf plan.json -r Name,Environment,Owner
- Validate tag values
validatetags-tf plan.json -v "Environment=dev","Team=[ops,dev]","Owner=^user.*$"
- Validate presence + values (fallback: -v takes precedence if duplicated)
validatetags-tf plan.json -r Name,Owner -v "Environment=dev","Team=[ops,dev]"
NOTE:
⚠️ Tags declared in both -r and -v will trigger a warning, as a fallback mechanisim -v values take precedence.
Terraform Plan JSON
tf-tagguard expects a Terraform plan in JSON format. Generate it with:
terraform plan -out=tfplan.binary
terraform show -json tfplan.binary > plan.json
Exit Codes
| Code | Description |
|---|---|
0 |
✅ All validations passed |
1 |
❌ Validation failed or error occurred |
Advanced Usage
Multiple Value Tags
Use separate -v flags for multiple validations:
validatetags-tf plan.json \
-v "Environment=[dev,staging,prod]" \
-v "Team=[ops,dev,qa]" \
-v "Owner=^user.*$"
CI/CD Integration
GitHub Actions:
- name: Validate Terraform Tags
run: |
terraform plan -out=tfplan.binary
terraform show -json tfplan.binary > plan.json
validatetags-tf plan.json -r Name,Environment,Owner
GitLab CI:
validate_tags:
script:
- terraform plan -out=tfplan.binary
- terraform show -json tfplan.binary > plan.json
- validatetags-tf plan.json -r Name,Environment,Owner
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
See CHANGELOG.md for version history and changes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tf_tagguard-0.1.0.tar.gz.
File metadata
- Download URL: tf_tagguard-0.1.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6446c2c08c496682ee53afa079a66ba423f4e9a59066f99196905b338491067f
|
|
| MD5 |
cac1bf23206e38aec6ec47ce9ce4c446
|
|
| BLAKE2b-256 |
0656c76864d56ca5ebc0b3fbd354ad3da89a75f795cc811895eb45b91ac43948
|
File details
Details for the file tf_tagguard-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tf_tagguard-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fc1331cc7f3000d695ac492e993404ab56240764b7bb6a9f88b893aeca7df9d
|
|
| MD5 |
219f9bf705c7c09b26f5932f87f66923
|
|
| BLAKE2b-256 |
fbb1a212eb8219394b0a04eae78dd2082c8697f623cd75744acc09749d6aa358
|