[Infrastructure as Code (IaC)] Terraform GitHub Examples about using Terraform GitHub Provider to manage GitHub repositories and SSH keys
Terraform GitHub Examples
Examples about using Terraform GitHub Provider to manage repositories and SSH keys.
Github: https://github.com/CloudoLife/terraform-github-examples
Prerequsites
Your must have a GitHub account, api token and an organization, and Terraform CLI have been installed.
GitHub Account
-
GitHub Account
Signing up for GitHub - GitHub Docs -
GitHub API Token
Creating a personal access token - GitHub Docs -
GitHub Organization
Creating organizations - GitHub Docs
SSH Key
Check out our guide to generating SSH keys or troubleshoot common SSH Problems.
Terrraform and Terrafrom GitHub Provider
-
Use Infrastructure as Code to provision and manage any cloud, infrastructure, or service
-
Provider: GitHub - Terraform by HashiCorp
The GitHub provider is used to interact with GitHub organization resources.
Configuration
GitHub Provider Variables
First, Specify values for GitHub Provider variables within terraform.tfvars.
Remember to replace
1 | github_token = "<Your GitHub Token>" |
SSH key
Config github_user_ssh_keys within ./ssh_keys
1 | # GitHub: github_user_ssh_key - Terraform by HashiCorp |
Repository
Config GitHub repositories within ./repositories
1 | # GitHub: github_repository - Terraform by HashiCorp |
Run
Terraform Init
1 | terraform init |
It will download the Terraform GitHub Provider binary.
Terraform apply
1 | terraform apply |
It will dispaly the execute plan and wait for your make yes or no.
Then yes to create GitHub SSH keys and repositories.
Known issues
Currently only organizaiton repositories is supported.