Skip to content

Commit 559e810

Browse files
committed
Refactor distribution out of the runner
1 parent 0e95c59 commit 559e810

File tree

7 files changed

+41
-44
lines changed

7 files changed

+41
-44
lines changed

main.tf

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,41 @@ resource "random_string" "random" {
44
upper = false
55
}
66

7+
module "dsitrubtion_cache" {
8+
source = "./modules/action-runner-binary-cache"
9+
10+
aws_region = var.aws_region
11+
environment = var.environment
12+
tags = var.tags
13+
14+
distribution_bucket_name = random_string.random.result
15+
}
16+
717
module "runners" {
818
source = "./modules/runners"
919

10-
aws_region = var.aws_region
11-
vpc_id = var.vpc_id
20+
aws_region = var.aws_region
21+
vpc_id = var.vpc_id
22+
environment = var.environment
23+
tags = var.tags
1224

13-
environment = var.environment
14-
tags = var.tags
15-
distribution_bucket_name = random_string.random.result
25+
s3_location_runner_distribution = module.dsitrubtion_cache.s3_location_runner_distribution
1626
}
1727

28+
29+
resource "aws_iam_policy" "dist_bucket" {
30+
name = "${var.environment}-gh-distribution-bucket"
31+
path = "/"
32+
description = "Policy for the runner to download the github action runner."
33+
34+
policy = templatefile("${path.module}/policies/action-runner-s3-policy.json",
35+
{
36+
s3_arn = module.dsitrubtion_cache.distribution_bucket.arn
37+
}
38+
)
39+
}
40+
41+
resource "aws_iam_role_policy_attachment" "dist_bucket" {
42+
role = module.runners.role.name
43+
policy_arn = aws_iam_policy.dist_bucket.arn
44+
}

modules/runners/main.tf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
locals {
2-
name_sg = var.overrides["name_sg"] == "" ? local.tags["Name"] : var.overrides["name_sg"]
3-
s3_location_runner_distribution = "s3://${aws_s3_bucket.action_dist.id}/${var.action_runner_dist_bucket_location}"
2+
name_sg = var.overrides["name_sg"] == "" ? local.tags["Name"] : var.overrides["name_sg"]
43

54
tags = merge(
65
{
@@ -69,7 +68,7 @@ resource "aws_launch_template" "runner" {
6968
environment = var.environment
7069
pre_install = var.userdata_pre_install
7170
post_install = var.userdata_post_install
72-
s3_location_runner_distribution = local.s3_location_runner_distribution
71+
s3_location_runner_distribution = var.s3_location_runner_distribution
7372
}))
7473
}
7574

modules/runners/outputs.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
output "s3_location_runner_distribution" {
2-
value = local.s3_location_runner_distribution
3-
}
4-
51
output "launch_template" {
62
value = aws_launch_template.runner
73
}
4+
5+
output "role" {
6+
value = aws_iam_role.runner
7+
}

modules/runners/policies.tf

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,6 @@ resource "aws_iam_role_policy_attachment" "runner_session_manager_aws_managed" {
2929
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
3030
}
3131

32-
resource "aws_iam_policy" "dist_bucket" {
33-
name = "${var.environment}-gh-distribution-bucket"
34-
path = "/"
35-
description = "Policy for the runner to download the github action runner."
36-
37-
policy = templatefile("${path.module}/policies/instance-runner-s3-policy.json",
38-
{
39-
s3_arn = aws_s3_bucket.action_dist.arn
40-
}
41-
)
42-
}
43-
44-
resource "aws_iam_role_policy_attachment" "dist_bucket" {
45-
role = aws_iam_role.runner.name
46-
policy_arn = aws_iam_policy.dist_bucket.arn
47-
}
48-
4932
resource "aws_iam_policy" "ssm_parameters" {
5033
name = "${var.environment}-runner-ssm-parameters"
5134
path = "/"

modules/runners/runner-dist.tf

Lines changed: 0 additions & 7 deletions
This file was deleted.

modules/runners/variables.tf

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ variable "environment" {
2828
type = string
2929
}
3030

31-
variable "distribution_bucket_name" {
32-
description = "Bucket for storing the action runner distribution."
31+
variable "s3_location_runner_distribution" {
32+
description = "S3 location of runner distribution."
3333
type = string
3434
}
3535

@@ -51,11 +51,6 @@ variable "instance_type" {
5151
default = "m5.large"
5252
}
5353

54-
variable "action_runner_dist_bucket_location" {
55-
description = "Default location action runner distribution."
56-
default = "actions-runner-linux.tar.gz"
57-
}
58-
5954
variable "ami_filter" {
6055
description = "List of maps used to create the AMI filter for the action runner AMI."
6156
type = map(list(string))

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ output "runners" {
33
launch_template_name = module.runners.launch_template.name
44
launch_template_id = module.runners.launch_template.id
55
launch_template_version = module.runners.launch_template.latest_version
6-
action_runner_distribution = module.runners.s3_location_runner_distribution
6+
action_runner_distribution = module.dsitrubtion_cache.s3_location_runner_distribution
77
}
88
}

0 commit comments

Comments
 (0)