Skip to content

Commit 748c343

Browse files
committed
first commit
0 parents  commit 748c343

File tree

7 files changed

+192
-0
lines changed

7 files changed

+192
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# terraform-github-repo
2+
3+
Terraform module to create a Github repo.

examples/full/main.tf

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module "example" {
2+
source = "../.."
3+
4+
name = "github-example-repo"
5+
description = "Example repo created using the terraform-github-repo"
6+
}

main.tf

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
resource "github_repository" "repository" {
2+
name = var.name
3+
4+
allow_merge_commit = var.allow_merge_commit
5+
allow_auto_merge = var.allow_auto_merge
6+
allow_squash_merge = var.allow_squash_merge
7+
allow_rebase_merge = var.allow_rebase_merge
8+
archived = var.archived
9+
description = "${var.description}: Managed by Terraform"
10+
delete_branch_on_merge = var.delete_branch_on_merge
11+
has_issues = true
12+
has_projects = false
13+
has_wiki = false
14+
has_downloads = false
15+
is_template = false
16+
17+
template {
18+
owner = "ntse"
19+
repository = "github-repo-template"
20+
include_all_branches = true
21+
}
22+
}
23+
24+
25+
resource "github_branch_protection" "this" {
26+
repository_id = github_repository.repository.node_id
27+
28+
pattern = "main"
29+
30+
restrict_pushes {
31+
push_allowances = [
32+
data.github_user.this.node_id,
33+
]
34+
}
35+
36+
}
37+
38+
data "github_user" "this" {
39+
username = "ntse"
40+
}
41+

variables.tf

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
variable "name" {
2+
description = "The name of the GitHub repository"
3+
type = string
4+
}
5+
6+
variable "allow_merge_commit" {
7+
description = "Set to true to allow merge commits"
8+
type = bool
9+
default = true
10+
}
11+
12+
variable "allow_auto_merge" {
13+
description = "Set to true to allow auto merging"
14+
type = bool
15+
default = false
16+
}
17+
18+
variable "allow_squash_merge" {
19+
description = "Set to true to allow squash merging"
20+
type = bool
21+
default = true
22+
}
23+
24+
variable "allow_rebase_merge" {
25+
description = "Set to true to allow rebase merging"
26+
type = bool
27+
default = true
28+
}
29+
30+
variable "archived" {
31+
description = "Set to true to archive the repository"
32+
type = bool
33+
default = false
34+
}
35+
36+
variable "description" {
37+
description = "A description of the repository"
38+
type = string
39+
default = ""
40+
}
41+
42+
variable "delete_branch_on_merge" {
43+
description = "Set to true to delete the branch on merge"
44+
type = bool
45+
default = false
46+
}

versions.tf

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
terraform {
2+
required_providers {
3+
github = {
4+
source = "integrations/github"
5+
version = "~> 6.0"
6+
}
7+
}
8+
}
9+
10+
provider "github" {
11+
owner = "ntse"
12+
}

workflows/bootstrap-example.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Run Github repo example
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
terraform:
10+
runs-on: ubuntu-latest
11+
12+
env:
13+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
14+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
15+
AWS_REGION: "eu-west-1"
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Terraform
22+
uses: hashicorp/setup-terraform@v3
23+
24+
- name: Initialize Terraform
25+
working-directory: ./examples/full
26+
run: terraform init -reconfigure -input=false
27+
28+
- name: Validate Terraform
29+
working-directory: ./examples/full
30+
run: terraform validate -no-color
31+
32+
- name: Plan Terraform
33+
working-directory: ./examples/full
34+
run: terraform plan -out=tfplan -no-color -input=false
35+
36+
- name: Apply Terraform
37+
working-directory: ./examples/full
38+
run: terraform apply -auto-approve -input=false tfplan

workflows/pr-workflow.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: PR Workflow
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- 'main'
7+
8+
jobs:
9+
terraform:
10+
runs-on: ubuntu-latest
11+
12+
env:
13+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
14+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
15+
AWS_REGION: "eu-west-1"
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Terraform
22+
uses: hashicorp/setup-terraform@v3
23+
24+
- name: Run Terraform fmt
25+
run: terraform fmt --recursive --check
26+
id: terraform_fmt
27+
continue-on-error: true
28+
29+
- name: Setup TFLint
30+
uses: terraform-linters/setup-tflint@v4
31+
32+
- name: Run TFLint
33+
run: tflint --recursive
34+
id: terraform_lint
35+
continue-on-error: true
36+
37+
- name: Generate summary of linting
38+
run: |
39+
terraform_fmt_status="❌"
40+
terraform_lint_status="❌"
41+
[ ${{ steps.terraform_fmt.outcome }} == 'success' ] && terraform_fmt_status="✅"
42+
[ ${{ steps.terraform_lint.outcome }} == 'success' ] && terraform_lint_status="✅"
43+
echo "Terraform Linting" >> $GITHUB_STEP_SUMMARY
44+
echo "" >> $GITHUB_STEP_SUMMARY
45+
echo "- Terraform Formating ${terraform_fmt_status}" >> $GITHUB_STEP_SUMMARY
46+
echo "- Terraform Linting ${terraform_lint_status}" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)