Terraform project to create and manage a GitHub repository using the integrations/github provider.
- Terraform >= 1.5.0
- A GitHub personal access token with the following scopes:
repo(full control of private repositories)delete_repo(required to destroy the repository via Terraform)admin:org(if managing repositories inside an organization)
-
Clone and enter the project:
git clone https://github.com/0xHackerSpace/terraformGithubRepo.git cd terraformGithubRepo -
Create your variable file:
cp terraform.tfvars.example terraform.tfvars
Edit
terraform.tfvarsand fill in yourgithub_token,github_owner, andrepository_name. -
Initialize Terraform:
terraform init
-
Preview the changes:
terraform plan
-
Apply the configuration:
terraform apply
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
github_token |
GitHub personal access token | string |
— | yes |
github_owner |
GitHub organization or user | string |
— | yes |
repository_name |
Name of the repository | string |
— | yes |
repository_description |
Short description | string |
"" |
no |
visibility |
public, private, or internal |
string |
"private" |
no |
has_issues |
Enable Issues | bool |
true |
no |
has_wiki |
Enable Wiki | bool |
false |
no |
has_discussions |
Enable Discussions | bool |
false |
no |
auto_init |
Initialize with README | bool |
true |
no |
gitignore_template |
Gitignore template name | string |
null |
no |
license_template |
SPDX license identifier | string |
null |
no |
allow_squash_merge |
Allow squash merges | bool |
true |
no |
delete_branch_on_merge |
Delete branch after merge | bool |
true |
no |
topics |
Repository topics | list(string) |
[] |
no |
vulnerability_alerts |
Enable vulnerability alerts | bool |
true |
no |
default_branch |
Default branch name | string |
"main" |
no |
enable_branch_protection |
Enable branch protection | bool |
false |
no |
required_approving_review_count |
Required PR approvals | number |
1 |
no |
enforce_admins |
Enforce rules for admins | bool |
false |
no |
| Name | Description |
|---|---|
repository_full_name |
Full name (owner/repo) |
repository_html_url |
URL on GitHub |
repository_ssh_clone_url |
SSH clone URL |
repository_http_clone_url |
HTTPS clone URL |
repository_default_branch |
Default branch name |
-
Never commit
terraform.tfvars— it contains your GitHub token. It is excluded by.gitignore. -
Never commit
*.tfstate— state files may contain sensitive data. -
Use a secrets manager (e.g., HashiCorp Vault, AWS Secrets Manager) or environment variables for token injection in CI/CD:
export TF_VAR_github_token="ghp_..."