From cd6919dde44aa4d72fb056beb63157114f36e072 Mon Sep 17 00:00:00 2001 From: Matthew Altberg Date: Tue, 14 May 2024 09:23:14 -0400 Subject: [PATCH 1/2] feat: add support for custom metric queries in customized metric spec --- modules/service/main.tf | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/modules/service/main.tf b/modules/service/main.tf index c024b52..b49afc2 100644 --- a/modules/service/main.tf +++ b/modules/service/main.tf @@ -1243,6 +1243,37 @@ resource "aws_appautoscaling_policy" "this" { for_each = try([target_tracking_scaling_policy_configuration.value.customized_metric_specification], []) content { + dynamic "metrics"{ + for_each = try(customized_metric_specification.value.metrics, []) + content { + id = metrics.value.id + label = try(metrics.value.label, null) + return_data = try(metrics.value.return_data, true) + expression = try(metrics.value.expression, null) + + + dynamic "metric_stat" { + for_each = try([metrics.value.metric_stat], []) + content { + stat = metric_stat.value.stat + dynamic "metric" { + for_each = try([metric_stat.value.metric], []) + content { + namespace = metric.value.namespace + metric_name = metric.value.metric_name + dynamic "dimensions" { + for_each = try(metric.value.dimensions, []) + content { + name = dimensions.value.name + value = dimensions.value.value + } + } + } + } + } + } + } + } dynamic "dimensions" { for_each = try(customized_metric_specification.value.dimensions, []) @@ -1252,9 +1283,9 @@ resource "aws_appautoscaling_policy" "this" { } } - metric_name = customized_metric_specification.value.metric_name - namespace = customized_metric_specification.value.namespace - statistic = customized_metric_specification.value.statistic + metric_name = try(customized_metric_specification.value.metric_name, null) + namespace = try(customized_metric_specification.value.namespace, null) + statistic = try(customized_metric_specification.value.statistic, null) unit = try(customized_metric_specification.value.unit, null) } } From aa6b6e737dfd10f6f6ad4a42ed86e4fffe284e0c Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Fri, 31 May 2024 13:27:17 -0400 Subject: [PATCH 2/2] fix: Update and run pre-commit checks to format --- .pre-commit-config.yaml | 4 ++-- modules/service/main.tf | 12 ++++++------ wrappers/cluster/versions.tf | 9 ++++++++- wrappers/container-definition/versions.tf | 9 ++++++++- wrappers/service/versions.tf | 9 ++++++++- wrappers/versions.tf | 9 ++++++++- 6 files changed, 40 insertions(+), 12 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 89d40d7..3f82491 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.86.0 + rev: v1.90.0 hooks: - id: terraform_fmt - id: terraform_wrapper_module_for_each @@ -24,7 +24,7 @@ repos: - '--args=--only=terraform_workspace_remote' - id: terraform_validate - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v4.6.0 hooks: - id: check-merge-conflict - id: end-of-file-fixer diff --git a/modules/service/main.tf b/modules/service/main.tf index b49afc2..61a3e5a 100644 --- a/modules/service/main.tf +++ b/modules/service/main.tf @@ -1243,13 +1243,13 @@ resource "aws_appautoscaling_policy" "this" { for_each = try([target_tracking_scaling_policy_configuration.value.customized_metric_specification], []) content { - dynamic "metrics"{ + dynamic "metrics" { for_each = try(customized_metric_specification.value.metrics, []) content { - id = metrics.value.id - label = try(metrics.value.label, null) + id = metrics.value.id + label = try(metrics.value.label, null) return_data = try(metrics.value.return_data, true) - expression = try(metrics.value.expression, null) + expression = try(metrics.value.expression, null) dynamic "metric_stat" { @@ -1259,12 +1259,12 @@ resource "aws_appautoscaling_policy" "this" { dynamic "metric" { for_each = try([metric_stat.value.metric], []) content { - namespace = metric.value.namespace + namespace = metric.value.namespace metric_name = metric.value.metric_name dynamic "dimensions" { for_each = try(metric.value.dimensions, []) content { - name = dimensions.value.name + name = dimensions.value.name value = dimensions.value.value } } diff --git a/wrappers/cluster/versions.tf b/wrappers/cluster/versions.tf index 51cad10..63e9319 100644 --- a/wrappers/cluster/versions.tf +++ b/wrappers/cluster/versions.tf @@ -1,3 +1,10 @@ terraform { - required_version = ">= 0.13.1" + required_version = ">= 1.3" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.34" + } + } } diff --git a/wrappers/container-definition/versions.tf b/wrappers/container-definition/versions.tf index 51cad10..63e9319 100644 --- a/wrappers/container-definition/versions.tf +++ b/wrappers/container-definition/versions.tf @@ -1,3 +1,10 @@ terraform { - required_version = ">= 0.13.1" + required_version = ">= 1.3" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.34" + } + } } diff --git a/wrappers/service/versions.tf b/wrappers/service/versions.tf index 51cad10..63e9319 100644 --- a/wrappers/service/versions.tf +++ b/wrappers/service/versions.tf @@ -1,3 +1,10 @@ terraform { - required_version = ">= 0.13.1" + required_version = ">= 1.3" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.34" + } + } } diff --git a/wrappers/versions.tf b/wrappers/versions.tf index 51cad10..63e9319 100644 --- a/wrappers/versions.tf +++ b/wrappers/versions.tf @@ -1,3 +1,10 @@ terraform { - required_version = ">= 0.13.1" + required_version = ">= 1.3" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.34" + } + } }