Skip to content

Commit 88d1cbf

Browse files
authored
Merge pull request #1 from cruxstack/dev
feat: expand option, improve ci testing, and improve compatibility
2 parents 700ca8b + eb24d3c commit 88d1cbf

File tree

5 files changed

+106
-38
lines changed

5 files changed

+106
-38
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Checkout Code
16-
uses: actions/checkout@v3
16+
uses: actions/checkout@v4
17+
1718
- name: Bump Version
1819
id: tag_version
1920
uses: mathieudutour/github-tag-action@v6.1
2021
with:
2122
github_token: ${{ secrets.GITHUB_TOKEN }}
2223
default_bump: minor
2324
custom_release_rules: bug:patch:Fixes,chore:patch:Chores,docs:patch:Documentation,feat:minor:Features,refactor:minor:Refactors,test:patch:Tests,ci:patch:Development,dev:patch:Development
25+
2426
- name: Create Release
2527
uses: ncipollo/release-action@v1.12.0
2628
with:

.github/workflows/semantic-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- name: Checkout Code
19-
uses: actions/checkout@v3
19+
uses: actions/checkout@v4
2020
- uses: amannn/action-semantic-pull-request@v5.2.0
2121
name: Check PR for Semantic Commit Message
2222
env:

.github/workflows/test.yml

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,70 @@ name: test
22

33
on:
44
pull_request:
5-
branches:
6-
- main
5+
branches: [ main ]
6+
push:
7+
branches: [ main ]
8+
9+
permissions:
10+
contents: read
11+
pull-requests: write
12+
13+
env:
14+
TF_IN_AUTOMATION: true
715

816
jobs:
9-
test:
17+
lint:
18+
name: lint
1019
runs-on: ubuntu-latest
20+
1121
steps:
12-
- name: Checkout Code
13-
uses: actions/checkout@v3
14-
- name: Terraform Setup
15-
run: |
16-
terraform init
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: setup terraform
26+
uses: hashicorp/setup-terraform@v3
27+
28+
- name: Cache Terraform Plugins
29+
uses: actions/cache@v4
30+
with:
31+
path: ${{ runner.temp }}/.terraform.d/plugin-cache
32+
key: tf-plugins-${{ runner.os }}-${{ hashFiles('**/.terraform.lock.hcl') }}
33+
34+
- name: Initialize Terraform
35+
run: terraform init
36+
37+
- name: Suggest Terraform Format
38+
if: github.event_name == 'pull_request'
39+
uses: reviewdog/action-suggester@v1
40+
with:
41+
tool_name: terraform-fmt
42+
level: warning
43+
github_token: ${{ secrets.GITHUB_TOKEN }}
44+
fail_level: error
45+
46+
- name: Check Terraform Format
47+
if: github.event_name == 'push'
48+
run: terraform fmt -recursive -check
49+
50+
- name: Validate Terraform
51+
uses: reviewdog/action-terraform-validate@v1
52+
with:
53+
github_token: ${{ secrets.GITHUB_TOKEN }}
54+
reporter: github-pr-review
55+
level: warning
56+
fail_level: error
57+
1758
- name: Lint Terraform
18-
uses: reviewdog/action-tflint@master
59+
uses: reviewdog/action-tflint@v1
60+
with:
61+
reporter: github-pr-review
62+
filter_mode: nofilter
63+
fail_level: error
64+
65+
- name: Lint GitHub Actions
66+
uses: reviewdog/action-actionlint@v1
1967
with:
20-
github_token: ${{ secrets.github_token }}
21-
filter_mode: "nofilter"
68+
reporter: github-pr-check
69+
fail_level: error
70+
filter_mode: nofilter
71+

main.tf

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
locals {
2+
aws_partition = data.aws_partition.current.partition
3+
24
vpc_dns_resolver = module.this.enabled ? cidrhost(data.aws_vpc.lookup[0].cidr_block, 2) : "10.0.0.2"
35
proxies = { for k, v in var.proxies : k => merge(v, { name = k }) }
46
proxies_port_range = [local.proxies.default.listener_port, local.proxies.default.listener_port]
@@ -27,16 +29,18 @@ locals {
2729
}
2830
}
2931

32+
data "aws_partition" "current" {}
33+
3034
# ================================================================== service ===
3135

