From 6958496951aee6d79d8f9d73cd58de527bfceeac Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Thu, 23 Dec 2021 09:01:09 -0500 Subject: [PATCH 1/5] feat!: remove launch configuration support, add support for ignoring `desired_capacity` BREAKING CHANGE: Launch configuration support is no longer provided now that AWS has stated that they are no longer adding/updating the APIs for launch configurations (launch templates are the successor). In its place, a second autoscaling group that is identical to the default has been added - the only difference between the two is that the second ASG now ignores `desired_capacity` changes to allow users to utilize autoscaling without reverting or showing up in Terraform plans/applies. --- .github/workflows/pr-title.yml | 53 +++++++ .pre-commit-config.yaml | 2 +- README.md | 88 ++++------- examples/complete/README.md | 72 +-------- examples/complete/main.tf | 170 +-------------------- examples/complete/outputs.tf | 262 +-------------------------------- main.tf | 238 +++++++++++++++++++----------- outputs.tf | 45 ++---- variables.tf | 130 ++++------------ 9 files changed, 279 insertions(+), 781 deletions(-) create mode 100644 .github/workflows/pr-title.yml diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml new file mode 100644 index 0000000..8b8b660 --- /dev/null +++ b/.github/workflows/pr-title.yml @@ -0,0 +1,53 @@ +name: 'Validate PR title' + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + +jobs: + main: + name: Validate PR title + runs-on: ubuntu-latest + steps: + # Please look up the latest version from + # https://github.com/amannn/action-semantic-pull-request/releases + - uses: amannn/action-semantic-pull-request@v3.4.6 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + # Configure which types are allowed. + # Default: https://github.com/commitizen/conventional-commit-types + types: + - fix + - feat + - docs + - ci + - chore + - BREAKING CHANGE + # Configure that a scope must always be provided. + requireScope: false + # Configure additional validation for the subject based on a regex. + # This example ensures the subject starts with an uppercase character. + subjectPattern: ^[A-Z].+$ + # If `subjectPattern` is configured, you can use this property to override + # the default error message that is shown when the pattern doesn't match. + # The variables `subject` and `title` can be used within the message. + subjectPatternError: | + The subject "{subject}" found in the pull request title "{title}" + didn't match the configured pattern. Please ensure that the subject + starts with an uppercase character. + # For work-in-progress PRs you can typically use draft pull requests + # from Github. However, private repositories on the free plan don't have + # this option and therefore this action allows you to opt-in to using the + # special "[WIP]" prefix to indicate this state. This will avoid the + # validation of the PR title and the pull request checks remain pending. + # Note that a second check will be reported if this is enabled. + wip: true + # When using "Squash and merge" on a PR with only one commit, GitHub + # will suggest using that commit message instead of the PR title for the + # merge commit, and it's easy to commit this by mistake. Enable this option + # to also validate the commit message for one commit PRs. + validateSingleCommit: false diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0da8049..928d6fd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/antonbabenko/pre-commit-terraform - rev: v1.58.0 + rev: v1.62.3 hooks: - id: terraform_fmt - id: terraform_validate diff --git a/README.md b/README.md index fedd371..d824121 100644 --- a/README.md +++ b/README.md @@ -4,17 +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 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" @@ -180,13 +179,6 @@ The following combinations are supported to conditionally create resources and/o create_asg = false ``` -- Create only a launch configuration: - -```hcl - create_asg = false - create_lc = true -``` - - Create only a launch template: ```hcl @@ -194,13 +186,6 @@ The following combinations are supported to conditionally create resources and/o 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 @@ -208,13 +193,6 @@ The following combinations are supported to conditionally create resources and/o create_lt = true ``` -- Create the autoscaling group using an externally created launch configuration: - -```hcl - use_lc = true - launch_configuration = aws_launch_configuration.my_launch_config.name -``` - - Create the autoscaling group using an externally created launch template: ```hcl @@ -248,7 +226,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 @@ -272,9 +250,9 @@ 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_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 | @@ -282,51 +260,45 @@ 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 | +| [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\_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 | | [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 | +| [description](#input\_description) | 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 | +| [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 | @@ -339,31 +311,26 @@ 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 | | [propagate\_name](#input\_propagate\_name) | Determines whether to propagate the `var.instance_name`/`var.name` tag to launch instances | `bool` | `true` | 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 | | [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 list of tag blocks. Each element should have keys named key, value, and propagate\_at\_launch | `list(map(string))` | `[]` | no | | [tags\_as\_map](#input\_tags\_as\_map) | A map of tags and values in the same format as other resources accept. This will be converted into the non-standard format that the aws\_autoscaling\_group requires. | `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 | +| [update\_default\_version](#input\_update\_default\_version) | Whether to update Default Version each update. Conflicts with `default_version` | `string` | `null` | no | | [use\_lt](#input\_use\_lt) | Determines whether to use a launch template in the autoscaling group or not | `bool` | `false` | 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 | @@ -387,9 +354,6 @@ No modules. | [autoscaling\_group\_target\_group\_arns](#output\_autoscaling\_group\_target\_group\_arns) | List of Target Group ARNs that apply to this AutoScaling Group | | [autoscaling\_group\_vpc\_zone\_identifier](#output\_autoscaling\_group\_vpc\_zone\_identifier) | The VPC zone identifier | | [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/examples/complete/README.md b/examples/complete/README.md index 787aa70..ca2a04a 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,14 +43,10 @@ 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 | | [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 | | [mixed\_instance](#module\_mixed\_instance) | ../../ | n/a | | [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 | @@ -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,22 +70,6 @@ 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\_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 | @@ -110,22 +87,6 @@ No inputs. | [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 | @@ -142,22 +103,6 @@ No inputs. | [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 | @@ -174,9 +119,6 @@ No inputs. | [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 | diff --git a/examples/complete/main.tf b/examples/complete/main.tf index bd213fd..b63201e 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -193,7 +193,7 @@ module "disabled" { } ################################################################################ -# Configuration only +# Launch template only ################################################################################ module "lt_only" { @@ -217,27 +217,6 @@ module "lt_only" { tags_as_map = local.tags_as_map } -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" - - tags = local.tags - tags_as_map = local.tags_as_map -} - ################################################################################ # Default ################################################################################ @@ -265,29 +244,6 @@ module "default_lt" { tags_as_map = local.tags_as_map } -# 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" - - tags = local.tags - tags_as_map = local.tags_as_map -} - ################################################################################ # External ################################################################################ @@ -322,36 +278,6 @@ module "external_lt" { tags_as_map = local.tags_as_map } -# 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 - - tags = local.tags - tags_as_map = local.tags_as_map -} - ################################################################################ # Complete ################################################################################ @@ -544,100 +470,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 - tags_as_map = local.tags_as_map -} - ################################################################################ # Mixed instance policy ################################################################################ diff --git a/examples/complete/outputs.tf b/examples/complete/outputs.tf index e74e8b5..3890573 100644 --- a/examples/complete/outputs.tf +++ b/examples/complete/outputs.tf @@ -1,8 +1,7 @@ ################################################################################ -# Configuration only +# Launch template only ################################################################################ -# Launch template output "lt_only_launch_template_id" { description = "The ID of the launch template" value = module.lt_only.launch_template_id @@ -18,22 +17,6 @@ output "lt_only_launch_template_latest_version" { 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 -} - ################################################################################ # Default ################################################################################ @@ -119,87 +102,6 @@ output "default_lt_autoscaling_group_target_group_arns" { 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 -} - ################################################################################ # External ################################################################################ @@ -285,87 +187,6 @@ output "external_lt_autoscaling_group_target_group_arns" { 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 -} - ################################################################################ # Complete ################################################################################ @@ -456,87 +277,6 @@ output "complete_lt_autoscaling_schedule_arns" { 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 -} - ################################################################################ # Mixed instance policy ################################################################################ diff --git a/main.tf b/main.tf index 229f6a2..6d5b231 100644 --- a/main.tf +++ b/main.tf @@ -1,9 +1,6 @@ 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 @@ -33,80 +30,6 @@ 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 ################################################################################ @@ -227,7 +150,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) @@ -272,14 +195,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 = can(network_interfaces.value.ipv4_addresses) ? 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 = can(network_interfaces.value.ipv6_addresses) ? 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 = can(network_interfaces.value.security_groups.null) ? network_interfaces.value.security_groups : [] subnet_id = lookup(network_interfaces.value, "subnet_id", null) } } @@ -314,16 +237,151 @@ resource "aws_launch_template" "this" { } ################################################################################ -# Autoscaling group +# Autoscaling group - default ################################################################################ resource "aws_autoscaling_group" "this" { - count = var.create_asg ? 1 : 0 + count = var.create_asg && !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_lt ? [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 + } + + tags = local.tags + + lifecycle { + create_before_destroy = true + } +} + +################################################################################ +# Autoscaling group - ignore desired capacity +################################################################################ + +resource "aws_autoscaling_group" "idc" { + count = var.create_asg && 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] : [] @@ -382,7 +440,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) @@ -397,7 +455,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) @@ -415,13 +473,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) } @@ -449,17 +507,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 : {} 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) diff --git a/outputs.tf b/outputs.tf index 51c8dc6..f74ce0c 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 c22541c..be175d0 100644 --- a/variables.tf +++ b/variables.tf @@ -8,6 +8,12 @@ variable "create_asg" { 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,12 +31,6 @@ 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 @@ -235,10 +235,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 @@ -270,7 +266,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 } @@ -293,76 +289,6 @@ 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 ################################################################################ @@ -392,127 +318,127 @@ variable "lt_use_name_prefix" { } variable "description" { - description = "(LT) Description of the launch template" + 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 = [] } From 174452c88858aaf585ca19b4b34647c0daa4ec30 Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Thu, 23 Dec 2021 10:00:59 -0500 Subject: [PATCH 2/5] refactor: update variable name usage and expand abbreviation --- README.md | 26 ++--- examples/complete/README.md | 114 +++++++++---------- examples/complete/main.tf | 47 +++----- examples/complete/outputs.tf | 211 +++++++++++++++++------------------ main.tf | 16 +-- variables.tf | 18 +-- 6 files changed, 199 insertions(+), 233 deletions(-) diff --git a/README.md b/README.md index d824121..cffbbc9 100644 --- a/README.md +++ b/README.md @@ -58,9 +58,6 @@ module "asg" { description = "Launch template example" update_default_version = true - use_lt = true - create_lt = true - image_id = "ami-ebd02392" instance_type = "t3.micro" ebs_optimized = true @@ -173,6 +170,8 @@ module "asg" { The following combinations are supported to conditionally create resources and/or use externally created resources within the module: +Note: the default behavior of the module is to create an autoscaling group and launch template. + - Disable resource creation (no resources created): ```hcl @@ -183,21 +182,19 @@ The following combinations are supported to conditionally create resources and/o ```hcl create_asg = false - create_lt = true ``` -- Create both the autoscaling group and launch template: +- Create an autoscaling group using an externally created launch template: ```hcl - use_lt = true - create_lt = true + 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 ``` ## Tags @@ -266,7 +263,7 @@ No modules. | [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\_asg](#input\_create\_asg) | Determines whether to create autoscaling group or not | `bool` | `true` | no | -| [create\_lt](#input\_create\_lt) | Determines whether to create launch template or not | `bool` | `false` | no | +| [create\_launch\_template](#input\_create\_launch\_template) | Determines whether to create launch template 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) | 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 | @@ -298,11 +295,11 @@ No modules. | [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\_template](#input\_launch\_template) | Name of an existing launch template to be used (created outside of this module) | `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 | @@ -327,7 +324,6 @@ No modules. | [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) | Whether to update Default Version each update. Conflicts with `default_version` | `string` | `null` | no | -| [use\_lt](#input\_use\_lt) | Determines whether to use a launch template in the autoscaling group or not | `bool` | `false` | 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\_base64](#input\_user\_data\_base64) | The Base64-encoded user data to provide when launching the instance | `string` | `null` | no | diff --git a/examples/complete/README.md b/examples/complete/README.md index ca2a04a..9dddbd1 100644 --- a/examples/complete/README.md +++ b/examples/complete/README.md @@ -43,14 +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\_lt](#module\_complete\_lt) | ../../ | 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\_lt](#module\_external\_lt) | ../../ | 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 @@ -70,58 +70,58 @@ No inputs. | Name | Description | |------|-------------| -| [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\_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\_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 | -| [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\_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 b63201e..8b7c4fa 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -196,20 +196,17 @@ module "disabled" { # Launch template only ################################################################################ -module "lt_only" { +module "launch_template_only" { source = "../../" create_asg = false - name = "lt-only-${local.name}" + 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" @@ -221,22 +218,17 @@ module "lt_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" @@ -248,7 +240,6 @@ module "default_lt" { # External ################################################################################ -# Launch template resource "aws_launch_template" "this" { name_prefix = "external-lt-${local.name}-" image_id = data.aws_ami.amazon_linux.id @@ -259,11 +250,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 @@ -271,8 +262,8 @@ module "external_lt" { desired_capacity = 1 # Launch template - use_lt = true - launch_template = aws_launch_template.this.name + create_launch_template = false + launch_template = aws_launch_template.this.name tags = local.tags tags_as_map = local.tags_as_map @@ -282,12 +273,11 @@ module "external_lt" { # 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" @@ -330,13 +320,10 @@ module "complete_lt" { } # Launch template - lt_name = "complete-lt-${local.name}" + launch_template_name = "complete-${local.name}" description = "Complete launch template example" update_default_version = true - use_lt = true - create_lt = true - image_id = data.aws_ami.amazon_linux.id instance_type = "t3.micro" user_data_base64 = base64encode(local.user_data) @@ -519,10 +506,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 = { @@ -552,21 +535,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 3890573..20dd5cf 100644 --- a/examples/complete/outputs.tf +++ b/examples/complete/outputs.tf @@ -2,279 +2,276 @@ # Launch template only ################################################################################ -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 + 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 + 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 + 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 + value = module.complete.autoscaling_schedule_arns } ################################################################################ diff --git a/main.tf b/main.tf index 6d5b231..0d00501 100644 --- a/main.tf +++ b/main.tf @@ -1,9 +1,9 @@ data "aws_default_tags" "current" {} locals { - 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 tags = distinct(concat( [for k, v in data.aws_default_tags.current.tags : @@ -35,10 +35,10 @@ locals { ################################################################################ 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 + 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.description ebs_optimized = var.ebs_optimized @@ -247,7 +247,7 @@ resource "aws_autoscaling_group" "this" { 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 @@ -384,7 +384,7 @@ resource "aws_autoscaling_group" "idc" { 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 diff --git a/variables.tf b/variables.tf index be175d0..8e45d24 100644 --- a/variables.tf +++ b/variables.tf @@ -37,7 +37,7 @@ variable "launch_template" { default = null } -variable "lt_version" { +variable "launch_template_version" { description = "Launch template version. Can be version number, `$Latest`, or `$Default`" type = string default = null @@ -293,26 +293,20 @@ variable "metadata_options" { # 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 } From 88f4382621359ba71dc152df76a2326dc69aaf0b Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Thu, 23 Dec 2021 11:20:53 -0500 Subject: [PATCH 3/5] chore: validate examples and populate migration document --- README.md | 15 ++-- UPGRADE-5.0.md | 173 ++++++++++++++++++++++++++++++++++++++ examples/complete/main.tf | 15 ++-- main.tf | 18 ++-- variables.tf | 4 +- 5 files changed, 201 insertions(+), 24 deletions(-) create mode 100644 UPGRADE-5.0.md diff --git a/README.md b/README.md index cffbbc9..bfcba05 100644 --- a/README.md +++ b/README.md @@ -54,9 +54,9 @@ module "asg" { } # Launch template - lt_name = "example-asg" - description = "Launch template example" - update_default_version = 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,13 +175,14 @@ Note: the default behavior of the module is to create an autoscaling group and l - Disable resource creation (no resources created): ```hcl - create_asg = false + create = false + create_launch_template = false ``` - Create only a launch template: ```hcl - create_asg = false + create = false ``` - Create an autoscaling group using an externally created launch template: @@ -262,14 +263,13 @@ No modules. | [capacity\_rebalance](#input\_capacity\_rebalance) | Indicates whether capacity rebalance is enabled | `bool` | `null` | 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\_asg](#input\_create\_asg) | Determines whether to create autoscaling group or not | `bool` | `true` | 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\_schedule](#input\_create\_schedule) | Determines whether to create autoscaling group schedule or not | `bool` | `true` | 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) | 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) | 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) | 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 | @@ -295,6 +295,7 @@ No modules. | [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\_template](#input\_launch\_template) | Name of an existing launch template to be used (created outside of this module) | `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 | diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md new file mode 100644 index 0000000..9733b39 --- /dev/null +++ b/UPGRADE-5.0.md @@ -0,0 +1,173 @@ +# 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 + +- 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: + + - `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_as_map = { + 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/main.tf b/examples/complete/main.tf index 8b7c4fa..5a7d4b7 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -186,7 +186,8 @@ module "alb" { module "disabled" { source = "../../" - create_asg = false + create = false + create_launch_template = false # Autoscaling group name = "disabled-${local.name}" @@ -199,8 +200,8 @@ module "disabled" { module "launch_template_only" { source = "../../" - create_asg = false - name = "launch-template-only-${local.name}" + create = false + name = "launch-template-only-${local.name}" vpc_zone_identifier = module.vpc.private_subnets min_size = 0 @@ -281,6 +282,8 @@ module "complete" { use_name_prefix = false instance_name = "my-instance-name" + ignore_desired_capacity_changes = true + min_size = 0 max_size = 1 desired_capacity = 1 @@ -320,9 +323,9 @@ module "complete" { } # Launch template - launch_template_name = "complete-${local.name}" - description = "Complete launch template example" - update_default_version = 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" diff --git a/main.tf b/main.tf index 0d00501..2f2d007 100644 --- a/main.tf +++ b/main.tf @@ -39,7 +39,7 @@ resource "aws_launch_template" "this" { 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.description + description = var.launch_template_description ebs_optimized = var.ebs_optimized image_id = var.image_id @@ -150,7 +150,7 @@ resource "aws_launch_template" "this" { market_type = instance_market_options.value.market_type dynamic "spot_options" { - for_each = can(instance_market_options.value["spot_options"]) ? [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) @@ -195,14 +195,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 = can(network_interfaces.value.ipv4_addresses) ? 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 = can(network_interfaces.value.ipv6_addresses) ? 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 = can(network_interfaces.value.security_groups.null) ? network_interfaces.value.security_groups : [] + security_groups = try(network_interfaces.value.security_groups, []) subnet_id = lookup(network_interfaces.value, "subnet_id", null) } } @@ -241,7 +241,7 @@ resource "aws_launch_template" "this" { ################################################################################ resource "aws_autoscaling_group" "this" { - count = var.create_asg && !var.ignore_desired_capacity_changes ? 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 @@ -336,7 +336,7 @@ resource "aws_autoscaling_group" "this" { } dynamic "override" { - for_each = can(mixed_instances_policy.value.override) ? [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) @@ -378,7 +378,7 @@ resource "aws_autoscaling_group" "this" { ################################################################################ resource "aws_autoscaling_group" "idc" { - count = var.create_asg && var.ignore_desired_capacity_changes ? 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 @@ -516,7 +516,7 @@ resource "aws_autoscaling_group" "idc" { ################################################################################ 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 = try(aws_autoscaling_group.this[0].name, aws_autoscaling_group.idc[0].name) diff --git a/variables.tf b/variables.tf index 8e45d24..a54514c 100644 --- a/variables.tf +++ b/variables.tf @@ -2,7 +2,7 @@ # Autoscaling group ################################################################################ -variable "create_asg" { +variable "create" { description = "Determines whether to create autoscaling group or not" type = bool default = true @@ -311,7 +311,7 @@ variable "launch_template_use_name_prefix" { default = true } -variable "description" { +variable "launch_template_description" { description = "Description of the launch template" type = string default = null From 48a1cbe54ec8c4c956f6b13bd870c033db34c4b8 Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Wed, 5 Jan 2022 17:43:10 -0500 Subject: [PATCH 4/5] chore: update release configs based on EKS findings --- .github/workflows/pr-title.yml | 15 ++++++------- .github/workflows/release.yml | 3 +++ .github/workflows/stale-actions.yaml | 32 ++++++++++++++++++++++++++++ .pre-commit-config.yaml | 2 +- .releaserc.json | 17 +++++++++++---- 5 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/stale-actions.yaml diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml index 8b8b660..b89795d 100644 --- a/.github/workflows/pr-title.yml +++ b/.github/workflows/pr-title.yml @@ -1,4 +1,4 @@ -name: 'Validate PR title' +name: "Validate PR title" on: pull_request_target: @@ -20,13 +20,12 @@ jobs: with: # Configure which types are allowed. # Default: https://github.com/commitizen/conventional-commit-types - types: - - fix - - feat - - docs - - ci - - chore - - BREAKING CHANGE + types: | + fix + feat + docs + ci + chore # Configure that a scope must always be provided. requireScope: false # Configure additional validation for the subject based on a regex. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 141937d..e5529a9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,8 +7,10 @@ on: - main - master paths: + - '**/*.tpl' - '**/*.py' - '**/*.tf' + - '.github/workflows/release.yml' jobs: release: @@ -28,5 +30,6 @@ jobs: extra_plugins: | @semantic-release/changelog@6.0.0 @semantic-release/git@10.0.0 + conventional-changelog-conventionalcommits@4.6.3 env: GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_TOKEN }} diff --git a/.github/workflows/stale-actions.yaml b/.github/workflows/stale-actions.yaml new file mode 100644 index 0000000..d2a5f6b --- /dev/null +++ b/.github/workflows/stale-actions.yaml @@ -0,0 +1,32 @@ +name: "Mark or close stale issues and PRs" +on: + schedule: + - cron: "0 0 * * *" + +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v4 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + # Staling issues and PR's + days-before-stale: 30 + stale-issue-label: stale + stale-pr-label: stale + stale-issue-message: | + This issue has been automatically marked as stale because it has been open 30 days + with no activity. Remove stale label or comment or this issue will be closed in 10 days + stale-pr-message: | + This PR has been automatically marked as stale because it has been open 30 days + with no activity. Remove stale label or comment or this PR will be closed in 10 days + # Not stale if have this labels or part of milestone + exempt-issue-labels: bug,wip,on-hold + exempt-pr-labels: bug,wip,on-hold + exempt-all-milestones: true + # Close issue operations + # Label will be automatically removed if the issues are no longer closed nor locked. + days-before-close: 10 + delete-branch: true + close-issue-message: This issue was automatically closed because of stale in 10 days + close-pr-message: This PR was automatically closed because of stale in 10 days diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 928d6fd..093121e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,7 +23,7 @@ repos: - '--args=--only=terraform_standard_module_structure' - '--args=--only=terraform_workspace_remote' - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 + rev: v4.1.0 hooks: - id: check-merge-conflict - id: end-of-file-fixer diff --git a/.releaserc.json b/.releaserc.json index 6e39031..66b3eef 100644 --- a/.releaserc.json +++ b/.releaserc.json @@ -5,13 +5,22 @@ ], "ci": false, "plugins": [ - "@semantic-release/commit-analyzer", - "@semantic-release/release-notes-generator", + [ + "@semantic-release/commit-analyzer", + { + "preset": "conventionalcommits" + } + ], + [ + "@semantic-release/release-notes-generator", + { + "preset": "conventionalcommits" + } + ], [ "@semantic-release/github", { - "successComment": - "This ${issue.pull_request ? 'PR is included' : 'issue has been resolved'} in version ${nextRelease.version} :tada:", + "successComment": "This ${issue.pull_request ? 'PR is included' : 'issue has been resolved'} in version ${nextRelease.version} :tada:", "labels": false, "releasedLabels": false } From 4d8814bf73209711b0b3a87fc39d9c6e764a2177 Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Mon, 14 Feb 2022 07:53:43 -0500 Subject: [PATCH 5/5] chore: upgrade migration document --- UPGRADE-5.0.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 9733b39..b25bd75 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -18,12 +18,15 @@ If you find a bug, please open an issue with supporting configuration to reprodu ### 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` @@ -123,7 +126,7 @@ module "asg" { image_id = "ami-ebd02392" instance_type = "t3.micro" - tags_as_map = { + tags = { extra_tag1 = "extra_value1" extra_tag2 = "extra_value2" }