From e0b7ed4bbdfec2057a60300f1d4e48c48eb220aa Mon Sep 17 00:00:00 2001 From: Nuru Date: Thu, 29 Apr 2021 17:46:35 -0700 Subject: [PATCH] Fix #55 and #64 (#65) --- .github/auto-release.yml | 2 +- .github/workflows/auto-release.yml | 4 +++- README.md | 8 +++++--- README.yaml | 4 ++++ docs/terraform.md | 4 ++-- examples/complete/main.tf | 17 +++++++++++++++++ main.tf | 16 ++++++++-------- variables.tf | 4 ++-- 8 files changed, 42 insertions(+), 17 deletions(-) diff --git a/.github/auto-release.yml b/.github/auto-release.yml index ba0c226..39a7f1e 100644 --- a/.github/auto-release.yml +++ b/.github/auto-release.yml @@ -46,7 +46,7 @@ template: | replacers: # Remove irrelevant information from Renovate bot -- search: '/---\s+^#.*(Renovate configuration|Configuration)(?:.|\n)*?This PR has been generated .*/gm' +- search: '/(?<=---\s+)+^#.*(Renovate configuration|Configuration)(?:.|\n)*?This PR has been generated .*/gm' replace: '' # Remove Renovate bot banner image - search: '/\[!\[[^\]]*Renovate\][^\]]*\](\([^)]*\))?\s*\n+/gm' diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml index c766b1f..1d06d9b 100644 --- a/.github/workflows/auto-release.yml +++ b/.github/workflows/auto-release.yml @@ -3,7 +3,9 @@ name: auto-release on: push: branches: + - main - master + - production jobs: publish: @@ -14,7 +16,7 @@ jobs: id: get-merged-pull-request with: github_token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} - # Drafts your next Release notes as Pull Requests are merged into "master" + # Drafts your next Release notes as Pull Requests are merged into "main" - uses: release-drafter/release-drafter@v5 if: "!contains(steps.get-merged-pull-request.outputs.labels, 'no-release')" with: diff --git a/README.md b/README.md index c1efd72..f52f5ec 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ + # terraform-aws-ec2-autoscale-group [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-ec2-autoscale-group.svg)](https://github.com/cloudposse/terraform-aws-ec2-autoscale-group/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) @@ -32,6 +33,8 @@ Terraform module to provision [Auto Scaling Group](https://www.terraform.io/docs The module also creates AutoScaling Policies and CloudWatch Metric Alarms to monitor CPU utilization on the EC2 instances and scale the number of instance in the AutoScaling Group up or down. If you don't want to use the provided functionality, or want to provide your own policies, disable it by setting the variable `autoscaling_policies_enabled` to `false`. +At present, although you can set the created AutoScaling Policy type to any legal value, in practice [only `SimpleScaling` is supported](https://github.com/cloudposse/terraform-aws-ec2-autoscale-group/issues/55). +To use a `StepScaling` or `TargetTrackingScaling` policy, create it yourself and then pass it in the `alarm_actions` field of `custom_alarms`. --- @@ -63,7 +66,6 @@ We literally have [*hundreds of terraform modules*][terraform_modules] that are - ## Security & Compliance [](https://bridgecrew.io/) Security scanning is graciously provided by Bridgecrew. Bridgecrew is the leading fully hosted, cloud-native solution providing continuous Terraform security and compliance. @@ -299,11 +301,11 @@ Available targets: | [regex\_replace\_chars](#input\_regex\_replace\_chars) | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no | | [scale\_down\_adjustment\_type](#input\_scale\_down\_adjustment\_type) | Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are `ChangeInCapacity`, `ExactCapacity` and `PercentChangeInCapacity` | `string` | `"ChangeInCapacity"` | no | | [scale\_down\_cooldown\_seconds](#input\_scale\_down\_cooldown\_seconds) | The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start | `number` | `300` | no | -| [scale\_down\_policy\_type](#input\_scale\_down\_policy\_type) | The scalling policy type, either `SimpleScaling`, `StepScaling` or `TargetTrackingScaling` | `string` | `"SimpleScaling"` | no | +| [scale\_down\_policy\_type](#input\_scale\_down\_policy\_type) | The scaling policy type. Currently only `SimpleScaling` is supported | `string` | `"SimpleScaling"` | no | | [scale\_down\_scaling\_adjustment](#input\_scale\_down\_scaling\_adjustment) | The number of instances by which to scale. `scale_down_scaling_adjustment` determines the interpretation of this number (e.g. as an absolute number or as a percentage of the existing Auto Scaling group size). A positive increment adds to the current capacity and a negative value removes from the current capacity | `number` | `-1` | no | | [scale\_up\_adjustment\_type](#input\_scale\_up\_adjustment\_type) | Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are `ChangeInCapacity`, `ExactCapacity` and `PercentChangeInCapacity` | `string` | `"ChangeInCapacity"` | no | | [scale\_up\_cooldown\_seconds](#input\_scale\_up\_cooldown\_seconds) | The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start | `number` | `300` | no | -| [scale\_up\_policy\_type](#input\_scale\_up\_policy\_type) | The scalling policy type, either `SimpleScaling`, `StepScaling` or `TargetTrackingScaling` | `string` | `"SimpleScaling"` | no | +| [scale\_up\_policy\_type](#input\_scale\_up\_policy\_type) | The scaling policy type. Currently only `SimpleScaling` is supported | `string` | `"SimpleScaling"` | no | | [scale\_up\_scaling\_adjustment](#input\_scale\_up\_scaling\_adjustment) | The number of instances by which to scale. `scale_up_adjustment_type` determines the interpretation of this number (e.g. as an absolute number or as a percentage of the existing Auto Scaling group size). A positive increment adds to the current capacity and a negative value removes from the current capacity | `number` | `1` | no | | [security\_group\_ids](#input\_security\_group\_ids) | A list of associated security group IDs | `list(string)` | `[]` | 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` | `""` | no | diff --git a/README.yaml b/README.yaml index 48f1c3e..8cb7c53 100644 --- a/README.yaml +++ b/README.yaml @@ -42,6 +42,10 @@ description: |- The module also creates AutoScaling Policies and CloudWatch Metric Alarms to monitor CPU utilization on the EC2 instances and scale the number of instance in the AutoScaling Group up or down. If you don't want to use the provided functionality, or want to provide your own policies, disable it by setting the variable `autoscaling_policies_enabled` to `false`. + + At present, although you can set the created AutoScaling Policy type to any legal value, in practice [only `SimpleScaling` is supported](https://github.com/cloudposse/terraform-aws-ec2-autoscale-group/issues/55). + To use a `StepScaling` or `TargetTrackingScaling` policy, create it yourself and then pass it in the `alarm_actions` field of `custom_alarms`. + # How to use this project usage: |2- diff --git a/docs/terraform.md b/docs/terraform.md index a47fd4a..4d24ccf 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -94,11 +94,11 @@ | [regex\_replace\_chars](#input\_regex\_replace\_chars) | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no | | [scale\_down\_adjustment\_type](#input\_scale\_down\_adjustment\_type) | Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are `ChangeInCapacity`, `ExactCapacity` and `PercentChangeInCapacity` | `string` | `"ChangeInCapacity"` | no | | [scale\_down\_cooldown\_seconds](#input\_scale\_down\_cooldown\_seconds) | The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start | `number` | `300` | no | -| [scale\_down\_policy\_type](#input\_scale\_down\_policy\_type) | The scalling policy type, either `SimpleScaling`, `StepScaling` or `TargetTrackingScaling` | `string` | `"SimpleScaling"` | no | +| [scale\_down\_policy\_type](#input\_scale\_down\_policy\_type) | The scaling policy type. Currently only `SimpleScaling` is supported | `string` | `"SimpleScaling"` | no | | [scale\_down\_scaling\_adjustment](#input\_scale\_down\_scaling\_adjustment) | The number of instances by which to scale. `scale_down_scaling_adjustment` determines the interpretation of this number (e.g. as an absolute number or as a percentage of the existing Auto Scaling group size). A positive increment adds to the current capacity and a negative value removes from the current capacity | `number` | `-1` | no | | [scale\_up\_adjustment\_type](#input\_scale\_up\_adjustment\_type) | Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are `ChangeInCapacity`, `ExactCapacity` and `PercentChangeInCapacity` | `string` | `"ChangeInCapacity"` | no | | [scale\_up\_cooldown\_seconds](#input\_scale\_up\_cooldown\_seconds) | The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start | `number` | `300` | no | -| [scale\_up\_policy\_type](#input\_scale\_up\_policy\_type) | The scalling policy type, either `SimpleScaling`, `StepScaling` or `TargetTrackingScaling` | `string` | `"SimpleScaling"` | no | +| [scale\_up\_policy\_type](#input\_scale\_up\_policy\_type) | The scaling policy type. Currently only `SimpleScaling` is supported | `string` | `"SimpleScaling"` | no | | [scale\_up\_scaling\_adjustment](#input\_scale\_up\_scaling\_adjustment) | The number of instances by which to scale. `scale_up_adjustment_type` determines the interpretation of this number (e.g. as an absolute number or as a percentage of the existing Auto Scaling group size). A positive increment adds to the current capacity and a negative value removes from the current capacity | `number` | `1` | no | | [security\_group\_ids](#input\_security\_group\_ids) | A list of associated security group IDs | `list(string)` | `[]` | 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` | `""` | no | diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 6bd8a58..1feaeac 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -49,6 +49,23 @@ module "autoscale_group" { cpu_utilization_high_threshold_percent = var.cpu_utilization_high_threshold_percent cpu_utilization_low_threshold_percent = var.cpu_utilization_low_threshold_percent + block_device_mappings = [ + { + device_name = "/dev/sdb" + no_device = null + virtual_name = null + ebs = { + delete_on_termination = true + encrypted = true + volume_size = 8 + volume_type = "gp2" + iops = null + kms_key_id = null + snapshot_id = null + } + } + ] + context = module.this.context } diff --git a/main.tf b/main.tf index 3711ada..535d342 100644 --- a/main.tf +++ b/main.tf @@ -11,15 +11,15 @@ resource "aws_launch_template" "default" { virtual_name = lookup(block_device_mappings.value, "virtual_name", null) dynamic "ebs" { - for_each = flatten(list(lookup(block_device_mappings.value, "ebs", []))) + for_each = lookup(block_device_mappings.value, "ebs", null) == null ? [] : ["ebs"] content { - delete_on_termination = lookup(ebs.value, "delete_on_termination", null) - encrypted = lookup(ebs.value, "encrypted", null) - iops = lookup(ebs.value, "iops", null) - kms_key_id = lookup(ebs.value, "kms_key_id", null) - snapshot_id = lookup(ebs.value, "snapshot_id", null) - volume_size = lookup(ebs.value, "volume_size", null) - volume_type = lookup(ebs.value, "volume_type", null) + delete_on_termination = lookup(block_device_mappings.value.ebs, "delete_on_termination", null) + encrypted = lookup(block_device_mappings.value.ebs, "encrypted", null) + iops = lookup(block_device_mappings.value.ebs, "iops", null) + kms_key_id = lookup(block_device_mappings.value.ebs, "kms_key_id", null) + snapshot_id = lookup(block_device_mappings.value.ebs, "snapshot_id", null) + volume_size = lookup(block_device_mappings.value.ebs, "volume_size", null) + volume_type = lookup(block_device_mappings.value.ebs, "volume_type", null) } } } diff --git a/variables.tf b/variables.tf index 720e4de..0174514 100644 --- a/variables.tf +++ b/variables.tf @@ -323,7 +323,7 @@ variable "scale_up_adjustment_type" { variable "scale_up_policy_type" { type = string default = "SimpleScaling" - description = "The scalling policy type, either `SimpleScaling`, `StepScaling` or `TargetTrackingScaling`" + description = "The scaling policy type. Currently only `SimpleScaling` is supported" } variable "scale_down_cooldown_seconds" { @@ -347,7 +347,7 @@ variable "scale_down_adjustment_type" { variable "scale_down_policy_type" { type = string default = "SimpleScaling" - description = "The scalling policy type, either `SimpleScaling`, `StepScaling` or `TargetTrackingScaling`" + description = "The scaling policy type. Currently only `SimpleScaling` is supported" } variable "cpu_utilization_high_evaluation_periods" {