Skip to content

Commit bfd5ed3

Browse files
authored
feat!: Upgrade AWS provider and min required Terraform version to 6.0 and 1.10 respectively (#436)
1 parent 5b17f94 commit bfd5ed3

File tree

21 files changed

+1181
-918
lines changed

21 files changed

+1181
-918
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.98.0
3+
rev: v1.99.4
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_wrapper_module_for_each

README.md

Lines changed: 66 additions & 48 deletions
Large diffs are not rendered by default.

UPGRADE-3.0.md renamed to docs/UPGRADE-3.0.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
If you have any questions regarding this upgrade process, please consult the `examples` directory:
44

55
- [Complete](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/tree/master/examples/complete)
6-
- [Volume Attachment](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/tree/master/examples/volume-attachment)
76

87
If you find a bug, please open an issue with supporting configuration to reproduce.
98

docs/UPGRADE-6.0.md

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# Upgrade from v5.x to v6.x
2+
3+
If you have any questions regarding this upgrade process, please consult the `examples` directory:
4+
5+
- [Complete](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/tree/master/examples/complete)
6+
7+
If you find a bug, please open an issue with supporting configuration to reproduce.
8+
9+
## List of backwards incompatible changes
10+
11+
- Terraform v1.10.0 is now minimum supported version
12+
- AWS provider v6.0.0 is now minimum supported version
13+
- The default value for `ami_ssm_parameter` was changed from `"/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2"` to `"/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64"`. AL2 is approaching end of life.
14+
15+
## Additional changes
16+
17+
### Added
18+
19+
- Support for creating a security group within the module; this is now the default behavior and can be disabled by setting `create_security_group = false`.
20+
- Support for `region` parameter to specify the AWS region for the resources created if different from the provider region.
21+
- Support for tagging spot instances
22+
23+
### Modified
24+
25+
- Variable definitions now contain detailed `object` types in place of the previously used `any` type.
26+
- Inline `ebs_block_device` argument has been removed in favor of `ebs_volumes` which is a map of EBS volumes created through `aws_ebs_volume` and `aws_ebs_volume_attachment` resources. This provides the same API as before, but allows for more flexibility without generating diffs when adding or removing EBS volumes as well as unintended changes to the volumes.
27+
- Correct tag precedence ordering (least specific to most specific)
28+
29+
### Removed
30+
31+
- The `volume-attachment` example has been removed since the module has been updated to use the corrected form of EBS volume creation and attachment (tl;dr - example is no longer useful).
32+
33+
### Variable and output changes
34+
35+
1. Removed variables:
36+
37+
- `cpu_core_count` - removed from provider `v6.x`
38+
- `cpu_threads_per_core` - removed from provider `v6.x`
39+
40+
2. Renamed variables:
41+
42+
- `ebs_block_device` -> `ebs_volumes`
43+
44+
3. Added variables:
45+
46+
- `region`
47+
- `enable_primary_ipv6`
48+
- `host_resource_group_arn`
49+
- `instance_market_options`
50+
- `placement_partition_number`
51+
- `create_security_group`
52+
- `security_group_name`
53+
- `security_group_use_name_prefix`
54+
- `security_group_description`
55+
- `security_group_vpc_id`
56+
- `security_group_tags`
57+
- `security_group_egress_rules`
58+
- `security_group_ingress_rules`
59+
60+
4. Removed outputs:
61+
62+
- None
63+
64+
5. Renamed outputs:
65+
66+
- None
67+
68+
6. Added outputs:
69+
70+
- `ebs_volumes`
71+
72+
## Upgrade State Migrations
73+
74+
### Before 5.x Example
75+
76+
```hcl
77+
module "ec2_upgrade" {
78+
source = "terraform-aws-modules/ec2-instance/aws"
79+
version = "5.8.0"
80+
81+
# Truncated for brevity, only relevant module API changes are shown ...
82+
83+
root_block_device = [
84+
{
85+
encrypted = true
86+
volume_size = 50
87+
volume_type = "gp3"
88+
throughput = 200
89+
tags = {
90+
Name = "my-root-block"
91+
}
92+
},
93+
]
94+
95+
ebs_block_device = [
96+
{
97+
device_name = "/dev/sdf"
98+
encrypted = true
99+
volume_size = 5
100+
volume_type = "gp3"
101+
throughput = 200
102+
tags = {
103+
MountPoint = "/mnt/data"
104+
}
105+
}
106+
]
107+
108+
network_interface = [
109+
{
110+
device_index = 0
111+
network_interface_id = aws_network_interface.this.id
112+
delete_on_termination = false
113+
}
114+
]
115+
116+
tags = local.tags
117+
}
118+
```
119+
120+
### After 6.x Example
121+
122+
```hcl
123+
module "ec2_upgrade" {
124+
source = "terraform-aws-modules/ec2-instance/aws"
125+
version = "6.0.0"
126+
127+
# Truncated for brevity, only relevant module API changes are shown ...
128+
129+
# There can only be one root block device, so the wrapping list is removed
130+
root_block_device = {
131+
encrypted = true
132+
size = 50 # Was `volume_size`
133+
type = "gp3" # Was `volume_type`
134+
throughput = 200
135+
tags = {
136+
Name = "my-root-block"
137+
}
138+
}
139+
140+
# Now a map of EBS volumes is used instead of a list
141+
ebs_volumes = {
142+
# The device_name can be the key of the map, or set by `device_name` attribute
143+
"/dev/sdf" = {
144+
encrypted = true
145+
size = 5 # Was `volume_size`
146+
type = "gp3" # Was `volume_type`, `gp3` is now the default
147+
throughput = 200
148+
tags = {
149+
MountPoint = "/mnt/data"
150+
}
151+
}
152+
}
153+
154+
# Now a map of network interfaces is used instead of a list
155+
network_interface = {
156+
# The device_index can be the key of the map, or set by `device_index` attribute
157+
0 = {
158+
network_interface_id = aws_network_interface.this.id
159+
delete_on_termination = false
160+
}
161+
}
162+
163+
tags = local.tags
164+
}
165+
```
166+
167+
To migrate from the `v5.x` version to `v6.x` version example shown above, the following state move commands can be performed to maintain the current resources without modification:
168+
169+
> [!NOTE]
170+
> State move commands should only be required on instances that have additional EBS volumes attached to them.
171+
172+
```bash
173+
terraform state rm 'module.ec2_complete.aws_instance.this[0]'
174+
terraform import 'module.ec2_complete.aws_instance.this[0]' <INSTANCE_ID>
175+
176+
# Do the following for each additional EBS volume attached to the instance
177+
terraform import 'module.ec2_complete.aws_ebs_volume.this["/dev/sdf"]' <VOLUME_ID>
178+
terraform import 'module.ec2_complete.aws_volume_attachment.this["/dev/sdf"]' <DEVICE_NAME>:<VOLUME_ID>:<INSTANCE_ID>
179+
```
180+
181+
> [!TIP]
182+
> If you encounter a situation where Terraform wants to recreate the instance due to user data changes, you can set the `user_data_replace_on_change` variable to `false` to prevent this behavior.
183+
> This is related to https://github.com/hashicorp/terraform-provider-aws/issues/5011

examples/complete/README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,20 @@ 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) | >= 1.0 |
23-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.66 |
22+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.10 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.0 |
2424

