Project: Infracost (Observability and Analysis / Continuous Optimization)
File: UPGRADE-3.0.md

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 `count` and `for_each` arguments at module level Removed variables: `instance_count` `subnetids` (only need to use `subnetid` now) `privateips` (only need to use `privateip` now) `usenumsuffix` `numsuffixformat` Renamed variables: `tags` -> `tags_all` Removed outputs: `availability_zone` `placement_group` `key_name` `ipv6_addresses` `private_ip` `security_groups` `vpcsecuritygroup_ids` `subnet_id` `credit_specification` `metadata_options` `rootblockdevicevolumeids` `ebsblockdevicevolumeids` `volume_tags` `instance_count` Renamed outputs: :info: All outputs used to be lists, and are now singular outputs due to the removal of `count` ```hcl module "ec2_upgrade" { source = "terraform-aws-modules/ec2-instance/aws" version = "2.21.0" instance_count = 3 name = local.name ami = data.awsami.amazonlinux.id instance_type = "c5.large" subnetids = module.vpc.privatesubnets vpcsecuritygroupids = [module.securitygroup.securitygroupid] associatepublicip_address = true tags = local.tags } ``` ```hcl locals { numsuffixformat = "-%d" multiple_instances = { 0 = { num_suffix = 1 instance_type = "c5.large" subnetid = element(module.vpc.privatesubnets, 0) } 1 = { num_suffix = 2 instance_type = "c5.large" subnetid = element(module.vpc.privatesubnets, 1) } 2 = { num_suffix = 3 instance_type = "c5.large" subnetid = element(module.vpc.privatesubnets, 2) } } } module "ec2_upgrade" { source = "../../" foreach = local.multipleinstances name = format("%s${local.numsuffixformat}", local.name, each.value.num_suffix) ami = data.awsami.amazonlinux.id instancetype = each.value.instancetype subnetid = each.value.subnetid vpcsecuritygroupids = [module.securitygroup.securitygroupid] associatepublicip_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: ```bash terraform state mv 'module.ec2upgrade.awsinstance.this[0]' 'module.ec2upgrade["0"].awsinstance.this[0]' terraform state mv 'module.ec2upgrade.awsinstance.this[1]' 'module.ec2upgrade["1"].awsinstance.this[0]' terraform state mv 'module.ec2upgrade.awsinstance.this[2]' 'module.ec2upgrade["2"].awsinstance.this[0]' ``` :info: Notes In the `v2.x` example we use `subnetids` 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 `privateips` 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 `numsuffixformat` 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.