From 54a386172f3a6b4acd708d507114c1d2b5304bde Mon Sep 17 00:00:00 2001 From: Illia Pshonkin Date: Thu, 20 Nov 2025 16:07:33 +0100 Subject: [PATCH 1/2] feat: Add workspace configuration support --- README.md | 3 +++ examples/complete/main.tf | 21 +++++++++++++++++++++ main.tf | 19 +++++++++++++++++++ variables.tf | 17 +++++++++++++++++ 4 files changed, 60 insertions(+) diff --git a/README.md b/README.md index abeb46b..fe9cede 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ No modules. | [aws_prometheus_alert_manager_definition.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/prometheus_alert_manager_definition) | resource | | [aws_prometheus_rule_group_namespace.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/prometheus_rule_group_namespace) | resource | | [aws_prometheus_workspace.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/prometheus_workspace) | resource | +| [aws_prometheus_workspace_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/prometheus_workspace_configuration) | resource | ## Inputs @@ -93,8 +94,10 @@ No modules. | [create\_alert\_manager](#input\_create\_alert\_manager) | Controls whether an Alert Manager definition is created along with the AMP workspace | `bool` | `true` | no | | [create\_workspace](#input\_create\_workspace) | Determines whether a workspace will be created or to use an existing workspace | `bool` | `true` | no | | [kms\_key\_arn](#input\_kms\_key\_arn) | The ARN of the KMS Key to for encryption at rest | `string` | `null` | no | +| [limits\_per\_label\_set](#input\_limits\_per\_label\_set) | Configuration block for setting limits on metrics with specific label sets. |
list(object({
label_set = map(string)
limits = object({
max_series = number
})
}))
| `null` | no | | [logging\_configuration](#input\_logging\_configuration) | The logging configuration of the prometheus workspace. |
object({
create_log_group = optional(bool, true)
logging_configuration = optional(string)
})
| `null` | no | | [region](#input\_region) | Region where the resource(s) will be managed. Defaults to the Region set in the provider configuration | `string` | `null` | no | +| [retention\_period\_in\_days](#input\_retention\_period\_in\_days) | Number of days to retain metric data in the workspace. | `number` | `null` | no | | [rule\_group\_namespaces](#input\_rule\_group\_namespaces) | A map of one or more rule group namespace definitions |
map(object({
name = string
data = string
}))
| `null` | no | | [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no | | [workspace\_alias](#input\_workspace\_alias) | The alias of the prometheus workspace. See more in the [AWS Docs](https://docs.aws.amazon.com/prometheus/latest/userguide/AMP-onboard-create-workspace.html) | `string` | `null` | no | diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 4407371..b5c38ed 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -21,6 +21,27 @@ module "prometheus" { # log_group_arn = "${aws_cloudwatch_log_group.this.arn}:*" } + retention_period_in_days = 60 + + limits_per_label_set = [ + { + label_set = { + "env" = "dev" + } + limits = { + max_series = 100000 + } + }, + { + label_set = { + "env" = "prod" + } + limits = { + max_series = 400000 + } + } + ] + create_alert_manager = true alert_manager_definition = <<-EOT alertmanager_config: | diff --git a/main.tf b/main.tf index 5673070..a72e140 100644 --- a/main.tf +++ b/main.tf @@ -25,6 +25,25 @@ resource "aws_prometheus_workspace" "this" { tags = var.tags } +resource "aws_prometheus_workspace_configuration" "this" { + count = var.create && var.create_workspace ? 1 : 0 + workspace_id = local.workspace_id + + retention_period_in_days = var.retention_period_in_days + + dynamic "limits_per_label_set" { + for_each = var.limits_per_label_set + content { + label_set = limits_per_label_set.value.label_set + + limits { + max_series = limits_per_label_set.value.limits.max_series + } + } + } + +} + ################################################################################ # Cloudwatch Log Group ################################################################################ diff --git a/variables.tf b/variables.tf index 131ce82..b9737e4 100644 --- a/variables.tf +++ b/variables.tf @@ -38,6 +38,23 @@ variable "workspace_alias" { default = null } +variable "retention_period_in_days" { + description = "Number of days to retain metric data in the workspace." + type = number + default = null +} + +variable "limits_per_label_set" { + description = "Configuration block for setting limits on metrics with specific label sets." + type = list(object({ + label_set = map(string) + limits = object({ + max_series = number + }) + })) + default = null +} + variable "logging_configuration" { description = "The logging configuration of the prometheus workspace." type = object({ From 9f0e229262b1bfc942be8638d3f64ccd57d9f57c Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Fri, 21 Nov 2025 10:38:35 -0600 Subject: [PATCH 2/2] fix: Update MSV AWS provider and separate workspace configuration --- .pre-commit-config.yaml | 2 +- README.md | 8 ++++---- examples/complete/README.md | 2 +- examples/complete/versions.tf | 2 +- main.tf | 20 +++++++++++++----- variables.tf | 38 +++++++++++++++++++---------------- versions.tf | 2 +- 7 files changed, 44 insertions(+), 30 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9223e3c..efc335f 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.103.0 + rev: v1.104.0 hooks: - id: terraform_fmt - id: terraform_docs diff --git a/README.md b/README.md index fe9cede..d44e096 100644 --- a/README.md +++ b/README.md @@ -58,13 +58,13 @@ Examples codified under the [`examples`](https://github.com/terraform-aws-module | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 1.5.7 | -| [aws](#requirement\_aws) | >= 6.0 | +| [aws](#requirement\_aws) | >= 6.22 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 6.0 | +| [aws](#provider\_aws) | >= 6.22 | ## Modules @@ -94,10 +94,10 @@ No modules. | [create\_alert\_manager](#input\_create\_alert\_manager) | Controls whether an Alert Manager definition is created along with the AMP workspace | `bool` | `true` | no | | [create\_workspace](#input\_create\_workspace) | Determines whether a workspace will be created or to use an existing workspace | `bool` | `true` | no | | [kms\_key\_arn](#input\_kms\_key\_arn) | The ARN of the KMS Key to for encryption at rest | `string` | `null` | no | -| [limits\_per\_label\_set](#input\_limits\_per\_label\_set) | Configuration block for setting limits on metrics with specific label sets. |
list(object({
label_set = map(string)
limits = object({
max_series = number
})
}))
| `null` | no | +| [limits\_per\_label\_set](#input\_limits\_per\_label\_set) | Configuration block for setting limits on metrics with specific label sets |
list(object({
label_set = map(string)
limits = object({
max_series = number
})
}))
| `null` | no | | [logging\_configuration](#input\_logging\_configuration) | The logging configuration of the prometheus workspace. |
object({
create_log_group = optional(bool, true)
logging_configuration = optional(string)
})
| `null` | no | | [region](#input\_region) | Region where the resource(s) will be managed. Defaults to the Region set in the provider configuration | `string` | `null` | no | -| [retention\_period\_in\_days](#input\_retention\_period\_in\_days) | Number of days to retain metric data in the workspace. | `number` | `null` | no | +| [retention\_period\_in\_days](#input\_retention\_period\_in\_days) | Number of days to retain metric data in the workspace | `number` | `null` | no | | [rule\_group\_namespaces](#input\_rule\_group\_namespaces) | A map of one or more rule group namespace definitions |
map(object({
name = string
data = string
}))
| `null` | no | | [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no | | [workspace\_alias](#input\_workspace\_alias) | The alias of the prometheus workspace. See more in the [AWS Docs](https://docs.aws.amazon.com/prometheus/latest/userguide/AMP-onboard-create-workspace.html) | `string` | `null` | no | diff --git a/examples/complete/README.md b/examples/complete/README.md index 5eb3555..b49dbf5 100644 --- a/examples/complete/README.md +++ b/examples/complete/README.md @@ -24,7 +24,7 @@ Note that this example may create resources which will incur monetary charges on | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 1.5.7 | -| [aws](#requirement\_aws) | >= 6.0 | +| [aws](#requirement\_aws) | >= 6.22 | ## Providers diff --git a/examples/complete/versions.tf b/examples/complete/versions.tf index db13b0a..0cf1cd7 100644 --- a/examples/complete/versions.tf +++ b/examples/complete/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 6.0" + version = ">= 6.22" } } } diff --git a/main.tf b/main.tf index a72e140..559508b 100644 --- a/main.tf +++ b/main.tf @@ -25,23 +25,33 @@ resource "aws_prometheus_workspace" "this" { tags = var.tags } +################################################################################ +# Workspace Configuration +################################################################################ + resource "aws_prometheus_workspace_configuration" "this" { - count = var.create && var.create_workspace ? 1 : 0 - workspace_id = local.workspace_id + count = var.create && var.create_workspace ? 1 : 0 + + region = var.region retention_period_in_days = var.retention_period_in_days + workspace_id = local.workspace_id dynamic "limits_per_label_set" { for_each = var.limits_per_label_set + content { label_set = limits_per_label_set.value.label_set - limits { - max_series = limits_per_label_set.value.limits.max_series + dynamic "limits" { + for_each = limits_per_label_set.value.limits + + content { + max_series = limits.value.max_series + } } } } - } ################################################################################ diff --git a/variables.tf b/variables.tf index b9737e4..d4e79c4 100644 --- a/variables.tf +++ b/variables.tf @@ -38,23 +38,6 @@ variable "workspace_alias" { default = null } -variable "retention_period_in_days" { - description = "Number of days to retain metric data in the workspace." - type = number - default = null -} - -variable "limits_per_label_set" { - description = "Configuration block for setting limits on metrics with specific label sets." - type = list(object({ - label_set = map(string) - limits = object({ - max_series = number - }) - })) - default = null -} - variable "logging_configuration" { description = "The logging configuration of the prometheus workspace." type = object({ @@ -70,6 +53,27 @@ variable "kms_key_arn" { default = null } +################################################################################ +# Workspace Configuration +################################################################################ + +variable "retention_period_in_days" { + description = "Number of days to retain metric data in the workspace" + type = number + default = null +} + +variable "limits_per_label_set" { + description = "Configuration block for setting limits on metrics with specific label sets" + type = list(object({ + label_set = map(string) + limits = object({ + max_series = number + }) + })) + default = null +} + ################################################################################ # CloudWatch Log Group ################################################################################ diff --git a/versions.tf b/versions.tf index db13b0a..0cf1cd7 100644 --- a/versions.tf +++ b/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 6.0" + version = ">= 6.22" } } }