From 91494b02b8cc67daa0456428f438e3bb0f1d5637 Mon Sep 17 00:00:00 2001 From: StepanHorbach Date: Mon, 24 Aug 2026 13:36:18 +0300 Subject: [PATCH 1/2] ADD: Terraform GitHub repository configuration --- .gitignore | 7 ++ .terraform.lock.hcl | 45 +++++++++++++ main.tf | 159 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 211 insertions(+) create mode 100644 .gitignore create mode 100644 .terraform.lock.hcl create mode 100644 main.tf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6316680 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.terraform/ +*.tfstate +*.tfstate.* +tfplan +crash.log +*.tfvars +*.tfvars.json \ No newline at end of file diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl new file mode 100644 index 0000000..e23226b --- /dev/null +++ b/.terraform.lock.hcl @@ -0,0 +1,45 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/tls" { + version = "4.3.0" + constraints = "~> 4.0" + hashes = [ + "h1:7QWrBlzkkFAFyDl9UsfC0tdfNFquFx03miHwZcta33Q=", + "zh:0ab58d6f8991d436c7d2dbd89ed814709b949b07ac5a54ee53b0aec1fa772a8b", + "zh:60b347abcb56f45d97c56f14d895069cd15a83993f199777f571b79fea3642ee", + "zh:6889be32640349230de3f23856e6f04e0e9ced4a84a27d3f552fa54684448218", + "zh:73f8e1ecf7135033165fb14b7e8bf4d656f3ce13065ec35762ea0481975328c7", + "zh:94ce25ee253eca0b42cae9c856b36bca8103b6453012d1b279c3623c805f2d42", + "zh:96bc6de9fd67bc446fd11257872e1ffb1029a996ed1d65a3f6b43f6d408ad9ab", + "zh:97c609a310a51bfd504d704e036d72064a84bf0bdb36cc08cd4cc66098212b41", + "zh:a12c16e94533c5bd123f75032576b9dc91dd5d5ccd5f7cf331d0f2e1adc55cf8", + "zh:c4f014f876adf7af57188795050bda5b0029d8c7d7773031102b6c36dcf1fc21", + "zh:d9b0a21583aaa3df3a95394fb949a3c515ff71c2ff5a1fc4a73d364aa90bfca5", + "zh:da510d22f0c6d71ad19a76406f106b782448f512375787ecfabb338ed1e311a7", + "zh:f0e9447a9ce3a24cdaa113089e65663c836d8b9bfdb915a1c0284e0112cab5c0", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + ] +} + +provider "registry.terraform.io/integrations/github" { + version = "6.13.0" + constraints = "~> 6.0" + hashes = [ + "h1:RhCWa2aaFVKF/HzeR0fkIxZmoJvkGrv07hE0z09aPQs=", + "zh:0ab29fc21699f34345cf0bbbe44745fd1b143b7c73b410c1dc4abe05ffad0a84", + "zh:1aed10d06755d420bb3a893bf548ab2932297a9d094c04c5a8501e949ca186ed", + "zh:2a6a11c21eae408055f45b9533c07afd2e845f6d496fd1b645aec2e873012103", + "zh:5dd05dee677f6ebdbed00cbb1b9be444ab2d1062d345cbc9ec50a47cb41b8622", + "zh:6b757d034831243d67ddda869eac4368cef539848bd97511f4d68f1aa38a9c88", + "zh:947c9b5b238f0364c57a705beabd24d3eea3159a6f3a24c07e3fbb13657ffae0", + "zh:a676549a98164b61630658cbeb6c17820331ca04a049dc9b5095996a0c31ffbe", + "zh:a8a81b7fe41dd61eb6a6fa5e08a4dd9ee070e862868252a7fd4cfce30364efee", + "zh:c26a9bca4865665084e7f59b1402d7aff34ee63a418d7401a0658fa280cad4d4", + "zh:c638d8d0762e62ea188f86302954ef4c92803f2160f0a45fca0cd13974bd3725", + "zh:e739a0b7e81ca816944a18a38e679f4015edf8be7ac319815cdea865ba7727d7", + "zh:ec099487ea3de8999c84b3b791e242d728461e51fe344832b37bd8d521201c77", + "zh:f016ff9e2daab5b88185cec0795213049d105439ffd585d3309a714514ccae13", + "zh:fbd1fee2c9df3aa19cf8851ce134dea6e45ea01cb85695c1726670c285797e25", + ] +} diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..5e51f01 --- /dev/null +++ b/main.tf @@ -0,0 +1,159 @@ +terraform { + required_version = ">= 1.5.0" + + required_providers { + github = { + source = "integrations/github" + version = "~> 6.0" + } + + tls = { + source = "hashicorp/tls" + version = "~> 4.0" + } + } +} + +variable "pat" { + description = "GitHub personal access token classic" + type = string + sensitive = true + + default = "ghp_000000000000000000000000000000000000" +} + +variable "discord_webhook_url" { + description = "Discord webhook URL without /github suffix" + type = string + sensitive = true + + default = "https://discord.com/api/webhooks/000000000000000000/placeholder" +} + +locals { + owner = "Practical-DevOps-GitHub" + repository = "github-terraform-task-StephanHorbach" +} + +provider "github" { + owner = local.owner +} + +resource "github_repository_collaborator" "softservedata" { + repository = local.repository + username = "softservedata" + permission = "push" +} + +resource "github_branch" "develop" { + repository = local.repository + branch = "develop" + source_branch = "main" +} + +resource "github_branch_default" "develop" { + repository = local.repository + branch = github_branch.develop.branch +} + +resource "github_repository_file" "codeowners" { + repository = local.repository + branch = "main" + file = ".github/CODEOWNERS" + content = "* @softservedata\n" + commit_message = "Add CODEOWNERS" + overwrite_on_create = true + + depends_on = [ + github_branch.develop, + github_repository_collaborator.softservedata + ] +} + +resource "github_repository_file" "pull_request_template" { + repository = local.repository + branch = "main" + file = ".github/pull_request_template.md" + + content = <<-EOT + ## Describe your changes + + ## Issue ticket number and link + + ## Checklist before requesting a review + - [ ] I have performed a self-review of my code + - [ ] If it is a core feature, I have added thorough tests + - [ ] Do we need to implement analytics? + - [ ] Will this be part of a product update? If yes, please write one phrase about this update + EOT + + commit_message = "Add pull request template" + overwrite_on_create = true + + depends_on = [github_branch.develop] +} + +resource "github_branch_protection" "develop" { + repository_id = local.repository + pattern = "develop" + enforce_admins = true + + allows_deletions = false + allows_force_pushes = false + + required_pull_request_reviews { + required_approving_review_count = 2 + dismiss_stale_reviews = true + } + + depends_on = [github_branch.develop] +} + +resource "github_branch_protection" "main" { + repository_id = local.repository + pattern = "main" + enforce_admins = true + + allows_deletions = false + allows_force_pushes = false + + required_pull_request_reviews { + required_approving_review_count = 0 + require_code_owner_reviews = true + dismiss_stale_reviews = true + } + + depends_on = [ + github_repository_file.codeowners, + github_repository_file.pull_request_template + ] +} + +resource "tls_private_key" "deploy_key" { + algorithm = "ED25519" +} + +resource "github_repository_deploy_key" "deploy_key" { + title = "DEPLOY_KEY" + repository = local.repository + key = tls_private_key.deploy_key.public_key_openssh + read_only = true +} + +resource "github_repository_webhook" "discord" { + repository = local.repository + events = ["pull_request"] + active = true + + configuration { + url = "${var.discord_webhook_url}/github" + content_type = "json" + insecure_ssl = false + } +} + +resource "github_actions_secret" "pat" { + repository = local.repository + secret_name = "PAT" + value = var.pat +} From 297a34f15346b1732667c4177b1785d32688073b Mon Sep 17 00:00:00 2001 From: StepanHorbach Date: Mon, 24 Aug 2026 13:47:30 +0300 Subject: [PATCH 2/2] FIX: discord server url format --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 5e51f01..603620b 100644 --- a/main.tf +++ b/main.tf @@ -146,7 +146,7 @@ resource "github_repository_webhook" "discord" { active = true configuration { - url = "${var.discord_webhook_url}/github" + url = format("%s/github", var.discord_webhook_url) content_type = "json" insecure_ssl = false }