Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Use launch_template_id instead of launch_template_name, raise MSV of AWS provider and Terraform to 5.0 and 1.0 respectively #204

Merged
merged 10 commits into from
Oct 9, 2023
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.79.1
rev: v1.83.4
hooks:
- id: terraform_fmt
- id: terraform_validate
Expand All @@ -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.4.0
rev: v4.5.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ Note: the default behavior of the module is to create an autoscaling group and l

- Create the autoscaling policies:

```
```hcl
scaling_policies = {
my-policy = {
policy_type = "TargetTrackingScaling"
Expand All @@ -226,14 +226,14 @@ Note: the default behavior of the module is to create an autoscaling group and l

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.57 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.57 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |

## Modules

Expand All @@ -251,7 +251,6 @@ No modules.
| [aws_iam_role.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
| [aws_iam_role_policy_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | 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 |
| [aws_iam_policy_document.assume_role_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |

Expand Down Expand Up @@ -309,8 +308,8 @@ No modules.
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | The type of the instance. If present then `instance_requirements` cannot be present | `string` | `null` | no |
| <a name="input_kernel_id"></a> [kernel\_id](#input\_kernel\_id) | The kernel ID | `string` | `null` | no |
| <a name="input_key_name"></a> [key\_name](#input\_key\_name) | The key name that should be used for the instance | `string` | `null` | no |
| <a name="input_launch_template"></a> [launch\_template](#input\_launch\_template) | Name of an existing launch template to be used (created outside of this module) | `string` | `null` | no |
| <a name="input_launch_template_description"></a> [launch\_template\_description](#input\_launch\_template\_description) | Description of the launch template | `string` | `null` | no |
| <a name="input_launch_template_id"></a> [launch\_template\_id](#input\_launch\_template\_id) | ID of an existing launch template to be used (created outside of this module) | `string` | `null` | no |
| <a name="input_launch_template_name"></a> [launch\_template\_name](#input\_launch\_template\_name) | Name of launch template to be created | `string` | `""` | no |
| <a name="input_launch_template_use_name_prefix"></a> [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 |
| <a name="input_launch_template_version"></a> [launch\_template\_version](#input\_launch\_template\_version) | Launch template version. Can be version number, `$Latest`, or `$Default` | `string` | `null` | no |
Expand Down
15 changes: 8 additions & 7 deletions examples/complete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ Note that this example may create resources which cost money. Run `terraform des

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.22 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.22 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_alb"></a> [alb](#module\_alb) | terraform-aws-modules/alb/aws | ~> 6.0 |
| <a name="module_alb_http_sg"></a> [alb\_http\_sg](#module\_alb\_http\_sg) | terraform-aws-modules/security-group/aws//modules/http-80 | ~> 4.0 |
| <a name="module_asg_sg"></a> [asg\_sg](#module\_asg\_sg) | terraform-aws-modules/security-group/aws | ~> 4.0 |
| <a name="module_alb"></a> [alb](#module\_alb) | terraform-aws-modules/alb/aws | ~> 8.0 |
| <a name="module_alb_http_sg"></a> [alb\_http\_sg](#module\_alb\_http\_sg) | terraform-aws-modules/security-group/aws//modules/http-80 | ~> 5.0 |
| <a name="module_asg_sg"></a> [asg\_sg](#module\_asg\_sg) | terraform-aws-modules/security-group/aws | ~> 5.0 |
| <a name="module_complete"></a> [complete](#module\_complete) | ../../ | n/a |
| <a name="module_default"></a> [default](#module\_default) | ../../ | n/a |
| <a name="module_disabled"></a> [disabled](#module\_disabled) | ../../ | n/a |
Expand All @@ -54,8 +54,9 @@ Note that this example may create resources which cost money. Run `terraform des
| <a name="module_instance_requirements_accelerators"></a> [instance\_requirements\_accelerators](#module\_instance\_requirements\_accelerators) | ../../ | n/a |
| <a name="module_launch_template_only"></a> [launch\_template\_only](#module\_launch\_template\_only) | ../../ | n/a |
| <a name="module_mixed_instance"></a> [mixed\_instance](#module\_mixed\_instance) | ../../ | n/a |
| <a name="module_step_scaling_alarm"></a> [step\_scaling\_alarm](#module\_step\_scaling\_alarm) | terraform-aws-modules/cloudwatch/aws//modules/metric-alarm | ~> 4.3 |
| <a name="module_target_tracking_customized_metrics"></a> [target\_tracking\_customized\_metrics](#module\_target\_tracking\_customized\_metrics) | ../../ | n/a |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |
| <a name="module_warm_pool"></a> [warm\_pool](#module\_warm\_pool) | ../../ | n/a |

## Resources
Expand Down
61 changes: 40 additions & 21 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,23 @@ module "complete" {
target_value = 800
}
}
scale-out = {
name = "scale-out"
adjustment_type = "ExactCapacity"
policy_type = "StepScaling"
estimated_instance_warmup = 120
step_adjustment = [
{
scaling_adjustment = 1
metric_interval_lower_bound = 0
metric_interval_upper_bound = 10
},
{
scaling_adjustment = 2
metric_interval_lower_bound = 10
}
]
}
}
}

Expand Down Expand Up @@ -713,7 +730,7 @@ module "external" {

# Launch template
create_launch_template = false
launch_template = aws_launch_template.this.name
launch_template_id = aws_launch_template.this.id

tags = local.tags
}
Expand Down Expand Up @@ -780,7 +797,7 @@ module "default" {

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 3.0"
version = "~> 5.0"

name = local.name
cidr = local.vpc_cidr
Expand All @@ -789,15 +806,12 @@ module "vpc" {
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k)]
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 10)]

enable_dns_hostnames = true
enable_dns_support = true

tags = local.tags
}

module "asg_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "~> 4.0"
version = "~> 5.0"

name = local.name
description = "A security group"
Expand Down Expand Up @@ -867,7 +881,7 @@ resource "aws_iam_role" "ssm" {

module "alb_http_sg" {
source = "terraform-aws-modules/security-group/aws//modules/http-80"
version = "~> 4.0"
version = "~> 5.0"

name = "${local.name}-alb-http"
vpc_id = module.vpc.vpc_id
Expand All @@ -880,7 +894,7 @@ module "alb_http_sg" {

module "alb" {
source = "terraform-aws-modules/alb/aws"
version = "~> 6.0"
version = "~> 8.0"

name = local.name

Expand Down Expand Up @@ -916,21 +930,26 @@ resource "aws_ec2_capacity_reservation" "targeted" {
instance_match_criteria = "targeted"
}

# resource "aws_licensemanager_license_configuration" "test" {
# license_count = 1
# license_count_hard_limit = true
# license_counting_type = "Socket"
# name = "test-license"

# license_rules = [
# "#allowedTenancy=EC2-DedicatedHost",
# "#maximumSockets=2",
# "#minimumSockets=2",
# ]
# }

resource "aws_sqs_queue" "this" {
name = local.name

tags = local.tags
}

module "step_scaling_alarm" {
source = "terraform-aws-modules/cloudwatch/aws//modules/metric-alarm"
version = "~> 4.3"

alarm_name = "${local.name}-step-scaling"
alarm_description = "Step Scaling Alarm Example"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = 1
threshold = 40
period = 300

namespace = "AWS/EC2"
metric_name = "CPUUtilization"
statistic = "Average"

alarm_actions = [module.complete.autoscaling_policy_arns["scale-out"]]
}
4 changes: 2 additions & 2 deletions examples/complete/versions.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
terraform {
required_version = ">= 0.13.1"
required_version = ">= 1.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.22"
version = ">= 5.0"
}
}
}
18 changes: 8 additions & 10 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
data "aws_partition" "current" {}
data "aws_default_tags" "current" {}

locals {
create = var.create && var.putin_khuylo

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_id = var.create_launch_template ? aws_launch_template.this[0].id : var.launch_template_id
launch_template_version = var.create_launch_template && var.launch_template_version == null ? aws_launch_template.this[0].latest_version : var.launch_template_version

asg_tags = merge(
data.aws_default_tags.current.tags,
var.tags,
{ "Name" = coalesce(var.instance_name, var.name) },
var.autoscaling_group_tags,
Expand Down Expand Up @@ -354,7 +352,7 @@ resource "aws_autoscaling_group" "this" {
for_each = var.use_mixed_instances_policy ? [] : [1]

content {
name = local.launch_template
id = local.launch_template_id
version = local.launch_template_version
}
}
Expand Down Expand Up @@ -438,8 +436,8 @@ resource "aws_autoscaling_group" "this" {

launch_template {
launch_template_specification {
launch_template_name = local.launch_template
version = local.launch_template_version
launch_template_id = local.launch_template_id
version = local.launch_template_version
}

dynamic "override" {
Expand Down Expand Up @@ -618,7 +616,7 @@ resource "aws_autoscaling_group" "idc" {
for_each = var.use_mixed_instances_policy ? [] : [1]

content {
name = local.launch_template
id = local.launch_template_id
version = local.launch_template_version
}
}
Expand Down Expand Up @@ -702,8 +700,8 @@ resource "aws_autoscaling_group" "idc" {

launch_template {
launch_template_specification {
launch_template_name = local.launch_template
version = local.launch_template_version
launch_template_id = local.launch_template_id
version = local.launch_template_version
}

dynamic "override" {
Expand Down Expand Up @@ -910,7 +908,7 @@ resource "aws_autoscaling_policy" "this" {
scaling_adjustment = try(each.value.scaling_adjustment, null)

dynamic "step_adjustment" {
for_each = try([each.value.step_adjustment], [])
for_each = try(each.value.step_adjustment, [])
content {
scaling_adjustment = step_adjustment.value.scaling_adjustment
metric_interval_lower_bound = try(step_adjustment.value.metric_interval_lower_bound, null)
Expand Down
4 changes: 2 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ variable "instance_name" {
default = ""
}

variable "launch_template" {
description = "Name of an existing launch template to be used (created outside of this module)"
variable "launch_template_id" {
description = "ID of an existing launch template to be used (created outside of this module)"
type = string
default = null
}
Expand Down
4 changes: 2 additions & 2 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
terraform {
required_version = ">= 0.13.1"
required_version = ">= 1.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.57"
version = ">= 5.0"
}
}
}