Skip to content

Commit 2aaa990

Browse files
feat: Add support for maintenance_options (#312)
Co-authored-by: magreenbaum <magreenbaum> Co-authored-by: Bryant Biggs <[email protected]> Resolves undefined
1 parent 2b0fb73 commit 2aaa990

File tree

7 files changed

+32
-17
lines changed

7 files changed

+32
-17
lines changed

.github/workflows/pre-commit.yml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
env:
1010
TERRAFORM_DOCS_VERSION: v0.16.0
11+
TFLINT_VERSION: v0.44.1
1112

1213
jobs:
1314
collectInputs:
@@ -21,7 +22,7 @@ jobs:
2122

2223
- name: Get root directories
2324
id: dirs
24-
uses: clowdhaus/terraform-composite-actions/[email protected].0
25+
uses: clowdhaus/terraform-composite-actions/[email protected].3
2526

2627
preCommitMinVersions:
2728
name: Min TF pre-commit
@@ -36,24 +37,26 @@ jobs:
3637

3738
- name: Terraform min/max versions
3839
id: minMax
39-
uses: clowdhaus/[email protected].0
40+
uses: clowdhaus/[email protected].4
4041
with:
4142
directory: ${{ matrix.directory }}
4243

4344
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
4445
# Run only validate pre-commit check on min version supported
4546
if: ${{ matrix.directory != '.' }}
46-
uses: clowdhaus/terraform-composite-actions/[email protected].0
47+
uses: clowdhaus/terraform-composite-actions/[email protected].3
4748
with:
4849
terraform-version: ${{ steps.minMax.outputs.minVersion }}
50+
tflint-version: ${{ env.TFLINT_VERSION }}
4951
args: 'terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*'
5052

5153
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
5254
# Run only validate pre-commit check on min version supported
5355
if: ${{ matrix.directory == '.' }}
54-
uses: clowdhaus/terraform-composite-actions/[email protected].0
56+
uses: clowdhaus/terraform-composite-actions/[email protected].3
5557
with:
5658
terraform-version: ${{ steps.minMax.outputs.minVersion }}
59+
tflint-version: ${{ env.TFLINT_VERSION }}
5760
args: 'terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)'
5861

5962
preCommitMaxVersion:
@@ -69,18 +72,12 @@ jobs:
6972

7073
- name: Terraform min/max versions
7174
id: minMax
72-
uses: clowdhaus/[email protected]
73-
74-
- name: Install hcledit (for terraform_wrapper_module_for_each hook)
75-
shell: bash
76-
run: |
77-
curl -L "$(curl -s https://api.github.com/repos/minamijoyo/hcledit/releases/latest | grep -o -E -m 1 "https://.+?_linux_amd64.tar.gz")" > hcledit.tgz
78-
sudo tar -xzf hcledit.tgz -C /usr/bin/ hcledit
79-
rm -f hcledit.tgz 2> /dev/null
80-
hcledit version
75+
uses: clowdhaus/[email protected]
8176

8277
- name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }}
83-
uses: clowdhaus/terraform-composite-actions/[email protected].0
78+
uses: clowdhaus/terraform-composite-actions/[email protected].3
8479
with:
8580
terraform-version: ${{ steps.minMax.outputs.maxVersion }}
81+
tflint-version: ${{ env.TFLINT_VERSION }}
8682
terraform-docs-version: ${{ env.TERRAFORM_DOCS_VERSION }}
83+
install-hcledit: true

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.76.0
3+
rev: v1.77.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_wrapper_module_for_each
@@ -24,7 +24,7 @@ repos:
2424
- '--args=--only=terraform_standard_module_structure'
2525
- '--args=--only=terraform_workspace_remote'
2626
- repo: https://github.com/pre-commit/pre-commit-hooks
27-
rev: v4.3.0
27+
rev: v4.4.0
2828
hooks:
2929
- id: check-merge-conflict
3030
- id: end-of-file-fixer

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ No modules.
232232
| <a name="input_ipv6_addresses"></a> [ipv6\_addresses](#input\_ipv6\_addresses) | Specify one or more IPv6 addresses from the range of the subnet to associate with the primary network interface | `list(string)` | `null` | no |
233233
| <a name="input_key_name"></a> [key\_name](#input\_key\_name) | Key name of the Key Pair to use for the instance; which can be managed using the `aws_key_pair` resource | `string` | `null` | no |
234234
| <a name="input_launch_template"></a> [launch\_template](#input\_launch\_template) | Specifies a Launch Template to configure the instance. Parameters configured on this resource will override the corresponding parameters in the Launch Template | `map(string)` | `null` | no |
235+
| <a name="input_maintenance_options"></a> [maintenance\_options](#input\_maintenance\_options) | The maintenance options for the instance | `any` | `{}` | no |
235236
| <a name="input_metadata_options"></a> [metadata\_options](#input\_metadata\_options) | Customize the metadata options of the instance | `map(string)` | `{}` | no |
236237
| <a name="input_monitoring"></a> [monitoring](#input\_monitoring) | If true, the launched EC2 instance will have detailed monitoring enabled | `bool` | `false` | no |
237238
| <a name="input_name"></a> [name](#input\_name) | Name to be used on EC2 instance created | `string` | `""` | no |

examples/complete/main.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ module "ec2_t2_unlimited" {
129129
vpc_security_group_ids = [module.security_group.security_group_id]
130130
associate_public_ip_address = true
131131

132+
maintenance_options = {
133+
auto_recovery = "default"
134+
}
135+
132136
tags = local.tags
133137
}
134138

@@ -233,7 +237,6 @@ module "ec2_spot_instance" {
233237
cpu_core_count = 2 # default 4
234238
cpu_threads_per_core = 1 # default 2
235239

236-
237240
enable_volume_tags = false
238241
root_block_device = [
239242
{

main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ resource "aws_instance" "this" {
127127
}
128128
}
129129

130+
dynamic "maintenance_options" {
131+
for_each = length(var.maintenance_options) > 0 ? [var.maintenance_options] : []
132+
content {
133+
auto_recovery = try(maintenance_options.value.auto_recovery, null)
134+
}
135+
}
136+
130137
enclave_options {
131138
enabled = var.enclave_options_enabled
132139
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ variable "associate_public_ip_address" {
2828
default = null
2929
}
3030

31+
variable "maintenance_options" {
32+
description = "The maintenance options for the instance"
33+
type = any
34+
default = {}
35+
}
36+
3137
variable "availability_zone" {
3238
description = "AZ to start the instance in"
3339
type = string

wrappers/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module "wrapper" {
88
ami_ssm_parameter = try(each.value.ami_ssm_parameter, var.defaults.ami_ssm_parameter, "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2")
99
ami = try(each.value.ami, var.defaults.ami, null)
1010
associate_public_ip_address = try(each.value.associate_public_ip_address, var.defaults.associate_public_ip_address, null)
11+
maintenance_options = try(each.value.maintenance_options, var.defaults.maintenance_options, {})
1112
availability_zone = try(each.value.availability_zone, var.defaults.availability_zone, null)
1213
capacity_reservation_specification = try(each.value.capacity_reservation_specification, var.defaults.capacity_reservation_specification, {})
1314
cpu_credits = try(each.value.cpu_credits, var.defaults.cpu_credits, null)

0 commit comments

Comments
 (0)