Skip to content

Commit 2d92dfe

Browse files
authored
BREAKING CHANGE: update module to include latest features and remove use of count for module count/for_each (#234)
1 parent 0817d0e commit 2d92dfe

22 files changed

+1038
-744
lines changed

.github/workflows/pre-commit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
- name: Install pre-commit dependencies
9292
run: |
9393
pip install pre-commit
94-
curl -Lo ./terraform-docs.tar.gz https://github.com/terraform-docs/terraform-docs/releases/download/v0.13.0/terraform-docs-v0.13.0-$(uname)-amd64.tar.gz && tar -xzf terraform-docs.tar.gz && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/
94+
curl -Lo ./terraform-docs.tar.gz https://github.com/terraform-docs/terraform-docs/releases/download/v0.13.0/terraform-docs-v0.13.0-$(uname)-amd64.tar.gz && tar -xzf terraform-docs.tar.gz terraform-docs && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/
9595
curl -L "$(curl -s https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.zip")" > tflint.zip && unzip tflint.zip && rm tflint.zip && sudo mv tflint /usr/bin/
9696
- name: Execute pre-commit
9797
# Run all pre-commit checks on max version supported

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ repos:
2121
- '--args=--only=terraform_standard_module_structure'
2222
- '--args=--only=terraform_workspace_remote'
2323
- repo: git://github.com/pre-commit/pre-commit-hooks
24-
rev: v3.4.0
24+
rev: v4.0.1
2525
hooks:
2626
- id: check-merge-conflict

README.md

Lines changed: 72 additions & 55 deletions
Large diffs are not rendered by default.

UPGRADE-3.0.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Upgrade from v2.x to v3.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+
- [Volume Attachment](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/tree/master/examples/volume-attachment)
7+
8+
If you find a bug, please open an issue with supporting configuration to reproduce.
9+
10+
## List of backwards incompatible changes
11+
12+
- Terraform v0.13.1 is now minimum supported version to take advantage of `count` and `for_each` arguments at module level
13+
14+
### Variable and output changes
15+
16+
1. Removed variables:
17+
18+
- `instance_count`
19+
- `subnet_ids` (only need to use `subnet_id` now)
20+
- `private_ips` (only need to use `private_ip` now)
21+
- `use_num_suffix`
22+
- `num_suffix_format`
23+
24+
2. Renamed variables:
25+
26+
- `tags` -> `tags_all`
27+
28+
3. Removed outputs:
29+
30+
- `availability_zone`
31+
- `placement_group`
32+
- `key_name`
33+
- `ipv6_addresses`
34+
- `private_ip`
35+
- `security_groups`
36+
- `vpc_security_group_ids`
37+
- `subnet_id`
38+
- `credit_specification`
39+
- `metadata_options`
40+
- `root_block_device_volume_ids`
41+
- `ebs_block_device_volume_ids`
42+
- `volume_tags`
43+
- `instance_count`
44+
45+
4. Renamed outputs:
46+
47+
:info: All outputs used to be lists, and are now singular outputs due to the removal of `count`
48+
49+
## Upgrade State Migrations
50+
51+
### Before 2.x Example
52+
53+
```hcl
54+
module "ec2_upgrade" {
55+
source = "terraform-aws-modules/ec2-instance/aws"
56+
version = "2.21.0"
57+
58+
instance_count = 3
59+
60+
name = local.name
61+
ami = data.aws_ami.amazon_linux.id
62+
instance_type = "c5.large"
63+
subnet_ids = module.vpc.private_subnets
64+
vpc_security_group_ids = [module.security_group.security_group_id]
65+
associate_public_ip_address = true
66+
67+
tags = local.tags
68+
}
69+
```
70+
71+
### After 3.x Example
72+
73+
```hcl
74+
locals {
75+
num_suffix_format = "-%d"
76+
multiple_instances = {
77+
0 = {
78+
num_suffix = 1
79+
instance_type = "c5.large"
80+
subnet_id = element(module.vpc.private_subnets, 0)
81+
}
82+
1 = {
83+
num_suffix = 2
84+
instance_type = "c5.large"
85+
subnet_id = element(module.vpc.private_subnets, 1)
86+
}
87+
2 = {
88+
num_suffix = 3
89+
instance_type = "c5.large"
90+
subnet_id = element(module.vpc.private_subnets, 2)
91+
}
92+
}
93+
}
94+
95+
module "ec2_upgrade" {
96+
source = "../../"
97+
98+
for_each = local.multiple_instances
99+
100+
name = format("%s${local.num_suffix_format}", local.name, each.value.num_suffix)
101+
102+
ami = data.aws_ami.amazon_linux.id
103+
instance_type = each.value.instance_type
104+
subnet_id = each.value.subnet_id
105+
vpc_security_group_ids = [module.security_group.security_group_id]
106+
associate_public_ip_address = true
107+
108+
tags = local.tags
109+
}
110+
```
111+
112+
To migrate from the `v2.x` version to `v3.x` version example shown above, the following state move commands can be performed to maintain the current resources without modification:
113+
114+
```bash
115+
terraform state mv 'module.ec2_upgrade.aws_instance.this[0]' 'module.ec2_upgrade["0"].aws_instance.this[0]'
116+
terraform state mv 'module.ec2_upgrade.aws_instance.this[1]' 'module.ec2_upgrade["1"].aws_instance.this[0]'
117+
terraform state mv 'module.ec2_upgrade.aws_instance.this[2]' 'module.ec2_upgrade["2"].aws_instance.this[0]'
118+
```
119+
120+
:info: Notes
121+
122+
- In the `v2.x` example we use `subnet_ids` which is an array of subnets. These are mapped to the respective instance based on their index location; therefore in the `v3.x` example we are doing a similar index lookup to map back to the existing subnet used for that instance. This would also be the case for `private_ips`
123+
- In the `v3.x` example we have shown how users can continue to use the same naming scheme that is currently in use by the `v2.x` module. By moving the `num_suffix_format` into the module name itself inside a format function, users can continue to customize the names generated in a similar manner as that of the `v2.x` module.

examples/basic/README.md

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)