Skip to content

Commit

Permalink
Merge branch 'release/4.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
npalm committed Aug 18, 2019
2 parents 16d2e2b + cb408fa commit 85e3ffa
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 28 deletions.
19 changes: 15 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## 4.2.0 - 2019-08-18

- Added
- Option to disable account id is used in bucket name #113 @Glen-Moonpig
- Cancel sport instances during destroy for example default and public.
- Changed:
- Fixed typos #118 @mpsq


## 4.1.0 - 2019-08-05

- Changed:
Expand Down Expand Up @@ -45,7 +55,7 @@ Module is available as Terraform 0.11 module, pin module to version 3.x. Please

## 3.7.0 - 2019-07-17
- Changed
- Creation of multiple instances of the runner is now supported. Cache is therefor moved to an internal module. Pleas see the example `runner-public` for a concrete sample. The change should have no effect if you apply the state migration script `migragations/migration-state-3.7.x.sh`.
- Creation of multiple instances of the runner is now supported. Cache is therefore moved to an internal module. Pleas see the example `runner-public` for a concrete sample. The change should have no effect if you apply the state migration script `migragations/migration-state-3.7.x.sh`.
- Examples are more generic by removing the time zone and AZ zone to variables. @@theBenForce

## 3.6.0 - 2019-07-04
Expand All @@ -63,7 +73,7 @@ Module is available as Terraform 0.11 module, pin module to version 3.x. Please

## 3.7.0 - 2019-07-17
- Changed
- Creation of multiple instances of the runner is now supported. Cache is therefor moved to an internal module. Pleas see the example `runner-public` for a concrete sample. The change should have no effect if you apply the state migration script `migragations/migration-state-3.7.x.sh`.
- Creation of multiple instances of the runner is now supported. Cache is therefore moved to an internal module. Pleas see the example `runner-public` for a concrete sample. The change should have no effect if you apply the state migration script `migragations/migration-state-3.7.x.sh`.
- Examples are more generic by removing the time zone and AZ zone to variables. @@theBenForce

## 3.6.0 - 2019-07-04
Expand All @@ -82,7 +92,7 @@ Module is available as Terraform 0.11 module, pin module to version 3.x. Please
## [3.4.0] - 2019-06-06
- Changed:
- Update default runner type, GitLab runner version, and versions in examples.
- Buffix #75 runner is not reachable when runners_use_private_address = false
- Buffix #75 runner is not reachable when runners_use_private_address = false
- Buffix - Missing typ - @Orkin
- Bugfix #72 - Detect and retry when docker machine download fails eliasdorneles
- Bugfix #68 - add count to prevent resource creation failing @philippefuentes
Expand Down Expand Up @@ -200,7 +210,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.1.0...HEAD
[Unreleased]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/4.2.0...HEAD
[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
[4.0.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/3.10.0...4.0.0
[3.10.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/3.9.0...3.10.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ terraform destroy
| ami\_owners | The list of owners used to select the AMI of Gitlab runner agent instances. | list(string) | `<list>` | no |
| aws\_region | AWS region. | string | n/a | yes |
| aws\_zone | AWS availability zone (typically 'a', 'b', or 'c'). | string | `"a"` | no |
| cache\_bucket | Configuration to control the creation of th the cache bucket. By default the bucket will be crated and used as shared cache. To use the same cache cross multiple runners disable the cration of the cache and provice a policy and bucket name. See the public runner example for more details. | map | `<map>` | 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 cross multiple runners disable the cration of the cache and provice a policy and bucket name. See the public runner example for more details. | map | `<map>` | 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 |
Expand Down
3 changes: 1 addition & 2 deletions _docs/TF_MODULE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
| ami\_owners | The list of owners used to select the AMI of Gitlab runner agent instances. | list(string) | `<list>` | no |
| aws\_region | AWS region. | string | n/a | yes |
| aws\_zone | AWS availability zone (typically 'a', 'b', or 'c'). | string | `"a"` | no |
| cache\_bucket | Configuration to control the creation of th the cache bucket. By default the bucket will be crated and used as shared cache. To use the same cache cross multiple runners disable the cration of the cache and provice a policy and bucket name. See the public runner example for more details. | map | `<map>` | 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 cross multiple runners disable the cration of the cache and provice a policy and bucket name. See the public runner example for more details. | map | `<map>` | 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 |
Expand Down Expand Up @@ -82,4 +82,3 @@
| runner\_cache\_bucket\_name | Name of the S3 for the build cache. |
| runner\_role\_arn | ARN of the role used for the docker machine runners. |
| runner\_role\_name | Name of the role used for the docker machine runners. |

4 changes: 2 additions & 2 deletions cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -32,7 +32,7 @@ module "runner" {
| 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. | string | `"false"` | no |
| cache\_expiration\_days | Number of days before cache objects expires. | number | `"1"` | no |
| create\_cache\_bucket | This module is by default included in the runner module. To disable the creation of the bucket this paramter can be disabled. | string | `"true"` | no |
| create\_cache\_bucket | This module is by default included in the runner module. To disable the creation of the bucket this parameter can be disabled. | string | `"true"` | no |
| environment | A name that identifies the environment, used as prefix and for tagging. | 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) | `<map>` | no |

Expand Down
3 changes: 1 addition & 2 deletions cache/_docs/TF_MODULE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
| 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. | string | `"false"` | no |
| cache\_expiration\_days | Number of days before cache objects expires. | number | `"1"` | no |
| create\_cache\_bucket | This module is by default included in the runner module. To disable the creation of the bucket this paramter can be disabled. | string | `"true"` | no |
| create\_cache\_bucket | This module is by default included in the runner module. To disable the creation of the bucket this parameter can be disabled. | string | `"true"` | no |
| environment | A name that identifies the environment, used as prefix and for tagging. | 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) | `<map>` | no |

Expand All @@ -16,4 +16,3 @@
| arn | The ARN of the created bucket. |
| bucket | Name of the created bucket. |
| policy\_arn | Policy for users of the cache (bucket). |

4 changes: 3 additions & 1 deletion cache/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ locals {
},
var.tags,
)

cache_bucket_name = var.cache_bucket_name_include_account_id ? "${var.cache_bucket_prefix}${data.aws_caller_identity.current[0].account_id}-gitlab-runner-cache" : "${var.cache_bucket_prefix}-gitlab-runner-cache"
}