3236
module "proxy" {
3337
source = "cloudposse/ec2-autoscale-group/aws"
34-
version = "0.41.0"
38+
version = "0.41.1"
3539

3640
image_id = data.aws_ssm_parameter.linux_ami.value
3741
instance_type = "t3.nano"
3842
health_check_type = "ELB"
39-
user_data_base64 = base64encode(module.this.enabled ? data.template_cloudinit_config.this[0].rendered : "")
43+
user_data_base64 = base64encode(module.this.enabled ? data.cloudinit_config.this[0].rendered : "")
4044
force_delete = true
4145
disable_api_termination = false
4246
update_default_version = true
@@ -50,39 +54,27 @@ module "proxy" {
5054
}
5155

5256
iam_instance_profile_name = module.this.enabled ? resource.aws_iam_instance_profile.this[0].id : null
53-
key_name = ""
57+
key_name = var.key_name
5458
metadata_http_tokens_required = true
5559

5660
autoscaling_policies_enabled = false
5761
desired_capacity = local.capacity.desired
58-
min_size = var.capacity.min
59-
max_size = var.capacity.max
62+
min_size = local.capacity.min
63+
max_size = local.capacity.max
6064
max_instance_lifetime = "604800"
6165
wait_for_capacity_timeout = "300s"
6266
tag_specifications_resource_types = ["instance", "volume", "spot-instances-request"]
6367

6468
mixed_instances_policy = {
6569
instances_distribution = {
66-
on_demand_base_capacity = 0
67-
on_demand_percentage_above_base_capacity = 0
70+
on_demand_base_capacity = var.spot.enabled ? 0 : 100
71+
on_demand_percentage_above_base_capacity = var.spot.enabled ? 0 : 100
6872
on_demand_allocation_strategy = "prioritized"
69-
spot_allocation_strategy = "capacity-optimized"
73+
spot_allocation_strategy = var.spot.allocation_strategy
7074
spot_instance_pools = 0
7175
spot_max_price = ""
7276
}
73-
override = [{
74-
instance_type = "t3.nano"
75-
weighted_capacity = 1
76-
}, {
77-
instance_type = "t3a.nano"
78-
weighted_capacity = 1
79-
}, {
80-
instance_type = "t3.micro"
81-
weighted_capacity = 1
82-
}, {
83-
instance_type = "t3a.micro"
84-
weighted_capacity = 1
85-
}]
77+
override = [for x in var.instance_types : { instance_type = x.type, weighted_capacity = x.weight }]
8678
}
8779

8880
associate_public_ip_address = false
@@ -94,7 +86,7 @@ module "proxy" {
9486
context = module.this.context
9587
}
9688

97-
data "template_cloudinit_config" "this" {
89+
data "cloudinit_config" "this" {
9890
count = module.this.enabled ? 1 : 0
9991

10092
gzip = true
@@ -266,7 +258,7 @@ resource "aws_iam_role_policy_attachment" "ssm_managed_instance_core" {
266258
count = module.this.enabled ? 1 : 0
267259

268260
role = resource.aws_iam_role.this[0].name
269-
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
261+
policy_arn = "arn:${local.aws_partition}:iam::aws:policy/AmazonSSMManagedInstanceCore"
270262
}
271263

272264
resource "aws_iam_policy" "this" {
@@ -307,8 +299,8 @@ data "aws_iam_policy_document" "this" {
307299
"s3:GetBucketLocation",
308300
]
309301
resources = [
310-
"arn:aws:s3:::${var.ssm_sessions.logs_bucket_name}",
311-
"arn:aws:s3:::${var.ssm_sessions.logs_bucket_name}/*"
302+
"arn:${local.aws_partition}:s3:::${var.ssm_sessions.logs_bucket_name}",
303+
"arn:${local.aws_partition}:s3:::${var.ssm_sessions.logs_bucket_name}/*"
312304
]
313305
}
314306
}

variables.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ variable "capacity" {
2727
default = {}
2828
}
2929

30+
variable "instance_types" {
31+
type = list(object({
32+
type = string
33+
weight = optional(number, 1)
34+
}))
35+
description = "List of instance types and their weighted capacity to be used."
36+
default = [{ type = "t3.nano" }, { type = "t3a.nano" }, { type = "t3.micro" }, { type = "t3a.micro" }]
37+
}
38+
39+
variable "spot" {
40+
type = object({
41+
enabled = optional(bool, true)
42+
allocation_strategy = optional(string, "capacity-optimized")
43+
})
44+
description = "Configuration of spot instances"
45+
default = {}
46+
}
47+
3048
variable "logs_bucket_name" {
3149
type = string
3250
description = "S3 bucket for storing logs."
@@ -44,6 +62,12 @@ variable "ssm_sessions" {
4462

4563
# --------------------------------------------------------------- networking ---
4664

65+
variable "key_name" {
66+
type = string
67+
description = "Name of existing SSH key to be assigned to instances."
68+
default = ""
69+
}
70+
4771
variable "public_accessible" {
4872
type = bool
4973
description = "Toggle whether the NLB is publicly accessible."

0 commit comments

Comments
 (0)