terraform-aws-gitlab-runner
terraform-aws-gitlab-runner copied to clipboard
fix Invalid Function Arguement when passing bucket as arg
see https://github.com/npalm/terraform-aws-gitlab-runner/issues/265
Description
fixes issue where passing a cache bucket to a runner module would fail on first run with Invalid Function Arguement
Migrations required
NO
Verification
tested with this as main.tf useing runners-public as template. only difference is ssm instead of ssh and using this branch. can't post the full repo since its private (sorry!).
data "aws_availability_zones" "available" {
state = "available"
}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "2.48"
name = "vpc-${var.environment}"
cidr = "10.1.0.0/16"
azs = [data.aws_availability_zones.available.names[0]]
public_subnets = ["10.1.101.0/24"]
map_public_ip_on_launch = "false"
tags = {
Environment = var.environment
}
}
module "cache" {
# source = "../../modules/cache"
source = "npalm/gitlab-runner/aws//modules/cache"
environment = var.environment
}
module "runner" {
# source = "../../"
# source = "npalm/gitlab-runner/aws"
source = "git::https://github.com/r33drichards/terraform-aws-gitlab-runner.git?ref=fix-cache-bucket-not-created-new-project"
aws_region = var.aws_region
environment = var.environment
enable_runner_ssm_access = true
runners_use_private_address = false
vpc_id = module.vpc.vpc_id
subnet_ids_gitlab_runner = module.vpc.public_subnets
subnet_id_runners = element(module.vpc.public_subnets, 0)
docker_machine_spot_price_bid = "0.04"
docker_machine_instance_type = "t3.medium"
runners_name = var.runner_name
runners_gitlab_url = var.gitlab_url
runners_privileged = "false"
runners_additional_volumes = ["/var/run/docker.sock:/var/run/docker.sock"]
gitlab_runner_registration_config = {
registration_token = var.registration_token
tag_list = "docker_spot_runner"
description = "runner public - auto"
locked_to_project = "false"
run_untagged = "true"
maximum_timeout = "3600"
}
overrides = {
name_sg = "my-security-group"
name_runner_agent_instance = "my-runner-agent"
name_docker_machine_runners = "my-runners-dm"
}
cache_shared = "true"
cache_bucket = {
create = false
policy = "${module.cache.policy_arn}"
bucket = "${module.cache.bucket}"
}
}
module "runner2" {
# source = "../../"
# source = "npalm/gitlab-runner/aws"
source = "git::https://github.com/r33drichards/terraform-aws-gitlab-runner.git?ref=fix-cache-bucket-not-created-new-project"
aws_region = var.aws_region
environment = "${var.environment}-2"
runners_use_private_address = false
enable_runner_ssm_access = true
vpc_id = module.vpc.vpc_id
subnet_ids_gitlab_runner = module.vpc.public_subnets
subnet_id_runners = element(module.vpc.public_subnets, 0)
docker_machine_spot_price_bid = "0.01"
docker_machine_instance_type = "t3.micro"
runners_name = var.runner_name
runners_gitlab_url = var.gitlab_url
gitlab_runner_registration_config = {
registration_token = var.registration_token
tag_list = "docker_spot_runner_2"
description = "runner public - auto"
locked_to_project = "false"
run_untagged = "true"
maximum_timeout = "3600"
}
cache_shared = "true"
cache_bucket = {
create = false
policy = "${module.cache.policy_arn}"
bucket = "${module.cache.bucket}"
}
}
resource "null_resource" "cancel_spot_requests" {
# Cancel active and open spot requests, terminate instances
triggers = {
environment = var.environment
}
provisioner "local-exec" {
when = destroy
command = "../../ci/bin/cancel-spot-instances.sh ${self.triggers.environment}"
}
}
Documentation
N/A
@r33drichards cool to see you are proposing a PR, is the PR still in WIP?
yea I wanted to make sure it worked on my project before it got merged
I got an error on one of my CI/CD pipelines for IAM stuff but I think that's an error on my end not here
The error I mentioned above with IAM was when trying to do shared cache based on runners-default. When I used this with runners-public it works fine. Still need to run terraform apply -target module.cache before applying the rest though.
@r33drichards do my best to review the PR this week
Not merged yet, will have a look what was changed causing the errors and require the cache module needs to applied fierst
@r33drichards your PR is still on my radar, give upgrading to tf 13 (and later 14) a bit more prio
this fix is needed for shared cache and multiple runners is it ready for release?
Waits for #614