Skip to content

Commit

Permalink
Merge branch 'release/4.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
npalm committed Aug 21, 2019
2 parents ff30b9d + 1e80e7c commit 7eb8d7b
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## 4.4.0 - 2019-08-21

- Added
- Allow for configurable root block size #123 @bsuv
- Enable ASG scheduling #119 @bsuv


## 4.3.0 - 2019-08-19

- Added
Expand Down Expand Up @@ -215,7 +222,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.3.0...HEAD
[Unreleased]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/4.4.0...HEAD
[4.4.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/4.3.0...4.4.0
[4.3.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/4.2.0...4.3.0
[4.2.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/4.1.0...4.2.0
[4.1.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/4.0.0...4.1.0
Expand Down
3 changes: 3 additions & 0 deletions _docs/TF_MODULE.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
| enable\_gitlab\_runner\_ssh\_access | Enables SSH Access to the gitlab runner instance. | 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\_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\_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) | `<map>` | no |
| gitlab\_runner\_ssh\_cidr\_blocks | List of CIDR blocks to allow SSH Access to the gitlab runner instance. | list(string) | `<list>` | no |
Expand All @@ -35,6 +36,7 @@
| runner\_ami\_filter | List of maps used to create the AMI filter for the Gitlab runner docker-machine AMI. | map(list(string)) | `<map>` | no |
| runner\_ami\_owners | The list of owners used to select the AMI of Gitlab runner docker-machine instances. | list(string) | `<list>` | 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 | `""` | no |
| runner\_root\_block\_device | The EC2 instance root block device configuration. Takes the following keys: `delete_on_termination`, `volume_type`, `volume_size`, `iops` | map(string) | `<map>` | no |
| runners\_additional\_volumes | Additional volumes that will be used in the runner config.toml, e.g Docker socket | list | `<list>` | no |
| runners\_concurrent | Concurrent value for the runners, will be used in the runner config.toml. | number | `"10"` | 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) | `<list>` | no |
Expand Down Expand Up @@ -63,6 +65,7 @@
| 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 |
| 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 | `<map>` | 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 | `""` | no |
| ssh\_public\_key | Public SSH key used for the GitLab runner EC2 instance. | string | `""` | no |
Expand Down
29 changes: 29 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,26 @@ resource "aws_autoscaling_group" "gitlab_runner_instance" {

}

resource "aws_autoscaling_schedule" "scale_in" {
count = var.enable_schedule ? 1 : 0
autoscaling_group_name = aws_autoscaling_group.gitlab_runner_instance.name
scheduled_action_name = "scale_in-${aws_autoscaling_group.gitlab_runner_instance.name}"
recurrence = var.schedule_config["scale_in_recurrence"]
min_size = var.schedule_config["scale_in_count"]
desired_capacity = var.schedule_config["scale_in_count"]
max_size = var.schedule_config["scale_in_count"]
}

resource "aws_autoscaling_schedule" "scale_out" {
count = var.enable_schedule ? 1 : 0
autoscaling_group_name = aws_autoscaling_group.gitlab_runner_instance.name
scheduled_action_name = "scale_out-${aws_autoscaling_group.gitlab_runner_instance.name}"
recurrence = var.schedule_config["scale_out_recurrence"]
min_size = var.schedule_config["scale_out_count"]
desired_capacity = var.schedule_config["scale_out_count"]
max_size = var.schedule_config["scale_out_count"]
}

data "aws_ami" "runner" {
most_recent = "true"

Expand All @@ -246,6 +266,15 @@ resource "aws_launch_configuration" "gitlab_runner_instance" {
instance_type = var.instance_type
spot_price = var.runner_instance_spot_price
iam_instance_profile = aws_iam_instance_profile.instance.name
dynamic "root_block_device" {
for_each = [var.runner_root_block_device]
content {
delete_on_termination = lookup(root_block_device.value, "delete_on_termination", true)
volume_type = lookup(root_block_device.value, "volume_type", "gp2")
volume_size = lookup(root_block_device.value, "volume_size", 8)
iops = lookup(root_block_device.value, "iops", null)
}
}

associate_public_ip_address = false == var.runners_use_private_address

Expand Down
23 changes: 23 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,26 @@ variable "enable_runner_user_data_trace_log" {
type = bool
default = false
}

variable "enable_schedule" {
description = "Flag used to enable/disable auto scaling group schedule for the runner instance. "
type = bool
default = false
}

variable "schedule_config" {
description = "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. "
type = map
default = {
scale_in_recurrence = "0 18 * * 1-5"
scale_in_count = 0
scale_out_recurrence = "0 8 * * 1-5"
scale_out_count = 1
}
}

variable "runner_root_block_device" {
description = "The EC2 instance root block device configuration. Takes the following keys: `delete_on_termination`, `volume_type`, `volume_size`, `iops`"
type = map(string)
default = {}
}

0 comments on commit 7eb8d7b

Please sign in to comment.