24 Commits

Author SHA1 Message Date
74ee55599f update 2023-11-26 11:54:07 -06:00
d23e3ed9cd [skip ci] 2023-11-26 11:49:41 -06:00
62090b47e1 Update deployment process 2023-11-26 10:54:44 -06:00
94df41bd5f [skip ci] 2023-11-26 10:52:17 -06:00
94d9c735dc update 2023-11-26 10:47:24 -06:00
fe210a909f update 2023-11-26 10:45:01 -06:00
7395e64da0 [skip ci] 2023-11-26 10:44:04 -06:00
e6a6968e35 [skip ci] 2023-11-26 10:42:42 -06:00
25d045aed4 update 2023-11-26 06:31:47 -06:00
73cf0bd314 updaate 2023-11-25 21:05:59 -06:00
99996e3a05 update 2023-11-25 21:00:57 -06:00
6a4c19b314 update 2023-11-25 19:58:22 -06:00
1b7a0fb045 [skip ci] 2023-11-25 19:58:06 -06:00
bb8774a842 update pipeline 2023-11-25 05:00:28 -06:00
e365c38695 [skip ci] 2023-11-24 08:58:37 -06:00
cc6aa74cbc Update variables 2023-11-23 16:04:11 -06:00
5562bd3173 remove container 2023-11-23 14:52:37 -06:00
4fc4e646e7 Update variables 2023-11-23 14:50:35 -06:00
a229cc96b2 Update variables 2023-11-23 14:47:49 -06:00
22ab70e34a Update variables 2023-11-23 14:20:56 -06:00
94964dea8c update 2023-11-23 13:52:50 -06:00
48ea006ca7 Update variables 2023-11-23 13:32:36 -06:00
admin
048c69938a initial commit 2023-11-23 13:11:19 -06:00
c1d2bb7de2 update 2023-11-23 12:46:58 -06:00
13 changed files with 247 additions and 55 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
.terraform*
.env
*.tfstate*

View File

@@ -1,5 +1,8 @@
include:
- project: 'developerdurp/yml'
ref: 'main'
file: 'pipelines/gitlab_generic_packages.yml'
- local: .variables.yml
file:
- 'pipeline.yml'
#- 'pipelines/gitlab_generic_packages.yml'
#- 'pipelines/docker-build-generic.yml'
- local: .variables.yml

View File

@@ -0,0 +1,100 @@
step "plan-to-apply-a-terraform-template" {
name = "Terraform Plan"
action "terraform-plan" {
action_type = "Octopus.TerraformPlan"
is_required = true
properties = {
Octopus.Action.GoogleCloud.ImpersonateServiceAccount = "False"
Octopus.Action.GoogleCloud.UseVMServiceAccount = "True"
Octopus.Action.Package.DownloadOnTentacle = "False"
Octopus.Action.Package.FeedId = "nexus-nuget"
Octopus.Action.Package.PackageId = "#{TF_PACKAGE}"
Octopus.Action.RunOnServer = "true"
Octopus.Action.Script.ScriptSource = "Package"
Octopus.Action.Terraform.AdditionalInitParams = "#{TF_INIT}"
Octopus.Action.Terraform.AllowPluginDownloads = "True"
Octopus.Action.Terraform.AzureAccount = "False"
Octopus.Action.Terraform.EnvVariables = "{\"TF_VAR_GITLAB_PROJECT_NAME\":\"#{GITLAB_PROJECT_NAME}\",\"TF_VAR_GITLAB_SHARED_RUNNER_ID\":\"#{GITLAB_SHARED_RUNNER_ID}\",\"TF_VAR_GITLAB_TOKEN\":\"#{GITLAB_TOKEN}\",\"TF_VAR_OCTO_TENANT_ID\":\"#{Octopus.Deployment.Tenant.Id}\",\"TF_VAR_OCTOAPI\":\"#{OCTOAPI}\",\"TF_VAR_Development\":\"#{Development}\"}"
Octopus.Action.Terraform.GoogleCloudAccount = "False"
Octopus.Action.Terraform.ManagedAccount = "None"
Octopus.Action.Terraform.PlanJsonOutput = "False"
Octopus.Action.Terraform.RunAutomaticFileSubstitution = "True"
OctopusUseBundledTooling = "False"
}
worker_pool_variable = ""
container {
feed = "nexus"
image = "#{TF_Container}"
}
packages {
acquisition_location = "Server"
feed = "nexus-nuget"
package_id = "#{TF_PACKAGE}"
properties = {
SelectionMode = "immediate"
}
}
}
}
step "approve-plan" {
name = "Approve Plan"
action {
action_type = "Octopus.Manual"
is_required = true
properties = {
Octopus.Action.Manual.BlockConcurrentDeployments = "False"
Octopus.Action.Manual.Instructions = <<-EOT
```
#{Octopus.Action[Terraform Plan].Output.TerraformPlanOutput}
```
EOT
Octopus.Action.RunOnServer = "false"
}
}
}
step "terraform-apply" {
name = "Terraform Apply"
action {
action_type = "Octopus.TerraformApply"
properties = {
Octopus.Action.GoogleCloud.ImpersonateServiceAccount = "False"
Octopus.Action.GoogleCloud.UseVMServiceAccount = "True"
Octopus.Action.Package.DownloadOnTentacle = "False"
Octopus.Action.Package.FeedId = "nexus-nuget"
Octopus.Action.Package.PackageId = "#{TF_PACKAGE}"
Octopus.Action.RunOnServer = "true"
Octopus.Action.Script.ScriptSource = "Package"
Octopus.Action.Terraform.AdditionalInitParams = "#{TF_INIT}"
Octopus.Action.Terraform.AllowPluginDownloads = "True"
Octopus.Action.Terraform.AzureAccount = "False"
Octopus.Action.Terraform.EnvVariables = "{\"TF_VAR_GITLAB_PROJECT_NAME\":\"#{GITLAB_PROJECT_NAME}\",\"TF_VAR_GITLAB_SHARED_RUNNER_ID\":\"#{GITLAB_SHARED_RUNNER_ID}\",\"TF_VAR_GITLAB_TOKEN\":\"#{GITLAB_TOKEN}\",\"TF_VAR_OCTOAPI\":\"#{OCTOAPI}\",\"TF_VAR_OCTO_TENANT_ID\":\"#{Octopus.Deployment.Tenant.Id}\",\"TF_VAR_Development\":\"#{Development}\"}"
Octopus.Action.Terraform.GoogleCloudAccount = "False"
Octopus.Action.Terraform.ManagedAccount = "None"
Octopus.Action.Terraform.PlanJsonOutput = "False"
Octopus.Action.Terraform.RunAutomaticFileSubstitution = "True"
OctopusUseBundledTooling = "False"
}
worker_pool_variable = ""
container {
feed = "nexus"
image = "#{TF_Container}"
}
packages {
acquisition_location = "Server"
feed = "nexus-nuget"
package_id = "#{TF_PACKAGE}"
properties = {
SelectionMode = "immediate"
}
}
}
}

