Skip to content

Commit

Permalink
Merge pull request #7 from code0-tech/create-shared-pages-domain-module
Browse files Browse the repository at this point in the history
Create shared module for pages domains
  • Loading branch information
Taucher2003 authored Feb 9, 2024
2 parents 34a0e14 + 8493520 commit e7658a8
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 43 deletions.
43 changes: 0 additions & 43 deletions domain/docs.tf

This file was deleted.

9 changes: 9 additions & 0 deletions domain/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,12 @@ resource "cloudflare_zone_settings_override" "main" {
ssl = "strict"
}
}

module "docs_pages" {
source = "../modules/gitlab/pages_domain"

cloudflare_domain_name = "docs"
cloudflare_zone_id = data.cloudflare_zone.main_domain.id
gitlab_project_path = "code0-tech/telescopium"
gitlab_unique_pages_url = "docs-code0-tech-c91f18c0d2259c041bf05138b194e6bb082059fe38eff2e.gitlab.io"
}
56 changes: 56 additions & 0 deletions modules/gitlab/pages_domain/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
terraform {
required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
version = "4.24.0"
}
gitlab = {
source = "gitlabhq/gitlab"
version = "16.8.1"
}
}
}

//noinspection MissingProperty
data "gitlab_project" "this" {
path_with_namespace = var.gitlab_project_path
}

resource "cloudflare_record" "gitlab_pages" {
name = var.cloudflare_domain_name
type = "CNAME"
zone_id = var.cloudflare_zone_id
value = var.gitlab_unique_pages_url
proxied = true
comment = "Managed by Terraform"
}

module "certificate" {
source = "../../cloudflare/certificate"

hostname = cloudflare_record.gitlab_pages.hostname
}

data "cloudflare_origin_ca_root_certificate" "cloudflare_root" {
algorithm = "rsa"
}

resource "gitlab_pages_domain" "this" {
project = data.gitlab_project.this.id
domain = cloudflare_record.gitlab_pages.hostname

key = module.certificate.private_key
certificate = <<-EOF
${module.certificate.certificate}
${data.cloudflare_origin_ca_root_certificate.cloudflare_root.cert_pem}
EOF
}

//noinspection HILUnresolvedReference
resource "cloudflare_record" "gitlab_pages_verification" {
name = "_gitlab-pages-verification-code.${var.cloudflare_domain_name}"
type = "TXT"
zone_id = var.cloudflare_zone_id
value = gitlab_pages_domain.this.verification_code
comment = "Managed by Terraform"
}
15 changes: 15 additions & 0 deletions modules/gitlab/pages_domain/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
variable "cloudflare_zone_id" {
type = string
}

variable "gitlab_project_path" {
type = string
}

variable "cloudflare_domain_name" {
type = string
}

variable "gitlab_unique_pages_url" {
type = string
}

0 comments on commit e7658a8

Please sign in to comment.