Skip to content

Commit 4d6d237

Browse files
committed
feat: roll instances + modify ASG sizes + add aqua
1 parent 8f57206 commit 4d6d237

File tree

5 files changed

+71
-31
lines changed

5 files changed

+71
-31
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,13 @@ Use [the awesome `gossm` project](https://github.com/gjbae1212/gossm).
7474
| Name | Version |
7575
|------|---------|
7676
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
77-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0 |
78-
| <a name="requirement_local"></a> [local](#requirement\_local) | >= 1.2 |
79-
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2.0 |
77+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
8078

8179
## Providers
8280

8381
| Name | Version |
8482
|------|---------|
85-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0 |
83+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
8684

8785
## Modules
8886

@@ -129,19 +127,21 @@ Use [the awesome `gossm` project](https://github.com/gjbae1212/gossm).
129127
| <a name="input_create_run_shell_document"></a> [create\_run\_shell\_document](#input\_create\_run\_shell\_document) | Whether or not to create the SSM-SessionManagerRunShell SSM Document. | `bool` | `true` | no |
130128
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
131129
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
130+
| <a name="input_desired_capacity"></a> [desired\_capacity](#input\_desired\_capacity) | Desired number of instances in the Auto Scaling Group | `number` | `1` | no |
132131
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
133132
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
134133
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for keep the existing setting, which defaults to `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
135-
| <a name="input_instance_count"></a> [instance\_count](#input\_instance\_count) | The number of SSM Agent instances you would like to deploy. | `number` | `1` | no |
136134
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | The instance type to use for the SSM Agent EC2 Instnace. | `string` | `"t3.nano"` | no |
137135
| <a name="input_key_pair_name"></a> [key\_pair\_name](#input\_key\_pair\_name) | The name of the key-pair to associate with the SSM Agent instances. This can be (and probably should) left empty unless you specifically plan to use `AWS-StartSSHSession`. | `string` | `null` | no |
138136
| <a name="input_label_key_case"></a> [label\_key\_case](#input\_label\_key\_case) | Controls the letter case of the `tags` keys (label names) for tags generated by this module.<br>Does not affect keys of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper`.<br>Default value: `title`. | `string` | `null` | no |
139137
| <a name="input_label_order"></a> [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.<br>Defaults to ["namespace", "environment", "stage", "name", "attributes"].<br>You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no |
140138
| <a name="input_label_value_case"></a> [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,<br>set as tag values, and output by this module individually.<br>Does not affect values of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper` and `none` (no transformation).<br>Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.<br>Default value: `lower`. | `string` | `null` | no |
141139
| <a name="input_labels_as_tags"></a> [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.<br>Default is to include all labels.<br>Tags with empty values will not be included in the `tags` output.<br>Set to `[]` to suppress all generated tags.<br>**Notes:**<br> The value of the `name` tag, if included, will be the `id`, not the `name`.<br> Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be<br> changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` | <pre>[<br> "default"<br>]</pre> | no |
140+
| <a name="input_max_size"></a> [max\_size](#input\_max\_size) | Maximum number of instances in the Auto Scaling Group | `number` | `2` | no |
142141
| <a name="input_metadata_http_endpoint_enabled"></a> [metadata\_http\_endpoint\_enabled](#input\_metadata\_http\_endpoint\_enabled) | Whether or not to enable the metadata http endpoint | `bool` | `true` | no |
143142
| <a name="input_metadata_http_protocol_ipv6_enabled"></a> [metadata\_http\_protocol\_ipv6\_enabled](#input\_metadata\_http\_protocol\_ipv6\_enabled) | Enable IPv6 metadata endpoint | `bool` | `false` | no |
144143
| <a name="input_metadata_imdsv2_enabled"></a> [metadata\_imdsv2\_enabled](#input\_metadata\_imdsv2\_enabled) | Whether or not the metadata service requires session tokens,<br>also referred to as Instance Metadata Service Version 2 (IMDSv2). | `bool` | `true` | no |
144+
| <a name="input_min_size"></a> [min\_size](#input\_min\_size) | Minimum number of instances in the Auto Scaling Group | `number` | `1` | no |
145145
| <a name="input_monitoring_enabled"></a> [monitoring\_enabled](#input\_monitoring\_enabled) | Enable detailed monitoring of instance | `bool` | `true` | no |
146146
| <a name="input_name"></a> [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.<br>This is the only ID element not also included as a `tag`.<br>The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no |
147147
| <a name="input_namespace"></a> [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no |

aqua.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
# aqua - Declarative CLI Version Manager
3+
# https://aquaproj.github.io/
4+
# checksum:
5+
# enabled: true
6+
# require_checksum: true
7+
# supported_envs:
8+
# - all
9+
registries:
10+
- type: standard
11+
ref: v4.137.0 # renovate: depName=aquaproj/aqua-registry
12+
packages:
13+
- name: terraform-docs/[email protected]
14+
- name: hashicorp/[email protected]
15+
- name: opentofu/[email protected]

main.tf

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ resource "aws_launch_template" "default" {
275275
key_name = var.key_pair_name
276276
user_data = base64encode(var.user_data)
277277

278+
update_default_version = true
279+
278280
monitoring {
279281
enabled = var.monitoring_enabled
280282
}
@@ -312,22 +314,13 @@ resource "aws_launch_template" "default" {
312314

313315
resource "aws_autoscaling_group" "default" {
314316
name_prefix = "${module.this.id}-asg"
315-
dynamic "tag" {
316-
for_each = module.this.tags
317-
content {
318-
key = tag.key
319-
value = tag.value
320-
propagate_at_launch = true
321-
}
322-
}
323-
launch_template {
324-
id = aws_launch_template.default.id
325-
version = "$Latest"
326-
}
327317

328-
max_size = var.instance_count
329-
min_size = var.instance_count
330-
desired_capacity = var.instance_count
318+
max_size = var.max_size
319+
min_size = var.min_size
320+
desired_capacity = var.desired_capacity
321+
322+
# We don't care to protect from scale in by default, as we want to roll instances frequently
323+
protect_from_scale_in = false
331324

332325
vpc_zone_identifier = var.subnet_ids
333326

@@ -339,6 +332,28 @@ resource "aws_autoscaling_group" "default" {
339332
"OldestLaunchConfiguration",
340333
]
341334

335+
launch_template {
336+
id = aws_launch_template.default.id
337+
version = aws_launch_template.default.latest_version
338+
}
339+
340+
instance_refresh {
341+
strategy = "Rolling"
342+
triggers = ["tag"]
343+
preferences {
344+
min_healthy_percentage = 50
345+
}
346+
}
347+
348+
dynamic "tag" {
349+
for_each = module.this.tags
350+
content {
351+
key = tag.key
352+
value = tag.value
353+
propagate_at_launch = true
354+
}
355+
}
356+
342357
lifecycle {
343358
create_before_destroy = true
344359
}

variables.tf

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ variable "ami" {
3030
description = "The AMI to use for the SSM Agent EC2 Instance. If not provided, the latest Amazon Linux 2 AMI will be used. Note: This will update periodically as AWS releases updates to their AL2 AMI. Pin to a specific AMI if you would like to avoid these updates."
3131
}
3232

33-
variable "instance_count" {
34-
default = 1
35-
type = number
36-
description = "The number of SSM Agent instances you would like to deploy."
37-
}
38-
3933
variable "user_data" {
4034
default = <<EOT
4135
#!/bin/bash
@@ -150,7 +144,25 @@ variable "create_run_shell_document" {
150144
}
151145

152146
variable "session_logging_ssm_document_name" {
153-
default = "SSM-SessionManagerRunShell"
154-
type = string
147+
default = "SSM-SessionManagerRunShell"
148+
type = string
149+
155150
description = "Name for `session_logging` SSM document. This is only applied if 2 conditions are met: (1) `session_logging_enabled` = true, (2) `create_run_shell_document` = true."
156151
}
152+
variable "max_size" {
153+
description = "Maximum number of instances in the Auto Scaling Group"
154+
type = number
155+
default = 2
156+
}
157+
158+
variable "min_size" {
159+
description = "Minimum number of instances in the Auto Scaling Group"
160+
type = number
161+
default = 1
162+
}
163+
164+
variable "desired_capacity" {
165+
description = "Desired number of instances in the Auto Scaling Group"
166+
type = number
167+
default = 1
168+
}

versions.tf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ terraform {
22
required_version = ">= 0.13.0"
33

44
required_providers {
5-
aws = ">= 4.0"
6-
local = ">= 1.2"
7-
null = ">= 2.0"
5+
aws = ">= 5.0"
86
}
97
}

0 commit comments

Comments
 (0)