diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 91e0d726f..e8e5b0fc7 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -1,5 +1,10 @@ name: Verify -on: [push, pull_request] +on: + push: + branches: + - master + - develop + pull_request: jobs: verify: @@ -9,7 +14,7 @@ jobs: - uses: actions/checkout@v1 - name: verify run: | - ./ci/bin/install.sh + source ./ci/bin/install.sh ./ci/bin/verify.sh verify-examples: @@ -19,5 +24,5 @@ jobs: - uses: actions/checkout@v1 - name: verify-examples run: | - ./ci/bin/install.sh + source ./ci/bin/install.sh ./ci/bin/verify-examples.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index c57fcf132..9f1b3900b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased + +## 4.21.0 - 2021-01-13 +- Changed: Updated default version of runner to 13.7 +- Changed: Updated default version of docker machine to GitLab v0.16.2-gitlab.2 +- Changed: Updated default runner ami to ubuntu 20.04 +- Added: Option to set docker runtime (#273) by @thomaskelm +- Added: Option to attach additional policies to the runner (#269) by @bliles +- Added: Random suffix to s3 bucket (#252) by @fliphess + + ## 4.20.0 - 2020-10-08 - Changed: upgrade default version for gitlab runner to 13.4.0 (#261) @@ -387,7 +397,8 @@ Module is available as Terraform 0.11 module, pin module to version 3.x. Please - Update default AMI's to The latest Amazon Linux AMI 2017.09.1 - released on 2018-01-17. - Minor updates in the example -[unreleased]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/4.20.0...HEAD +[unreleased]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/4.21.0...HEAD +[4.21.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/4.21.0...4.20.0 [4.20.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/4.20.0...4.19.0 [4.19.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/4.19.0...4.18.0 [4.18.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/4.18.0...4.17.0 diff --git a/README.md b/README.md index 4a8313b94..fe1ee5b5a 100644 --- a/README.md +++ b/README.md @@ -6,23 +6,6 @@ > "Added support to download docker machine from a different location, e.g. " -## Terraform versions - -### Terraform 0.12 - -Module is available as Terraform 0.12 module, pin to version 4.x. Please submit pull-requests to the `develop` branch. - -Migration from 0.11 to 0.12 is tested for the `runner-default` example. To migrate the runner, execute the following steps. - -- Update to Terraform 0.12 -- Migrate your Terraform code via Terraform `terraform 0.12upgrade`. -- Update the module from 3.10.0 to 4.0.0, next run `terraform init` -- Run `terraform apply`. This should trigger only a re-creation of the the auto launch configuration and a minor change in the auto-scaling group. - -### Terraform 0.11 - -Module is available as Terraform 0.11 module, pin module to version 3.x. Please submit pull-requests to the `terraform011` branch. - ## The module This [Terraform](https://www.terraform.io/) modules creates a [GitLab CI runner](https://docs.gitlab.com/runner/). A blog post describes the original version of the the runner. See the post at [040code](https://040code.github.io/2017/12/09/runners-on-the-spot/). The original setup of the module is based on the blog post: [Auto scale GitLab CI runners and save 90% on EC2 costs](https://about.gitlab.com/2017/11/23/autoscale-ci-runners/). @@ -264,105 +247,108 @@ terraform destroy ## Inputs -| Name | Description | Type | Default | Required | -| -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------: | -| agent\_tags | Map of tags that will be added to agent EC2 instances. | `map(string)` | `{}` | no | -| allow\_iam\_service\_linked\_role\_creation | Boolean used to control attaching the policy to a runner instance to create service linked roles. | `bool` | `true` | no | -| ami\_filter | List of maps used to create the AMI filter for the Gitlab runner agent AMI. Must resolve to an Amazon Linux 1 or 2 image. | `map(list(string))` |
{
"name": [
"amzn2-ami-hvm-2.*-x86_64-ebs"
]
}
| no | -| ami\_owners | The list of owners used to select the AMI of Gitlab runner agent instances. | `list(string)` |
[
"amazon"
]
| no | -| arn\_format | ARN format to be used. May be changed to support deployment in GovCloud/China regions. | `string` | `"arn:aws"` | no | -| aws\_region | AWS region. | `string` | n/a | yes | -| aws\_zone | Deprecated. Will be removed in the next major release. | `string` | `"a"` | no | -| cache\_bucket | Configuration to control the creation of the cache bucket. By default the bucket will be created and used as shared cache. To use the same cache across multiple runners disable the creation of the cache and provide a policy and bucket name. See the public runner example for more details. | `map` |
{
"bucket": "",
"create": true,
"policy": ""
}
| no | -| cache\_bucket\_name\_include\_account\_id | Boolean to add current account ID to cache bucket name. | `bool` | `true` | no | -| cache\_bucket\_prefix | Prefix for s3 cache bucket name. | `string` | `""` | no | -| cache\_bucket\_versioning | Boolean used to enable versioning on the cache bucket, false by default. | `bool` | `false` | no | -| cache\_expiration\_days | Number of days before cache objects expires. | `number` | `1` | no | -| cache\_shared | Enables cache sharing between runners, false by default. | `bool` | `false` | no | -| cloudwatch\_logging\_retention\_in\_days | Retention for cloudwatch logs. Defaults to unlimited | `number` | `0` | no | -| docker\_machine\_download\_url | Full url pointing to a linux x64 distribution of docker machine. Once set `docker_machine_version` will be ingored. For example the GitLab version, https://gitlab-docker-machine-downloads.s3.amazonaws.com/v0.16.2-gitlab.2/docker-machine. | `string` | `""` | no | -| docker\_machine\_instance\_type | Instance type used for the instances hosting docker-machine. | `string` | `"m5.large"` | no | -| 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 | -| docker\_machine\_role\_json | Docker machine runner instance override policy, expected to be in JSON format. | `string` | `""` | no | -| docker\_machine\_spot\_price\_bid | Spot price bid. | `string` | `"0.06"` | no | -| docker\_machine\_version | Version of docker-machine. The version will be ingored once `docker_machine_download_url` is set. | `string` | `"0.16.2"` | no | -| enable\_asg\_recreation | Enable automatic redeployment of the Runner ASG when the Launch Configs change. | `bool` | `true` | no | -| enable\_cloudwatch\_logging | Boolean used to enable or disable the CloudWatch logging. | `bool` | `true` | no | -| enable\_docker\_machine\_ssm\_access | Add IAM policies to the docker-machine instances to connect via the Session Manager. | `bool` | `false` | no | -| enable\_eip | Enable the assignment of an EIP to the gitlab runner instance | `bool` | `false` | no | -| enable\_forced\_updates | DEPRECATED! and is replaced by `enable_asg_recreation. Setting this variable to true will do the oposite as expected. For backward compatibility the variable will remain some releases. Old desription: Enable automatic redeployment of the Runner ASG when the Launch Configs change.` | `string` | `null` | no | -| enable\_gitlab\_runner\_ssh\_access | Enables SSH Access to the gitlab runner instance. | `bool` | `false` | no | -| enable\_kms | Let the module manage a KMS key, logs will be encrypted via KMS. Be-aware of the costs of an custom key. | `bool` | `false` | no | -| enable\_manage\_gitlab\_token | Boolean to enable the management of the GitLab token in SSM. If `true` the token will be stored in SSM, which means the SSM property is a terraform managed resource. If `false` the Gitlab token will be stored in the SSM by the user-data script during creation of the the instance. However the SSM parameter is not managed by terraform and will remain in SSM after a `terraform destroy`. | `bool` | `true` | no | -| enable\_ping | Allow ICMP Ping to the ec2 instances. | `bool` | `false` | no | -| enable\_runner\_ssm\_access | Add IAM policies to the runner agent instance to connect via the Session Manager. | `bool` | `false` | no | -| enable\_runner\_user\_data\_trace\_log | Enable bash xtrace for the user data script that creates the EC2 instance for the runner agent. Be aware this could log sensitive data such as you GitLab runner token. | `bool` | `false` | no | -| enable\_schedule | Flag used to enable/disable auto scaling group schedule for the runner instance. | `bool` | `false` | no | -| environment | A name that identifies the environment, used as prefix and for tagging. | `string` | n/a | yes | -| gitlab\_runner\_egress\_rules | List of egress rules for the gitlab runner instance. |
list(object({
cidr_blocks = list(string)
ipv6_cidr_blocks = list(string)
prefix_list_ids = list(string)
from_port = number
protocol = string
security_groups = list(string)
self = bool
to_port = number
description = string
}))
|
[
{
"cidr_blocks": [
"0.0.0.0/0"
],
"description": null,
"from_port": 0,
"ipv6_cidr_blocks": [
"::/0"
],
"prefix_list_ids": null,
"protocol": "-1",
"security_groups": null,
"self": null,
"to_port": 0
}
]
| no | -| 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)` |
{
"access_level": "",
"description": "",
"locked_to_project": "",
"maximum_timeout": "",
"registration_token": "",
"run_untagged": "",
"tag_list": ""
}
| no | -| gitlab\_runner\_security\_group\_ids | A list of security group ids that are allowed to access the gitlab runner agent | `list(string)` | `[]` | no | -| gitlab\_runner\_ssh\_cidr\_blocks | List of CIDR blocks to allow SSH Access to the gitlab runner instance. | `list(string)` | `[]` | no | -| gitlab\_runner\_version | Version of the GitLab runner. | `string` | `"13.4.0"` | no | -| instance\_role\_json | Default runner instance override policy, expected to be in JSON format. | `string` | `""` | no | -| instance\_type | Instance type used for the GitLab runner. | `string` | `"t3.micro"` | no | -| kms\_alias\_name | Alias added to the kms\_key (if created and not provided by kms\_key\_id) | `string` | `""` | no | -| kms\_deletion\_window\_in\_days | Key rotation window, set to 0 for no rotation. Only used when `enable_kms` is set to `true`. | `number` | `7` | no | -| kms\_key\_id | KMS key id to encrypted the CloudWatch logs. Ensure CloudWatch has access to the provided KMS key. | `string` | `""` | no | -| log\_group\_name | Option to override the default name (`environment`) of the log group, requires `enable_cloudwatch_logging = true`. | `string` | `null` | no | -| metrics\_autoscaling | A list of metrics to collect. The allowed values are GroupDesiredCapacity, GroupInServiceCapacity, GroupPendingCapacity, GroupMinSize, GroupMaxSize, GroupInServiceInstances, GroupPendingInstances, GroupStandbyInstances, GroupStandbyCapacity, GroupTerminatingCapacity, GroupTerminatingInstances, GroupTotalCapacity, GroupTotalInstances. | `list(string)` | `null` | no | -| overrides | This maps provides the possibility to override some defaults. The following attributes are supported: `name_sg` overwrite the `Name` tag for all security groups created by this module. `name_runner_agent_instance` override the `Name` tag for the ec2 instance defined in the auto launch configuration. `name_docker_machine_runners` ovverrid the `Name` tag spot instances created by the runner agent. | `map(string)` |
{
"name_docker_machine_runners": "",
"name_runner_agent_instance": "",
"name_sg": ""
}
| no | -| permissions\_boundary | Name of permissions boundary policy to attach to AWS IAM roles | `string` | `""` | no | -| runner\_ami\_filter | List of maps used to create the AMI filter for the Gitlab runner docker-machine AMI. | `map(list(string))` |
{
"name": [
"ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"
]
}
| no | -| runner\_ami\_owners | The list of owners used to select the AMI of Gitlab runner docker-machine instances. | `list(string)` |
[
"099720109477"
]
| no | -| runner\_iam\_policy\_arns | List of policy ARNs to be added to the instance profile of the runners. | `list(string)` | `[]` | no | -| runner\_instance\_ebs\_optimized | Enable the GitLab runner instance to be EBS-optimized. | `bool` | `true` | no | -| runner\_instance\_enable\_monitoring | Enable the GitLab runner instance to have detailed monitoring. | `bool` | `true` | no | -| 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. | `string` | `null` | no | -| runner\_root\_block\_device | The EC2 instance root block device configuration. Takes the following keys: `delete_on_termination`, `volume_type`, `volume_size`, `encrypted`, `iops` | `map(string)` | `{}` | no | -| runner\_tags | Map of tags that will be added to runner EC2 instances. | `map(string)` | `{}` | no | -| runners\_additional\_volumes | Additional volumes that will be used in the runner config.toml, e.g Docker socket | `list` | `[]` | no | -| runners\_concurrent | Concurrent value for the runners, will be used in the runner config.toml. | `number` | `10` | no | -| runners\_ebs\_optimized | Enable runners to be EBS-optimized. | `bool` | `true` | no | -| runners\_environment\_vars | Environment variables during build execution, e.g. KEY=Value, see runner-public example. Will be used in the runner config.toml | `list(string)` | `[]` | no | -| runners\_executor | The executor to use. Currently supports `docker+machine` or `docker`. | `string` | `"docker+machine"` | no | -| runners\_gitlab\_url | URL of the GitLab instance to connect to. | `string` | n/a | yes | -| runners\_iam\_instance\_profile\_name | IAM instance profile name of the runners, will be used in the runner config.toml | `string` | `""` | no | -| runners\_idle\_count | Idle count of the runners, will be used in the runner config.toml. | `number` | `0` | no | -| runners\_idle\_time | Idle time of the runners, will be used in the runner config.toml. | `number` | `600` | no | -| runners\_image | Image to run builds, will be used in the runner config.toml | `string` | `"docker:18.03.1-ce"` | no | -| runners\_limit | Limit for the runners, will be used in the runner config.toml. | `number` | `0` | no | -| runners\_machine\_autoscaling | Set autoscaling parameters based on periods, see https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnersmachine-section |
list(object({
periods = list(string)
idle_count = number
idle_time = number
timezone = string
}))
| `[]` | no | -| runners\_max\_builds | Max builds for each runner after which it will be removed, will be used in the runner config.toml. By default set to 0, no maxBuilds will be set in the configuration. | `number` | `0` | no | -| runners\_monitoring | Enable detailed cloudwatch monitoring for spot instances. | `bool` | `false` | no | -| runners\_name | Name of the runner, will be used in the runner config.toml. | `string` | n/a | yes | -| runners\_off\_peak\_idle\_count | Deprecated, please use `runners_machine_autoscaling`. Off peak idle count of the runners, will be used in the runner config.toml. | `string` | `-1` | no | -| runners\_off\_peak\_idle\_time | Deprecated, please use `runners_machine_autoscaling`. Off peak idle time of the runners, will be used in the runner config.toml. | `string` | `-1` | no | -| runners\_off\_peak\_periods | Deprecated, please use `runners_machine_autoscaling`. Off peak periods of the runners, will be used in the runner config.toml. | `string` | `null` | no | -| runners\_off\_peak\_timezone | Deprecated, please use `runners_machine_autoscaling`. Off peak idle time zone of the runners, will be used in the runner config.toml. | `string` | `null` | no | -| runners\_output\_limit | Sets the maximum build log size in kilobytes, by default set to 4096 (4MB) | `number` | `4096` | no | -| runners\_post\_build\_script | Commands to be executed on the Runner just after executing the build, but before executing after\_script. | `string` | `""` | no | -| runners\_pre\_build\_script | Script to execute in the pipeline just before the build, will be used in the runner config.toml | `string` | `""` | no | -| runners\_pre\_clone\_script | Commands to be executed on the Runner before cloning the Git repository. this can be used to adjust the Git client configuration first, for example. | `string` | `""` | no | -| runners\_privileged | Runners will run in privileged mode, will be used in the runner config.toml | `bool` | `true` | no | -| runners\_pull\_policy | pull\_policy for the runners, will be used in the runner config.toml | `string` | `"always"` | no | -| runners\_request\_concurrency | Limit number of concurrent requests for new jobs from GitLab (default 1) | `number` | `1` | no | -| runners\_request\_spot\_instance | Whether or not to request spot instances via docker-machine | `bool` | `true` | no | -| runners\_root\_size | Runner instance root size in GB. | `number` | `16` | no | -| runners\_services\_volumes\_tmpfs | n/a |
list(object({
volume = string
options = string
}))
| `[]` | no | -| runners\_shm\_size | shm\_size for the runners, will be used in the runner config.toml | `number` | `0` | no | -| runners\_token | Token for the runner, will be used in the runner config.toml. | `string` | `"__REPLACED_BY_USER_DATA__"` | no | -| runners\_use\_private\_address | Restrict runners to the use of a private IP address | `bool` | `true` | no | -| runners\_volumes\_tmpfs | n/a |
list(object({
volume = string
options = string
}))
| `[]` | no | -| schedule\_config | Map containing the configuration of the ASG scale-in and scale-up for the runner instance. Will only be used if enable\_schedule is set to true. | `map` |
{
"scale_in_count": 0,
"scale_in_recurrence": "0 18 * * 1-5",
"scale_out_count": 1,
"scale_out_recurrence": "0 8 * * 1-5"
}
| no | -| secure\_parameter\_store\_runner\_token\_key | The key name used store the Gitlab runner token in Secure Parameter Store | `string` | `"runner-token"` | no | -| ssh\_key\_pair | Set this to use existing AWS key pair | `string` | `null` | no | -| subnet\_id\_runners | List of subnets used for hosting the gitlab-runners. | `string` | n/a | yes | -| subnet\_ids\_gitlab\_runner | Subnet used for hosting the GitLab runner. | `list(string)` | n/a | yes | -| tags | Map of tags that will be added to created resources. By default resources will be tagged with name and environment. | `map(string)` | `{}` | no | -| userdata\_post\_install | User-data script snippet to insert after GitLab runner install | `string` | `""` | no | -| userdata\_pre\_install | User-data script snippet to insert before GitLab runner install | `string` | `""` | no | -| vpc\_id | The target VPC for the docker-machine and runner instances. | `string` | n/a | yes | +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| agent\_tags | Map of tags that will be added to agent EC2 instances. | `map(string)` | `{}` | no | +| allow\_iam\_service\_linked\_role\_creation | Boolean used to control attaching the policy to a runner instance to create service linked roles. | `bool` | `true` | no | +| ami\_filter | List of maps used to create the AMI filter for the Gitlab runner agent AMI. Must resolve to an Amazon Linux 1 or 2 image. | `map(list(string))` |
{
"name": [
"amzn2-ami-hvm-2.*-x86_64-ebs"
]
}
| no | +| ami\_owners | The list of owners used to select the AMI of Gitlab runner agent instances. | `list(string)` |
[
"amazon"
]
| no | +| arn\_format | ARN format to be used. May be changed to support deployment in GovCloud/China regions. | `string` | `"arn:aws"` | no | +| aws\_region | AWS region. | `string` | n/a | yes | +| aws\_zone | Deprecated. Will be removed in the next major release. | `string` | `"a"` | no | +| cache\_bucket | Configuration to control the creation of the cache bucket. By default the bucket will be created and used as shared cache. To use the same cache across multiple runners disable the creation of the cache and provide a policy and bucket name. See the public runner example for more details. | `map` |
{
"bucket": "",
"create": true,
"policy": ""
}
| no | +| cache\_bucket\_name\_include\_account\_id | Boolean to add current account ID to cache bucket name. | `bool` | `true` | no | +| cache\_bucket\_prefix | Prefix for s3 cache bucket name. | `string` | `""` | no | +| cache\_bucket\_set\_random\_suffix | Append the cache bucket name with a random string suffix | `bool` | `false` | no | +| cache\_bucket\_versioning | Boolean used to enable versioning on the cache bucket, false by default. | `bool` | `false` | no | +| cache\_expiration\_days | Number of days before cache objects expires. | `number` | `1` | no | +| cache\_shared | Enables cache sharing between runners, false by default. | `bool` | `false` | no | +| cloudwatch\_logging\_retention\_in\_days | Retention for cloudwatch logs. Defaults to unlimited | `number` | `0` | no | +| docker\_machine\_download\_url | Full url pointing to a linux x64 distribution of docker machine. Once set `docker_machine_version` will be ingored. For example the GitLab version, https://gitlab-docker-machine-downloads.s3.amazonaws.com/v0.16.2-gitlab.2/docker-machine. | `string` | `"https://gitlab-docker-machine-downloads.s3.amazonaws.com/v0.16.2-gitlab.10/docker-machine-Linux-aarch64"` | no | +| docker\_machine\_iam\_policy\_arns | List of policy ARNs to be added to the instance profile of the docker machine runners. | `list(string)` | `[]` | no | +| docker\_machine\_instance\_type | Instance type used for the instances hosting docker-machine. | `string` | `"m5.large"` | no | +| 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 | +| docker\_machine\_role\_json | Docker machine runner instance override policy, expected to be in JSON format. | `string` | `""` | no | +| docker\_machine\_spot\_price\_bid | Spot price bid. | `string` | `"0.06"` | no | +| 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` | `""` | no | +| enable\_asg\_recreation | Enable automatic redeployment of the Runner ASG when the Launch Configs change. | `bool` | `true` | no | +| enable\_cloudwatch\_logging | Boolean used to enable or disable the CloudWatch logging. | `bool` | `true` | no | +| enable\_docker\_machine\_ssm\_access | Add IAM policies to the docker-machine instances to connect via the Session Manager. | `bool` | `false` | no | +| enable\_eip | Enable the assignment of an EIP to the gitlab runner instance | `bool` | `false` | no | +| enable\_forced\_updates | DEPRECATED! and is replaced by `enable_asg_recreation. Setting this variable to true will do the oposite as expected. For backward compatibility the variable will remain some releases. Old desription: Enable automatic redeployment of the Runner ASG when the Launch Configs change.` | `string` | `null` | no | +| enable\_gitlab\_runner\_ssh\_access | Enables SSH Access to the gitlab runner instance. | `bool` | `false` | no | +| enable\_kms | Let the module manage a KMS key, logs will be encrypted via KMS. Be-aware of the costs of an custom key. | `bool` | `false` | no | +| enable\_manage\_gitlab\_token | Boolean to enable the management of the GitLab token in SSM. If `true` the token will be stored in SSM, which means the SSM property is a terraform managed resource. If `false` the Gitlab token will be stored in the SSM by the user-data script during creation of the the instance. However the SSM parameter is not managed by terraform and will remain in SSM after a `terraform destroy`. | `bool` | `true` | no | +| enable\_ping | Allow ICMP Ping to the ec2 instances. | `bool` | `false` | no | +| enable\_runner\_ssm\_access | Add IAM policies to the runner agent instance to connect via the Session Manager. | `bool` | `false` | no | +| enable\_runner\_user\_data\_trace\_log | Enable bash xtrace for the user data script that creates the EC2 instance for the runner agent. Be aware this could log sensitive data such as you GitLab runner token. | `bool` | `false` | no | +| enable\_schedule | Flag used to enable/disable auto scaling group schedule for the runner instance. | `bool` | `false` | no | +| environment | A name that identifies the environment, used as prefix and for tagging. | `string` | n/a | yes | +| gitlab\_runner\_egress\_rules | List of egress rules for the gitlab runner instance. |
list(object({
cidr_blocks = list(string)
ipv6_cidr_blocks = list(string)
prefix_list_ids = list(string)
from_port = number
protocol = string
security_groups = list(string)
self = bool
to_port = number
description = string
}))
|
[
{
"cidr_blocks": [
"0.0.0.0/0"
],
"description": null,
"from_port": 0,
"ipv6_cidr_blocks": [
"::/0"
],
"prefix_list_ids": null,
"protocol": "-1",
"security_groups": null,
"self": null,
"to_port": 0
}
]
| no | +| 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)` |
{
"access_level": "",
"description": "",
"locked_to_project": "",
"maximum_timeout": "",
"registration_token": "",
"run_untagged": "",
"tag_list": ""
}
| no | +| gitlab\_runner\_security\_group\_ids | A list of security group ids that are allowed to access the gitlab runner agent | `list(string)` | `[]` | no | +| gitlab\_runner\_ssh\_cidr\_blocks | List of CIDR blocks to allow SSH Access to the gitlab runner instance. | `list(string)` | `[]` | no | +| gitlab\_runner\_version | Version of the GitLab runner. | `string` | `"13.7.0"` | no | +| instance\_role\_json | Default runner instance override policy, expected to be in JSON format. | `string` | `""` | no | +| instance\_type | Instance type used for the GitLab runner. | `string` | `"t3.micro"` | no | +| kms\_alias\_name | Alias added to the kms\_key (if created and not provided by kms\_key\_id) | `string` | `""` | no | +| kms\_deletion\_window\_in\_days | Key rotation window, set to 0 for no rotation. Only used when `enable_kms` is set to `true`. | `number` | `7` | no | +| kms\_key\_id | KMS key id to encrypted the CloudWatch logs. Ensure CloudWatch has access to the provided KMS key. | `string` | `""` | no | +| log\_group\_name | Option to override the default name (`environment`) of the log group, requires `enable_cloudwatch_logging = true`. | `string` | `null` | no | +| metrics\_autoscaling | A list of metrics to collect. The allowed values are GroupDesiredCapacity, GroupInServiceCapacity, GroupPendingCapacity, GroupMinSize, GroupMaxSize, GroupInServiceInstances, GroupPendingInstances, GroupStandbyInstances, GroupStandbyCapacity, GroupTerminatingCapacity, GroupTerminatingInstances, GroupTotalCapacity, GroupTotalInstances. | `list(string)` | `null` | no | +| overrides | This maps provides the possibility to override some defaults. The following attributes are supported: `name_sg` overwrite the `Name` tag for all security groups created by this module. `name_runner_agent_instance` override the `Name` tag for the ec2 instance defined in the auto launch configuration. `name_docker_machine_runners` ovverrid the `Name` tag spot instances created by the runner agent. | `map(string)` |
{
"name_docker_machine_runners": "",
"name_runner_agent_instance": "",
"name_sg": ""
}
| no | +| permissions\_boundary | Name of permissions boundary policy to attach to AWS IAM roles | `string` | `""` | no | +| runner\_ami\_filter | List of maps used to create the AMI filter for the Gitlab runner docker-machine AMI. | `map(list(string))` |
{
"name": [
"ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"
]
}
| no | +| runner\_ami\_owners | The list of owners used to select the AMI of Gitlab runner docker-machine instances. | `list(string)` |
[
"099720109477"
]
| no | +| 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 | +| runner\_instance\_ebs\_optimized | Enable the GitLab runner instance to be EBS-optimized. | `bool` | `true` | no | +| runner\_instance\_enable\_monitoring | Enable the GitLab runner instance to have detailed monitoring. | `bool` | `true` | no | +| 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. | `string` | `null` | no | +| runner\_root\_block\_device | The EC2 instance root block device configuration. Takes the following keys: `delete_on_termination`, `volume_type`, `volume_size`, `encrypted`, `iops` | `map(string)` | `{}` | no | +| runner\_tags | Map of tags that will be added to runner EC2 instances. | `map(string)` | `{}` | no | +| runners\_additional\_volumes | Additional volumes that will be used in the runner config.toml, e.g Docker socket | `list` | `[]` | no | +| runners\_concurrent | Concurrent value for the runners, will be used in the runner config.toml. | `number` | `10` | no | +| runners\_docker\_runtime | docker runtime for runners, will be used in the runner config.toml | `string` | `""` | no | +| runners\_ebs\_optimized | Enable runners to be EBS-optimized. | `bool` | `true` | no | +| runners\_environment\_vars | Environment variables during build execution, e.g. KEY=Value, see runner-public example. Will be used in the runner config.toml | `list(string)` | `[]` | no | +| runners\_executor | The executor to use. Currently supports `docker+machine` or `docker`. | `string` | `"docker+machine"` | no | +| runners\_gitlab\_url | URL of the GitLab instance to connect to. | `string` | n/a | yes | +| runners\_iam\_instance\_profile\_name | IAM instance profile name of the runners, will be used in the runner config.toml | `string` | `""` | no | +| runners\_idle\_count | Idle count of the runners, will be used in the runner config.toml. | `number` | `0` | no | +| runners\_idle\_time | Idle time of the runners, will be used in the runner config.toml. | `number` | `600` | no | +| runners\_image | Image to run builds, will be used in the runner config.toml | `string` | `"docker:18.03.1-ce"` | no | +| runners\_limit | Limit for the runners, will be used in the runner config.toml. | `number` | `0` | no | +| runners\_machine\_autoscaling | Set autoscaling parameters based on periods, see https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnersmachine-section |
list(object({
periods = list(string)
idle_count = number
idle_time = number
timezone = string
}))
| `[]` | no | +| runners\_max\_builds | Max builds for each runner after which it will be removed, will be used in the runner config.toml. By default set to 0, no maxBuilds will be set in the configuration. | `number` | `0` | no | +| runners\_monitoring | Enable detailed cloudwatch monitoring for spot instances. | `bool` | `false` | no | +| runners\_name | Name of the runner, will be used in the runner config.toml. | `string` | n/a | yes | +| runners\_off\_peak\_idle\_count | Deprecated, please use `runners_machine_autoscaling`. Off peak idle count of the runners, will be used in the runner config.toml. | `string` | `-1` | no | +| runners\_off\_peak\_idle\_time | Deprecated, please use `runners_machine_autoscaling`. Off peak idle time of the runners, will be used in the runner config.toml. | `string` | `-1` | no | +| runners\_off\_peak\_periods | Deprecated, please use `runners_machine_autoscaling`. Off peak periods of the runners, will be used in the runner config.toml. | `string` | `null` | no | +| runners\_off\_peak\_timezone | Deprecated, please use `runners_machine_autoscaling`. Off peak idle time zone of the runners, will be used in the runner config.toml. | `string` | `null` | no | +| runners\_output\_limit | Sets the maximum build log size in kilobytes, by default set to 4096 (4MB) | `number` | `4096` | no | +| runners\_post\_build\_script | Commands to be executed on the Runner just after executing the build, but before executing after\_script. | `string` | `""` | no | +| runners\_pre\_build\_script | Script to execute in the pipeline just before the build, will be used in the runner config.toml | `string` | `""` | no | +| runners\_pre\_clone\_script | Commands to be executed on the Runner before cloning the Git repository. this can be used to adjust the Git client configuration first, for example. | `string` | `""` | no | +| runners\_privileged | Runners will run in privileged mode, will be used in the runner config.toml | `bool` | `true` | no | +| runners\_pull\_policy | pull\_policy for the runners, will be used in the runner config.toml | `string` | `"always"` | no | +| runners\_request\_concurrency | Limit number of concurrent requests for new jobs from GitLab (default 1) | `number` | `1` | no | +| runners\_request\_spot\_instance | Whether or not to request spot instances via docker-machine | `bool` | `true` | no | +| runners\_root\_size | Runner instance root size in GB. | `number` | `16` | no | +| runners\_services\_volumes\_tmpfs | n/a |
list(object({
volume = string
options = string
}))
| `[]` | no | +| runners\_shm\_size | shm\_size for the runners, will be used in the runner config.toml | `number` | `0` | no | +| runners\_token | Token for the runner, will be used in the runner config.toml. | `string` | `"__REPLACED_BY_USER_DATA__"` | no | +| runners\_use\_private\_address | Restrict runners to the use of a private IP address | `bool` | `true` | no | +| runners\_volumes\_tmpfs | n/a |
list(object({
volume = string
options = string
}))
| `[]` | no | +| schedule\_config | Map containing the configuration of the ASG scale-in and scale-up for the runner instance. Will only be used if enable\_schedule is set to true. | `map` |
{
"scale_in_count": 0,
"scale_in_recurrence": "0 18 * * 1-5",
"scale_out_count": 1,
"scale_out_recurrence": "0 8 * * 1-5"
}
| no | +| secure\_parameter\_store\_runner\_token\_key | The key name used store the Gitlab runner token in Secure Parameter Store | `string` | `"runner-token"` | no | +| ssh\_key\_pair | Set this to use existing AWS key pair | `string` | `null` | no | +| subnet\_id\_runners | List of subnets used for hosting the gitlab-runners. | `string` | n/a | yes | +| subnet\_ids\_gitlab\_runner | Subnet used for hosting the GitLab runner. | `list(string)` | n/a | yes | +| tags | Map of tags that will be added to created resources. By default resources will be tagged with name and environment. | `map(string)` | `{}` | no | +| userdata\_post\_install | User-data script snippet to insert after GitLab runner install | `string` | `""` | no | +| userdata\_pre\_install | User-data script snippet to insert before GitLab runner install | `string` | `""` | no | +| vpc\_id | The target VPC for the docker-machine and runner instances. | `string` | n/a | yes | ## Outputs diff --git a/ci/bin/terraform.sh b/ci/bin/terraform.sh index f82da61d9..b73df51a7 100755 --- a/ci/bin/terraform.sh +++ b/ci/bin/terraform.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash -TARGET_DIR=/opt -PATH=${PATH}:${TARGET_DIR} +export TARGET_DIR=/opt +export PATH=${TARGET_DIR}:${PATH} -TERRAFORM_VERSION=${1:-"0.12.29"} +TERRAFORM_VERSION=${1:-"0.13.6"} OS=${2:-"linux"} TERRAFORM_URL="https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_${OS}_amd64.zip" diff --git a/examples/.terraform-version b/examples/.terraform-version index 58828a74c..047fab311 100644 --- a/examples/.terraform-version +++ b/examples/.terraform-version @@ -1 +1 @@ -0.12.29 +0.13.6 \ No newline at end of file diff --git a/examples/runner-default/providers.tf b/examples/runner-default/providers.tf index 085b5b68e..9e46c4e6a 100644 --- a/examples/runner-default/providers.tf +++ b/examples/runner-default/providers.tf @@ -1,6 +1,6 @@ provider "aws" { region = var.aws_region - version = "2.68" + version = "~> 3.23.0" } provider "local" { @@ -8,9 +8,13 @@ provider "local" { } provider "null" { - version = "2.1.2" + version = "~> 3.0.0" } provider "tls" { version = "2.2.0" } + +provider "random" { + version = "~> 3.0.1" +} diff --git a/examples/runner-default/versions.tf b/examples/runner-default/versions.tf index ac97c6ac8..4df1c6260 100644 --- a/examples/runner-default/versions.tf +++ b/examples/runner-default/versions.tf @@ -1,4 +1,18 @@ terraform { - required_version = ">= 0.12" + required_version = ">= 0.13" + required_providers { + aws = { + source = "hashicorp/aws" + } + local = { + source = "hashicorp/local" + } + null = { + source = "hashicorp/null" + } + tls = { + source = "hashicorp/tls" + } + } } diff --git a/examples/runner-docker/versions.tf b/examples/runner-docker/versions.tf index ac97c6ac8..fd286dcbc 100644 --- a/examples/runner-docker/versions.tf +++ b/examples/runner-docker/versions.tf @@ -1,4 +1,17 @@ - terraform { - required_version = ">= 0.12" + required_providers { + aws = { + source = "hashicorp/aws" + } + local = { + source = "hashicorp/local" + } + null = { + source = "hashicorp/null" + } + tls = { + source = "hashicorp/tls" + } + } + required_version = ">= 0.13" } diff --git a/examples/runner-pre-registered/versions.tf b/examples/runner-pre-registered/versions.tf index ac97c6ac8..4df1c6260 100644 --- a/examples/runner-pre-registered/versions.tf +++ b/examples/runner-pre-registered/versions.tf @@ -1,4 +1,18 @@ terraform { - required_version = ">= 0.12" + required_version = ">= 0.13" + required_providers { + aws = { + source = "hashicorp/aws" + } + local = { + source = "hashicorp/local" + } + null = { + source = "hashicorp/null" + } + tls = { + source = "hashicorp/tls" + } + } } diff --git a/examples/runner-public/versions.tf b/examples/runner-public/versions.tf index ac97c6ac8..4df1c6260 100644 --- a/examples/runner-public/versions.tf +++ b/examples/runner-public/versions.tf @@ -1,4 +1,18 @@ terraform { - required_version = ">= 0.12" + required_version = ">= 0.13" + required_providers { + aws = { + source = "hashicorp/aws" + } + local = { + source = "hashicorp/local" + } + null = { + source = "hashicorp/null" + } + tls = { + source = "hashicorp/tls" + } + } } diff --git a/main.tf b/main.tf index 59ca7d6de..85fa72221 100644 --- a/main.tf +++ b/main.tf @@ -108,6 +108,7 @@ locals { runners_concurrent = var.runners_concurrent runners_image = var.runners_image runners_privileged = var.runners_privileged + runners_docker_runtime = var.runners_docker_runtime runners_shm_size = var.runners_shm_size runners_pull_policy = var.runners_pull_policy runners_idle_count = var.runners_idle_count @@ -243,6 +244,7 @@ module "cache" { create_cache_bucket = var.cache_bucket["create"] cache_bucket_prefix = var.cache_bucket_prefix cache_bucket_name_include_account_id = var.cache_bucket_name_include_account_id + cache_bucket_set_random_suffix = var.cache_bucket_set_random_suffix cache_bucket_versioning = var.cache_bucket_versioning cache_expiration_days = var.cache_expiration_days } @@ -336,6 +338,16 @@ resource "aws_iam_instance_profile" "docker_machine" { role = aws_iam_role.docker_machine.name } +################################################################################ +### Add user defined policies +################################################################################ +resource "aws_iam_role_policy_attachment" "docker_machine_user_defined_policies" { + count = length(var.docker_machine_iam_policy_arns) + role = aws_iam_role.docker_machine.name + policy_arn = var.docker_machine_iam_policy_arns[count.index] +} + +################################################################################ resource "aws_iam_role_policy_attachment" "docker_machine_session_manager_aws_managed" { count = var.enable_docker_machine_ssm_access ? 1 : 0 diff --git a/modules/cache/README.md b/modules/cache/README.md index 64de338d6..5ac84e53c 100644 --- a/modules/cache/README.md +++ b/modules/cache/README.md @@ -4,7 +4,7 @@ This sub module creates an S3 bucket for build caches. The cache will have by de ## Usages -``` +``` module "cache" { source = "https://github.com/npalm/terraform-aws-gitlab-runner/tree/move-cache-to-moudle/cache" @@ -36,6 +36,7 @@ module "runner" { | Name | Version | |------|---------| | aws | n/a | +| random | n/a | ## Inputs @@ -44,6 +45,7 @@ module "runner" { | arn\_format | ARN format to be used. May be changed to support deployment in GovCloud/China regions. | `string` | `"arn:aws"` | no | | cache\_bucket\_name\_include\_account\_id | Boolean to add current account ID to cache bucket name. | `bool` | `true` | no | | cache\_bucket\_prefix | Prefix for s3 cache bucket name. | `string` | `""` | no | +| cache\_bucket\_set\_random\_suffix | Random string suffix for s3 cache bucket | `bool` | `false` | no | | cache\_bucket\_versioning | Boolean used to enable versioning on the cache bucket, false by default. | `string` | `"false"` | no | | cache\_expiration\_days | Number of days before cache objects expires. | `number` | `1` | no | | cache\_lifecycle\_clear | Enable the rule to cleanup the cache for expired objects. | `bool` | `true` | no | @@ -60,4 +62,4 @@ module "runner" { | bucket | Name of the created bucket. | | policy\_arn | Policy for users of the cache (bucket). | - \ No newline at end of file + diff --git a/modules/cache/main.tf b/modules/cache/main.tf index ae98f0aae..7b5ca48d5 100644 --- a/modules/cache/main.tf +++ b/modules/cache/main.tf @@ -1,5 +1,6 @@ data "aws_caller_identity" "current" {} + locals { tags = merge( { @@ -11,7 +12,15 @@ locals { var.tags, ) - cache_bucket_name = var.cache_bucket_name_include_account_id ? "${var.cache_bucket_prefix}${data.aws_caller_identity.current.account_id}-gitlab-runner-cache" : "${var.cache_bucket_prefix}-gitlab-runner-cache" + cache_bucket_string = var.cache_bucket_name_include_account_id ? format("%s%s-gitlab-runner-cache", var.cache_bucket_prefix, data.aws_caller_identity.current.account_id) : format("%s-gitlab-runner-cache", var.cache_bucket_prefix) + cache_bucket_name = var.cache_bucket_set_random_suffix ? format("%s-%s", local.cache_bucket_string, random_string.s3_suffix[0].result) : local.cache_bucket_string +} + +resource "random_string" "s3_suffix" { + count = var.cache_bucket_set_random_suffix ? 1 : 0 + length = 8 + upper = false + special = false } resource "aws_s3_bucket" "build_cache" { diff --git a/modules/cache/variables.tf b/modules/cache/variables.tf index b2ddb5f8c..5e824625c 100644 --- a/modules/cache/variables.tf +++ b/modules/cache/variables.tf @@ -9,6 +9,12 @@ variable "cache_bucket_prefix" { default = "" } +variable "cache_bucket_set_random_suffix" { + description = "Random string suffix for s3 cache bucket" + type = bool + default = false +} + variable "cache_bucket_name_include_account_id" { description = "Boolean to add current account ID to cache bucket name." type = bool diff --git a/template/runner-config.tpl b/template/runner-config.tpl index 02c578a5e..d7dffb139 100644 --- a/template/runner-config.tpl +++ b/template/runner-config.tpl @@ -21,6 +21,7 @@ check_interval = 0 volumes = ["/cache"${runners_additional_volumes}] shm_size = ${runners_shm_size} pull_policy = "${runners_pull_policy}" + runtime = "${runners_docker_runtime}" [runners.docker.tmpfs] ${runners_volumes_tmpfs} [runners.docker.services_tmpfs] @@ -63,4 +64,4 @@ check_interval = 0 ${runners_off_peak_idle_count} ${runners_off_peak_idle_time} ${runners_off_peak_periods_string} - ${runners_machine_autoscaling} \ No newline at end of file + ${runners_machine_autoscaling} diff --git a/variables.tf b/variables.tf index bd639f5bc..020ffeeed 100644 --- a/variables.tf +++ b/variables.tf @@ -86,13 +86,13 @@ variable "docker_machine_spot_price_bid" { variable "docker_machine_download_url" { description = "Full url pointing to a linux x64 distribution of docker machine. Once set `docker_machine_version` will be ingored. For example the GitLab version, https://gitlab-docker-machine-downloads.s3.amazonaws.com/v0.16.2-gitlab.2/docker-machine." type = string - default = "" + default = "https://gitlab-docker-machine-downloads.s3.amazonaws.com/v0.16.2-gitlab.10/docker-machine-Linux-aarch64" } variable "docker_machine_version" { - description = "Version of docker-machine. The version will be ingored once `docker_machine_download_url` is set." + 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." type = string - default = "0.16.2" + default = "" } variable "runners_name" { @@ -171,6 +171,12 @@ variable "runners_shm_size" { default = 0 } +variable "runners_docker_runtime" { + description = "docker runtime for runners, will be used in the runner config.toml" + type = string + default = "" +} + variable "runners_pull_policy" { description = "pull_policy for the runners, will be used in the runner config.toml" type = string @@ -308,6 +314,12 @@ variable "cache_bucket_name_include_account_id" { default = true } +variable "cache_bucket_set_random_suffix" { + description = "Append the cache bucket name with a random string suffix" + type = bool + default = false +} + variable "cache_bucket_versioning" { description = "Boolean used to enable versioning on the cache bucket, false by default." type = bool @@ -329,7 +341,7 @@ variable "cache_shared" { variable "gitlab_runner_version" { description = "Version of the GitLab runner." type = string - default = "13.4.0" + default = "13.7.0" } variable "enable_ping" { @@ -456,7 +468,7 @@ variable "runner_ami_filter" { type = map(list(string)) default = { - name = ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"] + name = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"] } } @@ -633,3 +645,9 @@ variable "runner_iam_policy_arns" { description = "List of policy ARNs to be added to the instance profile of the gitlab runner agent ec2 instance." default = [] } + +variable "docker_machine_iam_policy_arns" { + type = list(string) + description = "List of policy ARNs to be added to the instance profile of the docker machine runners." + default = [] +} diff --git a/versions.tf b/versions.tf index ac97c6ac8..dca70d759 100644 --- a/versions.tf +++ b/versions.tf @@ -1,4 +1,12 @@ terraform { required_version = ">= 0.12" + required_providers { + aws = { + source = "hashicorp/aws" + } + null = { + source = "hashicorp/null" + } + } }