Skip to content

Commit

Permalink
feat: add gitlab test
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiehrhardt committed Jan 19, 2024
1 parent 705714f commit 22cb2af
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 31 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: stack test
on:
pull_request:
branches: ["master"]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: test
uses: "infinite-automations/terraform-all-in-one@v1"
with:
plan: false
test: true
directory: "./gitlab"
test-directory: "./gitlab"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
*.tar
gitlab-secrets.yml
*.pem
*.key
token.txt
39 changes: 8 additions & 31 deletions gitlab/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,14 @@ resource "helm_release" "gitlab" {
repository = "https://charts.gitlab.io/"
chart = "gitlab"
version = "7.5.0"
timeout = "720"
timeout = "1800"

values = [<<EOT
global:
ingress:
configureCertmanager: false
class: "nginx"
hosts:
domain: ${module.mk.ip}.nip.io
externalIP: "${module.mk.ip}"
kas:
enabled: false
certmanager:
install: false
nginx-ingress:
enabled: false
registry:
enabled: false
prometheus:
install: false
gitlab:
webservice:
minReplicas: 1
maxReplicas: 1
sidekiq:
minReplicas: 1
maxReplicas: 1
gitlab-shell:
enabled: false
gitlab-runner:
certsSecretName: gitlab-wildcard-tls-chain
EOT
values = [
templatefile("./values.tftpl.yaml", { ip = module.mk.ip })
]
}

# output used for testing
output "ip" {
value = module.mk.ip
}
16 changes: 16 additions & 0 deletions gitlab/main.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
run "setup_gitlab" {}

run "verify" {
variables {
mk_ip = run.setup_gitlab.ip
}

module {
source = "./tests/verify"
}

assert {
condition = data.terracurl_request.test.status_code == "200"
error_message = "terracurl failed"
}
}
64 changes: 64 additions & 0 deletions gitlab/tests/verify/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
terraform {
required_version = ">= 1.0"

required_providers {
terracurl = {
source = "devops-rob/terracurl"
version = "1.1.0"
}
}
}

provider "terracurl" {}

provider "kubernetes" {
config_path = "~/.kube/config"
}

variable "mk_ip" {
type = string
}

data "kubernetes_secret" "gitlab_ca" {
metadata {
name = "gitlab-wildcard-tls-ca"
namespace = "gitlab"
}
}

data "kubernetes_secret" "gitlab_cert" {
metadata {
name = "gitlab-wildcard-tls"
namespace = "gitlab"
}
}

resource "local_file" "ca" {
content = data.kubernetes_secret.gitlab_ca.data.cfssl_ca
filename = "${path.module}/ca.pem"
}

resource "local_file" "cert" {
content = data.kubernetes_secret.gitlab_cert.data["tls.crt"]
filename = "${path.module}/cert.pem"
}

resource "local_file" "key" {
content = data.kubernetes_secret.gitlab_cert.data["tls.key"]
filename = "${path.module}/cert.key"
}

data "terracurl_request" "test" {
name = "check"
url = "https://gitlab.${var.mk_ip}.nip.io"
method = "GET"

response_codes = [200]

ca_cert_file = local_file.ca.filename
cert_file = local_file.cert.filename
key_file = local_file.key.filename

max_retry = 3
retry_interval = 10
}
28 changes: 28 additions & 0 deletions gitlab/values.tftpl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
global:
ingress:
configureCertmanager: false
class: "nginx"
hosts:
domain: ${ip}.nip.io
externalIP: "${ip}"
kas:
enabled: false
certmanager:
install: false
nginx-ingress:
enabled: false
registry:
enabled: false
prometheus:
install: false
gitlab:
webservice:
minReplicas: 1
maxReplicas: 1
sidekiq:
minReplicas: 1
maxReplicas: 1
gitlab-shell:
enabled: false
gitlab-runner:
certsSecretName: gitlab-wildcard-tls-chain

0 comments on commit 22cb2af

Please sign in to comment.