Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create shared module for pages domains #7

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}