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

fix: Invalid Function Arguement when passing bucket as arg #266

Merged

Conversation

r33drichards
Copy link
Contributor

@r33drichards r33drichards commented Nov 3, 2020

see #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 r33drichards changed the title fix Invalid Function Arguement when passing bucket as arg WIP: fix Invalid Function Arguement when passing bucket as arg Nov 3, 2020
@npalm
Copy link
Collaborator

npalm commented Nov 6, 2020

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

@r33drichards
Copy link
Contributor Author

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

@r33drichards
Copy link
Contributor Author

r33drichards commented Nov 9, 2020

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
Copy link
Contributor Author

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 r33drichards changed the title WIP: fix Invalid Function Arguement when passing bucket as arg fix Invalid Function Arguement when passing bucket as arg Nov 15, 2020
@npalm
Copy link
Collaborator

npalm commented Nov 23, 2020

@r33drichards do my best to review the PR this week

npalm
npalm previously approved these changes Nov 23, 2020
@npalm
Copy link
Collaborator

npalm commented Nov 23, 2020

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

@npalm
Copy link
Collaborator

npalm commented Jan 13, 2021

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

@r33drichards r33drichards force-pushed the fix-cache-bucket-not-created-new-project branch from 7cc12a2 to a9ceed6 Compare August 11, 2021 20:09
@Bernix01
Copy link

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

kayman-mk
kayman-mk previously approved these changes Dec 29, 2022
@kayman-mk kayman-mk changed the base branch from develop to main December 30, 2022 11:14
@kayman-mk kayman-mk dismissed stale reviews from npalm and themself December 30, 2022 11:14

The base branch was changed.

@kayman-mk
Copy link
Collaborator

Waits for #614

@npalm npalm changed the title fix Invalid Function Arguement when passing bucket as arg fix: Invalid Function Arguement when passing bucket as arg Jan 1, 2023
@npalm npalm merged commit b9e73fe into cattle-ops:main Jan 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants