Skip to content

Commit

Permalink
Move gitlab runner configuration to a separate terraform module
Browse files Browse the repository at this point in the history
  • Loading branch information
danlamanna committed Feb 8, 2024
1 parent 3b2b28f commit 6fee49f
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 2 deletions.
6 changes: 6 additions & 0 deletions terraform/modules/spack/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ data "aws_region" "current" {}

# Data source that allows us to dynamically determine id of the current "canonical user"
data "aws_canonical_user_id" "current" {}

data "aws_caller_identity" "current" {}

data "gitlab_project" "spack" {
path_with_namespace = "spack/spack"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
gitlab = {
source = "gitlabhq/gitlab"
version = "16.3.0"
}
}
}

locals {
gitlab_domain = "gitlab${var.deployment_name == "prod" ? "" : ".staging"}.spack.io"

Expand Down Expand Up @@ -26,6 +39,7 @@ data "gitlab_project" "spack" {
path_with_namespace = "spack/spack"
}


data "tls_certificate" "gitlab" {
url = "https://${local.gitlab_domain}"
}
Expand Down Expand Up @@ -78,7 +92,7 @@ data "aws_iam_policy_document" "gitlab_runner" {
actions = ["s3:PutObject", "s3:DeleteObject"]

resources = [
each.key == "protected_binary_mirror" ? "${module.protected_binary_mirror.bucket_arn}/*" : "${module.pr_binary_mirror.bucket_arn}/*",
each.key == "protected_binary_mirror" ? "${var.protected_binary_bucket_arn}/*" : "${var.pr_binary_bucket_arn}/*",
]
}
}
Expand Down Expand Up @@ -110,7 +124,7 @@ resource "gitlab_project_variable" "binary_mirror_role_arn" {
resource "gitlab_project_variable" "pr_binary_mirror_bucket_arn" {
project = data.gitlab_project.spack.id
key = "PR_BINARY_MIRROR_BUCKET_ARN"
value = module.pr_binary_mirror.bucket_arn
value = var.pr_binary_bucket_arn
}

# attachments for the pre-existing hardcoded policies in production
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
variable "deployment_name" {
description = "The name of the deployment. This will be used as a prefix for all resources."
type = string
}

variable "protected_binary_bucket_arn" {
description = "The ARN of the S3 bucket that contains protected binaries."
type = string
}

variable "pr_binary_bucket_arn" {
description = "The ARN of the S3 bucket that contains PR binaries."
type = string
}
8 changes: 8 additions & 0 deletions terraform/modules/spack/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ output "oidc_provider" {
output "oidc_provider_arn" {
value = module.eks.oidc_provider_arn
}

output "protected_binary_bucket_arn" {
value = module.protected_binary_mirror.bucket_arn
}

output "pr_binary_bucket_arn" {
value = module.pr_binary_mirror.bucket_arn
}
9 changes: 9 additions & 0 deletions terraform/production/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,12 @@ module "production_cluster" {

ses_email_domain = "spack.io"
}

module "gitlab_runner_configuration" {
source = "../modules/spack/modules/gitlab_runner_configuration"

deployment_name = "prod"

protected_binary_bucket_arn = module.production_cluster.protected_binary_bucket_arn
pr_binary_bucket_arn = module.production_cluster.pr_binary_bucket_arn
}
9 changes: 9 additions & 0 deletions terraform/staging/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,12 @@ module "staging_cluster" {

ses_email_domain = "staging.spack.io"
}

module "gitlab_runner_configuration" {
source = "../modules/spack/modules/gitlab_runner_configuration"

deployment_name = "staging"

protected_binary_bucket_arn = module.staging_cluster.protected_binary_bucket_arn
pr_binary_bucket_arn = module.staging_cluster.pr_binary_bucket_arn
}

0 comments on commit 6fee49f

Please sign in to comment.