Skip to content

Commit

Permalink
feat: Tag aws_cloudwatch_event_rule resource + linting (#519)
Browse files Browse the repository at this point in the history
Co-authored-by: Antony Perigault <[email protected]>
  • Loading branch information
aperigault and Antony Perigault authored Jul 20, 2022
1 parent a5f53ae commit f2e98bb
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 42 deletions.
8 changes: 4 additions & 4 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
locals {
// Convert list to a string separated and prepend by a comma
# Convert list to a string separated and prepend by a comma
docker_machine_options_string = format(
",\"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",
join(",", formatlist("%q", concat(var.docker_machine_options, local.runners_docker_registry_mirror_option))),
)

runners_docker_registry_mirror_option = var.runners_docker_registry_mirror == "" ? [] : ["engine-registry-mirror=${var.runners_docker_registry_mirror}"]

// Ensure max builds is optional
# Ensure max builds is optional
runners_max_builds_string = var.runners_max_builds == 0 ? "" : format("MaxBuilds = %d", var.runners_max_builds)

// Define key for runner token for SSM
# Define key for runner token for SSM
secure_parameter_store_runner_token_key = "${var.environment}-${var.secure_parameter_store_runner_token_key}"
secure_parameter_store_runner_sentry_dsn = "${var.environment}-${var.secure_parameter_store_runner_sentry_dsn}"

// Custom names for runner agent instance, security groups, and IAM objects
# Custom names for runner agent instance, security groups, and IAM objects
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"]
name_iam_objects = lookup(var.overrides, "name_iam_objects", "") == "" ? local.tags["Name"] : var.overrides["name_iam_objects"]
Expand Down
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ locals {
runners_aws_zone = data.aws_availability_zone.runners.name_suffix
runners_instance_type = var.docker_machine_instance_type
runners_spot_price_bid = var.docker_machine_spot_price_bid == "on-demand-price" ? "" : var.docker_machine_spot_price_bid
runners_ami = data.aws_ami.docker-machine.id
runners_ami = data.aws_ami.docker_machine.id
runners_security_group_name = aws_security_group.docker_machine.name
runners_monitoring = var.runners_monitoring
runners_ebs_optimized = var.runners_ebs_optimized
Expand Down Expand Up @@ -138,7 +138,7 @@ locals {
)
}

data "aws_ami" "docker-machine" {
data "aws_ami" "docker_machine" {
most_recent = "true"

dynamic "filter" {
Expand Down
1 change: 0 additions & 1 deletion modules/cache/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ resource "aws_s3_bucket" "build_cache" {
tags = local.tags

force_destroy = true

}

resource "aws_s3_bucket_acl" "build_cache_acl" {
Expand Down
5 changes: 2 additions & 3 deletions modules/cache/versions.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

terraform {
required_version = ">= 0.15"
required_version = ">= 1"

required_providers {
aws = {
version = ">= 4.0"
version = ">= 4"
source = "hashicorp/aws"
}
}
Expand Down
4 changes: 3 additions & 1 deletion modules/terminate-instances/cloudwatch.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ resource "aws_cloudwatch_event_rule" "terminate_instances" {
}
}
EOF

tags = var.tags
}

resource "aws_cloudwatch_event_target" "terminate_instances" {
Expand All @@ -30,4 +32,4 @@ resource "aws_cloudwatch_log_group" "lambda" {
retention_in_days = var.cloudwatch_logging_retention_in_days

tags = var.tags
}
}
4 changes: 1 addition & 3 deletions modules/terminate-instances/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# Deploys a Lambda function, CloudWatch rule, and associated resources for
# terminating orphaned runner instances.
# ----------------------------------------------------------------------------
data "aws_caller_identity" "current" {}

locals {
source_sha256 = filesha256("${path.module}/lambda/lambda_function.py")
}
Expand Down Expand Up @@ -55,4 +53,4 @@ resource "aws_autoscaling_lifecycle_hook" "terminate_instances" {
default_result = "CONTINUE"
heartbeat_timeout = var.lifecycle_heartbeat_timeout
lifecycle_transition = "autoscaling:EC2_INSTANCE_TERMINATING"
}
}
10 changes: 8 additions & 2 deletions modules/terminate-instances/versions.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

terraform {
required_version = ">= 0.15"
required_version = ">= 1"

required_providers {
aws = {
version = ">= 4"
source = "hashicorp/aws"
}
}
}
24 changes: 2 additions & 22 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,6 @@ variable "docker_machine_instance_metadata_options" {
}
}

variable "runner_instance_metadata_options_http_endpoint" {
description = "DEPRECATED, replaced by runner_instance_metadata_options. Enable the Gitlab runner agent instance metadata service. The allowed values are enabled, disabled."
type = string
default = null

validation {
condition = var.runner_instance_metadata_options_http_endpoint == null
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."
}
}

variable "runner_instance_metadata_options_http_tokens" {
description = "DEPRECATED, replaced by runner_instance_metadata_options. Set if Gitlab runner agent instance metadata service session tokens are required. The allowed values are optional, required."
type = string
default = null

validation {
condition = var.runner_instance_metadata_options_http_tokens == null
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."
}
}

variable "docker_machine_instance_type" {
description = "Instance type used for the instances hosting docker-machine."
type = string
Expand Down Expand Up @@ -661,6 +639,7 @@ variable "enable_docker_machine_ssm_access" {
}

variable "runners_volumes_tmpfs" {
description = "Mount a tmpfs in runner container. https://docs.gitlab.com/runner/executors/docker.html#mounting-a-directory-in-ram"
type = list(object({
volume = string
options = string
Expand All @@ -669,6 +648,7 @@ variable "runners_volumes_tmpfs" {
}

variable "runners_services_volumes_tmpfs" {
description = "Mount a tmpfs in gitlab service container. https://docs.gitlab.com/runner/executors/docker.html#mounting-a-directory-in-ram"
type = list(object({
volume = string
options = string
Expand Down
4 changes: 0 additions & 4 deletions versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,5 @@ terraform {
version = "~> 4"
source = "hashicorp/aws"
}

null = {
source = "hashicorp/null"
}
}
}

0 comments on commit f2e98bb

Please sign in to comment.