Skip to content

Instantly share code, notes, and snippets.

@rhysjtevans
Created May 22, 2020 10:46
Show Gist options
  • Save rhysjtevans/0605200896560dbdb7ab05ed3f168eb0 to your computer and use it in GitHub Desktop.
Save rhysjtevans/0605200896560dbdb7ab05ed3f168eb0 to your computer and use it in GitHub Desktop.
A quick terraform module to provision standardised
resource "gitlab_project" "repository" {
name = var.gitlab_project_name
path = replace(lower(var.gitlab_project_name)," ","-")
description = var.gitlab_project_description
namespace_id = var.gitlab_group_id
default_branch = var.gitlab_project_default_branch
approvals_before_merge = var.gitlab_project_approvals_before_merge
merge_method = var.gitlab_project_merge_method
visibility_level = var.visibility_level
initialize_with_readme = var.initialize_with_readme
}
data "gitlab_group" "group" {
group_id = var.gitlab_group_id
}
resource "gitlab_project_hook" "example" {
count = length(var.gitlab_project_webhook_url) > 0 ? 1 : 0
project = gitlab_project.repository.id
url = var.gitlab_project_webhook_url
merge_requests_events = true
token = var.gitlab_project_webhook_token
}
resource "gitlab_branch_protection" "BranchProtect" {
count = var.gitlab_project_branch_protection ? 1 : 0
project = gitlab_project.repository.id
branch = var.gitlab_project_default_branch
push_access_level = var.gitlab_project_push_access_level
merge_access_level = var.gitlab_project_merge_access_level
}
resource "gitlab_project_push_rules" "project" {
# commit_message_regex = "^(added|removed|resolved|feature|fix|fixed|chore|docs):.*"
prevent_secrets = true
# branch_name_regex = "^(ENG-\\d+)(\\d)?"
# author_email_regex = "(@flexciton\\.com$)"
project = gitlab_project.repository.id
# max_file_size = var.gitlab_project_push_rules_max_file_size
# file_name_regex = var.gitlab_project_push_rules_file_name_regex
}
resource "gitlab_tag_protection" "TagProtect" {
count = var.gitlab_tag_protection ? 1 : 0
project = gitlab_project.repository.id
tag = "*"
create_access_level = "maintainer"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment