Skip to content

Commit 3ce66ff

Browse files
npalmkayman-mk
andauthored
feat: Add metadata options for docker mahcine (#490)
- set default the usage of metadata tokens to required - refactor usages close: #445 Co-authored-by: Matthias Kay <[email protected]>
1 parent c2e3776 commit 3ce66ff

File tree

6 files changed

+57
-16
lines changed

6 files changed

+57
-16
lines changed

Diff for: README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ terraform destroy
303303
| Name | Version |
304304
|------|---------|
305305
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1 |
306-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 3.35 |
306+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 4 |
307307

308308
## Providers
309309

@@ -397,12 +397,13 @@ terraform destroy
397397
| <a name="input_docker_machine_download_url"></a> [docker\_machine\_download\_url](#input\_docker\_machine\_download\_url) | (Optional) By default the module will use `docker_machine_version` to download the GitLab mantained version of Docker Machine. Alternative you can set this property to download location of the distribution of for the OS. See also https://docs.gitlab.com/runner/executors/docker_machine.html#install | `string` | `""` | no |
398398
| <a name="input_docker_machine_egress_rules"></a> [docker\_machine\_egress\_rules](#input\_docker\_machine\_egress\_rules) | List of egress rules for the docker-machine instance(s). | <pre>list(object({<br> cidr_blocks = list(string)<br> ipv6_cidr_blocks = list(string)<br> prefix_list_ids = list(string)<br> from_port = number<br> protocol = string<br> security_groups = list(string)<br> self = bool<br> to_port = number<br> description = string<br> }))</pre> | <pre>[<br> {<br> "cidr_blocks": [<br> "0.0.0.0/0"<br> ],<br> "description": "Allow all egress traffic for docker machine build runners",<br> "from_port": 0,<br> "ipv6_cidr_blocks": [<br> "::/0"<br> ],<br> "prefix_list_ids": null,<br> "protocol": "-1",<br> "security_groups": null,<br> "self": null,<br> "to_port": 0<br> }<br>]</pre> | no |
399399
| <a name="input_docker_machine_iam_policy_arns"></a> [docker\_machine\_iam\_policy\_arns](#input\_docker\_machine\_iam\_policy\_arns) | List of policy ARNs to be added to the instance profile of the docker machine runners. | `list(string)` | `[]` | no |
400+
| <a name="input_docker_machine_instance_metadata_options"></a> [docker\_machine\_instance\_metadata\_options](#input\_docker\_machine\_instance\_metadata\_options) | Enable the docker machine instances metadata service. Requires you use GitLab maintained docker machines. | <pre>object({<br> http_tokens = string<br> http_put_response_hop_limit = number<br> })</pre> | <pre>{<br> "http_put_response_hop_limit": 2,<br> "http_tokens": "required"<br>}</pre> | no |
400401
| <a name="input_docker_machine_instance_type"></a> [docker\_machine\_instance\_type](#input\_docker\_machine\_instance\_type) | Instance type used for the instances hosting docker-machine. | `string` | `"m5.large"` | no |
401402
| <a name="input_docker_machine_options"></a> [docker\_machine\_options](#input\_docker\_machine\_options) | List of additional options for the docker machine config. Each element of this list must be a key=value pair. E.g. '["amazonec2-zone=a"]' | `list(string)` | `[]` | no |
402403
| <a name="input_docker_machine_role_json"></a> [docker\_machine\_role\_json](#input\_docker\_machine\_role\_json) | Docker machine runner instance override policy, expected to be in JSON format. | `string` | `""` | no |
403404
| <a name="input_docker_machine_security_group_description"></a> [docker\_machine\_security\_group\_description](#input\_docker\_machine\_security\_group\_description) | A description for the docker-machine security group | `string` | `"A security group containing docker-machine instances"` | no |
404405
| <a name="input_docker_machine_spot_price_bid"></a> [docker\_machine\_spot\_price\_bid](#input\_docker\_machine\_spot\_price\_bid) | Spot price bid. The maximum price willing to pay. By default the price is limited by the current on demand price for the instance type chosen. | `string` | `"on-demand-price"` | no |
405-
| <a name="input_docker_machine_version"></a> [docker\_machine\_version](#input\_docker\_machine\_version) | By default docker\_machine\_download\_url is used to set the docker machine version. Version of docker-machine. The version will be ingored once `docker_machine_download_url` is set. | `string` | `"0.16.2-gitlab.12"` | no |
406+
| <a name="input_docker_machine_version"></a> [docker\_machine\_version](#input\_docker\_machine\_version) | By default docker\_machine\_download\_url is used to set the docker machine version. Version of docker-machine. The version will be ingored once `docker_machine_download_url` is set. | `string` | `"0.16.2-gitlab.15"` | no |
406407
| <a name="input_enable_asg_recreation"></a> [enable\_asg\_recreation](#input\_enable\_asg\_recreation) | Enable automatic redeployment of the Runner ASG when the Launch Configs change. | `bool` | `true` | no |
407408
| <a name="input_enable_cloudwatch_logging"></a> [enable\_cloudwatch\_logging](#input\_enable\_cloudwatch\_logging) | Boolean used to enable or disable the CloudWatch logging. | `bool` | `true` | no |
408409
| <a name="input_enable_docker_machine_ssm_access"></a> [enable\_docker\_machine\_ssm\_access](#input\_enable\_docker\_machine\_ssm\_access) | Add IAM policies to the docker-machine instances to connect via the Session Manager. | `bool` | `false` | no |
@@ -419,7 +420,7 @@ terraform destroy
419420
| <a name="input_gitlab_runner_registration_config"></a> [gitlab\_runner\_registration\_config](#input\_gitlab\_runner\_registration\_config) | Configuration used to register the runner. See the README for an example, or reference the examples in the examples directory of this repo. | `map(string)` | <pre>{<br> "access_level": "",<br> "description": "",<br> "locked_to_project": "",<br> "maximum_timeout": "",<br> "registration_token": "",<br> "run_untagged": "",<br> "tag_list": ""<br>}</pre> | no |
420421
| <a name="input_gitlab_runner_security_group_description"></a> [gitlab\_runner\_security\_group\_description](#input\_gitlab\_runner\_security\_group\_description) | A description for the gitlab-runner security group | `string` | `"A security group containing gitlab-runner agent instances"` | no |
421422
| <a name="input_gitlab_runner_security_group_ids"></a> [gitlab\_runner\_security\_group\_ids](#input\_gitlab\_runner\_security\_group\_ids) | A list of security group ids that are allowed to access the gitlab runner agent | `list(string)` | `[]` | no |
422-
| <a name="input_gitlab_runner_version"></a> [gitlab\_runner\_version](#input\_gitlab\_runner\_version) | Version of the [GitLab runner](https://gitlab.com/gitlab-org/gitlab-runner/-/releases). | `string` | `"14.8.2"` | no |
423+
| <a name="input_gitlab_runner_version"></a> [gitlab\_runner\_version](#input\_gitlab\_runner\_version) | Version of the [GitLab runner](https://gitlab.com/gitlab-org/gitlab-runner/-/releases). | `string` | `"14.8.3"` | no |
423424
| <a name="input_instance_role_json"></a> [instance\_role\_json](#input\_instance\_role\_json) | Default runner instance override policy, expected to be in JSON format. | `string` | `""` | no |
424425
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | Instance type used for the GitLab runner. | `string` | `"t3.micro"` | no |
425426
| <a name="input_kms_alias_name"></a> [kms\_alias\_name](#input\_kms\_alias\_name) | Alias added to the kms\_key (if created and not provided by kms\_key\_id) | `string` | `""` | no |
@@ -437,8 +438,9 @@ terraform destroy
437438
| <a name="input_runner_iam_policy_arns"></a> [runner\_iam\_policy\_arns](#input\_runner\_iam\_policy\_arns) | List of policy ARNs to be added to the instance profile of the gitlab runner agent ec2 instance. | `list(string)` | `[]` | no |
438439
| <a name="input_runner_instance_ebs_optimized"></a> [runner\_instance\_ebs\_optimized](#input\_runner\_instance\_ebs\_optimized) | Enable the GitLab runner instance to be EBS-optimized. | `bool` | `true` | no |
439440
| <a name="input_runner_instance_enable_monitoring"></a> [runner\_instance\_enable\_monitoring](#input\_runner\_instance\_enable\_monitoring) | Enable the GitLab runner instance to have detailed monitoring. | `bool` | `true` | no |
440-
| <a name="input_runner_instance_metadata_options_http_endpoint"></a> [runner\_instance\_metadata\_options\_http\_endpoint](#input\_runner\_instance\_metadata\_options\_http\_endpoint) | Enable the Gitlab runner agent instance metadata service. The allowed values are enabled, disabled. | `string` | `"enabled"` | no |
441-
| <a name="input_runner_instance_metadata_options_http_tokens"></a> [runner\_instance\_metadata\_options\_http\_tokens](#input\_runner\_instance\_metadata\_options\_http\_tokens) | Set if Gitlab runner agent instance metadata service session tokens are required. The allowed values are optional, required. | `string` | `"optional"` | no |
441+
| <a name="input_runner_instance_metadata_options"></a> [runner\_instance\_metadata\_options](#input\_runner\_instance\_metadata\_options) | Enable the Gitlab runner agent instance metadata service. | <pre>object({<br> http_endpoint = string<br> http_tokens = string<br> http_put_response_hop_limit = number<br> instance_metadata_tags = string<br> })</pre> | <pre>{<br> "http_endpoint": "enabled",<br> "http_put_response_hop_limit": 2,<br> "http_tokens": "required",<br> "instance_metadata_tags": "disabled"<br>}</pre> | no |
442+
| <a name="input_runner_instance_metadata_options_http_endpoint"></a> [runner\_instance\_metadata\_options\_http\_endpoint](#input\_runner\_instance\_metadata\_options\_http\_endpoint) | DEPRECATED, replaced by runner\_instance\_metadata\_options. Enable the Gitlab runner agent instance metadata service. The allowed values are enabled, disabled. | `string` | `null` | no |
443+
| <a name="input_runner_instance_metadata_options_http_tokens"></a> [runner\_instance\_metadata\_options\_http\_tokens](#input\_runner\_instance\_metadata\_options\_http\_tokens) | EPRECATED, replaced by runner\_instance\_metadata\_options. Set if Gitlab runner agent instance metadata service session tokens are required. The allowed values are optional, required. | `string` | `null` | no |
442444
| <a name="input_runner_instance_spot_price"></a> [runner\_instance\_spot\_price](#input\_runner\_instance\_spot\_price) | By setting a spot price bid price the runner agent will be created via a spot request. Be aware that spot instances can be stopped by AWS. Choose "on-demand-price" to pay up to the current on demand price for the instance type chosen. | `string` | `null` | no |
443445
| <a name="input_runner_root_block_device"></a> [runner\_root\_block\_device](#input\_runner\_root\_block\_device) | The EC2 instance root block device configuration. Takes the following keys: `device_name`, `delete_on_termination`, `volume_type`, `volume_size`, `encrypted`, `iops`, `throughput`, `kms_key_id` | `map(string)` | `{}` | no |
444446
| <a name="input_runner_tags"></a> [runner\_tags](#input\_runner\_tags) | Map of tags that will be added to runner EC2 instances. | `map(string)` | `{}` | no |

Diff for: examples/runner-default/main.tf

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ module "runner" {
4343

4444
gitlab_runner_security_group_ids = [data.aws_security_group.default.id]
4545

46-
docker_machine_download_url = "https://gitlab-docker-machine-downloads.s3.amazonaws.com/v0.16.2-gitlab.2/docker-machine"
4746
docker_machine_spot_price_bid = "on-demand-price"
4847

4948
gitlab_runner_registration_config = {

Diff for: locals.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
locals {
22
// Convert list to a string separated and prepend by a comma
33
docker_machine_options_string = format(
4-
",%s",
4+
",\"amazonec2-metadata-token=${var.docker_machine_instance_metadata_options.http_tokens}\", \"amazonec2-metadata-token-response-hop-limit=${var.docker_machine_instance_metadata_options.http_put_response_hop_limit}\",%s",
55
join(",", formatlist("%q", concat(var.docker_machine_options, local.runners_docker_registry_mirror_option))),
66
)
77

Diff for: main.tf

+4-2
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,10 @@ resource "aws_launch_template" "gitlab_runner_instance" {
277277
tags = local.tags
278278

279279
metadata_options {
280-
http_endpoint = var.runner_instance_metadata_options_http_endpoint
281-
http_tokens = var.runner_instance_metadata_options_http_tokens
280+
http_endpoint = var.runner_instance_metadata_options.http_endpoint
281+
http_tokens = var.runner_instance_metadata_options.http_tokens
282+
http_put_response_hop_limit = var.runner_instance_metadata_options.http_put_response_hop_limit
283+
instance_metadata_tags = var.runner_instance_metadata_options.instance_metadata_tags
282284
}
283285

284286
lifecycle {

Diff for: template/gitlab-runner.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fi
4242

4343
if [[ `echo ${docker_machine_download_url}` == "" ]]
4444
then
45-
curl --fail --retry 6 -L https://gitlab-docker-machine-downloads.s3.amazonaws.com/v${docker_machine_version}/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine
45+
curl --fail --retry 6 -L https://gitlab.com/gitlab-org/ci-cd/docker-machine/-/releases/v${docker_machine_version}/downloads/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine
4646
else
4747
curl --fail --retry 6 -L ${docker_machine_download_url} >/tmp/docker-machine
4848
fi

Diff for: variables.tf

+44-6
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,54 @@ variable "runner_instance_spot_price" {
6767
default = null
6868
}
6969

70+
variable "runner_instance_metadata_options" {
71+
description = "Enable the Gitlab runner agent instance metadata service."
72+
type = object({
73+
http_endpoint = string
74+
http_tokens = string
75+
http_put_response_hop_limit = number
76+
instance_metadata_tags = string
77+
})
78+
default = {
79+
http_endpoint = "enabled"
80+
http_tokens = "required"
81+
http_put_response_hop_limit = 2
82+
instance_metadata_tags = "disabled"
83+
}
84+
}
85+
86+
variable "docker_machine_instance_metadata_options" {
87+
description = "Enable the docker machine instances metadata service. Requires you use GitLab maintained docker machines."
88+
type = object({
89+
http_tokens = string
90+
http_put_response_hop_limit = number
91+
})
92+
default = {
93+
http_tokens = "required"
94+
http_put_response_hop_limit = 2
95+
}
96+
}
97+
7098
variable "runner_instance_metadata_options_http_endpoint" {
71-
description = "Enable the Gitlab runner agent instance metadata service. The allowed values are enabled, disabled."
99+
description = "DEPRECATED, replaced by runner_instance_metadata_options. Enable the Gitlab runner agent instance metadata service. The allowed values are enabled, disabled."
72100
type = string
73-
default = "enabled"
101+
default = null
102+
103+
validation {
104+
condition = var.runner_instance_metadata_options_http_endpoint == null
105+
error_message = "The \"runner_instance_metadata_options_http_endpoint\" variable is no longer used. To migrate, set the \"runner_instance_metadata_options.http_endpoint\" variable to the original value."
106+
}
74107
}
75108

76109
variable "runner_instance_metadata_options_http_tokens" {
77-
description = "Set if Gitlab runner agent instance metadata service session tokens are required. The allowed values are optional, required."
110+
description = "EPRECATED, replaced by runner_instance_metadata_options. Set if Gitlab runner agent instance metadata service session tokens are required. The allowed values are optional, required."
78111
type = string
79-
default = "optional"
112+
default = null
113+
114+
validation {
115+
condition = var.runner_instance_metadata_options_http_tokens == null
116+
error_message = "The \"runner_instance_metadata_options_http_tokens\" variable is no longer used. To migrate, set the \"runner_instance_metadata_options.http_token\" variable to the original value."
117+
}
80118
}
81119

82120
variable "docker_machine_instance_type" {
@@ -100,7 +138,7 @@ variable "docker_machine_download_url" {
100138
variable "docker_machine_version" {
101139
description = "By default docker_machine_download_url is used to set the docker machine version. Version of docker-machine. The version will be ingored once `docker_machine_download_url` is set."
102140
type = string
103-
default = "0.16.2-gitlab.12"
141+
default = "0.16.2-gitlab.15"
104142
}
105143

106144
variable "runners_name" {
@@ -367,7 +405,7 @@ variable "cache_shared" {
367405
variable "gitlab_runner_version" {
368406
description = "Version of the [GitLab runner](https://gitlab.com/gitlab-org/gitlab-runner/-/releases)."
369407
type = string
370-
default = "14.8.2"
408+
default = "14.8.3"
371409
}
372410

373411
variable "enable_ping" {

0 commit comments

Comments
 (0)