From e0f5fd7744e6e668db60dae83984e5aacaa829a7 Mon Sep 17 00:00:00 2001 From: shubhamsinha-sf <73998079+shubhamsinha-sf@users.noreply.github.com> Date: Tue, 6 Feb 2024 16:56:41 +0530 Subject: [PATCH] add docker-compose.yaml template override --- README.md | 1 + locals.tf | 10 ++++++++++ main.tf | 10 +--------- variables.tf | 10 ++++++++++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 5338c4d..40fde71 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,7 @@ module "runner" { |------|-------------|------|---------|:--------:| | [ami](#input\_ami) | AMI information for the EC2 instance |
object({
id = string
owner_id = string
})
|
{
"id": "ami-04505e74c0741db8d",
"owner_id": "099720109477"
}
| no | | [associate\_public\_ip\_address](#input\_associate\_public\_ip\_address) | Associate a public IP address with the instance | `bool` | `false` | no | +| [docker\_compose\_yaml\_override](#input\_docker\_compose\_yaml\_override) | This var allows the downstream module to override the docker-compose.yaml template used by this module.
When you set this variable, you own the docker compose stack for the runner."
Validate your docker-compose.yaml and pass it as a string. This module will bas64encode it. | `string` | `null` | no | | [ec2\_runner\_iam\_role\_policy\_arns](#input\_ec2\_runner\_iam\_role\_policy\_arns) | IAM role policies to attach to the Runner instance | `list(string)` |
[
"arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore",
"arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM"
]
| no | | [environment](#input\_environment) | Name of the environment, i.e. dev, stage, prod | `string` | n/a | yes | | [github\_owner](#input\_github\_owner) | GitHub Owner the runner belongs to. If you are adding a repo, the format will be `owner/repo` | `string` | `"sourcefuse"` | no | diff --git a/locals.tf b/locals.tf index 2359684..c563437 100644 --- a/locals.tf +++ b/locals.tf @@ -10,4 +10,14 @@ locals { runner_name = var.runner_name != null ? var.runner_name : "${var.namespace}-${var.environment}-github-runner-${random_string.runner.result}" aws_friendly_runner_labels = replace(var.runner_labels, ",", " + ") + docker_compose_default_template = base64encode(templatefile("${path.module}/templates/docker-compose.yml.tftpl", { + runner_token = data.aws_ssm_parameter.runner_token.value + runner_owner = var.github_owner + runner_name = local.runner_name + runner_user = var.runner_user + runner_image = var.runner_image + runner_labels = var.runner_labels + repos_or_orgs = var.repos_or_orgs + })) + docker_compose_config = var.docker_compose_yaml_override == null ? local.docker_compose_default_template : base64encode(var.docker_compose_yaml_override) } diff --git a/main.tf b/main.tf index 742e1c7..6ae4626 100644 --- a/main.tf +++ b/main.tf @@ -155,15 +155,7 @@ resource "aws_s3_object" "docker_compose" { bucket = aws_s3_bucket.runner.id key = "docker-compose.yml" - content_base64 = base64encode(templatefile("${path.module}/templates/docker-compose.yml.tftpl", { - runner_token = data.aws_ssm_parameter.runner_token.value - runner_owner = var.github_owner - runner_name = local.runner_name - runner_user = var.runner_user - runner_image = var.runner_image - runner_labels = var.runner_labels - repos_or_orgs = var.repos_or_orgs - })) + content_base64 = local.docker_compose_config depends_on = [ module.runner, diff --git a/variables.tf b/variables.tf index db4f9a8..4fecf8c 100644 --- a/variables.tf +++ b/variables.tf @@ -150,6 +150,16 @@ variable "runner_labels" { default = "" } +variable "docker_compose_yaml_override" { + description = <<-EOT + This var allows the downstream module to override the docker-compose.yaml template used by this module. + When you set this variable, you own the docker compose stack for the runner." + Validate your docker-compose.yaml and pass it as a string. This module will bas64encode it. + EOT + type = string + default = null +} + ################################################################################ ## security ################################################################################