Skip to content

Commit 0e95c59

Browse files
committed
Refactor, update docs
1 parent 3684eac commit 0e95c59

File tree

8 files changed

+77
-31
lines changed

8 files changed

+77
-31
lines changed

examples/default/main.tf

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
locals {
2-
environment = "test.default"
2+
environment = "default-action-runners"
33
aws_region = "eu-west-1"
44
}
55

6-
resource "random_string" "random" {
7-
length = 24
8-
special = false
9-
upper = false
10-
}
11-
126
module "runners" {
13-
source = "../../modules/runners"
7+
source = "../../"
148

159
aws_region = local.aws_region
1610
vpc_id = module.vpc.vpc_id
@@ -19,6 +13,6 @@ module "runners" {
1913
tags = {
2014
Project = "ProjectX"
2115
}
22-
distribution_bucket_name = random_string.random.result
16+
2317
}
2418

examples/default/outputs.tf

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
output "runners" {
1+
output "action_runners" {
22
value = {
3-
launch_template_name = module.runners.launch_template.name
4-
launch_template_id = module.runners.launch_template.id
5-
launch_template_version = module.runners.launch_template.latest_version
6-
action_runner_distribution = module.runners.s3_location_runner_distribution
3+
runners = module.runners.runners
74
}
85
}

main.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
resource "random_string" "random" {
2+
length = 24
3+
special = false
4+
upper = false
5+
}
6+
7+
module "runners" {
8+
source = "./modules/runners"
9+
10+
aws_region = var.aws_region
11+
vpc_id = var.vpc_id
12+
13+
environment = var.environment
14+
tags = var.tags
15+
distribution_bucket_name = random_string.random.result
16+
}
17+

modules/runners/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Action runner module
2+
3+
The module create resources to facilitate the `orchestrator labmda` to recreate action runners.
4+
5+
- *launch template* : A launch template is creates that can crate an action runner, by default a spot instance is requested. For configuration parameters SSM is used.
6+
- *security group* : Security groups attached to the action runner.
7+
- *s3 bucket* : To avoid the action runner distribution have to be download a cached version is expected in a S3 bucket.
8+
- *policies and roles* : Policies and roles for the action runner. By default the session manager is enabled
9+

modules/runners/templates/user-data.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ while [[ $(aws ssm get-parameters --names ${environment}-$INSTANCE_ID --with-dec
4141
echo Waiting for configuration ...
4242
sleep 1
4343
done
44-
config=$(aws ssm get-parameters --names ${environment}-$INSTANCE_ID --with-decryption --region $REGION | jq -r ".Parameters | .[0] | .Value")
45-
aws ssm delete-parameter --names ${environment}-$INSTANCE_ID --with-decryption --region $REGION
44+
CONFIG=$(aws ssm get-parameters --names ${environment}-$INSTANCE_ID --with-decryption --region $REGION | jq -r ".Parameters | .[0] | .Value")
45+
aws ssm delete-parameter --name ${environment}-$INSTANCE_ID --region $REGION
4646

4747
export RUNNER_ALLOW_RUNASROOT=1
48-
./config.sh --unattended --name $INSTANCE_ID --work "_work" $config
48+
./config.sh --unattended --name $INSTANCE_ID --work "_work" $CONFIG
4949

5050
chown -R ec2-user:ec2-user .
5151
./svc.sh install ec2-user

modules/runners/variables.tf

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ variable "aws_region" {
44
}
55

66
variable "vpc_id" {
7-
description = "The VPC to spin up instances in"
7+
description = "The VPC for the security groupss."
8+
type = string
89
}
910

10-
1111
variable "overrides" {
1212
description = "This maps provides the possibility to override some defaults. The following attributes are supported: `name_sg` overwrite the `Name` tag for all security groups created by this module. `name_runner_agent_instance` override the `Name` tag for the ec2 instance defined in the auto launch configuration. `name_docker_machine_runners` ovverrid the `Name` tag spot instances created by the runner agent."
1313
type = map(string)
@@ -29,7 +29,8 @@ variable "environment" {
2929
}
3030

3131
variable "distribution_bucket_name" {
32-
type = string
32+
description = "Bucket for storing the action runner distribution."
33+
type = string
3334
}
3435

3536
variable "block_device_mappings" {
@@ -39,25 +40,24 @@ variable "block_device_mappings" {
3940
}
4041

4142
variable "market_options" {
42-
default = "spot"
43+
description = "Market options for the action runner instances."
44+
type = string
45+
default = "spot"
4346
}
4447

4548
variable "instance_type" {
46-
default = "m5.large"
47-
}
48-
49-
variable "associate_public_ip_address" {
50-
type = bool
51-
default = false
49+
description = "Default instance type for the action runner."
50+
type = string
51+
default = "m5.large"
5252
}
5353

5454
variable "action_runner_dist_bucket_location" {
55-
default = "actions-runner-linux.tar.gz"
55+
description = "Default location action runner distribution."
56+
default = "actions-runner-linux.tar.gz"
5657
}
5758

58-
5959
variable "ami_filter" {
60-
description = "List of maps used to create the AMI filter for the runner AMI. Currently Amazon Linux 2 `amzn2-ami-hvm-2.0.????????-x86_64-ebs` looks to *not* be working for this configuration."
60+
description = "List of maps used to create the AMI filter for the action runner AMI."
6161
type = map(list(string))
6262

6363
default = {
@@ -66,7 +66,7 @@ variable "ami_filter" {
6666
}
6767

6868
variable "ami_owners" {
69-
description = "The list of owners used to select the AMI of runner instances."
69+
description = "The list of owners used to select the AMI of action runner instances."
7070
type = list(string)
7171
default = ["amazon"]
7272
}

outputs.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
output "runners" {
2+
value = {
3+
launch_template_name = module.runners.launch_template.name
4+
launch_template_id = module.runners.launch_template.id
5+
launch_template_version = module.runners.launch_template.latest_version
6+
action_runner_distribution = module.runners.s3_location_runner_distribution
7+
}
8+
}

variables.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
variable "aws_region" {
2+
description = "AWS region."
3+
type = string
4+
}
5+
6+
variable "vpc_id" {
7+
description = "The VPC for security groups of the action runners."
8+
type = string
9+
}
10+
11+
variable "tags" {
12+
description = "Map of tags that will be added to created resources. By default resources will be tagged with name and environment."
13+
type = map(string)
14+
default = {}
15+
}
16+
17+
variable "environment" {
18+
description = "A name that identifies the environment, used as prefix and for tagging."
19+
type = string
20+
}
21+

0 commit comments

Comments
 (0)