From fe210a909f155b9197805235923eb2ce2fc25723 Mon Sep 17 00:00:00 2001 From: developerdurp Date: Sun, 26 Nov 2023 10:44:59 -0600 Subject: [PATCH] update --- TERRAFORM.GITLAB.PROJECTS/gitlab.tf | 45 ++++++++++++++++++++++ TERRAFORM.GITLAB.PROJECTS/import.tf | 11 ++++++ TERRAFORM.GITLAB.PROJECTS/main.tf | 52 +++----------------------- TERRAFORM.GITLAB.PROJECTS/octopus.tf | 37 ++++++++++++++++++ TERRAFORM.GITLAB.PROJECTS/variables.tf | 3 ++ TERRAFORM.OCTOPUS.PROJECTS/main.tf | 13 ------- 6 files changed, 101 insertions(+), 60 deletions(-) create mode 100644 TERRAFORM.GITLAB.PROJECTS/gitlab.tf create mode 100644 TERRAFORM.GITLAB.PROJECTS/import.tf create mode 100644 TERRAFORM.GITLAB.PROJECTS/octopus.tf delete mode 100644 TERRAFORM.OCTOPUS.PROJECTS/main.tf diff --git a/TERRAFORM.GITLAB.PROJECTS/gitlab.tf b/TERRAFORM.GITLAB.PROJECTS/gitlab.tf new file mode 100644 index 0000000..e8dd798 --- /dev/null +++ b/TERRAFORM.GITLAB.PROJECTS/gitlab.tf @@ -0,0 +1,45 @@ +provider "gitlab" { + token = var.GITLAB_TOKEN +} + +resource "gitlab_project" "project" { + name = octopusdeploy_tenant.tenant.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 + visibility_level = "public" + ci_forward_deployment_enabled = true +} + +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 = octopusdeploy_tenant_common_variable.gitlabrunnerid.value +} + +#resource "gitlab_project_variable" "OCTOAPI" { +# count = var.OCTOAPI != "" ? 1 : 0 +# project = gitlab_project.project.id +# key = "OCTOAPI" +# value = var.OCTOAPI +# protected = false +# masked = true +#} diff --git a/TERRAFORM.GITLAB.PROJECTS/import.tf b/TERRAFORM.GITLAB.PROJECTS/import.tf new file mode 100644 index 0000000..917091b --- /dev/null +++ b/TERRAFORM.GITLAB.PROJECTS/import.tf @@ -0,0 +1,11 @@ +import { + to = octopusdeploy_tag.gitlabprojects + id = "TagSets-1/Tags-1" +} + +import { + to = octopusdeploy_tenant.tenant + id = var.OCTO_TENANT_ID +} + + diff --git a/TERRAFORM.GITLAB.PROJECTS/main.tf b/TERRAFORM.GITLAB.PROJECTS/main.tf index 2c4ae71..e909cef 100644 --- a/TERRAFORM.GITLAB.PROJECTS/main.tf +++ b/TERRAFORM.GITLAB.PROJECTS/main.tf @@ -1,56 +1,14 @@ terraform { - #backend "http" {} + backend "http" {} required_providers { gitlab = { source = "gitlabhq/gitlab" version = "16.2.0" } + octopusdeploy = { + source = "OctopusDeployLabs/octopusdeploy" + version = "0.13.3" + } } } -provider "gitlab" { - 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 - visibility_level = "public" - ci_forward_deployment_enabled = true -} - -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" { - count = var.GITLAB_SHARED_RUNNER_ID != 0 ? 1 : 0 - project = gitlab_project.project.id - runner_id = var.GITLAB_SHARED_RUNNER_ID -} - -resource "gitlab_project_variable" "OCTOAPI" { - count = var.OCTOAPI != "" ? 1 : 0 - project = gitlab_project.project.id - key = "OCTOAPI" - value = var.OCTOAPI - protected = false - masked = true -} diff --git a/TERRAFORM.GITLAB.PROJECTS/octopus.tf b/TERRAFORM.GITLAB.PROJECTS/octopus.tf new file mode 100644 index 0000000..01f1c67 --- /dev/null +++ b/TERRAFORM.GITLAB.PROJECTS/octopus.tf @@ -0,0 +1,37 @@ +provider "octopusdeploy" { + address = "https://octopus.internal.durp.info" + api_key = var.OCTOAPI +} + +resource "octopusdeploy_tenant" "tenant" { + name = var.GITLAB_PROJECT_NAME + project_environment { + environments = [ + "Environments-1" + ] + project_id = "Projects-1" + } + tenant_tags = [ + octopusdeploy_tag.gitlabprojects.canonical_tag_name + ] +} + +resource "octopusdeploy_tag" "gitlabprojects" { + name = "Gitlab Project" + color = "#333333" + tag_set_id = "TagSets-1" +} + +resource "octopusdeploy_tenant_common_variable" "gitlabprojectname" { + library_variable_set_id = "LibraryVariableSets-2" + template_id = "f14ad0ff-d8cf-44a8-bd8d-ff23b0fdb0f4" + tenant_id = octopusdeploy_tenant.tenant.id + value = var.GITLAB_PROJECT_NAME +} + +resource "octopusdeploy_tenant_common_variable" "gitlabrunnerid" { + library_variable_set_id = "LibraryVariableSets-2" + template_id = "25732879-3567-4d0b-9aad-2769befabf42" + tenant_id = octopusdeploy_tenant.tenant.id + value = var.GITLAB_SHARED_RUNNER_ID +} diff --git a/TERRAFORM.GITLAB.PROJECTS/variables.tf b/TERRAFORM.GITLAB.PROJECTS/variables.tf index e638c44..fab12c5 100644 --- a/TERRAFORM.GITLAB.PROJECTS/variables.tf +++ b/TERRAFORM.GITLAB.PROJECTS/variables.tf @@ -16,3 +16,6 @@ variable "OCTOAPI" { default = "" } +variable "OCTO_TENANT_ID" { + type = string +} diff --git a/TERRAFORM.OCTOPUS.PROJECTS/main.tf b/TERRAFORM.OCTOPUS.PROJECTS/main.tf deleted file mode 100644 index 32a7269..0000000 --- a/TERRAFORM.OCTOPUS.PROJECTS/main.tf +++ /dev/null @@ -1,13 +0,0 @@ -terraform { - required_providers { - octopusdeploy = { - source = "OctopusDeployLabs/octopusdeploy" - version = "0.13.3" - } - } -} - -provider "octopusdeploy" { - # Configuration options -} -