Skip to content

Commit 97d4727

Browse files
authored
fix: add module version constraints (#7)
* fix: add module version constraints This commit adds version constraints to the modules sourced from the Terraform registry. This commit also includes some minor changes like removing the `join` function in favor of using [`one`](https://www.terraform.io/docs/language/functions/one.html). Fixes #6 * chore: remove patch version from VPC module
1 parent a92d333 commit 97d4727

File tree

12 files changed

+146
-33
lines changed

12 files changed

+146
-33
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ repos:
22
- hooks:
33
- id: terraform_docs
44
repo: "https://github.com/antonbabenko/pre-commit-terraform.git"
5-
rev: v1.43.0
5+
rev: v1.51.0

.terraform.lock.hcl

+59
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ As always, thanks for using this module!
8686

8787
| Name | Version |
8888
|------|---------|
89+
| terraform | ~> 1.0 |
8990
| terraform | >= 0.13 |
9091

9192
## Providers

main.tf

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
terraform {
2+
required_version = "~> 1.0"
3+
}
4+
15
locals {
26
image_id = data.aws_ami.boundary.id
37

@@ -80,7 +84,8 @@ module "workers" {
8084
}
8185

8286
module "vpc" {
83-
source = "terraform-aws-modules/vpc/aws"
87+
source = "terraform-aws-modules/vpc/aws"
88+
version = "~> 3.7"
8489

8590
azs = data.aws_availability_zones.available.names
8691
cidr = var.cidr_block

modules/boundary/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
22
## Requirements
33

4-
No requirements.
4+
| Name | Version |
5+
|------|---------|
6+
| aws | ~> 3.0 |
57

68
## Providers
79

modules/boundary/main.tf

+37-15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 3.0"
6+
}
7+
}
8+
}
9+
110
locals {
211
desired_capacity = max(var.desired_capacity, var.min_size)
312

@@ -40,27 +49,40 @@ locals {
4049
}
4150

4251
module "autoscaling" {
43-
source = "terraform-aws-modules/autoscaling/aws"
52+
source = "terraform-aws-modules/autoscaling/aws"
53+
version = "~> 4.6"
54+
55+
create_lt = true
56+
desired_capacity = local.desired_capacity
57+
health_check_type = "EC2"
58+
iam_instance_profile_arn = var.iam_instance_profile
59+
image_id = var.image_id
4460

45-
desired_capacity = local.desired_capacity
46-
health_check_type = "EC2"
47-
iam_instance_profile = var.iam_instance_profile
48-
image_id = var.image_id
49-
instance_type = var.instance_type
50-
key_name = var.key_name
51-
max_size = var.max_size
52-
min_size = var.min_size
53-
name = var.auto_scaling_group_name
54-
recreate_asg_when_lc_changes = true
55-
security_groups = var.security_groups
56-
tags_as_map = var.tags
57-
target_group_arns = var.target_group_arns
61+
instance_refresh = {
62+
preferences = {
63+
min_healthy_percentage = 80
64+
}
5865

59-
user_data = <<EOF
66+
strategy = "Rolling"
67+
}
68+
69+
instance_type = var.instance_type
70+
key_name = var.key_name
71+
max_size = var.max_size
72+
min_size = var.min_size
73+
name = var.auto_scaling_group_name
74+
security_groups = var.security_groups
75+
tags_as_map = var.tags
76+
target_group_arns = var.target_group_arns
77+
update_default_version = true
78+
use_lt = true
79+
80+
user_data_base64 = base64encode(<<EOF
6081
## template: jinja
6182
#cloud-config
6283
${yamlencode(local.user_data)}
6384
EOF
85+
)
6486

6587
vpc_zone_identifier = var.vpc_zone_identifier
6688
}

modules/boundary/outputs.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
output "auto_scaling_group_name" {
22
description = "The name of the controller Auto Scaling group"
3-
value = module.autoscaling.this_autoscaling_group_name
3+
value = module.autoscaling.autoscaling_group_name
44
}

modules/controller/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
22
## Requirements
33

4-
No requirements.
4+
| Name | Version |
5+
|------|---------|
6+
| aws | ~> 3.0 |
57

68
## Providers
79

810
| Name | Version |
911
|------|---------|
10-
| aws | n/a |
12+
| aws | ~> 3.0 |
1113
| random | n/a |
1214

1315
## Inputs

modules/controller/main.tf

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 3.0"
6+
}
7+
}
8+
}
9+
110
locals {
211
configuration = templatefile(
312
"${path.module}/templates/configuration.hcl.tpl",
413
{
514
# Database URL for PostgreSQL
615
database_url = format(
716
"postgresql://%s:%s@%s/%s",
8-
module.postgresql.this_db_instance_username,
9-
module.postgresql.this_db_instance_password,
10-
module.postgresql.this_db_instance_endpoint,
11-
module.postgresql.this_db_instance_name
17+
module.postgresql.db_instance_username,
18+
module.postgresql.db_instance_password,
19+
module.postgresql.db_instance_endpoint,
20+
module.postgresql.db_instance_name
1221
)
1322

1423
keys = [
@@ -80,7 +89,7 @@ resource "aws_security_group_rule" "ssh" {
8089
from_port = 22
8190
protocol = "TCP"
8291
security_group_id = aws_security_group.controller.id
83-
source_security_group_id = join("", aws_security_group.bastion[*].id)
92+
source_security_group_id = one(aws_security_group.bastion[*].id)
8493
to_port = 22
8594
type = "ingress"
8695
}
@@ -116,7 +125,8 @@ resource "aws_security_group" "postgresql" {
116125
}
117126

118127
module "alb" {
119-
source = "terraform-aws-modules/alb/aws"
128+
source = "terraform-aws-modules/alb/aws"
129+
version = "~> 6.5"
120130

121131
http_tcp_listeners = [
122132
{
@@ -148,7 +158,8 @@ resource "random_password" "postgresql" {
148158
}
149159

150160
module "postgresql" {
151-
source = "terraform-aws-modules/rds/aws"
161+
source = "terraform-aws-modules/rds/aws"
162+
version = "~> 3.4"
152163

153164
allocated_storage = 5
154165
backup_retention_period = 0
@@ -321,5 +332,5 @@ resource "aws_instance" "bastion" {
321332
key_name = var.key_name
322333
subnet_id = var.public_subnets[0]
323334
tags = merge(var.tags, { Name = "Boundary Bastion" })
324-
vpc_security_group_ids = [join("", aws_security_group.bastion[*].id)]
335+
vpc_security_group_ids = [one(aws_security_group.bastion[*].id)]
325336
}

modules/controller/outputs.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
output "bastion_security_group" {
22
description = "The ID of the bastion security group"
3-
value = join("", aws_security_group.bastion[*].id)
3+
value = one(aws_security_group.bastion[*].id)
44
}
55

66
output "dns_name" {
77
description = "The public DNS name of the load balancer"
8-
value = module.alb.this_lb_dns_name
8+
value = module.alb.lb_dns_name
99
}
1010

1111
output "ip_addresses" {

modules/worker/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
22
## Requirements
33

4-
No requirements.
4+
| Name | Version |
5+
|------|---------|
6+
| aws | ~> 3.0 |
57

68
## Providers
79

810
| Name | Version |
911
|------|---------|
10-
| aws | n/a |
12+
| aws | ~> 3.0 |
1113

1214
## Inputs
1315

modules/worker/main.tf

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 3.0"
6+
}
7+
}
8+
}
9+
110
locals {
211
configuration = templatefile(
312
"${path.module}/templates/configuration.hcl.tpl",

0 commit comments

Comments
 (0)