Skip to content

qermit/git-repository-files

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform Git Repository Files Module

Terraform module for managing files inside a Git repository.

Initially this module was created to generate and maintain Ansible inventory files from Terraform-managed infrastructure. It later evolved into a more generic solution for synchronizing and managing arbitrary files in a Git repository.

The module allows Terraform configurations to create, update and remove files in a target repository in a controlled and repeatable manner. It is designed to support multiple independent Terraform projects managing content within the same repository while preserving ownership boundaries and preventing accidental modifications of unrelated files.

Features

  • Create and update files in a Git repository
  • Remove Terraform-managed files
  • Support multiple independent Terraform projects using the same repository
  • Preserve ownership boundaries between projects
  • Prevent accidental modification of unrelated files
  • Automatically commit changes to Git
  • Maintain a dedicated working directory for repository operations
  • Suitable for infrastructure-driven workflows
  • Can be used for Ansible inventory generation or general file synchronization

Original Use Case

The original purpose of this module was managing Ansible inventory repositories.

Example workflow:

Terraform project
        ↓
Generate inventory files
        ↓
Update Git repository
        ↓
Commit changes
        ↓
Automation pipeline detects changes
        ↓
Run Ansible playbooks

However, the module is intentionally generic and can be used for any scenario where Terraform should maintain files inside a Git repository.

Examples include:

  • Ansible inventories
  • Configuration repositories
  • Generated YAML files
  • Generated JSON files
  • Kubernetes manifests
  • Documentation artifacts
  • Application configuration

Usage

module "repository_files" {
  source = "git::https://github.com/qermit/git-repository-files.git?ref=master"

  repo_url    = "https://github.com/example/inventory.git"
  repo_branch = "master"
  repo_prefix = "projects/my-project"
  source_dir  = "${path.module}/inventory"
}

Requirements

Name Version
Terraform >= 1.6

Inputs

Name Description Type Default
repo_url Git repository URL used as the synchronization target. string n/a
repo_prefix Path prefix inside the repository where files will be managed. string n/a
repo_branch Git branch used for synchronization. string "master"
source_dir Local directory containing files that should be synchronized to the repository. string n/a
root_module_name Optional root module name used in generated commit messages and ownership metadata. string null
workdir Optional local working directory used for Git operations. string null

Outputs

Name Description
commit_id Git commit ID after changes
changed_files List of modified files

Notes

This module assumes Git authentication and repository permissions are configured outside the module.

License

This project is licensed under the Mozilla Public License Version 2.0. See LICENSE for details.

About

Terraform Git Repository Files Module

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors