diff --git a/README.md b/README.md
index 02005f7..cf8442f 100644
--- a/README.md
+++ b/README.md
@@ -4,18 +4,16 @@ Terraform module which creates Auto Scaling resources on AWS.
Available features
-- Autoscaling group with launch configuration - either created by the module or utilizing an existing launch configuration
- Autoscaling group with launch template - either created by the module or utilizing an existing launch template
- Autoscaling group utilizing mixed instances policy
- Ability to configure autoscaling groups to set instance refresh configuration and add lifecycle hooks
-- Ability to configure autoscaling policies
+- Ability to create an autoscaling group that respects `desired_capacity` or one that ignores to allow for scaling without conflicting Terraform diffs
## Usage
```hcl
module "asg" {
source = "terraform-aws-modules/autoscaling/aws"
- version = "~> 4.0"
# Autoscaling group
name = "example-asg"
@@ -56,12 +54,9 @@ module "asg" {
}
# Launch template
- lt_name = "example-asg"
- description = "Launch template example"
- update_default_version = true
-
- use_lt = true
- create_lt = true
+ launch_template_name = "example-asg"
+ launch_template_description = "Launch template example"
+ update_default_version = true
image_id = "ami-ebd02392"
instance_type = "t3.micro"
@@ -175,52 +170,32 @@ module "asg" {
The following combinations are supported to conditionally create resources and/or use externally created resources within the module:
-- Disable resource creation (no resources created):
+Note: the default behavior of the module is to create an autoscaling group and launch template.
-```hcl
- create_asg = false
-```
-
-- Create only a launch configuration:
+- Disable resource creation (no resources created):
```hcl
- create_asg = false
- create_lc = true
+ create = false
+ create_launch_template = false
```
- Create only a launch template:
```hcl
- create_asg = false
- create_lt = true
-```
-
-- Create both the autoscaling group and launch configuration:
-
-```hcl
- use_lc = true
- create_lc = true
-```
-
-- Create both the autoscaling group and launch template:
-
-```hcl
- use_lt = true
- create_lt = true
+ create = false
```
-- Create the autoscaling group using an externally created launch configuration:
+- Create an autoscaling group using an externally created launch template:
```hcl
- use_lc = true
- launch_configuration = aws_launch_configuration.my_launch_config.name
+ create_launch_template = false
+ launch_template = aws_launch_template.my_launch_template.name
```
-- Create the autoscaling group using an externally created launch template:
+- Create an autoscaling group with a mixed instance policy:
```hcl
- use_lt = true
- launch_template = aws_launch_template.my_launch_template.name
+ use_mixed_instances_policy = true
```
- Create the autoscaling policies:
@@ -266,7 +241,7 @@ There are two ways to specify tags for auto-scaling group in this module - `tags
## Examples
-- [Complete](https://github.com/terraform-aws-modules/terraform-aws-autoscaling/tree/master/examples/complete) - Creates several variations of resources for autoscaling groups, launch templates, launch configurations.
+- [Complete](https://github.com/terraform-aws-modules/terraform-aws-autoscaling/tree/master/examples/complete) - Creates several variations of resources for autoscaling groups and launch templates.
## Requirements
@@ -290,10 +265,10 @@ No modules.
| Name | Type |
|------|------|
+| [aws_autoscaling_group.idc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group) | resource |
| [aws_autoscaling_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group) | resource |
| [aws_autoscaling_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_policy) | resource |
| [aws_autoscaling_schedule.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_schedule) | resource |
-| [aws_launch_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_configuration) | resource |
| [aws_launch_template.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template) | resource |
| [aws_default_tags.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/default_tags) | data source |
@@ -301,56 +276,50 @@ No modules.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
-| [associate\_public\_ip\_address](#input\_associate\_public\_ip\_address) | (LC) Associate a public ip address with an instance in a VPC | `bool` | `null` | no |
| [availability\_zone](#input\_availability\_zone) | A list of one or more availability zones for the group. Used for EC2-Classic and default subnets when not specified with `vpc_zone_identifier` argument. Conflicts with `vpc_zone_identifier` | `list(string)` | `null` | no |
-| [block\_device\_mappings](#input\_block\_device\_mappings) | (LT) Specify volumes to attach to the instance besides the volumes specified by the AMI | `list(any)` | `[]` | no |
+| [block\_device\_mappings](#input\_block\_device\_mappings) | Specify volumes to attach to the instance besides the volumes specified by the AMI | `list(any)` | `[]` | no |
| [capacity\_rebalance](#input\_capacity\_rebalance) | Indicates whether capacity rebalance is enabled | `bool` | `null` | no |
-| [capacity\_reservation\_specification](#input\_capacity\_reservation\_specification) | (LT) Targeting for EC2 capacity reservations | `any` | `null` | no |
-| [cpu\_options](#input\_cpu\_options) | (LT) The CPU options for the instance | `map(string)` | `null` | no |
-| [create\_asg](#input\_create\_asg) | Determines whether to create autoscaling group or not | `bool` | `true` | no |
-| [create\_lc](#input\_create\_lc) | Determines whether to create launch configuration or not | `bool` | `false` | no |
-| [create\_lt](#input\_create\_lt) | Determines whether to create launch template or not | `bool` | `false` | no |
+| [capacity\_reservation\_specification](#input\_capacity\_reservation\_specification) | Targeting for EC2 capacity reservations | `any` | `null` | no |
+| [cpu\_options](#input\_cpu\_options) | The CPU options for the instance | `map(string)` | `null` | no |
+| [create](#input\_create) | Determines whether to create autoscaling group or not | `bool` | `true` | no |
+| [create\_launch\_template](#input\_create\_launch\_template) | Determines whether to create launch template or not | `bool` | `true` | no |
| [create\_scaling\_policy](#input\_create\_scaling\_policy) | Determines whether to create target scaling policy schedule or not | `bool` | `true` | no |
| [create\_schedule](#input\_create\_schedule) | Determines whether to create autoscaling group schedule or not | `bool` | `true` | no |
-| [credit\_specification](#input\_credit\_specification) | (LT) Customize the credit specification of the instance | `map(string)` | `null` | no |
+| [credit\_specification](#input\_credit\_specification) | Customize the credit specification of the instance | `map(string)` | `null` | no |
| [default\_cooldown](#input\_default\_cooldown) | The amount of time, in seconds, after a scaling activity completes before another scaling activity can start | `number` | `null` | no |
-| [default\_version](#input\_default\_version) | (LT) Default Version of the launch template | `string` | `null` | no |
+| [default\_version](#input\_default\_version) | Default Version of the launch template | `string` | `null` | no |
| [delete\_timeout](#input\_delete\_timeout) | Delete timeout to wait for destroying autoscaling group | `string` | `null` | no |
-| [description](#input\_description) | (LT) Description of the launch template | `string` | `null` | no |
| [desired\_capacity](#input\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the autoscaling group | `number` | `null` | no |
-| [disable\_api\_termination](#input\_disable\_api\_termination) | (LT) If true, enables EC2 instance termination protection | `bool` | `null` | no |
-| [ebs\_block\_device](#input\_ebs\_block\_device) | (LC) Additional EBS block devices to attach to the instance | `list(map(string))` | `[]` | no |
+| [disable\_api\_termination](#input\_disable\_api\_termination) | If true, enables EC2 instance termination protection | `bool` | `null` | no |
| [ebs\_optimized](#input\_ebs\_optimized) | If true, the launched EC2 instance will be EBS-optimized | `bool` | `null` | no |
-| [elastic\_gpu\_specifications](#input\_elastic\_gpu\_specifications) | (LT) The elastic GPU to attach to the instance | `map(string)` | `null` | no |
-| [elastic\_inference\_accelerator](#input\_elastic\_inference\_accelerator) | (LT) Configuration block containing an Elastic Inference Accelerator to attach to the instance | `map(string)` | `null` | no |
+| [elastic\_gpu\_specifications](#input\_elastic\_gpu\_specifications) | The elastic GPU to attach to the instance | `map(string)` | `null` | no |
+| [elastic\_inference\_accelerator](#input\_elastic\_inference\_accelerator) | Configuration block containing an Elastic Inference Accelerator to attach to the instance | `map(string)` | `null` | no |
| [enable\_monitoring](#input\_enable\_monitoring) | Enables/disables detailed monitoring | `bool` | `null` | no |
| [enabled\_metrics](#input\_enabled\_metrics) | A list of metrics to collect. The allowed values are `GroupDesiredCapacity`, `GroupInServiceCapacity`, `GroupPendingCapacity`, `GroupMinSize`, `GroupMaxSize`, `GroupInServiceInstances`, `GroupPendingInstances`, `GroupStandbyInstances`, `GroupStandbyCapacity`, `GroupTerminatingCapacity`, `GroupTerminatingInstances`, `GroupTotalCapacity`, `GroupTotalInstances` | `list(string)` | `null` | no |
-| [enclave\_options](#input\_enclave\_options) | (LT) Enable Nitro Enclaves on launched instances | `map(string)` | `null` | no |
-| [ephemeral\_block\_device](#input\_ephemeral\_block\_device) | (LC) Customize Ephemeral (also known as 'Instance Store') volumes on the instance | `list(map(string))` | `[]` | no |
+| [enclave\_options](#input\_enclave\_options) | Enable Nitro Enclaves on launched instances | `map(string)` | `null` | no |
| [force\_delete](#input\_force\_delete) | Allows deleting the Auto Scaling Group without waiting for all instances in the pool to terminate. You can force an Auto Scaling Group to delete even if it's in the process of scaling a resource. Normally, Terraform drains all the instances before deleting the group. This bypasses that behavior and potentially leaves resources dangling | `bool` | `null` | no |
| [health\_check\_grace\_period](#input\_health\_check\_grace\_period) | Time (in seconds) after instance comes into service before checking health | `number` | `null` | no |
| [health\_check\_type](#input\_health\_check\_type) | `EC2` or `ELB`. Controls how health checking is done | `string` | `null` | no |
-| [hibernation\_options](#input\_hibernation\_options) | (LT) The hibernation options for the instance | `map(string)` | `null` | no |
-| [iam\_instance\_profile\_arn](#input\_iam\_instance\_profile\_arn) | (LT) The IAM Instance Profile ARN to launch the instance with | `string` | `null` | no |
+| [hibernation\_options](#input\_hibernation\_options) | The hibernation options for the instance | `map(string)` | `null` | no |
+| [iam\_instance\_profile\_arn](#input\_iam\_instance\_profile\_arn) | The IAM Instance Profile ARN to launch the instance with | `string` | `null` | no |
| [iam\_instance\_profile\_name](#input\_iam\_instance\_profile\_name) | The name attribute of the IAM instance profile to associate with launched instances | `string` | `null` | no |
+| [ignore\_desired\_capacity\_changes](#input\_ignore\_desired\_capacity\_changes) | Determines whether the `desired_capacity` value is ignored after initial apply. See README note for more details | `bool` | `false` | no |
| [image\_id](#input\_image\_id) | The AMI from which to launch the instance | `string` | `""` | no |
| [initial\_lifecycle\_hooks](#input\_initial\_lifecycle\_hooks) | One or more Lifecycle Hooks to attach to the Auto Scaling Group before instances are launched. The syntax is exactly the same as the separate `aws_autoscaling_lifecycle_hook` resource, without the `autoscaling_group_name` attribute. Please note that this will only work when creating a new Auto Scaling Group. For all other use-cases, please use `aws_autoscaling_lifecycle_hook` resource | `list(map(string))` | `[]` | no |
-| [instance\_initiated\_shutdown\_behavior](#input\_instance\_initiated\_shutdown\_behavior) | (LT) Shutdown behavior for the instance. Can be `stop` or `terminate`. (Default: `stop`) | `string` | `null` | no |
-| [instance\_market\_options](#input\_instance\_market\_options) | (LT) The market (purchasing) option for the instance | `any` | `null` | no |
+| [instance\_initiated\_shutdown\_behavior](#input\_instance\_initiated\_shutdown\_behavior) | Shutdown behavior for the instance. Can be `stop` or `terminate`. (Default: `stop`) | `string` | `null` | no |
+| [instance\_market\_options](#input\_instance\_market\_options) | The market (purchasing) option for the instance | `any` | `null` | no |
| [instance\_name](#input\_instance\_name) | Name that is propogated to launched EC2 instances via a tag - if not provided, defaults to `var.name` | `string` | `""` | no |
| [instance\_refresh](#input\_instance\_refresh) | If this block is configured, start an Instance Refresh when this Auto Scaling Group is updated | `any` | `null` | no |
| [instance\_type](#input\_instance\_type) | The type of the instance to launch | `string` | `""` | no |
-| [kernel\_id](#input\_kernel\_id) | (LT) The kernel ID | `string` | `null` | no |
+| [kernel\_id](#input\_kernel\_id) | The kernel ID | `string` | `null` | no |
| [key\_name](#input\_key\_name) | The key name that should be used for the instance | `string` | `null` | no |
-| [launch\_configuration](#input\_launch\_configuration) | Name of an existing launch configuration to be used (created outside of this module) | `string` | `null` | no |
| [launch\_template](#input\_launch\_template) | Name of an existing launch template to be used (created outside of this module) | `string` | `null` | no |
-| [lc\_name](#input\_lc\_name) | Name of launch configuration to be created | `string` | `""` | no |
-| [lc\_use\_name\_prefix](#input\_lc\_use\_name\_prefix) | Determines whether to use `lc_name` as is or create a unique name beginning with the `lc_name` as the prefix | `bool` | `true` | no |
-| [license\_specifications](#input\_license\_specifications) | (LT) A list of license specifications to associate with | `map(string)` | `null` | no |
+| [launch\_template\_description](#input\_launch\_template\_description) | Description of the launch template | `string` | `null` | no |
+| [launch\_template\_name](#input\_launch\_template\_name) | Name of launch template to be created | `string` | `""` | no |
+| [launch\_template\_use\_name\_prefix](#input\_launch\_template\_use\_name\_prefix) | Determines whether to use `launch_template_name` as is or create a unique name beginning with the `launch_template_name` as the prefix | `bool` | `true` | no |
+| [launch\_template\_version](#input\_launch\_template\_version) | Launch template version. Can be version number, `$Latest`, or `$Default` | `string` | `null` | no |
+| [license\_specifications](#input\_license\_specifications) | A list of license specifications to associate with | `map(string)` | `null` | no |
| [load\_balancers](#input\_load\_balancers) | A list of elastic load balancer names to add to the autoscaling group names. Only valid for classic load balancers. For ALBs, use `target_group_arns` instead | `list(string)` | `[]` | no |
-| [lt\_name](#input\_lt\_name) | Name of launch template to be created | `string` | `""` | no |
-| [lt\_use\_name\_prefix](#input\_lt\_use\_name\_prefix) | Determines whether to use `lt_name` as is or create a unique name beginning with the `lt_name` as the prefix | `bool` | `true` | no |
-| [lt\_version](#input\_lt\_version) | Launch template version. Can be version number, `$Latest`, or `$Default` | `string` | `null` | no |
| [max\_instance\_lifetime](#input\_max\_instance\_lifetime) | The maximum amount of time, in seconds, that an instance can be in service, values must be either equal to 0 or between 86400 and 31536000 seconds | `number` | `null` | no |
| [max\_size](#input\_max\_size) | The maximum size of the autoscaling group | `number` | `null` | no |
| [metadata\_options](#input\_metadata\_options) | Customize the metadata options for the instance | `map(string)` | `null` | no |
@@ -359,30 +328,24 @@ No modules.
| [min\_size](#input\_min\_size) | The minimum size of the autoscaling group | `number` | `null` | no |
| [mixed\_instances\_policy](#input\_mixed\_instances\_policy) | Configuration block containing settings to define launch targets for Auto Scaling groups | `any` | `null` | no |
| [name](#input\_name) | Name used across the resources created | `string` | n/a | yes |
-| [network\_interfaces](#input\_network\_interfaces) | (LT) Customize network interfaces to be attached at instance boot time | `list(any)` | `[]` | no |
-| [placement](#input\_placement) | (LT) The placement of the instance | `map(string)` | `null` | no |
+| [network\_interfaces](#input\_network\_interfaces) | Customize network interfaces to be attached at instance boot time | `list(any)` | `[]` | no |
+| [placement](#input\_placement) | The placement of the instance | `map(string)` | `null` | no |
| [placement\_group](#input\_placement\_group) | The name of the placement group into which you'll launch your instances, if any | `string` | `null` | no |
-| [placement\_tenancy](#input\_placement\_tenancy) | (LC) The tenancy of the instance. Valid values are `default` or `dedicated` | `string` | `null` | no |
| [protect\_from\_scale\_in](#input\_protect\_from\_scale\_in) | Allows setting instance protection. The autoscaling group will not select instances with this setting for termination during scale in events. | `bool` | `false` | no |
-| [ram\_disk\_id](#input\_ram\_disk\_id) | (LT) The ID of the ram disk | `string` | `null` | no |
-| [root\_block\_device](#input\_root\_block\_device) | (LC) Customize details about the root block device of the instance | `list(map(string))` | `[]` | no |
+| [ram\_disk\_id](#input\_ram\_disk\_id) | The ID of the ram disk | `string` | `null` | no |
| [scaling\_policies](#input\_scaling\_policies) | Map of target scaling policy schedule to create | `any` | `{}` | no |
| [schedules](#input\_schedules) | Map of autoscaling group schedule to create | `map(any)` | `{}` | no |
| [security\_groups](#input\_security\_groups) | A list of security group IDs to associate | `list(string)` | `null` | no |
| [service\_linked\_role\_arn](#input\_service\_linked\_role\_arn) | The ARN of the service-linked role that the ASG will use to call other AWS services | `string` | `null` | no |
-| [spot\_price](#input\_spot\_price) | (LC) The maximum price to use for reserving spot instances (defaults to on-demand price) | `string` | `null` | no |
| [suspended\_processes](#input\_suspended\_processes) | A list of processes to suspend for the Auto Scaling Group. The allowed values are `Launch`, `Terminate`, `HealthCheck`, `ReplaceUnhealthy`, `AZRebalance`, `AlarmNotification`, `ScheduledActions`, `AddToLoadBalancer`. Note that if you suspend either the `Launch` or `Terminate` process types, it can prevent your Auto Scaling Group from functioning properly | `list(string)` | `null` | no |
-| [tag\_specifications](#input\_tag\_specifications) | (LT) The tags to apply to the resources during launch | `list(any)` | `[]` | no |
+| [tag\_specifications](#input\_tag\_specifications) | The tags to apply to the resources during launch | `list(any)` | `[]` | no |
| [tags](#input\_tags) | A map of tags to assign to resources | `map(string)` | `{}` | no |
| [target\_group\_arns](#input\_target\_group\_arns) | A set of `aws_alb_target_group` ARNs, for use with Application or Network Load Balancing | `list(string)` | `[]` | no |
| [termination\_policies](#input\_termination\_policies) | A list of policies to decide how the instances in the Auto Scaling Group should be terminated. The allowed values are `OldestInstance`, `NewestInstance`, `OldestLaunchConfiguration`, `ClosestToNextInstanceHour`, `OldestLaunchTemplate`, `AllocationStrategy`, `Default` | `list(string)` | `null` | no |
-| [update\_default\_version](#input\_update\_default\_version) | (LT) Whether to update Default Version each update. Conflicts with `default_version` | `string` | `null` | no |
-| [use\_lc](#input\_use\_lc) | Determines whether to use a launch configuration in the autoscaling group or not | `bool` | `false` | no |
-| [use\_lt](#input\_use\_lt) | Determines whether to use a launch template in the autoscaling group or not | `bool` | `false` | no |
+| [update\_default\_version](#input\_update\_default\_version) | Whether to update Default Version each update. Conflicts with `default_version` | `string` | `null` | no |
| [use\_mixed\_instances\_policy](#input\_use\_mixed\_instances\_policy) | Determines whether to use a mixed instances policy in the autoscaling group or not | `bool` | `false` | no |
| [use\_name\_prefix](#input\_use\_name\_prefix) | Determines whether to use `name` as is or create a unique name beginning with the `name` as the prefix | `bool` | `true` | no |
-| [user\_data](#input\_user\_data) | (LC) The user data to provide when launching the instance. Do not pass gzip-compressed data via this argument nor when using Launch Templates; see `user_data_base64` instead | `string` | `null` | no |
-| [user\_data\_base64](#input\_user\_data\_base64) | The Base64-encoded user data to provide when launching the instance. You should use this for Launch Templates instead user\_data | `string` | `null` | no |
+| [user\_data\_base64](#input\_user\_data\_base64) | The Base64-encoded user data to provide when launching the instance | `string` | `null` | no |
| [vpc\_zone\_identifier](#input\_vpc\_zone\_identifier) | A list of subnet IDs to launch resources in. Subnets automatically determine which availability zones the group will reside. Conflicts with `availability_zones` | `list(string)` | `null` | no |
| [wait\_for\_capacity\_timeout](#input\_wait\_for\_capacity\_timeout) | A maximum duration that Terraform should wait for ASG instances to be healthy before timing out. (See also Waiting for Capacity below.) Setting this to '0' causes Terraform to skip all Capacity Waiting behavior. | `string` | `null` | no |
| [wait\_for\_elb\_capacity](#input\_wait\_for\_elb\_capacity) | Setting this will cause Terraform to wait for exactly this number of healthy instances in all attached load balancers on both create and update operations. Takes precedence over `min_elb_capacity` behavior. | `number` | `null` | no |
@@ -407,9 +370,6 @@ No modules.
| [autoscaling\_group\_vpc\_zone\_identifier](#output\_autoscaling\_group\_vpc\_zone\_identifier) | The VPC zone identifier |
| [autoscaling\_policy\_arns](#output\_autoscaling\_policy\_arns) | ARNs of autoscaling policies |
| [autoscaling\_schedule\_arns](#output\_autoscaling\_schedule\_arns) | ARNs of autoscaling group schedules |
-| [launch\_configuration\_arn](#output\_launch\_configuration\_arn) | The ARN of the launch configuration |
-| [launch\_configuration\_id](#output\_launch\_configuration\_id) | The ID of the launch configuration |
-| [launch\_configuration\_name](#output\_launch\_configuration\_name) | The name of the launch configuration |
| [launch\_template\_arn](#output\_launch\_template\_arn) | The ARN of the launch template |
| [launch\_template\_id](#output\_launch\_template\_id) | The ID of the launch template |
| [launch\_template\_latest\_version](#output\_launch\_template\_latest\_version) | The latest version of the launch template |
diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md
new file mode 100644
index 0000000..b25bd75
--- /dev/null
+++ b/UPGRADE-5.0.md
@@ -0,0 +1,176 @@
+# Upgrade from v4.x to v5.x
+
+If you have any questions regarding this upgrade process, please consult the [`examples`](https://github.com/terraform-aws-modules/terraform-aws-autoscaling/tree/master/examples/complete) directory:
+
+⚠️ Instructions detailed here are for migrating from `v4.x` to `v5.x`. For instructions on upgrading to `v4.x` first, please see [UPGRADE-4.0.md](https://github.com/terraform-aws-modules/terraform-aws-autoscaling/blob/master/UPGRADE-4.0.md).
+
+If you find a bug, please open an issue with supporting configuration to reproduce.
+
+## List of backwards incompatible changes
+
+- Launch configuration support has been removed. [AWS has stated that launch configurations will no longer receive updates](https://aws.amazon.com/blogs/compute/amazon-ec2-auto-scaling-will-no-longer-add-support-for-new-ec2-features-to-launch-configurations/) and that launch templates should be used since they are the successor.
+
+## Additional changes
+
+### Added
+
+- A second autoscaling group `idc` (ignore desired capacity) has been added to allow users to utilize an autoscaling group that will ignore changes to `desired_capacity`
+
+### Modified
+
+- `var.tags` was previously a list of maps of `key`, `value`, and `propagate_at_launch`. It has been changed to a standard map of `key` = `value` pairs
+- The use of `for_each = lookup(map.value, "attr", null) != null ? [map.value.attr] : []` pattern has been replaced with a more concise, readable pattern of `for_each = can(map.value.attr) ? [map.value.attr] : []`. This is a no-op change for users
+
+### Variable and output changes
+
+1. Removed variables:
+
+ - `propagate_name`
+ - `tags_as_map` (use `tags` instead)
+ - `use_lt` -> this is now the default; only launch templates are supported
+ - `launch_configuration`
+ - `create_lc`
+ - `use_lc`
+ - `lc_name`
+ - `lc_use_name_prefix`
+ - `user_data`
+ - `associate_public_ip_address`
+ - `spot_price`
+ - `placement_tenancy`
+ - `ebs_block_device`
+ - `ephemeral_block_device`
+ - `root_block_device`
+
+2. Renamed variables:
+
+ - `create_asg` -> `create`
+ - `create_lt` -> `create_launch_template`
+ - `lt_name` -> `launch_template_name`
+ - `lt_use_name_prefix` -> `launch_template_use_name_prefix`
+ - `lt_version` -> `launch_template_version`
+
+3. Added variables:
+
+ - `ignore_desired_capacity_changes` -> to flip between using a standard autoscaling group that respects `desired_capacity` setting or one that ignores
+
+4. Removed outputs:
+
+ - `launch_configuration_id`
+ - `launch_configuration_arn`
+ - `launch_configuration_name`
+
+5. Renamed outputs:
+
+ - None
+
+6. Added outputs:
+
+ - None
+
+## Upgrade Migrations
+
+### Before 4.x Example
+
+```hcl
+module "asg" {
+ source = "terraform-aws-modules/autoscaling/aws"
+ version = "~> 4.0"
+
+ # Autoscaling group
+ name = "example-asg"
+
+ min_size = 0
+ max_size = 1
+ desired_capacity = 1
+ health_check_type = "EC2"
+ vpc_zone_identifier = ["subnet-1235678", "subnet-87654321"]
+
+ # Launch template
+ lt_name = "example-asg"
+ description = "Launch template example"
+ update_default_version = true
+ use_lt = true
+ create_lt = true
+
+ image_id = "ami-ebd02392"
+ instance_type = "t3.micro"
+
+ tags_as_map = {
+ extra_tag1 = "extra_value1"
+ extra_tag2 = "extra_value2"
+ }
+}
+```
+
+### After 5.x Example
+
+```hcl
+module "asg" {
+ source = "terraform-aws-modules/autoscaling/aws"
+ version = "~> 5.0"
+
+ # Autoscaling group
+ name = "example-asg"
+
+ min_size = 0
+ max_size = 1
+ desired_capacity = 1
+ health_check_type = "EC2"
+ vpc_zone_identifier = ["subnet-1235678", "subnet-87654321"]
+
+ # Launch template
+ launch_template_name = "example-asg"
+ launch_template_description = "Launch template example"
+ update_default_version = true
+
+ image_id = "ami-ebd02392"
+ instance_type = "t3.micro"
+
+ tags = {
+ extra_tag1 = "extra_value1"
+ extra_tag2 = "extra_value2"
+ }
+}
+```
+
+### State Changes
+
+There are no required state changes to migrate from `v4.x` to `v5.x`. If you are using launch configuration support, you can continue to do so with the `v4.x` version pinned or evaluate switching to a new autoscaling group that is backed by launch templates.
+
+If you wish to opt into the new feature `ignore_desired_capacity_changes`, you can perform the following state mv commands on your group(s) if desired:
+
+ℹ️ Be sure to add the `ignore_desired_capacity_changes = true` to your configuration.
+
+```bash
+terraform state mv 'module..aws_autoscaling_group.this[0]' 'module..aws_autoscaling_group.idc[0]'
+```
+
+For example, if you previously had a configuration such as (truncated for brevity):
+
+```hcl
+module "example" {
+ source = "terraform-aws-modules/autoscaling/aws"
+ version = "~> 4.x"
+
+ #
+}
+```
+
+After updating the configuration to the latest `v5.x` changes:
+
+```hcl
+module "example" {
+ source = "terraform-aws-modules/autoscaling/aws"
+ version = "~> 5.x"
+
+ #
+
+ ignore_desired_capacity_changes = true
+}
+```
+
+The associated Terraform state move command would be:
+
+```bash
+terraform state mv 'module.example.aws_autoscaling_group.this[0]' 'module.example.aws_autoscaling_group.idc[0]'
+```
diff --git a/examples/complete/README.md b/examples/complete/README.md
index 8d01a26..d57ea1d 100644
--- a/examples/complete/README.md
+++ b/examples/complete/README.md
@@ -1,16 +1,14 @@
# Complete Auto Scaling Group
-Configuration in this directory creates several different variations of resources for autoscaling groups, launch templates, and launch configurations.
-
-Note: the term configuration file is used to describe either the launch template or launch configuration. For most of the examples detailed below, examples are provided for using a launch configuration file as well as a launch template file (save for `disabled` and `mixed instance`)
+Configuration in this directory creates several different variations of resources for autoscaling groups and launch templates.
There are primarily six different setups shown in this example project:
-- `disabled` - demonstrates how to completely disable creation of both the autoscaling group and the associated configuration file (no resources will be created)
-- `config only` - demonstrates how to create a configuration file only (launch template or launch configuration) without creating an autoscaling group
-- `default` - demonstrates the bare minimum amount of information required to create an autoscaling group using a configuration file, relying mostly on default values
-- `external` - demonstrates how to create an autoscaling group using an externally created configuration file
-- `complete` - demonstrates the vast majority of the functionality available for creating an autoscaling group using a configuration file
-- `mixed instance` - demonstrates how to create an autoscaling group using a launch template configured to use a mixed instance policy
+- `disabled` - demonstrates how to completely disable creation of both the autoscaling group and the associated launch template (no resources will be created)
+- `template only` - demonstrates how to create a launch template without creating an autoscaling group
+- `default` - demonstrates the bare minimum amount of information required to create an autoscaling group, relying mostly on default values
+- `external` - demonstrates how to create an autoscaling group using an externally created launch template
+- `complete` - demonstrates the vast majority of the functionality available for creating an autoscaling group
+- `mixed instance` - demonstrates how to create an autoscaling group configured to use a mixed instance policy
## Usage
@@ -45,18 +43,14 @@ Note that this example may create resources which cost money. Run `terraform des
| [alb](#module\_alb) | terraform-aws-modules/alb/aws | ~> 6.0 |
| [alb\_http\_sg](#module\_alb\_http\_sg) | terraform-aws-modules/security-group/aws//modules/http-80 | ~> 4.0 |
| [asg\_sg](#module\_asg\_sg) | terraform-aws-modules/security-group/aws | ~> 4.0 |
-| [complete\_lc](#module\_complete\_lc) | ../../ | n/a |
-| [complete\_lt](#module\_complete\_lt) | ../../ | n/a |
-| [default\_lc](#module\_default\_lc) | ../../ | n/a |
-| [default\_lt](#module\_default\_lt) | ../../ | n/a |
+| [complete](#module\_complete) | ../../ | n/a |
+| [default](#module\_default) | ../../ | n/a |
| [disabled](#module\_disabled) | ../../ | n/a |
-| [external\_lc](#module\_external\_lc) | ../../ | n/a |
-| [external\_lt](#module\_external\_lt) | ../../ | n/a |
-| [lc\_only](#module\_lc\_only) | ../../ | n/a |
-| [lt\_only](#module\_lt\_only) | ../../ | n/a |
+| [external](#module\_external) | ../../ | n/a |
+| [launch\_template\_only](#module\_launch\_template\_only) | ../../ | n/a |
| [mixed\_instance](#module\_mixed\_instance) | ../../ | n/a |
| [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
-| [warmed\_lt](#module\_warmed\_lt) | ../../ | n/a |
+| [warm\_pool](#module\_warm\_pool) | ../../ | n/a |
## Resources
@@ -65,7 +59,6 @@ Note that this example may create resources which cost money. Run `terraform des
| [aws_iam_instance_profile.ssm](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_instance_profile) | resource |
| [aws_iam_role.ssm](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
| [aws_iam_service_linked_role.autoscaling](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_service_linked_role) | resource |
-| [aws_launch_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_configuration) | resource |
| [aws_launch_template.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template) | resource |
| [aws_ami.amazon_linux](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |
@@ -77,110 +70,59 @@ No inputs.
| Name | Description |
|------|-------------|
-| [complete\_lc\_autoscaling\_group\_arn](#output\_complete\_lc\_autoscaling\_group\_arn) | The ARN for this AutoScaling Group |
-| [complete\_lc\_autoscaling\_group\_availability\_zones](#output\_complete\_lc\_autoscaling\_group\_availability\_zones) | The availability zones of the autoscale group |
-| [complete\_lc\_autoscaling\_group\_default\_cooldown](#output\_complete\_lc\_autoscaling\_group\_default\_cooldown) | Time between a scaling activity and the succeeding scaling activity |
-| [complete\_lc\_autoscaling\_group\_desired\_capacity](#output\_complete\_lc\_autoscaling\_group\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group |
-| [complete\_lc\_autoscaling\_group\_health\_check\_grace\_period](#output\_complete\_lc\_autoscaling\_group\_health\_check\_grace\_period) | Time after instance comes into service before checking health |
-| [complete\_lc\_autoscaling\_group\_health\_check\_type](#output\_complete\_lc\_autoscaling\_group\_health\_check\_type) | EC2 or ELB. Controls how health checking is done |
-| [complete\_lc\_autoscaling\_group\_id](#output\_complete\_lc\_autoscaling\_group\_id) | The autoscaling group id |
-| [complete\_lc\_autoscaling\_group\_load\_balancers](#output\_complete\_lc\_autoscaling\_group\_load\_balancers) | The load balancer names associated with the autoscaling group |
-| [complete\_lc\_autoscaling\_group\_max\_size](#output\_complete\_lc\_autoscaling\_group\_max\_size) | The maximum size of the autoscale group |
-| [complete\_lc\_autoscaling\_group\_min\_size](#output\_complete\_lc\_autoscaling\_group\_min\_size) | The minimum size of the autoscale group |
-| [complete\_lc\_autoscaling\_group\_name](#output\_complete\_lc\_autoscaling\_group\_name) | The autoscaling group name |
-| [complete\_lc\_autoscaling\_group\_target\_group\_arns](#output\_complete\_lc\_autoscaling\_group\_target\_group\_arns) | List of Target Group ARNs that apply to this AutoScaling Group |
-| [complete\_lc\_autoscaling\_group\_vpc\_zone\_identifier](#output\_complete\_lc\_autoscaling\_group\_vpc\_zone\_identifier) | The VPC zone identifier |
-| [complete\_lc\_autoscaling\_policy\_arns](#output\_complete\_lc\_autoscaling\_policy\_arns) | ARNs of autoscaling policies |
-| [complete\_lc\_launch\_configuration\_arn](#output\_complete\_lc\_launch\_configuration\_arn) | The ARN of the launch configuration |
-| [complete\_lc\_launch\_configuration\_id](#output\_complete\_lc\_launch\_configuration\_id) | The ID of the launch configuration |
-| [complete\_lc\_launch\_configuration\_name](#output\_complete\_lc\_launch\_configuration\_name) | The name of the launch configuration |
-| [complete\_lt\_autoscaling\_group\_arn](#output\_complete\_lt\_autoscaling\_group\_arn) | The ARN for this AutoScaling Group |
-| [complete\_lt\_autoscaling\_group\_availability\_zones](#output\_complete\_lt\_autoscaling\_group\_availability\_zones) | The availability zones of the autoscale group |
-| [complete\_lt\_autoscaling\_group\_default\_cooldown](#output\_complete\_lt\_autoscaling\_group\_default\_cooldown) | Time between a scaling activity and the succeeding scaling activity |
-| [complete\_lt\_autoscaling\_group\_desired\_capacity](#output\_complete\_lt\_autoscaling\_group\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group |
-| [complete\_lt\_autoscaling\_group\_health\_check\_grace\_period](#output\_complete\_lt\_autoscaling\_group\_health\_check\_grace\_period) | Time after instance comes into service before checking health |
-| [complete\_lt\_autoscaling\_group\_health\_check\_type](#output\_complete\_lt\_autoscaling\_group\_health\_check\_type) | EC2 or ELB. Controls how health checking is done |
-| [complete\_lt\_autoscaling\_group\_id](#output\_complete\_lt\_autoscaling\_group\_id) | The autoscaling group id |
-| [complete\_lt\_autoscaling\_group\_load\_balancers](#output\_complete\_lt\_autoscaling\_group\_load\_balancers) | The load balancer names associated with the autoscaling group |
-| [complete\_lt\_autoscaling\_group\_max\_size](#output\_complete\_lt\_autoscaling\_group\_max\_size) | The maximum size of the autoscale group |
-| [complete\_lt\_autoscaling\_group\_min\_size](#output\_complete\_lt\_autoscaling\_group\_min\_size) | The minimum size of the autoscale group |
-| [complete\_lt\_autoscaling\_group\_name](#output\_complete\_lt\_autoscaling\_group\_name) | The autoscaling group name |
-| [complete\_lt\_autoscaling\_group\_target\_group\_arns](#output\_complete\_lt\_autoscaling\_group\_target\_group\_arns) | List of Target Group ARNs that apply to this AutoScaling Group |
-| [complete\_lt\_autoscaling\_group\_vpc\_zone\_identifier](#output\_complete\_lt\_autoscaling\_group\_vpc\_zone\_identifier) | The VPC zone identifier |
-| [complete\_lt\_autoscaling\_schedule\_arns](#output\_complete\_lt\_autoscaling\_schedule\_arns) | ARNs of autoscaling group schedules |
-| [complete\_lt\_launch\_template\_arn](#output\_complete\_lt\_launch\_template\_arn) | The ARN of the launch template |
-| [complete\_lt\_launch\_template\_id](#output\_complete\_lt\_launch\_template\_id) | The ID of the launch template |
-| [complete\_lt\_launch\_template\_latest\_version](#output\_complete\_lt\_launch\_template\_latest\_version) | The latest version of the launch template |
-| [default\_lc\_autoscaling\_group\_arn](#output\_default\_lc\_autoscaling\_group\_arn) | The ARN for this AutoScaling Group |
-| [default\_lc\_autoscaling\_group\_availability\_zones](#output\_default\_lc\_autoscaling\_group\_availability\_zones) | The availability zones of the autoscale group |
-| [default\_lc\_autoscaling\_group\_default\_cooldown](#output\_default\_lc\_autoscaling\_group\_default\_cooldown) | Time between a scaling activity and the succeeding scaling activity |
-| [default\_lc\_autoscaling\_group\_desired\_capacity](#output\_default\_lc\_autoscaling\_group\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group |
-| [default\_lc\_autoscaling\_group\_health\_check\_grace\_period](#output\_default\_lc\_autoscaling\_group\_health\_check\_grace\_period) | Time after instance comes into service before checking health |
-| [default\_lc\_autoscaling\_group\_health\_check\_type](#output\_default\_lc\_autoscaling\_group\_health\_check\_type) | EC2 or ELB. Controls how health checking is done |
-| [default\_lc\_autoscaling\_group\_id](#output\_default\_lc\_autoscaling\_group\_id) | The autoscaling group id |
-| [default\_lc\_autoscaling\_group\_load\_balancers](#output\_default\_lc\_autoscaling\_group\_load\_balancers) | The load balancer names associated with the autoscaling group |
-| [default\_lc\_autoscaling\_group\_max\_size](#output\_default\_lc\_autoscaling\_group\_max\_size) | The maximum size of the autoscale group |
-| [default\_lc\_autoscaling\_group\_min\_size](#output\_default\_lc\_autoscaling\_group\_min\_size) | The minimum size of the autoscale group |
-| [default\_lc\_autoscaling\_group\_name](#output\_default\_lc\_autoscaling\_group\_name) | The autoscaling group name |
-| [default\_lc\_autoscaling\_group\_target\_group\_arns](#output\_default\_lc\_autoscaling\_group\_target\_group\_arns) | List of Target Group ARNs that apply to this AutoScaling Group |
-| [default\_lc\_autoscaling\_group\_vpc\_zone\_identifier](#output\_default\_lc\_autoscaling\_group\_vpc\_zone\_identifier) | The VPC zone identifier |
-| [default\_lc\_launch\_configuration\_arn](#output\_default\_lc\_launch\_configuration\_arn) | The ARN of the launch configuration |
-| [default\_lc\_launch\_configuration\_id](#output\_default\_lc\_launch\_configuration\_id) | The ID of the launch configuration |
-| [default\_lc\_launch\_configuration\_name](#output\_default\_lc\_launch\_configuration\_name) | The name of the launch configuration |
-| [default\_lt\_autoscaling\_group\_arn](#output\_default\_lt\_autoscaling\_group\_arn) | The ARN for this AutoScaling Group |
-| [default\_lt\_autoscaling\_group\_availability\_zones](#output\_default\_lt\_autoscaling\_group\_availability\_zones) | The availability zones of the autoscale group |
-| [default\_lt\_autoscaling\_group\_default\_cooldown](#output\_default\_lt\_autoscaling\_group\_default\_cooldown) | Time between a scaling activity and the succeeding scaling activity |
-| [default\_lt\_autoscaling\_group\_desired\_capacity](#output\_default\_lt\_autoscaling\_group\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group |
-| [default\_lt\_autoscaling\_group\_health\_check\_grace\_period](#output\_default\_lt\_autoscaling\_group\_health\_check\_grace\_period) | Time after instance comes into service before checking health |
-| [default\_lt\_autoscaling\_group\_health\_check\_type](#output\_default\_lt\_autoscaling\_group\_health\_check\_type) | EC2 or ELB. Controls how health checking is done |
-| [default\_lt\_autoscaling\_group\_id](#output\_default\_lt\_autoscaling\_group\_id) | The autoscaling group id |
-| [default\_lt\_autoscaling\_group\_load\_balancers](#output\_default\_lt\_autoscaling\_group\_load\_balancers) | The load balancer names associated with the autoscaling group |
-| [default\_lt\_autoscaling\_group\_max\_size](#output\_default\_lt\_autoscaling\_group\_max\_size) | The maximum size of the autoscale group |
-| [default\_lt\_autoscaling\_group\_min\_size](#output\_default\_lt\_autoscaling\_group\_min\_size) | The minimum size of the autoscale group |
-| [default\_lt\_autoscaling\_group\_name](#output\_default\_lt\_autoscaling\_group\_name) | The autoscaling group name |
-| [default\_lt\_autoscaling\_group\_target\_group\_arns](#output\_default\_lt\_autoscaling\_group\_target\_group\_arns) | List of Target Group ARNs that apply to this AutoScaling Group |
-| [default\_lt\_autoscaling\_group\_vpc\_zone\_identifier](#output\_default\_lt\_autoscaling\_group\_vpc\_zone\_identifier) | The VPC zone identifier |
-| [default\_lt\_launch\_template\_arn](#output\_default\_lt\_launch\_template\_arn) | The ARN of the launch template |
-| [default\_lt\_launch\_template\_id](#output\_default\_lt\_launch\_template\_id) | The ID of the launch template |
-| [default\_lt\_launch\_template\_latest\_version](#output\_default\_lt\_launch\_template\_latest\_version) | The latest version of the launch template |
-| [external\_lc\_autoscaling\_group\_arn](#output\_external\_lc\_autoscaling\_group\_arn) | The ARN for this AutoScaling Group |
-| [external\_lc\_autoscaling\_group\_availability\_zones](#output\_external\_lc\_autoscaling\_group\_availability\_zones) | The availability zones of the autoscale group |
-| [external\_lc\_autoscaling\_group\_default\_cooldown](#output\_external\_lc\_autoscaling\_group\_default\_cooldown) | Time between a scaling activity and the succeeding scaling activity |
-| [external\_lc\_autoscaling\_group\_desired\_capacity](#output\_external\_lc\_autoscaling\_group\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group |
-| [external\_lc\_autoscaling\_group\_health\_check\_grace\_period](#output\_external\_lc\_autoscaling\_group\_health\_check\_grace\_period) | Time after instance comes into service before checking health |
-| [external\_lc\_autoscaling\_group\_health\_check\_type](#output\_external\_lc\_autoscaling\_group\_health\_check\_type) | EC2 or ELB. Controls how health checking is done |
-| [external\_lc\_autoscaling\_group\_id](#output\_external\_lc\_autoscaling\_group\_id) | The autoscaling group id |
-| [external\_lc\_autoscaling\_group\_load\_balancers](#output\_external\_lc\_autoscaling\_group\_load\_balancers) | The load balancer names associated with the autoscaling group |
-| [external\_lc\_autoscaling\_group\_max\_size](#output\_external\_lc\_autoscaling\_group\_max\_size) | The maximum size of the autoscale group |
-| [external\_lc\_autoscaling\_group\_min\_size](#output\_external\_lc\_autoscaling\_group\_min\_size) | The minimum size of the autoscale group |
-| [external\_lc\_autoscaling\_group\_name](#output\_external\_lc\_autoscaling\_group\_name) | The autoscaling group name |
-| [external\_lc\_autoscaling\_group\_target\_group\_arns](#output\_external\_lc\_autoscaling\_group\_target\_group\_arns) | List of Target Group ARNs that apply to this AutoScaling Group |
-| [external\_lc\_autoscaling\_group\_vpc\_zone\_identifier](#output\_external\_lc\_autoscaling\_group\_vpc\_zone\_identifier) | The VPC zone identifier |
-| [external\_lc\_launch\_configuration\_arn](#output\_external\_lc\_launch\_configuration\_arn) | The ARN of the launch configuration |
-| [external\_lc\_launch\_configuration\_id](#output\_external\_lc\_launch\_configuration\_id) | The ID of the launch configuration |
-| [external\_lc\_launch\_configuration\_name](#output\_external\_lc\_launch\_configuration\_name) | The name of the launch configuration |
-| [external\_lt\_autoscaling\_group\_arn](#output\_external\_lt\_autoscaling\_group\_arn) | The ARN for this AutoScaling Group |
-| [external\_lt\_autoscaling\_group\_availability\_zones](#output\_external\_lt\_autoscaling\_group\_availability\_zones) | The availability zones of the autoscale group |
-| [external\_lt\_autoscaling\_group\_default\_cooldown](#output\_external\_lt\_autoscaling\_group\_default\_cooldown) | Time between a scaling activity and the succeeding scaling activity |
-| [external\_lt\_autoscaling\_group\_desired\_capacity](#output\_external\_lt\_autoscaling\_group\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group |
-| [external\_lt\_autoscaling\_group\_health\_check\_grace\_period](#output\_external\_lt\_autoscaling\_group\_health\_check\_grace\_period) | Time after instance comes into service before checking health |
-| [external\_lt\_autoscaling\_group\_health\_check\_type](#output\_external\_lt\_autoscaling\_group\_health\_check\_type) | EC2 or ELB. Controls how health checking is done |
-| [external\_lt\_autoscaling\_group\_id](#output\_external\_lt\_autoscaling\_group\_id) | The autoscaling group id |
-| [external\_lt\_autoscaling\_group\_load\_balancers](#output\_external\_lt\_autoscaling\_group\_load\_balancers) | The load balancer names associated with the autoscaling group |
-| [external\_lt\_autoscaling\_group\_max\_size](#output\_external\_lt\_autoscaling\_group\_max\_size) | The maximum size of the autoscale group |
-| [external\_lt\_autoscaling\_group\_min\_size](#output\_external\_lt\_autoscaling\_group\_min\_size) | The minimum size of the autoscale group |
-| [external\_lt\_autoscaling\_group\_name](#output\_external\_lt\_autoscaling\_group\_name) | The autoscaling group name |
-| [external\_lt\_autoscaling\_group\_target\_group\_arns](#output\_external\_lt\_autoscaling\_group\_target\_group\_arns) | List of Target Group ARNs that apply to this AutoScaling Group |
-| [external\_lt\_autoscaling\_group\_vpc\_zone\_identifier](#output\_external\_lt\_autoscaling\_group\_vpc\_zone\_identifier) | The VPC zone identifier |
-| [external\_lt\_launch\_template\_arn](#output\_external\_lt\_launch\_template\_arn) | The ARN of the launch template |
-| [external\_lt\_launch\_template\_id](#output\_external\_lt\_launch\_template\_id) | The ID of the launch template |
-| [external\_lt\_launch\_template\_latest\_version](#output\_external\_lt\_launch\_template\_latest\_version) | The latest version of the launch template |
-| [lc\_only\_launch\_configuration\_arn](#output\_lc\_only\_launch\_configuration\_arn) | The ARN of the launch configuration |
-| [lc\_only\_launch\_configuration\_id](#output\_lc\_only\_launch\_configuration\_id) | The ID of the launch configuration |
-| [lc\_only\_launch\_configuration\_name](#output\_lc\_only\_launch\_configuration\_name) | The name of the launch configuration |
-| [lt\_only\_launch\_template\_arn](#output\_lt\_only\_launch\_template\_arn) | The ARN of the launch template |
-| [lt\_only\_launch\_template\_id](#output\_lt\_only\_launch\_template\_id) | The ID of the launch template |
-| [lt\_only\_launch\_template\_latest\_version](#output\_lt\_only\_launch\_template\_latest\_version) | The latest version of the launch template |
+| [complete\_autoscaling\_group\_arn](#output\_complete\_autoscaling\_group\_arn) | The ARN for this AutoScaling Group |
+| [complete\_autoscaling\_group\_availability\_zones](#output\_complete\_autoscaling\_group\_availability\_zones) | The availability zones of the autoscale group |
+| [complete\_autoscaling\_group\_default\_cooldown](#output\_complete\_autoscaling\_group\_default\_cooldown) | Time between a scaling activity and the succeeding scaling activity |
+| [complete\_autoscaling\_group\_desired\_capacity](#output\_complete\_autoscaling\_group\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group |
+| [complete\_autoscaling\_group\_health\_check\_grace\_period](#output\_complete\_autoscaling\_group\_health\_check\_grace\_period) | Time after instance comes into service before checking health |
+| [complete\_autoscaling\_group\_health\_check\_type](#output\_complete\_autoscaling\_group\_health\_check\_type) | EC2 or ELB. Controls how health checking is done |
+| [complete\_autoscaling\_group\_id](#output\_complete\_autoscaling\_group\_id) | The autoscaling group id |
+| [complete\_autoscaling\_group\_load\_balancers](#output\_complete\_autoscaling\_group\_load\_balancers) | The load balancer names associated with the autoscaling group |
+| [complete\_autoscaling\_group\_max\_size](#output\_complete\_autoscaling\_group\_max\_size) | The maximum size of the autoscale group |
+| [complete\_autoscaling\_group\_min\_size](#output\_complete\_autoscaling\_group\_min\_size) | The minimum size of the autoscale group |
+| [complete\_autoscaling\_group\_name](#output\_complete\_autoscaling\_group\_name) | The autoscaling group name |
+| [complete\_autoscaling\_group\_target\_group\_arns](#output\_complete\_autoscaling\_group\_target\_group\_arns) | List of Target Group ARNs that apply to this AutoScaling Group |
+| [complete\_autoscaling\_group\_vpc\_zone\_identifier](#output\_complete\_autoscaling\_group\_vpc\_zone\_identifier) | The VPC zone identifier |
+| [complete\_autoscaling\_policy\_arns](#output\_complete\_autoscaling\_policy\_arns) | ARNs of autoscaling policies |
+| [complete\_autoscaling\_schedule\_arns](#output\_complete\_autoscaling\_schedule\_arns) | ARNs of autoscaling group schedules |
+| [complete\_launch\_template\_arn](#output\_complete\_launch\_template\_arn) | The ARN of the launch template |
+| [complete\_launch\_template\_id](#output\_complete\_launch\_template\_id) | The ID of the launch template |
+| [complete\_launch\_template\_latest\_version](#output\_complete\_launch\_template\_latest\_version) | The latest version of the launch template |
+| [default\_autoscaling\_group\_arn](#output\_default\_autoscaling\_group\_arn) | The ARN for this AutoScaling Group |
+| [default\_autoscaling\_group\_availability\_zones](#output\_default\_autoscaling\_group\_availability\_zones) | The availability zones of the autoscale group |
+| [default\_autoscaling\_group\_default\_cooldown](#output\_default\_autoscaling\_group\_default\_cooldown) | Time between a scaling activity and the succeeding scaling activity |
+| [default\_autoscaling\_group\_desired\_capacity](#output\_default\_autoscaling\_group\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group |
+| [default\_autoscaling\_group\_health\_check\_grace\_period](#output\_default\_autoscaling\_group\_health\_check\_grace\_period) | Time after instance comes into service before checking health |
+| [default\_autoscaling\_group\_health\_check\_type](#output\_default\_autoscaling\_group\_health\_check\_type) | EC2 or ELB. Controls how health checking is done |
+| [default\_autoscaling\_group\_id](#output\_default\_autoscaling\_group\_id) | The autoscaling group id |
+| [default\_autoscaling\_group\_load\_balancers](#output\_default\_autoscaling\_group\_load\_balancers) | The load balancer names associated with the autoscaling group |
+| [default\_autoscaling\_group\_max\_size](#output\_default\_autoscaling\_group\_max\_size) | The maximum size of the autoscale group |
+| [default\_autoscaling\_group\_min\_size](#output\_default\_autoscaling\_group\_min\_size) | The minimum size of the autoscale group |
+| [default\_autoscaling\_group\_name](#output\_default\_autoscaling\_group\_name) | The autoscaling group name |
+| [default\_autoscaling\_group\_target\_group\_arns](#output\_default\_autoscaling\_group\_target\_group\_arns) | List of Target Group ARNs that apply to this AutoScaling Group |
+| [default\_autoscaling\_group\_vpc\_zone\_identifier](#output\_default\_autoscaling\_group\_vpc\_zone\_identifier) | The VPC zone identifier |
+| [default\_launch\_template\_arn](#output\_default\_launch\_template\_arn) | The ARN of the launch template |
+| [default\_launch\_template\_id](#output\_default\_launch\_template\_id) | The ID of the launch template |
+| [default\_launch\_template\_latest\_version](#output\_default\_launch\_template\_latest\_version) | The latest version of the launch template |
+| [external\_autoscaling\_group\_arn](#output\_external\_autoscaling\_group\_arn) | The ARN for this AutoScaling Group |
+| [external\_autoscaling\_group\_availability\_zones](#output\_external\_autoscaling\_group\_availability\_zones) | The availability zones of the autoscale group |
+| [external\_autoscaling\_group\_default\_cooldown](#output\_external\_autoscaling\_group\_default\_cooldown) | Time between a scaling activity and the succeeding scaling activity |
+| [external\_autoscaling\_group\_desired\_capacity](#output\_external\_autoscaling\_group\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group |
+| [external\_autoscaling\_group\_health\_check\_grace\_period](#output\_external\_autoscaling\_group\_health\_check\_grace\_period) | Time after instance comes into service before checking health |
+| [external\_autoscaling\_group\_health\_check\_type](#output\_external\_autoscaling\_group\_health\_check\_type) | EC2 or ELB. Controls how health checking is done |
+| [external\_autoscaling\_group\_id](#output\_external\_autoscaling\_group\_id) | The autoscaling group id |
+| [external\_autoscaling\_group\_load\_balancers](#output\_external\_autoscaling\_group\_load\_balancers) | The load balancer names associated with the autoscaling group |
+| [external\_autoscaling\_group\_max\_size](#output\_external\_autoscaling\_group\_max\_size) | The maximum size of the autoscale group |
+| [external\_autoscaling\_group\_min\_size](#output\_external\_autoscaling\_group\_min\_size) | The minimum size of the autoscale group |
+| [external\_autoscaling\_group\_name](#output\_external\_autoscaling\_group\_name) | The autoscaling group name |
+| [external\_autoscaling\_group\_target\_group\_arns](#output\_external\_autoscaling\_group\_target\_group\_arns) | List of Target Group ARNs that apply to this AutoScaling Group |
+| [external\_autoscaling\_group\_vpc\_zone\_identifier](#output\_external\_autoscaling\_group\_vpc\_zone\_identifier) | The VPC zone identifier |
+| [external\_launch\_template\_arn](#output\_external\_launch\_template\_arn) | The ARN of the launch template |
+| [external\_launch\_template\_id](#output\_external\_launch\_template\_id) | The ID of the launch template |
+| [external\_launch\_template\_latest\_version](#output\_external\_launch\_template\_latest\_version) | The latest version of the launch template |
+| [launch\_template\_only\_launch\_template\_arn](#output\_launch\_template\_only\_launch\_template\_arn) | The ARN of the launch template |
+| [launch\_template\_only\_launch\_template\_id](#output\_launch\_template\_only\_launch\_template\_id) | The ID of the launch template |
+| [launch\_template\_only\_launch\_template\_latest\_version](#output\_launch\_template\_only\_launch\_template\_latest\_version) | The latest version of the launch template |
| [mixed\_instance\_autoscaling\_group\_arn](#output\_mixed\_instance\_autoscaling\_group\_arn) | The ARN for this AutoScaling Group |
| [mixed\_instance\_autoscaling\_group\_availability\_zones](#output\_mixed\_instance\_autoscaling\_group\_availability\_zones) | The availability zones of the autoscale group |
| [mixed\_instance\_autoscaling\_group\_default\_cooldown](#output\_mixed\_instance\_autoscaling\_group\_default\_cooldown) | Time between a scaling activity and the succeeding scaling activity |
diff --git a/examples/complete/main.tf b/examples/complete/main.tf
index c883269..5c89011 100644
--- a/examples/complete/main.tf
+++ b/examples/complete/main.tf
@@ -170,50 +170,28 @@ module "alb" {
module "disabled" {
source = "../../"
- create_asg = false
+ create = false
+ create_launch_template = false
# Autoscaling group
name = "disabled-${local.name}"
}
################################################################################
-# Configuration only
+# Launch template only
################################################################################
-module "lt_only" {
+module "launch_template_only" {
source = "../../"
- create_asg = false
- name = "lt-only-${local.name}"
+ create = false
+ name = "launch-template-only-${local.name}"
vpc_zone_identifier = module.vpc.private_subnets
min_size = 0
max_size = 1
desired_capacity = 1
- # Launch template
- create_lt = true
-
- image_id = data.aws_ami.amazon_linux.id
- instance_type = "t3.micro"
-
- tags = local.tags
-}
-
-module "lc_only" {
- source = "../../"
-
- create_asg = false
- name = "lc-only-${local.name}"
-
- vpc_zone_identifier = module.vpc.private_subnets
- min_size = 0
- max_size = 1
- desired_capacity = 1
-
- # Launch configuration
- create_lc = true
-
image_id = data.aws_ami.amazon_linux.id
instance_type = "t3.micro"
@@ -224,44 +202,17 @@ module "lc_only" {
# Default
################################################################################
-# Launch template
-module "default_lt" {
+module "default" {
source = "../../"
# Autoscaling group
- name = "default-lt-${local.name}"
+ name = "default-${local.name}"
vpc_zone_identifier = module.vpc.private_subnets
min_size = 0
max_size = 1
desired_capacity = 1
- # Launch template
- use_lt = true
- create_lt = true
-
- image_id = data.aws_ami.amazon_linux.id
- instance_type = "t3.micro"
-
- tags = local.tags
-}
-
-# Launch configuration
-module "default_lc" {
- source = "../../"
-
- # Autoscaling group
- name = "default-lc-${local.name}"
-
- vpc_zone_identifier = module.vpc.private_subnets
- min_size = 0
- max_size = 1
- desired_capacity = 1
-
- # Launch configuration
- use_lc = true
- create_lc = true
-
image_id = data.aws_ami.amazon_linux.id
instance_type = "t3.micro"
@@ -272,7 +223,6 @@ module "default_lc" {
# External
################################################################################
-# Launch template
resource "aws_launch_template" "this" {
name_prefix = "external-lt-${local.name}-"
image_id = data.aws_ami.amazon_linux.id
@@ -283,11 +233,11 @@ resource "aws_launch_template" "this" {
}
}
-module "external_lt" {
+module "external" {
source = "../../"
# Autoscaling group
- name = "external-lt-${local.name}"
+ name = "external-${local.name}"
vpc_zone_identifier = module.vpc.private_subnets
min_size = 0
@@ -295,37 +245,8 @@ module "external_lt" {
desired_capacity = 1
# Launch template
- use_lt = true
- launch_template = aws_launch_template.this.name
-
- tags = local.tags
-}
-
-# Launch configuration
-resource "aws_launch_configuration" "this" {
- name_prefix = "external-lc-${local.name}-"
- image_id = data.aws_ami.amazon_linux.id
- instance_type = "t3.micro"
-
- lifecycle {
- create_before_destroy = true
- }
-}
-
-module "external_lc" {
- source = "../../"
-
- # Autoscaling group
- name = "external-lc-${local.name}"
-
- vpc_zone_identifier = module.vpc.private_subnets
- min_size = 0
- max_size = 1
- desired_capacity = 1
-
- # Launch config
- use_lc = true
- launch_configuration = aws_launch_configuration.this.name
+ create_launch_template = false
+ launch_template = aws_launch_template.this.name
tags = local.tags
}
@@ -334,15 +255,16 @@ module "external_lc" {
# Complete
################################################################################
-# Launch template
-module "complete_lt" {
+module "complete" {
source = "../../"
# Autoscaling group
- name = "complete-lt-${local.name}"
+ name = "complete-${local.name}"
use_name_prefix = false
instance_name = "my-instance-name"
+ ignore_desired_capacity_changes = true
+
min_size = 0
max_size = 1
desired_capacity = 1
@@ -382,12 +304,9 @@ module "complete_lt" {
}
# Launch template
- lt_name = "complete-lt-${local.name}"
- description = "Complete launch template example"
- update_default_version = true
-
- use_lt = true
- create_lt = true
+ launch_template_name = "complete-${local.name}"
+ launch_template_description = "Complete launch template example"
+ update_default_version = true
image_id = data.aws_ami.amazon_linux.id
instance_type = "t3.micro"
@@ -552,99 +471,6 @@ module "complete_lt" {
}
}
-# Launch configuration
-module "complete_lc" {
- source = "../../"
-
- # Autoscaling group
- name = "complete-lc-${local.name}"
- use_name_prefix = false
- instance_name = "my-instance-name"
-
- min_size = 0
- max_size = 1
- desired_capacity = 1
- wait_for_capacity_timeout = 0
- health_check_type = "EC2"
- vpc_zone_identifier = module.vpc.private_subnets
- service_linked_role_arn = aws_iam_service_linked_role.autoscaling.arn
-
- initial_lifecycle_hooks = [
- {
- name = "ExampleStartupLifeCycleHook"
- default_result = "CONTINUE"
- heartbeat_timeout = 60
- lifecycle_transition = "autoscaling:EC2_INSTANCE_LAUNCHING"
- # This could be a rendered data resource
- notification_metadata = jsonencode({ "hello" = "world" })
- },
- {
- name = "ExampleTerminationLifeCycleHook"
- default_result = "CONTINUE"
- heartbeat_timeout = 180
- lifecycle_transition = "autoscaling:EC2_INSTANCE_TERMINATING"
- # This could be a rendered data resource
- notification_metadata = jsonencode({ "goodbye" = "world" })
- }
- ]
-
- instance_refresh = {
- strategy = "Rolling"
- preferences = {
- checkpoint_delay = 600
- checkpoint_percentages = [35, 70, 100]
- instance_warmup = 300
- min_healthy_percentage = 50
- }
- triggers = ["tag"]
- }
-
- # Launch configuration
- lc_name = "complete-lc-${local.name}"
- use_lc = true
- create_lc = true
-
- image_id = data.aws_ami.amazon_linux.id
- instance_type = "t3.micro"
- user_data = local.user_data
- ebs_optimized = true
- enable_monitoring = true
-
- iam_instance_profile_arn = aws_iam_instance_profile.ssm.arn
- security_groups = [module.asg_sg.security_group_id]
- associate_public_ip_address = true
-
- spot_price = "0.014"
- target_group_arns = module.alb.target_group_arns
-
- ebs_block_device = [
- {
- device_name = "/dev/xvdz"
- delete_on_termination = true
- encrypted = true
- volume_type = "gp2"
- volume_size = "50"
- },
- ]
-
- root_block_device = [
- {
- delete_on_termination = true
- encrypted = true
- volume_size = "50"
- volume_type = "gp2"
- },
- ]
-
- metadata_options = {
- http_endpoint = "enabled"
- http_tokens = "required"
- http_put_response_hop_limit = 32
- }
-
- tags = local.tags
-}
-
################################################################################
# Mixed instance policy
################################################################################
@@ -694,10 +520,6 @@ module "mixed_instance" {
triggers = ["tag"]
}
- # Launch template
- create_lt = true
- update_default_version = true
-
# Mixed instances
use_mixed_instances_policy = true
mixed_instances_policy = {
@@ -726,21 +548,17 @@ module "mixed_instance" {
# With warm pool
################################################################################
-module "warmed_lt" {
+module "warm_pool" {
source = "../../"
# Autoscaling group
- name = "warmed-lt-${local.name}"
+ name = "warm-pool-${local.name}"
vpc_zone_identifier = module.vpc.private_subnets
min_size = 0
max_size = 1
desired_capacity = 1
- # Launch template
- use_lt = true
- create_lt = true
-
image_id = data.aws_ami.amazon_linux.id
instance_type = "t3.micro"
diff --git a/examples/complete/outputs.tf b/examples/complete/outputs.tf
index dbb4da8..dffa396 100644
--- a/examples/complete/outputs.tf
+++ b/examples/complete/outputs.tf
@@ -1,545 +1,282 @@
################################################################################
-# Configuration only
+# Launch template only
################################################################################
-# Launch template
-output "lt_only_launch_template_id" {
+output "launch_template_only_launch_template_id" {
description = "The ID of the launch template"
- value = module.lt_only.launch_template_id
+ value = module.launch_template_only.launch_template_id
}
-output "lt_only_launch_template_arn" {
+output "launch_template_only_launch_template_arn" {
description = "The ARN of the launch template"
- value = module.lt_only.launch_template_arn
+ value = module.launch_template_only.launch_template_arn
}
-output "lt_only_launch_template_latest_version" {
+output "launch_template_only_launch_template_latest_version" {
description = "The latest version of the launch template"
- value = module.lt_only.launch_template_latest_version
-}
-
-# Launch configuration
-output "lc_only_launch_configuration_id" {
- description = "The ID of the launch configuration"
- value = module.lc_only.launch_configuration_id
-}
-
-output "lc_only_launch_configuration_arn" {
- description = "The ARN of the launch configuration"
- value = module.lc_only.launch_configuration_arn
-}
-
-output "lc_only_launch_configuration_name" {
- description = "The name of the launch configuration"
- value = module.lc_only.launch_configuration_name
+ value = module.launch_template_only.launch_template_latest_version
}
################################################################################
# Default
################################################################################
-# Launch template
-output "default_lt_launch_template_id" {
+output "default_launch_template_id" {
description = "The ID of the launch template"
- value = module.default_lt.launch_template_id
+ value = module.default.launch_template_id
}
-output "default_lt_launch_template_arn" {
+output "default_launch_template_arn" {
description = "The ARN of the launch template"
- value = module.default_lt.launch_template_arn
+ value = module.default.launch_template_arn
}
-output "default_lt_launch_template_latest_version" {
+output "default_launch_template_latest_version" {
description = "The latest version of the launch template"
- value = module.default_lt.launch_template_latest_version
+ value = module.default.launch_template_latest_version
}
-output "default_lt_autoscaling_group_id" {
+output "default_autoscaling_group_id" {
description = "The autoscaling group id"
- value = module.default_lt.autoscaling_group_id
+ value = module.default.autoscaling_group_id
}
-output "default_lt_autoscaling_group_name" {
+output "default_autoscaling_group_name" {
description = "The autoscaling group name"
- value = module.default_lt.autoscaling_group_name
+ value = module.default.autoscaling_group_name
}
-output "default_lt_autoscaling_group_arn" {
+output "default_autoscaling_group_arn" {
description = "The ARN for this AutoScaling Group"
- value = module.default_lt.autoscaling_group_arn
+ value = module.default.autoscaling_group_arn
}
-output "default_lt_autoscaling_group_min_size" {
+output "default_autoscaling_group_min_size" {
description = "The minimum size of the autoscale group"
- value = module.default_lt.autoscaling_group_min_size
+ value = module.default.autoscaling_group_min_size
}
-output "default_lt_autoscaling_group_max_size" {
+output "default_autoscaling_group_max_size" {
description = "The maximum size of the autoscale group"
- value = module.default_lt.autoscaling_group_max_size
+ value = module.default.autoscaling_group_max_size
}
-output "default_lt_autoscaling_group_desired_capacity" {
+output "default_autoscaling_group_desired_capacity" {
description = "The number of Amazon EC2 instances that should be running in the group"
- value = module.default_lt.autoscaling_group_desired_capacity
+ value = module.default.autoscaling_group_desired_capacity
}
-output "default_lt_autoscaling_group_default_cooldown" {
+output "default_autoscaling_group_default_cooldown" {
description = "Time between a scaling activity and the succeeding scaling activity"
- value = module.default_lt.autoscaling_group_default_cooldown
+ value = module.default.autoscaling_group_default_cooldown
}
-output "default_lt_autoscaling_group_health_check_grace_period" {
+output "default_autoscaling_group_health_check_grace_period" {
description = "Time after instance comes into service before checking health"
- value = module.default_lt.autoscaling_group_health_check_grace_period
+ value = module.default.autoscaling_group_health_check_grace_period
}
-output "default_lt_autoscaling_group_health_check_type" {
+output "default_autoscaling_group_health_check_type" {
description = "EC2 or ELB. Controls how health checking is done"
- value = module.default_lt.autoscaling_group_health_check_type
+ value = module.default.autoscaling_group_health_check_type
}
-output "default_lt_autoscaling_group_availability_zones" {
+output "default_autoscaling_group_availability_zones" {
description = "The availability zones of the autoscale group"
- value = module.default_lt.autoscaling_group_availability_zones
+ value = module.default.autoscaling_group_availability_zones
}
-output "default_lt_autoscaling_group_vpc_zone_identifier" {
+output "default_autoscaling_group_vpc_zone_identifier" {
description = "The VPC zone identifier"
- value = module.default_lt.autoscaling_group_vpc_zone_identifier
+ value = module.default.autoscaling_group_vpc_zone_identifier
}
-output "default_lt_autoscaling_group_load_balancers" {
+output "default_autoscaling_group_load_balancers" {
description = "The load balancer names associated with the autoscaling group"
- value = module.default_lt.autoscaling_group_load_balancers
+ value = module.default.autoscaling_group_load_balancers
}
-output "default_lt_autoscaling_group_target_group_arns" {
+output "default_autoscaling_group_target_group_arns" {
description = "List of Target Group ARNs that apply to this AutoScaling Group"
- value = module.default_lt.autoscaling_group_target_group_arns
-}
-
-# Launch configuration
-output "default_lc_launch_configuration_id" {
- description = "The ID of the launch configuration"
- value = module.default_lc.launch_configuration_id
-}
-
-output "default_lc_launch_configuration_arn" {
- description = "The ARN of the launch configuration"
- value = module.default_lc.launch_configuration_arn
-}
-
-output "default_lc_launch_configuration_name" {
- description = "The name of the launch configuration"
- value = module.default_lc.launch_configuration_name
-}
-
-output "default_lc_autoscaling_group_id" {
- description = "The autoscaling group id"
- value = module.default_lc.autoscaling_group_id
-}
-
-output "default_lc_autoscaling_group_name" {
- description = "The autoscaling group name"
- value = module.default_lc.autoscaling_group_name
-}
-
-output "default_lc_autoscaling_group_arn" {
- description = "The ARN for this AutoScaling Group"
- value = module.default_lc.autoscaling_group_arn
-}
-
-output "default_lc_autoscaling_group_min_size" {
- description = "The minimum size of the autoscale group"
- value = module.default_lc.autoscaling_group_min_size
-}
-
-output "default_lc_autoscaling_group_max_size" {
- description = "The maximum size of the autoscale group"
- value = module.default_lc.autoscaling_group_max_size
-}
-
-output "default_lc_autoscaling_group_desired_capacity" {
- description = "The number of Amazon EC2 instances that should be running in the group"
- value = module.default_lc.autoscaling_group_desired_capacity
-}
-
-output "default_lc_autoscaling_group_default_cooldown" {
- description = "Time between a scaling activity and the succeeding scaling activity"
- value = module.default_lc.autoscaling_group_default_cooldown
-}
-
-output "default_lc_autoscaling_group_health_check_grace_period" {
- description = "Time after instance comes into service before checking health"
- value = module.default_lc.autoscaling_group_health_check_grace_period
-}
-
-output "default_lc_autoscaling_group_health_check_type" {
- description = "EC2 or ELB. Controls how health checking is done"
- value = module.default_lc.autoscaling_group_health_check_type
-}
-
-output "default_lc_autoscaling_group_availability_zones" {
- description = "The availability zones of the autoscale group"
- value = module.default_lc.autoscaling_group_availability_zones
-}
-
-output "default_lc_autoscaling_group_vpc_zone_identifier" {
- description = "The VPC zone identifier"
- value = module.default_lc.autoscaling_group_vpc_zone_identifier
-}
-
-output "default_lc_autoscaling_group_load_balancers" {
- description = "The load balancer names associated with the autoscaling group"
- value = module.default_lc.autoscaling_group_load_balancers
-}
-
-output "default_lc_autoscaling_group_target_group_arns" {
- description = "List of Target Group ARNs that apply to this AutoScaling Group"
- value = module.default_lc.autoscaling_group_target_group_arns
+ value = module.default.autoscaling_group_target_group_arns
}
################################################################################
# External
################################################################################
-# Launch template
-output "external_lt_launch_template_id" {
+output "external_launch_template_id" {
description = "The ID of the launch template"
- value = module.external_lt.launch_template_id
+ value = module.external.launch_template_id
}
-output "external_lt_launch_template_arn" {
+output "external_launch_template_arn" {
description = "The ARN of the launch template"
- value = module.external_lt.launch_template_arn
+ value = module.external.launch_template_arn
}
-output "external_lt_launch_template_latest_version" {
+output "external_launch_template_latest_version" {
description = "The latest version of the launch template"
- value = module.external_lt.launch_template_latest_version
+ value = module.external.launch_template_latest_version
}
-output "external_lt_autoscaling_group_id" {
+output "external_autoscaling_group_id" {
description = "The autoscaling group id"
- value = module.external_lt.autoscaling_group_id
+ value = module.external.autoscaling_group_id
}
-output "external_lt_autoscaling_group_name" {
+output "external_autoscaling_group_name" {
description = "The autoscaling group name"
- value = module.external_lt.autoscaling_group_name
+ value = module.external.autoscaling_group_name
}
-output "external_lt_autoscaling_group_arn" {
+output "external_autoscaling_group_arn" {
description = "The ARN for this AutoScaling Group"
- value = module.external_lt.autoscaling_group_arn
+ value = module.external.autoscaling_group_arn
}
-output "external_lt_autoscaling_group_min_size" {
+output "external_autoscaling_group_min_size" {
description = "The minimum size of the autoscale group"
- value = module.external_lt.autoscaling_group_min_size
+ value = module.external.autoscaling_group_min_size
}
-output "external_lt_autoscaling_group_max_size" {
+output "external_autoscaling_group_max_size" {
description = "The maximum size of the autoscale group"
- value = module.external_lt.autoscaling_group_max_size
+ value = module.external.autoscaling_group_max_size
}
-output "external_lt_autoscaling_group_desired_capacity" {
+output "external_autoscaling_group_desired_capacity" {
description = "The number of Amazon EC2 instances that should be running in the group"
- value = module.external_lt.autoscaling_group_desired_capacity
+ value = module.external.autoscaling_group_desired_capacity
}
-output "external_lt_autoscaling_group_default_cooldown" {
+output "external_autoscaling_group_default_cooldown" {
description = "Time between a scaling activity and the succeeding scaling activity"
- value = module.external_lt.autoscaling_group_default_cooldown
+ value = module.external.autoscaling_group_default_cooldown
}
-output "external_lt_autoscaling_group_health_check_grace_period" {
+output "external_autoscaling_group_health_check_grace_period" {
description = "Time after instance comes into service before checking health"
- value = module.external_lt.autoscaling_group_health_check_grace_period
+ value = module.external.autoscaling_group_health_check_grace_period
}
-output "external_lt_autoscaling_group_health_check_type" {
+output "external_autoscaling_group_health_check_type" {
description = "EC2 or ELB. Controls how health checking is done"
- value = module.external_lt.autoscaling_group_health_check_type
+ value = module.external.autoscaling_group_health_check_type
}
-output "external_lt_autoscaling_group_availability_zones" {
+output "external_autoscaling_group_availability_zones" {
description = "The availability zones of the autoscale group"
- value = module.external_lt.autoscaling_group_availability_zones
+ value = module.external.autoscaling_group_availability_zones
}
-output "external_lt_autoscaling_group_vpc_zone_identifier" {
+output "external_autoscaling_group_vpc_zone_identifier" {
description = "The VPC zone identifier"
- value = module.external_lt.autoscaling_group_vpc_zone_identifier
+ value = module.external.autoscaling_group_vpc_zone_identifier
}
-output "external_lt_autoscaling_group_load_balancers" {
+output "external_autoscaling_group_load_balancers" {
description = "The load balancer names associated with the autoscaling group"
- value = module.external_lt.autoscaling_group_load_balancers
+ value = module.external.autoscaling_group_load_balancers
}
-output "external_lt_autoscaling_group_target_group_arns" {
+output "external_autoscaling_group_target_group_arns" {
description = "List of Target Group ARNs that apply to this AutoScaling Group"
- value = module.external_lt.autoscaling_group_target_group_arns
-}
-
-# Launch configuration
-output "external_lc_launch_configuration_id" {
- description = "The ID of the launch configuration"
- value = module.external_lc.launch_configuration_id
-}
-
-output "external_lc_launch_configuration_arn" {
- description = "The ARN of the launch configuration"
- value = module.external_lc.launch_configuration_arn
-}
-
-output "external_lc_launch_configuration_name" {
- description = "The name of the launch configuration"
- value = module.external_lc.launch_configuration_name
-}
-
-output "external_lc_autoscaling_group_id" {
- description = "The autoscaling group id"
- value = module.external_lc.autoscaling_group_id
-}
-
-output "external_lc_autoscaling_group_name" {
- description = "The autoscaling group name"
- value = module.external_lc.autoscaling_group_name
-}
-
-output "external_lc_autoscaling_group_arn" {
- description = "The ARN for this AutoScaling Group"
- value = module.external_lc.autoscaling_group_arn
-}
-
-output "external_lc_autoscaling_group_min_size" {
- description = "The minimum size of the autoscale group"
- value = module.external_lc.autoscaling_group_min_size
-}
-
-output "external_lc_autoscaling_group_max_size" {
- description = "The maximum size of the autoscale group"
- value = module.external_lc.autoscaling_group_max_size
-}
-
-output "external_lc_autoscaling_group_desired_capacity" {
- description = "The number of Amazon EC2 instances that should be running in the group"
- value = module.external_lc.autoscaling_group_desired_capacity
-}
-
-output "external_lc_autoscaling_group_default_cooldown" {
- description = "Time between a scaling activity and the succeeding scaling activity"
- value = module.external_lc.autoscaling_group_default_cooldown
-}
-
-output "external_lc_autoscaling_group_health_check_grace_period" {
- description = "Time after instance comes into service before checking health"
- value = module.external_lc.autoscaling_group_health_check_grace_period
-}
-
-output "external_lc_autoscaling_group_health_check_type" {
- description = "EC2 or ELB. Controls how health checking is done"
- value = module.external_lc.autoscaling_group_health_check_type
-}
-
-output "external_lc_autoscaling_group_availability_zones" {
- description = "The availability zones of the autoscale group"
- value = module.external_lc.autoscaling_group_availability_zones
-}
-
-output "external_lc_autoscaling_group_vpc_zone_identifier" {
- description = "The VPC zone identifier"
- value = module.external_lc.autoscaling_group_vpc_zone_identifier
-}
-
-output "external_lc_autoscaling_group_load_balancers" {
- description = "The load balancer names associated with the autoscaling group"
- value = module.external_lc.autoscaling_group_load_balancers
-}
-
-output "external_lc_autoscaling_group_target_group_arns" {
- description = "List of Target Group ARNs that apply to this AutoScaling Group"
- value = module.external_lc.autoscaling_group_target_group_arns
+ value = module.external.autoscaling_group_target_group_arns
}
################################################################################
# Complete
################################################################################
-# Launch template
-output "complete_lt_launch_template_id" {
+output "complete_launch_template_id" {
description = "The ID of the launch template"
- value = module.complete_lt.launch_template_id
+ value = module.complete.launch_template_id
}
-output "complete_lt_launch_template_arn" {
+output "complete_launch_template_arn" {
description = "The ARN of the launch template"
- value = module.complete_lt.launch_template_arn
+ value = module.complete.launch_template_arn
}
-output "complete_lt_launch_template_latest_version" {
+output "complete_launch_template_latest_version" {
description = "The latest version of the launch template"
- value = module.complete_lt.launch_template_latest_version
+ value = module.complete.launch_template_latest_version
}
-output "complete_lt_autoscaling_group_id" {
+output "complete_autoscaling_group_id" {
description = "The autoscaling group id"
- value = module.complete_lt.autoscaling_group_id
+ value = module.complete.autoscaling_group_id
}
-output "complete_lt_autoscaling_group_name" {
+output "complete_autoscaling_group_name" {
description = "The autoscaling group name"
- value = module.complete_lt.autoscaling_group_name
+ value = module.complete.autoscaling_group_name
}
-output "complete_lt_autoscaling_group_arn" {
+output "complete_autoscaling_group_arn" {
description = "The ARN for this AutoScaling Group"
- value = module.complete_lt.autoscaling_group_arn
+ value = module.complete.autoscaling_group_arn
}
-output "complete_lt_autoscaling_group_min_size" {
+output "complete_autoscaling_group_min_size" {
description = "The minimum size of the autoscale group"
- value = module.complete_lt.autoscaling_group_min_size
+ value = module.complete.autoscaling_group_min_size
}
-output "complete_lt_autoscaling_group_max_size" {
+output "complete_autoscaling_group_max_size" {
description = "The maximum size of the autoscale group"
- value = module.complete_lt.autoscaling_group_max_size
+ value = module.complete.autoscaling_group_max_size
}
-output "complete_lt_autoscaling_group_desired_capacity" {
+output "complete_autoscaling_group_desired_capacity" {
description = "The number of Amazon EC2 instances that should be running in the group"
- value = module.complete_lt.autoscaling_group_desired_capacity
+ value = module.complete.autoscaling_group_desired_capacity
}
-output "complete_lt_autoscaling_group_default_cooldown" {
+output "complete_autoscaling_group_default_cooldown" {
description = "Time between a scaling activity and the succeeding scaling activity"
- value = module.complete_lt.autoscaling_group_default_cooldown
+ value = module.complete.autoscaling_group_default_cooldown
}
-output "complete_lt_autoscaling_group_health_check_grace_period" {
+output "complete_autoscaling_group_health_check_grace_period" {
description = "Time after instance comes into service before checking health"
- value = module.complete_lt.autoscaling_group_health_check_grace_period
+ value = module.complete.autoscaling_group_health_check_grace_period
}
-output "complete_lt_autoscaling_group_health_check_type" {
+output "complete_autoscaling_group_health_check_type" {
description = "EC2 or ELB. Controls how health checking is done"
- value = module.complete_lt.autoscaling_group_health_check_type
+ value = module.complete.autoscaling_group_health_check_type
}
-output "complete_lt_autoscaling_group_availability_zones" {
+output "complete_autoscaling_group_availability_zones" {
description = "The availability zones of the autoscale group"
- value = module.complete_lt.autoscaling_group_availability_zones
+ value = module.complete.autoscaling_group_availability_zones
}
-output "complete_lt_autoscaling_group_vpc_zone_identifier" {
+output "complete_autoscaling_group_vpc_zone_identifier" {
description = "The VPC zone identifier"
- value = module.complete_lt.autoscaling_group_vpc_zone_identifier
+ value = module.complete.autoscaling_group_vpc_zone_identifier
}
-output "complete_lt_autoscaling_group_load_balancers" {
+output "complete_autoscaling_group_load_balancers" {
description = "The load balancer names associated with the autoscaling group"
- value = module.complete_lt.autoscaling_group_load_balancers
+ value = module.complete.autoscaling_group_load_balancers
}
-output "complete_lt_autoscaling_group_target_group_arns" {
+output "complete_autoscaling_group_target_group_arns" {
description = "List of Target Group ARNs that apply to this AutoScaling Group"
- value = module.complete_lt.autoscaling_group_target_group_arns
+ value = module.complete.autoscaling_group_target_group_arns
}
-output "complete_lt_autoscaling_schedule_arns" {
+output "complete_autoscaling_schedule_arns" {
description = "ARNs of autoscaling group schedules"
- value = module.complete_lt.autoscaling_schedule_arns
-}
-
-# Launch configuration
-output "complete_lc_launch_configuration_id" {
- description = "The ID of the launch configuration"
- value = module.complete_lc.launch_configuration_id
-}
-
-output "complete_lc_launch_configuration_arn" {
- description = "The ARN of the launch configuration"
- value = module.complete_lc.launch_configuration_arn
-}
-
-output "complete_lc_launch_configuration_name" {
- description = "The name of the launch configuration"
- value = module.complete_lc.launch_configuration_name
-}
-
-output "complete_lc_autoscaling_group_id" {
- description = "The autoscaling group id"
- value = module.complete_lc.autoscaling_group_id
-}
-
-output "complete_lc_autoscaling_group_name" {
- description = "The autoscaling group name"
- value = module.complete_lc.autoscaling_group_name
-}
-
-output "complete_lc_autoscaling_group_arn" {
- description = "The ARN for this AutoScaling Group"
- value = module.complete_lc.autoscaling_group_arn
-}
-
-output "complete_lc_autoscaling_group_min_size" {
- description = "The minimum size of the autoscale group"
- value = module.complete_lc.autoscaling_group_min_size
-}
-
-output "complete_lc_autoscaling_group_max_size" {
- description = "The maximum size of the autoscale group"
- value = module.complete_lc.autoscaling_group_max_size
-}
-
-output "complete_lc_autoscaling_group_desired_capacity" {
- description = "The number of Amazon EC2 instances that should be running in the group"
- value = module.complete_lc.autoscaling_group_desired_capacity
-}
-
-output "complete_lc_autoscaling_group_default_cooldown" {
- description = "Time between a scaling activity and the succeeding scaling activity"
- value = module.complete_lc.autoscaling_group_default_cooldown
-}
-
-output "complete_lc_autoscaling_group_health_check_grace_period" {
- description = "Time after instance comes into service before checking health"
- value = module.complete_lc.autoscaling_group_health_check_grace_period
-}
-
-output "complete_lc_autoscaling_group_health_check_type" {
- description = "EC2 or ELB. Controls how health checking is done"
- value = module.complete_lc.autoscaling_group_health_check_type
-}
-
-output "complete_lc_autoscaling_group_availability_zones" {
- description = "The availability zones of the autoscale group"
- value = module.complete_lc.autoscaling_group_availability_zones
-}
-
-output "complete_lc_autoscaling_group_vpc_zone_identifier" {
- description = "The VPC zone identifier"
- value = module.complete_lc.autoscaling_group_vpc_zone_identifier
-}
-
-output "complete_lc_autoscaling_group_load_balancers" {
- description = "The load balancer names associated with the autoscaling group"
- value = module.complete_lc.autoscaling_group_load_balancers
-}
-
-output "complete_lc_autoscaling_group_target_group_arns" {
- description = "List of Target Group ARNs that apply to this AutoScaling Group"
- value = module.complete_lc.autoscaling_group_target_group_arns
+ value = module.complete.autoscaling_schedule_arns
}
-output "complete_lc_autoscaling_policy_arns" {
+output "complete_autoscaling_policy_arns" {
description = "ARNs of autoscaling policies"
- value = module.complete_lt.autoscaling_policy_arns
+ value = module.complete.autoscaling_policy_arns
}
################################################################################
diff --git a/main.tf b/main.tf
index 0746a0b..5137efc 100644
--- a/main.tf
+++ b/main.tf
@@ -1,12 +1,9 @@
data "aws_default_tags" "current" {}
locals {
- lc_name = coalesce(var.lc_name, var.name)
- launch_configuration = var.create_lc ? aws_launch_configuration.this[0].name : var.launch_configuration
-
- lt_name = coalesce(var.lt_name, var.name)
- launch_template = var.create_lt ? aws_launch_template.this[0].name : var.launch_template
- launch_template_version = var.create_lt && var.lt_version == null ? aws_launch_template.this[0].latest_version : var.lt_version
+ launch_template_name = coalesce(var.launch_template_name, var.name)
+ launch_template = var.create_launch_template ? aws_launch_template.this[0].name : var.launch_template
+ launch_template_version = var.create_launch_template && var.launch_template_version == null ? aws_launch_template.this[0].latest_version : var.launch_template_version
asg_tags = merge(
data.aws_default_tags.current.tags,
@@ -15,90 +12,16 @@ locals {
)
}
-################################################################################
-# Launch configuration
-################################################################################
-
-resource "aws_launch_configuration" "this" {
- count = var.create_lc ? 1 : 0
-
- name = var.lc_use_name_prefix ? null : local.lc_name
- name_prefix = var.lc_use_name_prefix ? "${local.lc_name}-" : null
-
- ebs_optimized = var.ebs_optimized
- image_id = var.image_id
- instance_type = var.instance_type
- iam_instance_profile = var.iam_instance_profile_name
- key_name = var.key_name
- user_data = var.user_data
- user_data_base64 = var.user_data_base64
-
- security_groups = var.security_groups
- associate_public_ip_address = var.associate_public_ip_address
-
- enable_monitoring = var.enable_monitoring
- spot_price = var.spot_price
- placement_tenancy = var.spot_price == null ? var.placement_tenancy : null
-
- dynamic "ebs_block_device" {
- for_each = var.ebs_block_device
- content {
- device_name = ebs_block_device.value.device_name
- delete_on_termination = lookup(ebs_block_device.value, "delete_on_termination", null)
- encrypted = lookup(ebs_block_device.value, "encrypted", null)
- iops = lookup(ebs_block_device.value, "iops", null)
- throughput = lookup(ebs_block_device.value, "throughput", null)
- no_device = lookup(ebs_block_device.value, "no_device", null)
- snapshot_id = lookup(ebs_block_device.value, "snapshot_id", null)
- volume_size = lookup(ebs_block_device.value, "volume_size", null)
- volume_type = lookup(ebs_block_device.value, "volume_type", null)
- }
- }
-
- dynamic "ephemeral_block_device" {
- for_each = var.ephemeral_block_device
- content {
- device_name = ephemeral_block_device.value.device_name
- virtual_name = ephemeral_block_device.value.virtual_name
- }
- }
-
- dynamic "root_block_device" {
- for_each = var.root_block_device
- content {
- delete_on_termination = lookup(root_block_device.value, "delete_on_termination", null)
- encrypted = lookup(root_block_device.value, "encrypted", null)
- iops = lookup(root_block_device.value, "iops", null)
- throughput = lookup(root_block_device.value, "throughput", null)
- volume_size = lookup(root_block_device.value, "volume_size", null)
- volume_type = lookup(root_block_device.value, "volume_type", null)
- }
- }
-
- dynamic "metadata_options" {
- for_each = var.metadata_options != null ? [var.metadata_options] : []
- content {
- http_endpoint = lookup(metadata_options.value, "http_endpoint", null)
- http_tokens = lookup(metadata_options.value, "http_tokens", null)
- http_put_response_hop_limit = lookup(metadata_options.value, "http_put_response_hop_limit", null)
- }
- }
-
- lifecycle {
- create_before_destroy = true
- }
-}
-
################################################################################
# Launch template
################################################################################
resource "aws_launch_template" "this" {
- count = var.create_lt ? 1 : 0
+ count = var.create_launch_template ? 1 : 0
- name = var.lt_use_name_prefix ? null : local.lt_name
- name_prefix = var.lt_use_name_prefix ? "${local.lt_name}-" : null
- description = var.description
+ name = var.launch_template_use_name_prefix ? null : local.launch_template_name
+ name_prefix = var.launch_template_use_name_prefix ? "${local.launch_template_name}-" : null
+ description = var.launch_template_description
ebs_optimized = var.ebs_optimized
image_id = var.image_id
@@ -209,7 +132,7 @@ resource "aws_launch_template" "this" {
market_type = instance_market_options.value.market_type
dynamic "spot_options" {
- for_each = lookup(instance_market_options.value, "spot_options", null) != null ? [instance_market_options.value.spot_options] : []
+ for_each = can(instance_market_options.value.spot_options) ? [instance_market_options.value.spot_options] : []
content {
block_duration_minutes = lookup(spot_options.value, "block_duration_minutes", null)
instance_interruption_behavior = lookup(spot_options.value, "instance_interruption_behavior", null)
@@ -255,14 +178,14 @@ resource "aws_launch_template" "this" {
description = lookup(network_interfaces.value, "description", null)
device_index = lookup(network_interfaces.value, "device_index", null)
interface_type = lookup(network_interfaces.value, "interface_type", null)
- ipv4_addresses = lookup(network_interfaces.value, "ipv4_addresses", null) != null ? network_interfaces.value.ipv4_addresses : []
+ ipv4_addresses = try(network_interfaces.value.ipv4_addresses, [])
ipv4_address_count = lookup(network_interfaces.value, "ipv4_address_count", null)
- ipv6_addresses = lookup(network_interfaces.value, "ipv6_addresses", null) != null ? network_interfaces.value.ipv6_addresses : []
+ ipv6_addresses = try(network_interfaces.value.ipv6_addresses, [])
ipv6_address_count = lookup(network_interfaces.value, "ipv6_address_count", null)
network_interface_id = lookup(network_interfaces.value, "network_interface_id", null)
network_card_index = lookup(network_interfaces.value, "network_card_index", null)
private_ip_address = lookup(network_interfaces.value, "private_ip_address", null)
- security_groups = lookup(network_interfaces.value, "security_groups", null) != null ? network_interfaces.value.security_groups : []
+ security_groups = try(network_interfaces.value.security_groups, [])
subnet_id = lookup(network_interfaces.value, "subnet_id", null)
}
}
@@ -297,19 +220,161 @@ resource "aws_launch_template" "this" {
}
################################################################################
-# Autoscaling group
+# Autoscaling group - default
################################################################################
resource "aws_autoscaling_group" "this" {
- count = var.create_asg ? 1 : 0
+ count = var.create && !var.ignore_desired_capacity_changes ? 1 : 0
name = var.use_name_prefix ? null : var.name
name_prefix = var.use_name_prefix ? "${var.name}-" : null
- launch_configuration = var.use_lc ? local.launch_configuration : null
+ dynamic "launch_template" {
+ for_each = var.use_mixed_instances_policy ? [] : [1]
+
+ content {
+ name = local.launch_template
+ version = local.launch_template_version
+ }
+ }
+
+ availability_zones = var.availability_zone
+ vpc_zone_identifier = var.vpc_zone_identifier
+
+ min_size = var.min_size
+ max_size = var.max_size
+ desired_capacity = var.desired_capacity
+ capacity_rebalance = var.capacity_rebalance
+ min_elb_capacity = var.min_elb_capacity
+ wait_for_elb_capacity = var.wait_for_elb_capacity
+ wait_for_capacity_timeout = var.wait_for_capacity_timeout
+ default_cooldown = var.default_cooldown
+ protect_from_scale_in = var.protect_from_scale_in
+
+ load_balancers = var.load_balancers
+ target_group_arns = var.target_group_arns
+ placement_group = var.placement_group
+ health_check_type = var.health_check_type
+ health_check_grace_period = var.health_check_grace_period
+
+ force_delete = var.force_delete
+ termination_policies = var.termination_policies
+ suspended_processes = var.suspended_processes
+ max_instance_lifetime = var.max_instance_lifetime
+
+ enabled_metrics = var.enabled_metrics
+ metrics_granularity = var.metrics_granularity
+ service_linked_role_arn = var.service_linked_role_arn
+
+ dynamic "initial_lifecycle_hook" {
+ for_each = var.initial_lifecycle_hooks
+ content {
+ name = initial_lifecycle_hook.value.name
+ default_result = lookup(initial_lifecycle_hook.value, "default_result", null)
+ heartbeat_timeout = lookup(initial_lifecycle_hook.value, "heartbeat_timeout", null)
+ lifecycle_transition = initial_lifecycle_hook.value.lifecycle_transition
+ notification_metadata = lookup(initial_lifecycle_hook.value, "notification_metadata", null)
+ notification_target_arn = lookup(initial_lifecycle_hook.value, "notification_target_arn", null)
+ role_arn = lookup(initial_lifecycle_hook.value, "role_arn", null)
+ }
+ }
+
+ dynamic "instance_refresh" {
+ for_each = var.instance_refresh != null ? [var.instance_refresh] : []
+ content {
+ strategy = instance_refresh.value.strategy
+ triggers = lookup(instance_refresh.value, "triggers", null)
+
+ dynamic "preferences" {
+ for_each = can(instance_refresh.value.preferences) ? [instance_refresh.value.preferences] : []
+ content {
+ checkpoint_delay = lookup(preferences.value, "checkpoint_delay", null)
+ checkpoint_percentages = lookup(preferences.value, "checkpoint_percentages", null)
+ instance_warmup = lookup(preferences.value, "instance_warmup", null)
+ min_healthy_percentage = lookup(preferences.value, "min_healthy_percentage", null)
+ }
+ }
+ }
+ }
+
+ dynamic "mixed_instances_policy" {
+ for_each = var.use_mixed_instances_policy ? [var.mixed_instances_policy] : []
+ content {
+ dynamic "instances_distribution" {
+ for_each = can(mixed_instances_policy.value.instances_distribution) ? [mixed_instances_policy.value.instances_distribution] : []
+ content {
+ on_demand_allocation_strategy = lookup(instances_distribution.value, "on_demand_allocation_strategy", null)
+ on_demand_base_capacity = lookup(instances_distribution.value, "on_demand_base_capacity", null)
+ on_demand_percentage_above_base_capacity = lookup(instances_distribution.value, "on_demand_percentage_above_base_capacity", null)
+ spot_allocation_strategy = lookup(instances_distribution.value, "spot_allocation_strategy", null)
+ spot_instance_pools = lookup(instances_distribution.value, "spot_instance_pools", null)
+ spot_max_price = lookup(instances_distribution.value, "spot_max_price", null)
+ }
+ }
+
+ launch_template {
+ launch_template_specification {
+ launch_template_name = local.launch_template
+ version = local.launch_template_version
+ }
+
+ dynamic "override" {
+ for_each = can(mixed_instances_policy.value.override) ? mixed_instances_policy.value.override : []
+ content {
+ instance_type = lookup(override.value, "instance_type", null)
+ weighted_capacity = lookup(override.value, "weighted_capacity", null)
+
+ dynamic "launch_template_specification" {
+ for_each = can(override.value.launch_template_specification) ? [override.value.launch_template_specification] : []
+ content {
+ launch_template_id = lookup(launch_template_specification.value, "launch_template_id", null)
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ dynamic "warm_pool" {
+ for_each = var.warm_pool != null ? [var.warm_pool] : []
+ content {
+ pool_state = lookup(warm_pool.value, "pool_state", null)
+ min_size = lookup(warm_pool.value, "min_size", null)
+ max_group_prepared_capacity = lookup(warm_pool.value, "max_group_prepared_capacity", null)
+ }
+ }
+
+ timeouts {
+ delete = var.delete_timeout
+ }
+
+ dynamic "tag" {
+ for_each = local.asg_tags
+ content {
+ key = tag.key
+ value = tag.value
+ propagate_at_launch = true
+ }
+ }
+
+ lifecycle {
+ create_before_destroy = true
+ }
+}
+
+################################################################################
+# Autoscaling group - ignore desired capacity
+################################################################################
+
+resource "aws_autoscaling_group" "idc" {
+ count = var.create && var.ignore_desired_capacity_changes ? 1 : 0
+
+ name = var.use_name_prefix ? null : var.name
+ name_prefix = var.use_name_prefix ? "${var.name}-" : null
dynamic "launch_template" {
- for_each = var.use_lt ? [1] : []
+ for_each = var.use_mixed_instances_policy ? [] : [1]
content {
name = local.launch_template
@@ -365,7 +430,7 @@ resource "aws_autoscaling_group" "this" {
triggers = lookup(instance_refresh.value, "triggers", null)
dynamic "preferences" {
- for_each = lookup(instance_refresh.value, "preferences", null) != null ? [instance_refresh.value.preferences] : []
+ for_each = can(instance_refresh.value.preferences) ? [instance_refresh.value.preferences] : []
content {
checkpoint_delay = lookup(preferences.value, "checkpoint_delay", null)
checkpoint_percentages = lookup(preferences.value, "checkpoint_percentages", null)
@@ -380,7 +445,7 @@ resource "aws_autoscaling_group" "this" {
for_each = var.use_mixed_instances_policy ? [var.mixed_instances_policy] : []
content {
dynamic "instances_distribution" {
- for_each = lookup(mixed_instances_policy.value, "instances_distribution", null) != null ? [mixed_instances_policy.value.instances_distribution] : []
+ for_each = can(mixed_instances_policy.value.instances_distribution) ? [mixed_instances_policy.value.instances_distribution] : []
content {
on_demand_allocation_strategy = lookup(instances_distribution.value, "on_demand_allocation_strategy", null)
on_demand_base_capacity = lookup(instances_distribution.value, "on_demand_base_capacity", null)
@@ -398,13 +463,13 @@ resource "aws_autoscaling_group" "this" {
}
dynamic "override" {
- for_each = lookup(mixed_instances_policy.value, "override", null) != null ? mixed_instances_policy.value.override : []
+ for_each = can(mixed_instances_policy.value.override) ? [mixed_instances_policy.value.override] : []
content {
instance_type = lookup(override.value, "instance_type", null)
weighted_capacity = lookup(override.value, "weighted_capacity", null)
dynamic "launch_template_specification" {
- for_each = lookup(override.value, "launch_template_specification", null) != null ? override.value.launch_template_specification : []
+ for_each = can(override.value.launch_template_specification) ? [override.value.launch_template_specification] : []
content {
launch_template_id = lookup(launch_template_specification.value, "launch_template_id", null)
}
@@ -439,17 +504,19 @@ resource "aws_autoscaling_group" "this" {
lifecycle {
create_before_destroy = true
+ ignore_changes = [desired_capacity]
}
}
################################################################################
# Autoscaling group schedule
################################################################################
+
resource "aws_autoscaling_schedule" "this" {
- for_each = var.create_asg && var.create_schedule ? var.schedules : {}
+ for_each = var.create && var.create_schedule ? var.schedules : {}
scheduled_action_name = each.key
- autoscaling_group_name = aws_autoscaling_group.this[0].name
+ autoscaling_group_name = try(aws_autoscaling_group.this[0].name, aws_autoscaling_group.idc[0].name)
min_size = lookup(each.value, "min_size", null)
max_size = lookup(each.value, "max_size", null)
@@ -468,10 +535,10 @@ resource "aws_autoscaling_schedule" "this" {
################################################################################
resource "aws_autoscaling_policy" "this" {
- for_each = { for k, v in var.scaling_policies : k => v if var.create_asg && var.create_scaling_policy }
+ for_each = { for k, v in var.scaling_policies : k => v if var.create && var.create_scaling_policy }
name = lookup(each.value, "name", each.key)
- autoscaling_group_name = aws_autoscaling_group.this[0].name
+ autoscaling_group_name = var.ignore_desired_capacity_changes ? aws_autoscaling_group.idc[0].name : aws_autoscaling_group.this[0].name
adjustment_type = lookup(each.value, "adjustment_type", null)
policy_type = lookup(each.value, "policy_type", null)
diff --git a/outputs.tf b/outputs.tf
index 41887e7..ad01899 100644
--- a/outputs.tf
+++ b/outputs.tf
@@ -1,22 +1,3 @@
-################################################################################
-# Launch configuration
-################################################################################
-
-output "launch_configuration_id" {
- description = "The ID of the launch configuration"
- value = try(aws_launch_configuration.this[0].id, "")
-}
-
-output "launch_configuration_arn" {
- description = "The ARN of the launch configuration"
- value = try(aws_launch_configuration.this[0].arn, "")
-}
-
-output "launch_configuration_name" {
- description = "The name of the launch configuration"
- value = try(aws_launch_configuration.this[0].name, "")
-}
-
################################################################################
# Launch template
################################################################################
@@ -42,67 +23,67 @@ output "launch_template_latest_version" {
output "autoscaling_group_id" {
description = "The autoscaling group id"
- value = try(aws_autoscaling_group.this[0].id, "")
+ value = try(aws_autoscaling_group.this[0].id, aws_autoscaling_group.idc[0].id, "")
}
output "autoscaling_group_name" {
description = "The autoscaling group name"
- value = try(aws_autoscaling_group.this[0].name, "")
+ value = try(aws_autoscaling_group.this[0].name, aws_autoscaling_group.idc[0].name, "")
}
output "autoscaling_group_arn" {
description = "The ARN for this AutoScaling Group"
- value = try(aws_autoscaling_group.this[0].arn, "")
+ value = try(aws_autoscaling_group.this[0].arn, aws_autoscaling_group.idc[0].arn, "")
}
output "autoscaling_group_min_size" {
description = "The minimum size of the autoscale group"
- value = try(aws_autoscaling_group.this[0].min_size, "")
+ value = try(aws_autoscaling_group.this[0].min_size, aws_autoscaling_group.idc[0].min_size, "")
}
output "autoscaling_group_max_size" {
description = "The maximum size of the autoscale group"
- value = try(aws_autoscaling_group.this[0].max_size, "")
+ value = try(aws_autoscaling_group.this[0].max_size, aws_autoscaling_group.idc[0].max_size, "")
}
output "autoscaling_group_desired_capacity" {
description = "The number of Amazon EC2 instances that should be running in the group"
- value = try(aws_autoscaling_group.this[0].desired_capacity, "")
+ value = try(aws_autoscaling_group.this[0].desired_capacity, aws_autoscaling_group.idc[0].desired_capacity, "")
}
output "autoscaling_group_default_cooldown" {
description = "Time between a scaling activity and the succeeding scaling activity"
- value = try(aws_autoscaling_group.this[0].default_cooldown, "")
+ value = try(aws_autoscaling_group.this[0].default_cooldown, aws_autoscaling_group.idc[0].default_cooldown, "")
}
output "autoscaling_group_health_check_grace_period" {
description = "Time after instance comes into service before checking health"
- value = try(aws_autoscaling_group.this[0].health_check_grace_period, "")
+ value = try(aws_autoscaling_group.this[0].health_check_grace_period, aws_autoscaling_group.idc[0].health_check_grace_period, "")
}
output "autoscaling_group_health_check_type" {
description = "EC2 or ELB. Controls how health checking is done"
- value = try(aws_autoscaling_group.this[0].health_check_type, "")
+ value = try(aws_autoscaling_group.this[0].health_check_type, aws_autoscaling_group.idc[0].health_check_type, "")
}
output "autoscaling_group_availability_zones" {
description = "The availability zones of the autoscale group"
- value = try(aws_autoscaling_group.this[0].availability_zones, [])
+ value = try(aws_autoscaling_group.this[0].availability_zones, aws_autoscaling_group.idc[0].availability_zones, [])
}
output "autoscaling_group_vpc_zone_identifier" {
description = "The VPC zone identifier"
- value = try(aws_autoscaling_group.this[0].vpc_zone_identifier, [])
+ value = try(aws_autoscaling_group.this[0].vpc_zone_identifier, aws_autoscaling_group.idc[0].vpc_zone_identifier, [])
}
output "autoscaling_group_load_balancers" {
description = "The load balancer names associated with the autoscaling group"
- value = try(aws_autoscaling_group.this[0].load_balancers, [])
+ value = try(aws_autoscaling_group.this[0].load_balancers, aws_autoscaling_group.idc[0].load_balancers, [])
}
output "autoscaling_group_target_group_arns" {
description = "List of Target Group ARNs that apply to this AutoScaling Group"
- value = try(aws_autoscaling_group.this[0].target_group_arns, [])
+ value = try(aws_autoscaling_group.this[0].target_group_arns, aws_autoscaling_group.idc[0].target_group_arns, [])
}
################################################################################
diff --git a/variables.tf b/variables.tf
index ce93cd1..5db3254 100644
--- a/variables.tf
+++ b/variables.tf
@@ -2,12 +2,18 @@
# Autoscaling group
################################################################################
-variable "create_asg" {
+variable "create" {
description = "Determines whether to create autoscaling group or not"
type = bool
default = true
}
+variable "ignore_desired_capacity_changes" {
+ description = "Determines whether the `desired_capacity` value is ignored after initial apply. See README note for more details"
+ type = bool
+ default = false
+}
+
variable "name" {
description = "Name used across the resources created"
type = string
@@ -25,19 +31,13 @@ variable "instance_name" {
default = ""
}
-variable "launch_configuration" {
- description = "Name of an existing launch configuration to be used (created outside of this module)"
- type = string
- default = null
-}
-
variable "launch_template" {
description = "Name of an existing launch template to be used (created outside of this module)"
type = string
default = null
}
-variable "lt_version" {
+variable "launch_template_version" {
description = "Launch template version. Can be version number, `$Latest`, or `$Default`"
type = string
default = null
@@ -223,10 +223,6 @@ variable "warm_pool" {
default = null
}
-################################################################################
-# Common - launch configuration or launch template
-################################################################################
-
variable "ebs_optimized" {
description = "If true, the launched EC2 instance will be EBS-optimized"
type = bool
@@ -258,7 +254,7 @@ variable "key_name" {
}
variable "user_data_base64" {
- description = "The Base64-encoded user data to provide when launching the instance. You should use this for Launch Templates instead user_data"
+ description = "The Base64-encoded user data to provide when launching the instance"
type = string
default = null
}
@@ -281,226 +277,150 @@ variable "metadata_options" {
default = null
}
-################################################################################
-# Launch configuration
-################################################################################
-
-variable "create_lc" {
- description = "Determines whether to create launch configuration or not"
- type = bool
- default = false
-}
-
-variable "use_lc" {
- description = "Determines whether to use a launch configuration in the autoscaling group or not"
- type = bool
- default = false
-}
-
-variable "lc_name" {
- description = "Name of launch configuration to be created"
- type = string
- default = ""
-}
-
-variable "lc_use_name_prefix" {
- description = "Determines whether to use `lc_name` as is or create a unique name beginning with the `lc_name` as the prefix"
- type = bool
- default = true
-}
-
-variable "user_data" {
- description = "(LC) The user data to provide when launching the instance. Do not pass gzip-compressed data via this argument nor when using Launch Templates; see `user_data_base64` instead"
- type = string
- default = null
-}
-
-variable "associate_public_ip_address" {
- description = "(LC) Associate a public ip address with an instance in a VPC"
- type = bool
- default = null
-}
-
-variable "spot_price" {
- description = "(LC) The maximum price to use for reserving spot instances (defaults to on-demand price)"
- type = string
- default = null
-}
-
-variable "placement_tenancy" {
- description = "(LC) The tenancy of the instance. Valid values are `default` or `dedicated`"
- type = string
- default = null
-}
-
-variable "ebs_block_device" {
- description = "(LC) Additional EBS block devices to attach to the instance"
- type = list(map(string))
- default = []
-}
-
-variable "ephemeral_block_device" {
- description = "(LC) Customize Ephemeral (also known as 'Instance Store') volumes on the instance"
- type = list(map(string))
- default = []
-}
-
-variable "root_block_device" {
- description = "(LC) Customize details about the root block device of the instance"
- type = list(map(string))
- default = []
-}
-
################################################################################
# Launch template
################################################################################
-variable "create_lt" {
+variable "create_launch_template" {
description = "Determines whether to create launch template or not"
type = bool
- default = false
-}
-
-variable "use_lt" {
- description = "Determines whether to use a launch template in the autoscaling group or not"
- type = bool
- default = false
+ default = true
}
-variable "lt_name" {
+variable "launch_template_name" {
description = "Name of launch template to be created"
type = string
default = ""
}
-variable "lt_use_name_prefix" {
- description = "Determines whether to use `lt_name` as is or create a unique name beginning with the `lt_name` as the prefix"
+variable "launch_template_use_name_prefix" {
+ description = "Determines whether to use `launch_template_name` as is or create a unique name beginning with the `launch_template_name` as the prefix"
type = bool
default = true
}
-variable "description" {
- description = "(LT) Description of the launch template"
+variable "launch_template_description" {
+ description = "Description of the launch template"
type = string
default = null
}
variable "default_version" {
- description = "(LT) Default Version of the launch template"
+ description = "Default Version of the launch template"
type = string
default = null
}
variable "update_default_version" {
- description = "(LT) Whether to update Default Version each update. Conflicts with `default_version`"
+ description = "Whether to update Default Version each update. Conflicts with `default_version`"
type = string
default = null
}
variable "disable_api_termination" {
- description = "(LT) If true, enables EC2 instance termination protection"
+ description = "If true, enables EC2 instance termination protection"
type = bool
default = null
}
variable "instance_initiated_shutdown_behavior" {
- description = "(LT) Shutdown behavior for the instance. Can be `stop` or `terminate`. (Default: `stop`)"
+ description = "Shutdown behavior for the instance. Can be `stop` or `terminate`. (Default: `stop`)"
type = string
default = null
}
variable "kernel_id" {
- description = "(LT) The kernel ID"
+ description = "The kernel ID"
type = string
default = null
}
variable "ram_disk_id" {
- description = "(LT) The ID of the ram disk"
+ description = "The ID of the ram disk"
type = string
default = null
}
variable "block_device_mappings" {
- description = "(LT) Specify volumes to attach to the instance besides the volumes specified by the AMI"
+ description = "Specify volumes to attach to the instance besides the volumes specified by the AMI"
type = list(any)
default = []
}
variable "capacity_reservation_specification" {
- description = "(LT) Targeting for EC2 capacity reservations"
+ description = "Targeting for EC2 capacity reservations"
type = any
default = null
}
variable "cpu_options" {
- description = "(LT) The CPU options for the instance"
+ description = "The CPU options for the instance"
type = map(string)
default = null
}
variable "credit_specification" {
- description = "(LT) Customize the credit specification of the instance"
+ description = "Customize the credit specification of the instance"
type = map(string)
default = null
}
variable "elastic_gpu_specifications" {
- description = "(LT) The elastic GPU to attach to the instance"
+ description = "The elastic GPU to attach to the instance"
type = map(string)
default = null
}
variable "elastic_inference_accelerator" {
- description = "(LT) Configuration block containing an Elastic Inference Accelerator to attach to the instance"
+ description = "Configuration block containing an Elastic Inference Accelerator to attach to the instance"
type = map(string)
default = null
}
variable "enclave_options" {
- description = "(LT) Enable Nitro Enclaves on launched instances"
+ description = "Enable Nitro Enclaves on launched instances"
type = map(string)
default = null
}
variable "hibernation_options" {
- description = "(LT) The hibernation options for the instance"
+ description = "The hibernation options for the instance"
type = map(string)
default = null
}
variable "iam_instance_profile_arn" {
- description = "(LT) The IAM Instance Profile ARN to launch the instance with"
+ description = "The IAM Instance Profile ARN to launch the instance with"
type = string
default = null
}
variable "instance_market_options" {
- description = "(LT) The market (purchasing) option for the instance"
+ description = "The market (purchasing) option for the instance"
type = any
default = null
}
variable "license_specifications" {
- description = "(LT) A list of license specifications to associate with"
+ description = "A list of license specifications to associate with"
type = map(string)
default = null
}
variable "network_interfaces" {
- description = "(LT) Customize network interfaces to be attached at instance boot time"
+ description = "Customize network interfaces to be attached at instance boot time"
type = list(any)
default = []
}
variable "placement" {
- description = "(LT) The placement of the instance"
+ description = "The placement of the instance"
type = map(string)
default = null
}
variable "tag_specifications" {
- description = "(LT) The tags to apply to the resources during launch"
+ description = "The tags to apply to the resources during launch"
type = list(any)
default = []
}