Skip to content

Commit 9d4e0ca

Browse files
authored
feat!: Raise minimum required Terraform version to 1.0+ (#331)
1 parent 7ffbfc3 commit 9d4e0ca

File tree

15 files changed

+511
-227
lines changed

15 files changed

+511
-227
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.77.0
3+
rev: v1.77.3
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_wrapper_module_for_each

README.md

Lines changed: 21 additions & 25 deletions
Large diffs are not rendered by default.

examples/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Examples
2+
3+
Please note - the examples provided serve two primary means:
4+
5+
1. Show users working examples of the various ways in which the module can be configured and features supported
6+
2. A means of testing/validating module changes
7+
8+
Please do not mistake the examples provided as "best practices". It is up to users to consult the AWS service documentation for best practices, usage recommendations, etc.

examples/complete/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ Note that this example may create resources which can cost money. Run `terraform
1919

2020
| Name | Version |
2121
|------|---------|
22-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
23-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.7 |
22+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.20 |
2424

2525
## Providers
2626

2727
| Name | Version |
2828
|------|---------|
29-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.7 |
29+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.20 |
3030

3131
## Modules
3232

@@ -43,7 +43,7 @@ Note that this example may create resources which can cost money. Run `terraform
4343
| <a name="module_ec2_t3_unlimited"></a> [ec2\_t3\_unlimited](#module\_ec2\_t3\_unlimited) | ../../ | n/a |
4444
| <a name="module_ec2_targeted_capacity_reservation"></a> [ec2\_targeted\_capacity\_reservation](#module\_ec2\_targeted\_capacity\_reservation) | ../../ | n/a |
4545
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
46-
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
46+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 4.0 |
4747

4848
## Resources
4949

@@ -55,6 +55,7 @@ Note that this example may create resources which can cost money. Run `terraform
5555
| [aws_network_interface.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/network_interface) | resource |
5656
| [aws_placement_group.web](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/placement_group) | resource |
5757
| [aws_ami.amazon_linux](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |
58+
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
5859

5960
## Inputs
6061

examples/complete/main.tf

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

5+
data "aws_availability_zones" "available" {}
6+
57
locals {
6-
name = "example-ec2-complete"
8+
name = "ex-${basename(path.cwd)}"
79
region = "eu-west-1"
810

11+
vpc_cidr = "10.0.0.0/16"
12+
azs = slice(data.aws_availability_zones.available.names, 0, 3)
13+
914
user_data = <<-EOT
10-
#!/bin/bash
11-
echo "Hello Terraform!"
15+
#!/bin/bash
16+
echo "Hello Terraform!"
1217
EOT
1318

1419
tags = {
15-
Owner = "user"
16-
Environment = "dev"
20+
Name = local.name
21+
Example = local.name
22+
Repository = "https://github.com/terraform-aws-modules/terraform-aws-ec2-instance"
1723
}
1824
}
1925

2026
################################################################################
2127
# EC2 Module
2228
################################################################################
2329

24-
module "ec2_disabled" {
25-
source = "../../"
26-
27-
create = false
28-
}
29-
3030
module "ec2_complete" {
3131
source = "../../"
3232

@@ -153,6 +153,13 @@ module "ec2_t3_unlimited" {
153153
tags = local.tags
154154
}
155155

156+
157+
module "ec2_disabled" {
158+
source = "../../"
159+
160+
create = false
161+
}
162+
156163
################################################################################
157164
# EC2 Module - multiple instances with `for_each`
158165
################################################################################
@@ -333,15 +340,14 @@ resource "aws_ec2_capacity_reservation" "targeted" {
333340

334341
module "vpc" {
335342
source = "terraform-aws-modules/vpc/aws"
336-
version = "~> 3.0"
343+
version = "~> 4.0"
337344

338345
name = local.name
339-
cidr = "10.99.0.0/18"
346+
cidr = local.vpc_cidr
340347

341-
azs = ["${local.region}a", "${local.region}b", "${local.region}c"]
342-
public_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"]
343-
private_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"]
344-
database_subnets = ["10.99.7.0/24", "10.99.8.0/24", "10.99.9.0/24"]
348+
azs = local.azs
349+
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 4, k)]
350+
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 48)]
345351

346352
tags = local.tags
347353
}

examples/complete/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 = ">= 0.13.1"
2+
required_version = ">= 1.0"
33

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

examples/volume-attachment/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ Note that this example may create resources which can cost money. Run `terraform
2121

2222
| Name | Version |
2323
|------|---------|
24-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
25-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.72 |
24+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
25+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.20 |
2626

2727
## Providers
2828

2929
| Name | Version |
3030
|------|---------|
31-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.72 |
31+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.20 |
3232

3333
## Modules
3434

3535
| Name | Source | Version |
3636
|------|--------|---------|
3737
| <a name="module_ec2"></a> [ec2](#module\_ec2) | ../../ | n/a |
3838
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
39-
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
39+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 4.0 |
4040

4141
## Resources
4242

@@ -45,6 +45,7 @@ Note that this example may create resources which can cost money. Run `terraform
4545
| [aws_ebs_volume.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ebs_volume) | resource |
4646
| [aws_volume_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/volume_attachment) | resource |
4747
| [aws_ami.amazon_linux](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |
48+
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
4849

4950
## Inputs
5051

examples/volume-attachment/main.tf

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

5+
data "aws_availability_zones" "available" {}
6+
57
locals {
6-
availability_zone = "${local.region}a"
7-
name = "example-ec2-volume-attachment"
8-
region = "eu-west-1"
8+
name = "ex-${basename(path.cwd)}"
9+
region = "eu-west-1"
10+
11+
vpc_cidr = "10.0.0.0/16"
12+
azs = slice(data.aws_availability_zones.available.names, 0, 3)
13+
914
tags = {
10-
Owner = "user"
11-
Environment = "dev"
15+
Name = local.name
16+
Example = local.name
17+
Repository = "https://github.com/terraform-aws-modules/terraform-aws-ec2-instance"
1218
}
1319
}
1420

21+
################################################################################
22+
# EC2 Module
23+
################################################################################
24+
25+
module "ec2" {
26+
source = "../../"
27+
28+
name = local.name
29+
30+
ami = data.aws_ami.amazon_linux.id
31+
instance_type = "c5.large"
32+
availability_zone = element(local.azs, 0)
33+
subnet_id = element(module.vpc.private_subnets, 0)
34+
vpc_security_group_ids = [module.security_group.security_group_id]
35+
associate_public_ip_address = true
36+
37+
tags = local.tags
38+
}
39+
40+
resource "aws_volume_attachment" "this" {
41+
device_name = "/dev/sdh"
42+
volume_id = aws_ebs_volume.this.id
43+
instance_id = module.ec2.id
44+
}
45+
46+
resource "aws_ebs_volume" "this" {
47+
availability_zone = element(local.azs, 0)
48+
size = 1
49+
50+
tags = local.tags
51+
}
52+
1553
################################################################################
1654
# Supporting Resources
1755
################################################################################
1856

1957
module "vpc" {
2058
source = "terraform-aws-modules/vpc/aws"
21-
version = "~> 3.0"
59+
version = "~> 4.0"
2260

2361
name = local.name
24-
cidr = "10.99.0.0/18"
62+
cidr = local.vpc_cidr
2563

26-
azs = ["${local.region}a", "${local.region}b", "${local.region}c"]
27-
public_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"]
28-
private_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"]
29-
database_subnets = ["10.99.7.0/24", "10.99.8.0/24", "10.99.9.0/24"]
64+
azs = local.azs
65+
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 4, k)]
66+
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 48)]
3067

3168
tags = local.tags
3269
}
@@ -55,35 +92,3 @@ module "security_group" {
5592

5693
tags = local.tags
5794
}
58-
59-
################################################################################
60-
# EC2 Module
61-
################################################################################
62-
63-
module "ec2" {
64-
source = "../../"
65-
66-
name = local.name
67-
68-
ami = data.aws_ami.amazon_linux.id
69-
instance_type = "c5.large"
70-
availability_zone = local.availability_zone
71-
subnet_id = element(module.vpc.private_subnets, 0)
72-
vpc_security_group_ids = [module.security_group.security_group_id]
73-
associate_public_ip_address = true
74-
75-
tags = local.tags
76-
}
77-
78-
resource "aws_volume_attachment" "this" {
79-
device_name = "/dev/sdh"
80-
volume_id = aws_ebs_volume.this.id
81-
instance_id = module.ec2.id
82-
}
83-
84-
resource "aws_ebs_volume" "this" {
85-
availability_zone = local.availability_zone
86-
size = 1
87-
88-
tags = local.tags
89-
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
2-
required_version = ">= 0.13.1"
2+
required_version = ">= 1.0"
33

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

0 commit comments

Comments
 (0)