AutoDevOps includes built-in Git version control integration that automatically commits each generated infrastructure file with descriptive commit messages.
Every generated infrastructure file is automatically committed to Git with:
- Descriptive commit messages including the file name and generator type
- Metadata about the user request, IaC type, provider, and action
- Timestamp for audit trail
- Author information (configurable)
Generate main.tf
Generated by AutoDevOps TerraformGenerator
Configuration:
user_request: Create an EC2 instance with t3.micro on AWS
iac_type: terraform
provider: aws
action: create
- Complete history of all infrastructure changes
- File-specific commit history
- Diff tracking for changes
- Tag support for releases
from audit.version_control import GitVersionControl
from generators.terraform import TerraformGenerator
# Initialize Git integration
git = GitVersionControl(
repo_path="./infrastructure",
auto_commit=True,
user_name="AutoDevOps Bot",
user_email="bot@autodevops.io"
)
# Create generator with Git integration
generator = TerraformGenerator(
output_dir="./infrastructure/terraform",
git_integration=git,
auto_commit=True
)
# Generate and save (automatically commits)
code = generator.generate(intent, parameters)
file_path = generator.save_to_file(
code=code,
filename="main.tf",
commit_metadata={
"user_request": "Create EC2 instance",
"iac_type": "terraform",
"provider": "aws"
}
)Configure Git integration via environment variables in .env:
# Git Configuration
GIT_ENABLED=true
GIT_REPO_PATH=./infrastructure
GIT_AUTO_COMMIT=true
GIT_USER_NAME=AutoDevOps Bot
GIT_USER_EMAIL=bot@autodevops.io# Commit a specific file
git.commit_file(
file_path="terraform/main.tf",
message="Update EC2 instance configuration"
)
# Commit multiple files
git.commit_multiple_files(
file_paths=["terraform/main.tf", "terraform/variables.tf"],
message="Update Terraform configuration"
)
# Get commit history
history = git.get_file_history("terraform/main.tf", max_count=10)
for commit in history:
print(f"{commit['short_sha']} - {commit['message']}")
# Check for uncommitted changes
if git.has_uncommitted_changes():
print("There are uncommitted changes")
print(git.get_diff())
# Create a tag
git.create_tag("v1.0.0", message="Production release")
# Get latest commit
latest = git.get_latest_commit()
print(f"Latest: {latest['short_sha']} by {latest['author']}")Located in src/audit/version_control.py, this class provides:
- Repository initialization: Automatically creates or opens Git repository
- Auto-commit: Commits files when saved by generators
- History tracking: Retrieves commit history for files
- Diff support: Shows uncommitted changes
- Tag management: Create and list tags
All generators inherit from BaseGenerator which includes:
def save_to_file(
self,
code: str,
filename: str,
subdirectory: Optional[str] = None,
commit_metadata: Optional[Dict[str, Any]] = None
) -> Path:
# Save file
# Auto-commit if enabled
if self.auto_commit and self.git_integration:
self.git_integration.commit_file(...)Every infrastructure change is tracked with:
- Who made the change (user/system)
- When it was made (timestamp)
- What was changed (file content)
- Why it was changed (user request in metadata)
# View history
cd infrastructure
git log
# Rollback to previous version
git checkout <commit-hash> main.tf
# Create a new branch for testing
git checkout -b test-changes- Meets regulatory requirements for change tracking
- Provides complete audit trail
- Supports compliance frameworks (SOC2, HIPAA, etc.)
- Multiple users can work on infrastructure
- Changes are tracked per user
- Easy to review and merge changes
- Complete history of infrastructure state
- Easy to restore previous configurations
- Tagged releases for production deployments
-
User Request: "Create a load-balanced web application on AWS"
-
AutoDevOps Generates:
terraform/main.tf(EC2, ALB, ASG)terraform/variables.tf(Input variables)terraform/outputs.tf(Output values)
-
Auto-Commit: Each file is committed separately:
commit 1: Generate main.tf commit 2: Generate variables.tf commit 3: Generate outputs.tf -
Review: User reviews the generated code:
cd infrastructure git log --oneline git show <commit-hash>
-
Apply: User applies the infrastructure:
terraform init terraform plan terraform apply
-
Tag Release: Mark this as a release:
git.create_tag("v1.0.0", message="Initial production deployment")
Run the demo script to see Git integration in action:
python examples/git_integration_demo.pyThis will:
- Initialize a Git repository
- Generate Terraform and Kubernetes files
- Auto-commit each file
- Show commit history
- Display file-specific history
If GitPython is not installed:
pip install gitpythonEnsure the user has write permissions to the infrastructure directory:
chmod -R u+w ./infrastructureIf there are uncommitted changes:
# Check status
if git.has_uncommitted_changes():
# View changes
print(git.get_diff())
# Commit manually
git.commit_multiple_files(
file_paths=[...],
message="Manual commit of pending changes"
)- Use Descriptive Metadata: Include relevant information in commit metadata
- Tag Releases: Create tags for production deployments
- Review Before Apply: Always review generated code before applying
- Regular Backups: Push to remote repository regularly
- Branch Strategy: Use branches for testing changes
To push to a remote repository:
cd infrastructure
git remote add origin <your-repo-url>
git push -u origin mainConfigure in .env:
GIT_REMOTE_URL=https://github.com/your-org/infrastructure.git
GIT_AUTO_PUSH=true- Secrets: Never commit secrets or credentials
.gitignore: Properly configured to exclude sensitive files- Access Control: Use repository permissions to control access
- Encryption: Consider using git-crypt for sensitive data
AutoDevOps Git integration provides:
- ✅ Automatic version control for all generated files
- ✅ Complete audit trail with metadata
- ✅ Easy rollback and disaster recovery
- ✅ Compliance and regulatory support
- ✅ Collaboration and review workflows
- ✅ Production-ready infrastructure management