2525
## Providers
2626

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

3131
## Modules
3232

3333
| Name | Source | Version |
3434
|------|--------|---------|
3535
| <a name="module_ec2_complete"></a> [ec2\_complete](#module\_ec2\_complete) | ../../ | n/a |
36-
| <a name="module_ec2_cpu_options"></a> [ec2\_cpu\_options](#module\_ec2\_cpu\_options) | ../../ | n/a |
3736
| <a name="module_ec2_disabled"></a> [ec2\_disabled](#module\_ec2\_disabled) | ../../ | n/a |
3837
| <a name="module_ec2_ignore_ami_changes"></a> [ec2\_ignore\_ami\_changes](#module\_ec2\_ignore\_ami\_changes) | ../../ | n/a |
3938
| <a name="module_ec2_metadata_options"></a> [ec2\_metadata\_options](#module\_ec2\_metadata\_options) | ../../ | n/a |
@@ -44,8 +43,8 @@ Note that this example may create resources which can cost money. Run `terraform
4443
| <a name="module_ec2_t2_unlimited"></a> [ec2\_t2\_unlimited](#module\_ec2\_t2\_unlimited) | ../../ | n/a |
4544
| <a name="module_ec2_t3_unlimited"></a> [ec2\_t3\_unlimited](#module\_ec2\_t3\_unlimited) | ../../ | n/a |
4645
| <a name="module_ec2_targeted_capacity_reservation"></a> [ec2\_targeted\_capacity\_reservation](#module\_ec2\_targeted\_capacity\_reservation) | ../../ | n/a |
47-
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
48-
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |
46+
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 5.0 |
47+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 6.0 |
4948

5049
## Resources
5150

@@ -57,7 +56,6 @@ Note that this example may create resources which can cost money. Run `terraform
5756
| [aws_network_interface.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/network_interface) | resource |
5857
| [aws_placement_group.web](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/placement_group) | resource |
5958
| [aws_ami.amazon_linux](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |
60-
| [aws_ami.amazon_linux_23](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |
6159
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
6260

6361
## Inputs

0 commit comments

Comments
 (0)