Skip to content

Commit 8dc85b9

Browse files
committed
feat: Bump MSV of Terraform and AWS provider, update attribute lookup syntax, change policies from list to map
1 parent c478369 commit 8dc85b9

File tree

11 files changed

+226
-210
lines changed

11 files changed

+226
-210
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
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.96.1
3+
rev: v1.96.2
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_docs

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,14 @@ Examples codified under the [`examples`](https://github.com/terraform-aws-module
163163

164164
| Name | Version |
165165
|------|---------|
166-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
167-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0 |
166+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
167+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.78 |
168168

169169
## Providers
170170

171171
| Name | Version |
172172
|------|---------|
173-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0 |
173+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.78 |
174174

175175
## Modules
176176

@@ -207,7 +207,7 @@ No modules.
207207
| <a name="input_create_job_queues"></a> [create\_job\_queues](#input\_create\_job\_queues) | Determines whether to create job queues | `bool` | `true` | no |
208208
| <a name="input_create_service_iam_role"></a> [create\_service\_iam\_role](#input\_create\_service\_iam\_role) | Determines whether a an IAM role is created or to use an existing IAM role | `bool` | `true` | no |
209209
| <a name="input_create_spot_fleet_iam_role"></a> [create\_spot\_fleet\_iam\_role](#input\_create\_spot\_fleet\_iam\_role) | Determines whether a an IAM role is created or to use an existing IAM role | `bool` | `false` | no |
210-
| <a name="input_instance_iam_role_additional_policies"></a> [instance\_iam\_role\_additional\_policies](#input\_instance\_iam\_role\_additional\_policies) | Additional policies to be added to the IAM role | `list(string)` | `[]` | no |
210+
| <a name="input_instance_iam_role_additional_policies"></a> [instance\_iam\_role\_additional\_policies](#input\_instance\_iam\_role\_additional\_policies) | Additional policies to be added to the IAM role | `map(string)` | `{}` | no |
211211
| <a name="input_instance_iam_role_description"></a> [instance\_iam\_role\_description](#input\_instance\_iam\_role\_description) | Cluster instance IAM role description | `string` | `null` | no |
212212
| <a name="input_instance_iam_role_name"></a> [instance\_iam\_role\_name](#input\_instance\_iam\_role\_name) | Cluster instance IAM role name | `string` | `null` | no |
213213
| <a name="input_instance_iam_role_path"></a> [instance\_iam\_role\_path](#input\_instance\_iam\_role\_path) | Cluster instance IAM role path | `string` | `null` | no |
@@ -216,14 +216,14 @@ No modules.
216216
| <a name="input_instance_iam_role_use_name_prefix"></a> [instance\_iam\_role\_use\_name\_prefix](#input\_instance\_iam\_role\_use\_name\_prefix) | Determines whether the IAM role name (`instance_iam_role_name`) is used as a prefix | `string` | `true` | no |
217217
| <a name="input_job_definitions"></a> [job\_definitions](#input\_job\_definitions) | Map of job definitions to create | `any` | `{}` | no |
218218
| <a name="input_job_queues"></a> [job\_queues](#input\_job\_queues) | Map of job queue and scheduling policy defintions to create | `any` | `{}` | no |
219-
| <a name="input_service_iam_role_additional_policies"></a> [service\_iam\_role\_additional\_policies](#input\_service\_iam\_role\_additional\_policies) | Additional policies to be added to the IAM role | `list(string)` | `[]` | no |
219+
| <a name="input_service_iam_role_additional_policies"></a> [service\_iam\_role\_additional\_policies](#input\_service\_iam\_role\_additional\_policies) | Additional policies to be added to the IAM role | `map(string)` | `{}` | no |
220220
| <a name="input_service_iam_role_description"></a> [service\_iam\_role\_description](#input\_service\_iam\_role\_description) | Batch service IAM role description | `string` | `null` | no |
221221
| <a name="input_service_iam_role_name"></a> [service\_iam\_role\_name](#input\_service\_iam\_role\_name) | Batch service IAM role name | `string` | `null` | no |
222222
| <a name="input_service_iam_role_path"></a> [service\_iam\_role\_path](#input\_service\_iam\_role\_path) | Batch service IAM role path | `string` | `null` | no |
223223
| <a name="input_service_iam_role_permissions_boundary"></a> [service\_iam\_role\_permissions\_boundary](#input\_service\_iam\_role\_permissions\_boundary) | ARN of the policy that is used to set the permissions boundary for the IAM role | `string` | `null` | no |
224224
| <a name="input_service_iam_role_tags"></a> [service\_iam\_role\_tags](#input\_service\_iam\_role\_tags) | A map of additional tags to add to the IAM role created | `map(string)` | `{}` | no |
225225
| <a name="input_service_iam_role_use_name_prefix"></a> [service\_iam\_role\_use\_name\_prefix](#input\_service\_iam\_role\_use\_name\_prefix) | Determines whether the IAM role name (`service_iam_role_name`) is used as a prefix | `bool` | `true` | no |
226-
| <a name="input_spot_fleet_iam_role_additional_policies"></a> [spot\_fleet\_iam\_role\_additional\_policies](#input\_spot\_fleet\_iam\_role\_additional\_policies) | Additional policies to be added to the IAM role | `list(string)` | `[]` | no |
226+
| <a name="input_spot_fleet_iam_role_additional_policies"></a> [spot\_fleet\_iam\_role\_additional\_policies](#input\_spot\_fleet\_iam\_role\_additional\_policies) | Additional policies to be added to the IAM role | `map(string)` | `{}` | no |
227227
| <a name="input_spot_fleet_iam_role_description"></a> [spot\_fleet\_iam\_role\_description](#input\_spot\_fleet\_iam\_role\_description) | Spot fleet IAM role description | `string` | `null` | no |
228228
| <a name="input_spot_fleet_iam_role_name"></a> [spot\_fleet\_iam\_role\_name](#input\_spot\_fleet\_iam\_role\_name) | Spot fleet IAM role name | `string` | `null` | no |
229229
| <a name="input_spot_fleet_iam_role_path"></a> [spot\_fleet\_iam\_role\_path](#input\_spot\_fleet\_iam\_role\_path) | Spot fleet IAM role path | `string` | `null` | no |

examples/ec2/README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,30 @@ Note that this example may create resources which will incur monetary charges on
2424

2525
| Name | Version |
2626
|------|---------|
27-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
28-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0 |
27+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
28+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.78 |
2929

3030
## Providers
3131

3232
| Name | Version |
3333
|------|---------|
34-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0 |
34+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.78 |
3535

3636
## Modules
3737

3838
| Name | Source | Version |
3939
|------|--------|---------|
4040
| <a name="module_batch"></a> [batch](#module\_batch) | ../.. | n/a |
4141
| <a name="module_batch_disabled"></a> [batch\_disabled](#module\_batch\_disabled) | ../.. | n/a |
42-
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 4.0 |
43-
| <a name="module_vpc_endpoint_security_group"></a> [vpc\_endpoint\_security\_group](#module\_vpc\_endpoint\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
44-
| <a name="module_vpc_endpoints"></a> [vpc\_endpoints](#module\_vpc\_endpoints) | terraform-aws-modules/vpc/aws//modules/vpc-endpoints | ~> 4.0 |
42+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |
43+
| <a name="module_vpc_endpoints"></a> [vpc\_endpoints](#module\_vpc\_endpoints) | terraform-aws-modules/vpc/aws//modules/vpc-endpoints | ~> 5.0 |
4544

4645
## Resources
4746

4847
| Name | Type |
4948
|------|------|
5049
| [aws_cloudwatch_log_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource |
51-
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
50+
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
5251

5352
## Inputs
5453

examples/ec2/main.tf

Lines changed: 48 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ provider "aws" {
22
region = local.region
33
}
44

5+
data "aws_availability_zones" "available" {}
6+
57
locals {
68
region = "us-east-1"
7-
name = "batch-ex-${replace(basename(path.cwd), "_", "-")}"
9+
name = "batch-ex-${basename(path.cwd)}"
10+
11+
vpc_cidr = "10.0.0.0/16"
12+
azs = slice(data.aws_availability_zones.available.names, 0, 3)
813

914
tags = {
1015
Name = local.name
@@ -13,8 +18,6 @@ locals {
1318
}
1419
}
1520

16-
data "aws_region" "current" {}
17-
1821
################################################################################
1922
# Batch Module
2023
################################################################################
@@ -31,9 +34,9 @@ module "batch" {
3134
instance_iam_role_name = "${local.name}-ecs-instance"
3235
instance_iam_role_path = "/batch/"
3336
instance_iam_role_description = "IAM instance role/profile for AWS Batch ECS instance(s)"
34-
instance_iam_role_additional_policies = [
35-
"arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
36-
]
37+
instance_iam_role_additional_policies = {
38+
AmazonSSMManagedInstanceCore = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
39+
}
3740
instance_iam_role_tags = {
3841
ModuleCreatedRole = "Yes"
3942
}
@@ -64,7 +67,7 @@ module "batch" {
6467
desired_vcpus = 4
6568
instance_types = ["m5.large", "r5.large"]
6669

67-
security_group_ids = [module.vpc_endpoint_security_group.security_group_id]
70+
security_group_ids = [module.vpc_endpoints.security_group_id]
6871
subnets = module.vpc.private_subnets
6972

7073
# Note - any tag changes here will force compute environment replacement
@@ -91,7 +94,7 @@ module "batch" {
9194
desired_vcpus = 4
9295
instance_types = ["m4.large", "m3.large", "r4.large", "r3.large"]
9396

94-
security_group_ids = [module.vpc_endpoint_security_group.security_group_id]
97+
security_group_ids = [module.vpc_endpoints.security_group_id]
9598
subnets = module.vpc.private_subnets
9699

97100
# Note - any tag changes here will force compute environment replacement
@@ -201,88 +204,60 @@ module "batch" {
201204

202205
module "vpc" {
203206
source = "terraform-aws-modules/vpc/aws"
204-
version = "~> 4.0"
207+
version = "~> 5.0"
205208

206209
name = local.name
207-
cidr = "10.99.0.0/18"
210+
cidr = local.vpc_cidr
208211

209-
azs = ["${local.region}a", "${local.region}b", "${local.region}c"]
210-
public_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"]
211-
private_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"]
212+
azs = local.azs
213+
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 4, k)]
214+
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 48)]
212215

213216
enable_nat_gateway = true
214217
single_nat_gateway = true
215218

216-
public_route_table_tags = { Name = "${local.name}-public" }
217-
public_subnet_tags = { Name = "${local.name}-public" }
218-
private_route_table_tags = { Name = "${local.name}-private" }
219-
private_subnet_tags = { Name = "${local.name}-private" }
220-
221-
enable_dhcp_options = true
222-
enable_dns_hostnames = true
223-
dhcp_options_domain_name = data.aws_region.current.name == "us-east-1" ? "ec2.internal" : "${data.aws_region.current.name}.compute.internal"
224-
225219
tags = local.tags
226220
}
227221

228222
module "vpc_endpoints" {
229223
source = "terraform-aws-modules/vpc/aws//modules/vpc-endpoints"
230-
version = "~> 4.0"
231-
232-
vpc_id = module.vpc.vpc_id
233-
security_group_ids = [module.vpc_endpoint_security_group.security_group_id]
234-
235-
endpoints = {
236-
ecr_api = {
237-
service = "ecr.api"
238-
private_dns_enabled = true
239-
subnet_ids = module.vpc.private_subnets
240-
}
241-
ecr_dkr = {
242-
service = "ecr.dkr"
243-
private_dns_enabled = true
244-
subnet_ids = module.vpc.private_subnets
245-
}
246-
ecs = {
247-
service = "ecs"
248-
private_dns_enabled = true
249-
subnet_ids = module.vpc.private_subnets
250-
}
251-
ssm = {
252-
service = "ssm"
253-
private_dns_enabled = true
254-
subnet_ids = module.vpc.private_subnets
255-
}
256-
s3 = {
257-
service = "s3"
258-
service_type = "Gateway"
259-
route_table_ids = module.vpc.private_route_table_ids
224+
version = "~> 5.0"
225+
226+
vpc_id = module.vpc.vpc_id
227+
228+
# Security group
229+
create_security_group = true
230+
security_group_name_prefix = "${local.name}-vpc-endpoints-"
231+
security_group_description = "VPC endpoint security group"
232+
security_group_rules = {
233+
ingress_https = {
234+
description = "HTTPS from VPC"
235+
cidr_blocks = [module.vpc.vpc_cidr_block]
260236
}
261237
}
262238

263-
tags = local.tags
264-
}
265-
266-
module "vpc_endpoint_security_group" {
267-
source = "terraform-aws-modules/security-group/aws"
268-
version = "~> 4.0"
269-
270-
name = "${local.name}-vpc-endpoint"
271-
description = "Security group for VPC endpoints"
272-
vpc_id = module.vpc.vpc_id
273-
274-
ingress_with_self = [
239+
endpoints = merge(
275240
{
276-
from_port = 443
277-
to_port = 443
278-
protocol = "tcp"
279-
description = "Container to VPC endpoint service"
280-
self = true
241+
s3 = {
242+
service = "s3"
243+
service_type = "Gateway"
244+
route_table_ids = module.vpc.private_route_table_ids
245+
tags = {
246+
Name = "${local.name}-s3"
247+
}
248+
}
281249
},
282-
]
283-
284-
egress_cidr_blocks = ["0.0.0.0/0"]
285-
egress_rules = ["https-443-tcp"]
250+
{
251+
for service in toset(["ecr.api", "ecr.dkr", "ecs", "ssm"]) :
252+
replace(service, ".", "_") =>
253+
{
254+
service = service
255+
subnet_ids = module.vpc.private_subnets
256+
private_dns_enabled = true
257+
tags = { Name = "${local.name}-${service}" }
258+
}
259+
}
260+
)
286261

287262
tags = local.tags
288263
}

examples/ec2/versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
2-
required_version = ">= 1.0"
2+
required_version = ">= 1.3"
33

44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 4.0"
7+
version = ">= 5.78"
88
}
99
}
1010
}

examples/fargate/README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,23 @@ Note that this example may create resources which will incur monetary charges on
2424

2525
| Name | Version |
2626
|------|---------|
27-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
28-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0 |
27+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
28+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.78 |
2929

3030
## Providers
3131

3232
| Name | Version |
3333
|------|---------|
34-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0 |
34+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.78 |
3535

3636
## Modules
3737

3838
| Name | Source | Version |
3939
|------|--------|---------|
4040
| <a name="module_batch"></a> [batch](#module\_batch) | ../.. | n/a |
4141
| <a name="module_batch_disabled"></a> [batch\_disabled](#module\_batch\_disabled) | ../.. | n/a |
42-
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 4.0 |
43-
| <a name="module_vpc_endpoint_security_group"></a> [vpc\_endpoint\_security\_group](#module\_vpc\_endpoint\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
44-
| <a name="module_vpc_endpoints"></a> [vpc\_endpoints](#module\_vpc\_endpoints) | terraform-aws-modules/vpc/aws//modules/vpc-endpoints | ~> 4.0 |
42+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |
43+
| <a name="module_vpc_endpoints"></a> [vpc\_endpoints](#module\_vpc\_endpoints) | terraform-aws-modules/vpc/aws//modules/vpc-endpoints | ~> 5.0 |
4544

4645
## Resources
4746

@@ -50,8 +49,8 @@ Note that this example may create resources which will incur monetary charges on
5049
| [aws_cloudwatch_log_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource |
5150
| [aws_iam_role.ecs_task_execution_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
5251
| [aws_iam_role_policy_attachment.ecs_task_execution_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
52+
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
5353
| [aws_iam_policy_document.ecs_task_execution_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
54-
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
5554

5655
## Inputs
5756

0 commit comments

Comments
 (0)