View File

@@ -0,0 +1,7 @@
connectivity_policy {
allow_deployments_to_no_targets = true
}
versioning_strategy {
template = "#{Octopus.Version.LastMajor}.#{Octopus.Version.LastMinor}.#{Octopus.Version.NextPatch}"
}

View File

@@ -0,0 +1 @@
version = 6

15
.octopus/variables.ocl Normal file
View File

@@ -0,0 +1,15 @@
variable "TF_PACKAGE" {
value "TERRAFORM.GITLAB.PROJECTS" {}
}
variable "TF_CONTAINER" {
value "developerdurp/octopus-build-container:22.4.0" {}
}
variable "TF_INIT" {
value "-backend-config=\"address=https://gitlab.com/api/v4/projects/#{GITLAB_PROJECT_ID}/terraform/state/#{Octopus.Deployment.Tenant.Id}\" -backend-config=\"lock_address=https://gitlab.com/api/v4/projects/#{GITLAB_PROJECT_ID}/terraform/state/#{Octopus.Deployment.Tenant.Id}/lock\" -backend-config=\"unlock_address=https://gitlab.com/api/v4/projects/#{GITLAB_PROJECT_ID}/terraform/state/#{Octopus.Deployment.Tenant.Id}/lock\" -backend-config=\"username=developerdurp\" -backend-config=\"password=#{GITLAB_TOKEN}\" -backend-config=\"lock_method=POST\" -backend-config=\"unlock_method=DELETE\" -backend-config=\"retry_wait_min=5\"" {}
}
variable "GITLAB_PROJECT_ID" {
value "52389386" {}
}

View File

@@ -1,3 +1,4 @@
variables:
PROJECT_NAME: TERRAFORM.GITLAB.PROJECTS
OCTO_PROJECT_NAME: "Gitlab Projects"
PIPELINE: 'gitlab'
PROJECT_NAME: "TERRAFORM.GITLAB.PROJECTS"
OCTO_PROJECT_NAME: "Gitlab Projects"

View File

@@ -1,13 +0,0 @@
FROM ubuntu:22.04
RUN apt-get update && \
apt-get install -y --no-install-recommends \
curl \
unzip \
apt-transport-https \
software-properties-common && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN curl https://releases.hashicorp.com/terraform/1.6.4/terraform_1.6.4_linux_amd64.zip -o tf.zip
RUN unzip -d /usr/local/bin/ tf.zip && rm tf.zip

View File

@@ -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
#}

View File

@@ -0,0 +1,11 @@
import {
to = octopusdeploy_tag.gitlabprojects
id = "TagSets-1/Tags-1"
}
import {
to = octopusdeploy_tenant.tenant
id = var.OCTO_TENANT_ID
}

View File

@@ -5,40 +5,10 @@ terraform {
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
}
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
}

View File

@@ -0,0 +1,40 @@
provider "octopusdeploy" {
address = "https://octopus.internal.durp.info"
api_key = var.OCTOAPI
}
resource "octopusdeploy_tenant" "tenant" {
name = var.GITLAB_PROJECT_NAME
project_environment {
environments = var.Development ? [
"Environments-1",
"Environments-2"
] : [
"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 = octopusdeploy_tenant.tenant.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
}

View File

@@ -2,14 +2,25 @@ variable "GITLAB_TOKEN" {
type = string
}
variable "GITLAB_PROJECT_ID" {
type = number
}
variable "GITLAB_PROJECT_NAME" {
type = string
}
variable "GITLAB_SHARED_RUNNER_ID" {
type = number
default = 0
}
variable "OCTOAPI" {
type = string
default = ""
}
variable "OCTO_TENANT_ID" {
type = string
}
variable "Development" {
type = bool
default = false
}