terraform-aws-gitlab-runner icon indicating copy to clipboard operation
terraform-aws-gitlab-runner copied to clipboard

fix Invalid Function Arguement when passing bucket as arg

Open r33drichards opened this issue 5 years ago • 8 comments
trafficstars

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 avatar Nov 03 '20 03:11 r33drichards

@r33drichards cool to see you are proposing a PR, is the PR still in WIP?

npalm avatar Nov 06 '20 22:11 npalm

yea I wanted to make sure it worked on my project before it got merged

r33drichards avatar Nov 09 '20 00:11 r33drichards

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

r33drichards avatar Nov 09 '20 00:11 r33drichards

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 avatar Nov 15 '20 17:11 r33drichards

@r33drichards do my best to review the PR this week

npalm avatar Nov 23 '20 20:11 npalm

Not merged yet, will have a look what was changed causing the errors and require the cache module needs to applied fierst

npalm avatar Nov 23 '20 21:11 npalm

@r33drichards your PR is still on my radar, give upgrading to tf 13 (and later 14) a bit more prio

npalm avatar Jan 13 '21 22:01 npalm

this fix is needed for shared cache and multiple runners is it ready for release?

Bernix01 avatar Jun 30 '22 15:06 Bernix01

Waits for #614

kayman-mk avatar Dec 30 '22 11:12 kayman-mk