Skip to content

Commit

Permalink
Merge the tags for the runner agent to remove duplicate tags (cattle-…
Browse files Browse the repository at this point in the history
…ops#238)

* Release 4.18.0

* Create a separate array to hold all tags for the runner agent. This replaces duplicate tags, e.g. Name.

* Refactor variable name for runner agent name.

* Update documentation to show the correct usage for the runner name.

* Remove old code.

* Add changelog entry.

* Reformat the code.

Co-authored-by: Niek Palm <[email protected]>
Co-authored-by: kayma <[email protected]>
  • Loading branch information
3 people committed Jul 12, 2020
1 parent cd07638 commit 28e1623
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 17 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ and this project adheres to [Semantic Versioning](http:https://semver.org/).
- Changed: Update default runner version to 13.0.1


- Bugfix: Remove duplicate tag names from the tags assigned to the runner agent instance to ensure the correct name (#233) @kayma-hl

## 4.18.0 - 2020-06-01

- Changed: Update default runner version to 13.0.1


## 4.17.0 - 2020-05-28

- Added: Asg metrics (#228) @nlarzonNiklas
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ The runners created by the module using by default spot instances for running th
- Logs streamed to CloudWatch.
- Runner agents registered automatically.

The name of the runner agent and runner is set with the overrides variable. Adding an agent runner name tag does not work.

``` hcl
...
overrides = {
name_sg = ""
name_runner_agent_instance = "Gitlab Runner Agent"
name_docker_machine_runners = "Gitlab Runner Terraform"
}
//this doesn't work
agent_tags = merge(local.my_tags, map("Name", "Gitlab Runner Agent"))
```

The runner support 3 main scenario's:

### GitLab CI docker-machine runner - one runner agent
Expand Down
2 changes: 1 addition & 1 deletion locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ locals {
secure_parameter_store_runner_token_key = "${var.environment}-${var.secure_parameter_store_runner_token_key}"

// custom names for instances and security groups
name_runner_instance = var.overrides["name_runner_agent_instance"] == "" ? local.tags["Name"] : var.overrides["name_runner_agent_instance"]
name_runner_agent_instance = var.overrides["name_runner_agent_instance"] == "" ? local.tags["Name"] : var.overrides["name_runner_agent_instance"]
name_sg = var.overrides["name_sg"] == "" ? local.tags["Name"] : var.overrides["name_sg"]
runners_additional_volumes = <<-EOT
%{~for volume in var.runners_additional_volumes~},"${volume}"%{endfor~}
Expand Down
17 changes: 1 addition & 16 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,7 @@ resource "aws_autoscaling_group" "gitlab_runner_instance" {
health_check_grace_period = 0
launch_configuration = aws_launch_configuration.gitlab_runner_instance.name
enabled_metrics = var.metrics_autoscaling
tags = concat(
data.null_data_source.tags.*.outputs,
[
{
"key" = "Name"
"value" = local.name_runner_instance
"propagate_at_launch" = true
},
],
[for key in keys(var.agent_tags) : {
"key" = key,
"value" = lookup(var.agent_tags, key),
"propagate_at_launch" = true
}]
)

tags = data.null_data_source.agent_tags.*.outputs
}

resource "aws_autoscaling_schedule" "scale_in" {
Expand Down
20 changes: 20 additions & 0 deletions tags.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ locals {
var.tags,
)

agent_tags = merge(
{
"Name" = format("%s", local.name_runner_agent_instance)
},
{
"Environment" = format("%s", var.environment)
},
var.tags,
var.agent_tags
)

tags_string = join(",", flatten([
for key in keys(local.tags) : [key, lookup(local.tags, key)]
]))
Expand All @@ -28,3 +39,12 @@ data "null_data_source" "tags" {
}
}

data "null_data_source" "agent_tags" {
count = length(local.agent_tags)

inputs = {
key = element(keys(local.agent_tags), count.index)
value = element(values(local.agent_tags), count.index)
propagate_at_launch = "true"
}
}

0 comments on commit 28e1623

Please sign in to comment.