diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c14a3ad --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.terraform* +.env diff --git a/TERRAFORM.GITLAB.PROJECTS/main.tf b/TERRAFORM.GITLAB.PROJECTS/main.tf index 4168cd2..d786dd4 100644 --- a/TERRAFORM.GITLAB.PROJECTS/main.tf +++ b/TERRAFORM.GITLAB.PROJECTS/main.tf @@ -1,13 +1,44 @@ terraform { - backend "http" {} - required_providers { - gitlab { - source = "gitlabhq/gitlab" - verison = "16.2.0" - } + backend "http" {} + required_providers { + gitlab = { + source = "gitlabhq/gitlab" + version = "16.2.0" } + } } provider "gitlab" { - token = var.GITLAB_TOKEN -} \ No newline at end of file + token = var.GITLAB_TOKEN +} + +resource "gitlab_project" "project" { + name = var.GITLAB_PROJECT_NAME + allow_merge_on_skipped_pipeline = false + only_allow_merge_if_pipeline_succeeds = true + remove_source_branch_after_merge = true + squash_option = "default_on" + ci_config_path = ".gitlab/.gitlab-ci.yml" + shared_runners_enabled = false +} + +resource "gitlab_branch_protection" "master" { + project = gitlab_project.project.id + branch = "main" + push_access_level = "maintainer" + merge_access_level = "developer" + allow_force_push = false +} + +resource "gitlab_branch_protection" "release" { + project = gitlab_project.project.id + branch = "release/*" + push_access_level = "maintainer" + merge_access_level = "developer" + allow_force_push = false +} + +resource "gitlab_project_runner_enablement" "k3s" { + project = gitlab_project.project.id + runner_id = var.GITLAB_SHARED_RUNNER_ID +} diff --git a/TERRAFORM.GITLAB.PROJECTS/variables.tf b/TERRAFORM.GITLAB.PROJECTS/variables.tf index 1b2a215..606f4c8 100644 --- a/TERRAFORM.GITLAB.PROJECTS/variables.tf +++ b/TERRAFORM.GITLAB.PROJECTS/variables.tf @@ -1,3 +1,15 @@ -variable "GITLAB_TOKEN { - type = string -} \ No newline at end of file +variable "GITLAB_TOKEN" { + type = string +} + +variable "GITLAB_PROJECT_ID" { + type = number +} + +variable "GITLAB_PROJECT_NAME" { + type = string +} + +variable "GITLAB_SHARED_RUNNER_ID" { + type = number +}