If you have any questions regarding this upgrade process, please consult the examples directory:
If you find a bug, please open an issue with supporting configuration to reproduce.
- Terraform v0.13.1 is now minimum supported version to take advantage of
countandfor_eacharguments at module level
-
Removed variables:
instance_countsubnet_ids(only need to usesubnet_idnow)private_ips(only need to useprivate_ipnow)use_num_suffixnum_suffix_format
-
Renamed variables:
tags->tags_all
-
Removed outputs:
availability_zoneplacement_groupkey_nameipv6_addressesprivate_ipsecurity_groupsvpc_security_group_idssubnet_idcredit_specificationmetadata_optionsroot_block_device_volume_idsebs_block_device_volume_idsvolume_tagsinstance_count
-
Renamed outputs:
:info: All outputs used to be lists, and are now singular outputs due to the removal of
count
module "ec2_upgrade" {
source = "terraform-aws-modules/ec2-instance/aws"
version = "2.21.0"
instance_count = 3
name = local.name
ami = data.aws_ami.amazon_linux.id
instance_type = "c5.large"
subnet_ids = module.vpc.private_subnets
vpc_security_group_ids = [module.security_group.security_group_id]
associate_public_ip_address = true
tags = local.tags
}locals {
num_suffix_format = "-%d"
multiple_instances = {
0 = {
num_suffix = 1
instance_type = "c5.large"
subnet_id = element(module.vpc.private_subnets, 0)
}
1 = {
num_suffix = 2
instance_type = "c5.large"
subnet_id = element(module.vpc.private_subnets, 1)
}
2 = {
num_suffix = 3
instance_type = "c5.large"
subnet_id = element(module.vpc.private_subnets, 2)
}
}
}
module "ec2_upgrade" {
source = "../../"
for_each = local.multiple_instances
name = format("%s${local.num_suffix_format}", local.name, each.value.num_suffix)
ami = data.aws_ami.amazon_linux.id
instance_type = each.value.instance_type
subnet_id = each.value.subnet_id
vpc_security_group_ids = [module.security_group.security_group_id]
associate_public_ip_address = true
tags = local.tags
}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:
terraform state mv 'module.ec2_upgrade.aws_instance.this[0]' 'module.ec2_upgrade["0"].aws_instance.this[0]'
terraform state mv 'module.ec2_upgrade.aws_instance.this[1]' 'module.ec2_upgrade["1"].aws_instance.this[0]'
terraform state mv 'module.ec2_upgrade.aws_instance.this[2]' 'module.ec2_upgrade["2"].aws_instance.this[0]':info: Notes
- In the
v2.xexample we usesubnet_idswhich is an array of subnets. These are mapped to the respective instance based on their index location; therefore in thev3.xexample we are doing a similar index lookup to map back to the existing subnet used for that instance. This would also be the case forprivate_ips - In the
v3.xexample we have shown how users can continue to use the same naming scheme that is currently in use by thev2.xmodule. By moving thenum_suffix_formatinto the module name itself inside a format function, users can continue to customize the names generated in a similar manner as that of thev2.xmodule.