resource "aws_s3_bucket" "build_cache" {
count = var.create_cache_bucket ? 1 : 0

bucket = "${var.cache_bucket_prefix}${data.aws_caller_identity.current[0].account_id}-gitlab-runner-cache"
bucket = local.cache_bucket_name
acl = "private"

tags = local.tags
Expand Down
9 changes: 7 additions & 2 deletions cache/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ variable "cache_bucket_prefix" {
default = ""
}

variable "cache_bucket_name_include_account_id" {
description = "Boolean to add current account ID to cache bucket name."
type = bool
default = true
}

variable "cache_bucket_versioning" {
description = "Boolean used to enable versioning on the cache bucket, false by default."
type = string
Expand All @@ -28,8 +34,7 @@ variable "tags" {
}

variable "create_cache_bucket" {
description = "This module is by default included in the runner module. To disable the creation of the bucket this paramter can be disabled."
description = "This module is by default included in the runner module. To disable the creation of the bucket this parameter can be disabled."
type = string
default = true
}

6 changes: 6 additions & 0 deletions ci/bin/cancel-spot-instances.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

SPOT_REQUESTS=$(aws ec2 describe-spot-instance-requests --filters "Name=state,Values=active,open" | jq -r '[ .SpotInstanceRequests[] | select( .LaunchSpecification.IamInstanceProfile.Name | contains("'$1'")) ]')

echo $SPOT_REQUESTS | jq -r '.[].InstanceId' | xargs aws ec2 terminate-instances --instance-ids
echo $SPOT_REQUESTS | jq -r '.[].SpotInstanceRequestId' | xargs aws ec2 cancel-spot-instance-requests --spot-instance-request-ids
4 changes: 2 additions & 2 deletions ci/bin/run-local.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

docker run --entrypoint="/bin/sh" -it --rm -w /build -v $(pwd):/build hashicorp/terraform:0.12.3 ./ci/bin/verify.sh
docker run --entrypoint="/bin/sh" -it --rm -w /build -v $(pwd):/build hashicorp/terraform:0.12.3 ./ci/bin/verify-examples.sh
docker run --entrypoint="/bin/sh" -it --rm -w /build -v $(pwd):/build hashicorp/terraform:0.12.6 ./ci/bin/verify.sh
docker run --entrypoint="/bin/sh" -it --rm -w /build -v $(pwd):/build hashicorp/terraform:0.12.6 ./ci/bin/verify-examples.sh
4 changes: 2 additions & 2 deletions ci/bin/terraform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ verifyModulesAndPlugins() {
}

formatCheck() {
RESULT=$(terraform fmt -write=false)
RESULT=$(terraform fmt -recursive -write=false)
if [[ ! -z ${RESULT} ]] ; then
echo The following files are formatted incorrectly: $RESULT
exit 1
Expand All @@ -32,5 +32,5 @@ formatCheck() {
validate() {
echo "Validating and checking format of terraform code in $PWD"
terraform validate
formatCheck
}

4 changes: 4 additions & 0 deletions ci/bin/verify-examples.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
DIR=${1:-examples}
_PWD=$PWD

source $(dirname $0)/terraform.sh

Expand All @@ -16,6 +17,9 @@ for example in ${EXAMPLES} ; do
echo no tf files
exit 1
fi
cd ${example}
verifyModulesAndPlugins ${example}
formatCheck ${example}
validate ${example}
cd $_PWD
done
2 changes: 1 addition & 1 deletion ci/bin/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
source $(dirname $0)/terraform.sh

verifyModulesAndPlugins
validate
formatCheck
2 changes: 1 addition & 1 deletion examples/runner-default/.terraform-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.5
0.12.6
17 changes: 16 additions & 1 deletion examples/runner-default/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,30 @@ module "runner" {
}

tags = {
"tf-aws-gitlab-runner:example" = "runner-default"
"tf-aws-gitlab-runner:example" = "runner-default"
"tf-aws-gitlab-runner:instancelifecycle" = "spot:yes"
}

runners_off_peak_timezone = var.timezone
runners_off_peak_idle_count = 0
runners_off_peak_idle_time = 60

runners_privileged = "true"
# runners_additional_volumes = ["/var/run/docker.sock:/var/run/docker.sock"]
runners_additional_volumes = ["/certs/client"]


# working 9 to 5 :)
runners_off_peak_periods = "[\"* * 0-9,17-23 * * mon-fri *\", \"* * * * * sat,sun *\"]"
}



resource "null_resource" "cancel_spot_requests" {
# Cancel active and open spot requests, terminate instances

provisioner "local-exec" {
when = "destroy"
command = "../../ci/bin/cancel-spot-instances.sh ${var.environment}"
}
}
2 changes: 1 addition & 1 deletion examples/runner-docker/.terraform-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.3
0.12.6
2 changes: 1 addition & 1 deletion examples/runner-public/.terraform-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.3
0.12.6
9 changes: 9 additions & 0 deletions examples/runner-public/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,12 @@ module "runner2" {
bucket = "${module.cache.bucket}"
}
}

resource "null_resource" "cancel_spot_requests" {
# Cancel active and open spot requests, terminate instances

provisioner "local-exec" {
when = "destroy"
command = "../../ci/bin/cancel-spot-instances.sh ${var.environment}"
}
}
9 changes: 5 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,11 @@ module "cache" {
environment = var.environment
tags = local.tags

create_cache_bucket = var.cache_bucket["create"]
cache_bucket_prefix = var.cache_bucket_prefix
cache_bucket_versioning = var.cache_bucket_versioning
cache_expiration_days = var.cache_expiration_days
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_versioning = var.cache_bucket_versioning
cache_expiration_days = var.cache_expiration_days
}

################################################################################
Expand Down
8 changes: 7 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ variable "cache_bucket_prefix" {
default = ""
}

variable "cache_bucket_name_include_account_id" {
description = "Boolean to add current account ID to cache bucket name."
type = bool
default = true
}

variable "cache_bucket_versioning" {
description = "Boolean used to enable versioning on the cache bucket, false by default."
type = bool
Expand Down Expand Up @@ -410,7 +416,7 @@ variable "overrides" {
}

variable "cache_bucket" {
description = "Configuration to control the creation of th the cache bucket. By default the bucket will be crated and used as shared cache. To use the same cache cross multiple runners disable the cration of the cache and provice a policy and bucket name. See the public runner example for more details."
description = "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 cross multiple runners disable the cration of the cache and provice a policy and bucket name. See the public runner example for more details."
type = map

default = {
Expand Down

0 comments on commit 85e3ffa

Please sign in to comment.