Skip to content

Commit 0b5b30a

Browse files
authored
Add Terraform configuration for GitHub integration
1 parent 1a15297 commit 0b5b30a

1 file changed

Lines changed: 94 additions & 0 deletions

File tree

main.tf

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
terraform {
2+
required_providers {
3+
github = {
4+
source = "integrations/github"
5+
version = "~> 6.2"
6+
}
7+
}
8+
}
9+
10+
provider "github" {
11+
token = var.github_token
12+
owner = "Practical-DevOps-GitHub" # the org that owns the repo
13+
}
14+
15+
variable "github_token" {
16+
description = "Your Github PAT"
17+
type = string
18+
sensitive = true
19+
}
20+
21+
locals {
22+
repo_name = "github-terraform-task-harturicko" # short name only
23+
}
24+
25+
data "github_repository" "repo" {
26+
full_name = "Practical-DevOps-GitHub/${local.repo_name}" # full_name for data source
27+
}
28+
29+
resource "github_repository_collaborator" "repo_collaborator" {
30+
repository = local.repo_name # short name — owner comes from provider
31+
username = "softservedata"
32+
permission = "admin"
33+
}
34+
35+
resource "github_branch" "develop" {
36+
repository = local.repo_name
37+
branch = "develop"
38+
}
39+
40+
resource "github_branch_default" "default" {
41+
repository = local.repo_name
42+
branch = github_branch.develop.branch
43+
}
44+
45+
resource "github_repository_file" "codeowners_main" {
46+
repository = local.repo_name
47+
branch = "main"
48+
file = ".github/CODEOWNERS"
49+
content = "* @softservedata\n"
50+
overwrite_on_create = true
51+
}
52+
53+
resource "github_repository_file" "codeowners_develop" {
54+
repository = local.repo_name
55+
branch = github_branch.develop.branch
56+
file = ".github/CODEOWNERS"
57+
content = "* @softservedata\n"
58+
overwrite_on_create = true
59+
depends_on = [github_branch.develop]
60+
}
61+
62+
resource "github_branch_protection" "main_protection" {
63+
repository_id = data.github_repository.repo.node_id # node_id is fine here
64+
pattern = "main"
65+
enforce_admins = true
66+
67+
required_pull_request_reviews {
68+
required_approving_review_count = 1
69+
require_code_owner_reviews = true
70+
dismiss_stale_reviews = true
71+
}
72+
depends_on = [github_repository_file.codeowners_main]
73+
}
74+
75+
resource "github_branch_protection" "develop_protection" {
76+
repository_id = data.github_repository.repo.node_id
77+
pattern = "develop"
78+
enforce_admins = true
79+
80+
required_pull_request_reviews {
81+
required_approving_review_count = 2
82+
require_code_owner_reviews = true
83+
dismiss_stale_reviews = true
84+
}
85+
depends_on = [github_repository_file.codeowners_develop]
86+
}
87+
88+
89+
resource "github_actions_secret" "terraform_secret" {
90+
repository = local.repo_name
91+
secret_name = "TERRAFORM"
92+
plaintext_value = file("${path.module}/demo.tf") # reads your .tf file content
93+
}
94+

0 commit comments

Comments
 (0)