From 628235135d4e01dd1a1bde5b8f5a063eff73c05e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20=C4=86wikli=C5=84ski?= <19205612+Hunqer@users.noreply.github.com> Date: Wed, 16 Feb 2022 18:23:02 +0100 Subject: [PATCH] feat: Parameterise delete_on_termination (#1758) Issue: #1745 Variablize delete_on_termination for EBS volume. Make default as true (which make more sense to delete volumes as they are no longer used by runners). Co-authored-by: Grzegorz Cwiklinski --- images/linux-amzn2/github_agent.linux.pkr.hcl | 15 +++++++++++---- images/ubuntu-focal/github_agent.ubuntu.pkr.hcl | 15 +++++++++++---- .../github_agent.windows.pkr.hcl | 13 ++++++++++++- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/images/linux-amzn2/github_agent.linux.pkr.hcl b/images/linux-amzn2/github_agent.linux.pkr.hcl index e478bd8cef..d039229212 100644 --- a/images/linux-amzn2/github_agent.linux.pkr.hcl +++ b/images/linux-amzn2/github_agent.linux.pkr.hcl @@ -42,6 +42,12 @@ variable "root_volume_size_gb" { default = 8 } +variable "ebs_delete_on_termination" { + description = "Indicates whether the EBS volume is deleted on instance termination." + type = bool + default = true +} + variable "global_tags" { description = "Tags to apply to everything" type = map(string) @@ -91,9 +97,10 @@ source "amazon-ebs" "githubrunner" { launch_block_device_mappings { - device_name = "/dev/xvda" - volume_size = "${var.root_volume_size_gb}" - volume_type = "gp3" + device_name = "/dev/xvda" + volume_size = "${var.root_volume_size_gb}" + volume_type = "gp3" + delete_on_termination = "${var.ebs_delete_on_termination}" } } @@ -151,4 +158,4 @@ build { ] } -} \ No newline at end of file +} diff --git a/images/ubuntu-focal/github_agent.ubuntu.pkr.hcl b/images/ubuntu-focal/github_agent.ubuntu.pkr.hcl index 02c3d7a21e..9c4f0b44d1 100644 --- a/images/ubuntu-focal/github_agent.ubuntu.pkr.hcl +++ b/images/ubuntu-focal/github_agent.ubuntu.pkr.hcl @@ -42,6 +42,12 @@ variable "root_volume_size_gb" { default = 8 } +variable "ebs_delete_on_termination" { + description = "Indicates whether the EBS volume is deleted on instance termination." + type = bool + default = true +} + variable "global_tags" { description = "Tags to apply to everything" type = map(string) @@ -90,9 +96,10 @@ source "amazon-ebs" "githubrunner" { ) launch_block_device_mappings { - device_name = "/dev/sda1" - volume_size = "${var.root_volume_size_gb}" - volume_type = "gp3" + device_name = "/dev/sda1" + volume_size = "${var.root_volume_size_gb}" + volume_type = "gp3" + delete_on_termination = "${var.ebs_delete_on_termination}" } } @@ -161,4 +168,4 @@ build { ] } -} \ No newline at end of file +} diff --git a/images/windows-core-2019/github_agent.windows.pkr.hcl b/images/windows-core-2019/github_agent.windows.pkr.hcl index d15d462476..bde19e3b33 100644 --- a/images/windows-core-2019/github_agent.windows.pkr.hcl +++ b/images/windows-core-2019/github_agent.windows.pkr.hcl @@ -19,6 +19,12 @@ variable "region" { default = "eu-west-1" } +variable "ebs_delete_on_termination" { + description = "Indicates whether the EBS volume is deleted on instance termination." + type = bool + default = true +} + source "amazon-ebs" "githubrunner" { ami_name = "github-runner-windows-core-2019-${formatdate("YYYYMMDDhhmm", timestamp())}" communicator = "winrm" @@ -43,6 +49,11 @@ source "amazon-ebs" "githubrunner" { winrm_port = 5986 winrm_use_ssl = true winrm_username = "Administrator" + + launch_block_device_mappings { + device_name = "/dev/sda1" + delete_on_termination = "${var.ebs_delete_on_termination}" + } } build { @@ -63,4 +74,4 @@ build { action_runner_url = var.action_runner_url })] } -} \ No newline at end of file +}