This repository is for deploying repositories to GitHub using Terraform and GitHub Actions.
This project requires Homebrew for macOS or Linux. All other dependencies will be installed automatically.
-
Install Homebrew and all required tools:
make bootstrap
This will install:
-
Restart your terminal or reload your shell (for Homebrew PATH)
-
Setup the development environment:
just setup
This will:
- Install tools defined in
.tool-versionsvia mise (Terraform v1.13.3) - Set up pre-commit hooks using prek
- Initialize Terraform
- Install tools defined in
Check that all required tools are installed:
just check-toolsThis project supports parallel development using git worktree. This allows you to work on multiple branches simultaneously without switching between them.
just worktree-setupThis will guide you through creating a new worktree. Worktrees are created in the parent directory with the pattern: terraform-github-<branch-name>
Create a new worktree:
# For a new branch
git worktree add ../terraform-github-feature-name -b feature/feature-name
# For an existing branch
git worktree add ../terraform-github-feature-name feature/feature-nameList all worktrees:
git worktree listRemove a worktree:
git worktree remove ../terraform-github-feature-namemake bootstrap- Install Homebrew and all required toolsmake help- Show Makefile targets
Show all available tasks:
just helpCommon tasks:
just setup- Setup development environment (install tools and initialize)just check-tools- Verify all required tools are installedjust worktree-setup- Interactive git worktree setupjust fmt- Format all Terraform filesjust validate- Validate Terraform configurationjust lint- Run all linters (prek)just init- Initialize Terraformjust plan- Run Terraform planjust apply- Run Terraform apply (use with caution)just clean- Clean Terraform temporary filesjust version- Show tool versions (Terraform, mise, just)just status- Show mise-managed tool versionsjust install- Install tools from .tool-versionsjust update- Update mise-managed tools
- A GitHub Actions workflow is triggered (e.g., when a pull request is merged).
- The
set-matrixaction is executed to create a list of directories for Terraform execution. - The
setup-terraformaction is executed to set up Terraform. - The
terraform-planaction is executed to create a Terraform plan. - The
terraform-applyaction is executed to apply the Terraform plan.
graph TD
A[actions checkout] --> B[AWS credential aws-credential]
B --> C[Generate GitHub App token]
C --> D[Terraform Plan]
D --> E[Start Deployment]
E --> F{push or workflow_dispatch}
F -- Yes --> G[Terraform Apply]
F -- No --> H[Skip]
G --> I[Finish Deployment]
H --> I
This workflow is used to import existing GitHub repositories into Terraform management.
- The
terraform-importworkflow allows you to import existing GitHub repositories and branch protection settings into the Terraform state. - It is executed manually (
workflow_dispatch) by specifying the target module name and repository name.
graph TD
A[Select Import workflow in Actions tab] --> B[Enter module and repo then run]
B --> C[Checkout repository]
C --> D[Configure AWS credentials]
D --> E[Initialize Terraform]
E --> F[Import repository info to state]
F --> G[Done]
module: Terraform module name (e.g.,local-workspace-provisioning,terraform-aws,boilerplate-saas, etc.)repo: GitHub repository name (e.g.,local-workspace-provisioning,terraform-aws,boilerplate-saas, etc.)
- Go to the Actions tab in GitHub and select the
Terraform Importworkflow. - Click the
Run workflowbutton, enter themoduleandrepovalues, and start the workflow.- Example:
module=local-workspace-provisioning,repo=local-workspace-provisioning - Example:
module=terraform-aws,repo=terraform-aws
- Example:
- When the workflow completes, the specified repository information will be imported into the Terraform state.
- For
module, specify the module name underterraform/src/repository/. - For
repo, specify the repository name on GitHub. - Make sure that
secrets.TERRAFORM_GITHUB_TOKENis set as required.