cattle-ops / terraform-aws-gitlab-runner

Terraform module for AWS GitLab runners on ec2 (spot) instances
https://registry.terraform.io/modules/cattle-ops/gitlab-runner/aws
MIT License
584 stars 331 forks source link

Migrating from 6.5.1 to 7.1.1 - Migration script provided fails #1027

Closed mahela-aws closed 9 months ago

mahela-aws commented 1 year ago

Describe the bug

We are trying to migrate the module from 6.5.1 to 7.1.1 but when we try to use the migration script provided it fails to produce the new file

To Reproduce

module calling file looks like below

  source  = "npalm/gitlab-runner/aws"
  version = "6.5.1"

  aws_region  = var.aws_region
  environment = var.bn_context

  vpc_id              = var.vpc_id
  subnet_id           = var.subnet_type == "private" ? element(data.aws_subnets.private.ids, 0) : element(data.aws_subnets.public.ids, 0)
  metrics_autoscaling = ["GroupDesiredCapacity", "GroupInServiceCapacity"]

  instance_type                     = "t3a.medium"
  runner_instance_enable_monitoring = false
  show_user_data_in_plan            = false
  runner_root_block_device = {
    volume_size = 32
  }

  use_fleet           = true
  fleet_key_pair_name = "${var.name}-${local.subnet_type}-fleet-key"
  docker_machine_instance_types_fleet = [
    "r6a.large",
    "m6a.large",
    "m5a.large",
    "r5a.large",
    "r5ad.large",
    "m5ad.large",
  ]
  enable_runner_ssm_access                                     = true
  runners_name                                                 = var.name
  runners_gitlab_url                                           = var.gitlab_url
  runners_max_builds                                           = 8
  runners_root_size                                            = 32
  runners_request_concurrency                                  = 20
  runners_request_spot_instance                                = true
  enable_eip                                                   = var.subnet_type != "private"
  runners_use_private_address                                  = var.subnet_type == "private"
  runner_agent_uses_private_address                            = var.subnet_type == "private"
  runners_output_limit                                         = 51200
  gitlab_runner_version                                        = "16.1.0"
  docker_machine_spot_price_bid                                = "on-demand-price"
  enable_schedule                                              = false
  runners_volume_type                                          = "gp3"
  runners_image                                                = "docker:20.10.24"
  secure_parameter_store_gitlab_runner_registration_token_name = "registration_token"
  secure_parameter_store_runner_token_key                      = "${local.subnet_type}-runner-token"
  secure_parameter_store_runner_sentry_dsn                     = "${local.subnet_type}-sentry-dsn"
  asg_terminate_lifecycle_hook_name                            = "${local.subnet_type}-terminate-instances"

  gitlab_runner_registration_config = {
    tag_list          = format("aws_runner_spot%s", var.subnet_type == "private" ? "_${local.subnet_type}" : "")
    description       = "runner docker+machine - scalable"
    locked_to_project = "false"
    run_untagged      = "false"
    maximum_timeout   = "3600"
  }

  overrides = {
    name_sg                    = "${var.bn_context}-${var.aws_region}-${local.subnet_type}-glr"
    name_iam_objects           = "${var.bn_context}-${var.aws_region}-${local.subnet_type}-glr"
    name_runner_agent_instance = "${var.bn_context}-${var.aws_region}-${local.subnet_type}-glr"
    name_docker_machine_runners = "${var.bn_context}-${local.subnet_type}-glr"
  }

  log_group_name             = "/ec2/${var.name}-${var.aws_region}-${local.subnet_type}-glr"
  runners_privileged         = "true"
  runners_additional_volumes = ["/certs/client"]

  runners_volumes_tmpfs = [
    {
      volume  = "/var/opt/cache",
      options = "rw,noexec"
    }
  ]

  runners_services_volumes_tmpfs = [
    {
      volume  = "/var/lib/mysql",
      options = "rw,noexec"
    }
  ]

  cache_bucket_prefix            = var.aws_region
  cache_bucket_set_random_suffix = true
  cache_expiration_days          = 30
  tags = {
    "Terraform"                              = "True"
    "tf-aws-gitlab-runner:instancelifecycle" = "spot:yes"
  }
}

we are getting below error when trying to execute the script

MacBook-Pro:gitlab-runner mahela$ bash migrate-to-7-0-0.sh runner.tf
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
head: illegal line count -- -1
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin
sed: -I or -i may not be used with stdin

sed: -I or -i may not be used with stdin
migrate-to-7-0-0.sh: line 661: subnet_id: command not found
migrate-to-7-0-0.sh: line 661: subnet_id_runners: command not found
Not all cases are handled by this script. Please check the output file and make sure that all variables are converted correctly.
Take some time and sort the variables again for better readability.

Known issues:
  - commented lines are not supported. Remove them.
  - variable definitions with multiple lines are not supported. Rework manually.
  -  was taken from . Make sure that this is correct.

Expected behavior

We should be able to execute the script without getting any errors

Additional context

we have tried different shells like zsh and bash, but it's throwing the same error

OpenGLShaders commented 1 year ago

@mahela-aws I had the same issues on mac. As a workaround I added a line at the top to use gsed: alias sed='gsed' I also had to alias head as negative numbers aren't supported on mac.

Add to top of file:

alias sed='gsed'
alias head='ghead'

Install: brew install coreutils brew install gsed

kayman-mk commented 1 year ago

Not sure where it's documented. But running this script from an Alpine container should do the job.

mahela-aws commented 1 year ago

@mahela-aws I had the same issues on mac. As a workaround I added a line at the top to use gsed: alias sed='gsed' I also had to alias head as negative numbers aren't supported on mac.

Add to top of file:

alias sed='gsed'
alias head='ghead'

Install: brew install coreutils brew install gsed

@OpenGLShaders awesome will try this out. thanks a lot

kayman-mk commented 12 months ago

@mahela-aws Did everything work? I will add a comment to the next migration script to use an Alpine image in case something is not working as expected.

mahela-aws commented 12 months ago

@kayman-mk I did it manually anyway, didn't worry too much about the migration script. I thought it would be better this way since we get to see the changes more

github-actions[bot] commented 10 months ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days.

github-actions[bot] commented 9 months ago

This issue was closed because it has been stalled for 15 days with no activity.