Skip to content

Commit 9041bed

Browse files
authored
feat!: Upgrade AWS provider and min required Terraform version to 6.0 and 1.5.7 respectively (#24)
1 parent 4ab499f commit 9041bed

File tree

8 files changed

+115
-43
lines changed

8 files changed

+115
-43
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ Examples codified under the [`examples`](https://github.com/terraform-aws-module
5757

5858
| Name | Version |
5959
|------|---------|
60-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
61-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.32 |
60+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5.7 |
61+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.0 |
6262

6363
## Providers
6464

6565
| Name | Version |
6666
|------|---------|
67-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.32 |
67+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 6.0 |
6868

6969
## Modules
7070

@@ -74,6 +74,7 @@ No modules.
7474

7575
| Name | Type |
7676
|------|------|
77+
| [aws_cloudwatch_log_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource |
7778
| [aws_prometheus_alert_manager_definition.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/prometheus_alert_manager_definition) | resource |
7879
| [aws_prometheus_rule_group_namespace.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/prometheus_rule_group_namespace) | resource |
7980
| [aws_prometheus_workspace.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/prometheus_workspace) | resource |
@@ -83,12 +84,18 @@ No modules.
8384
| Name | Description | Type | Default | Required |
8485
|------|-------------|------|---------|:--------:|
8586
| <a name="input_alert_manager_definition"></a> [alert\_manager\_definition](#input\_alert\_manager\_definition) | The alert manager definition that you want to be applied. See more in the [AWS Docs](https://docs.aws.amazon.com/prometheus/latest/userguide/AMP-alert-manager.html) | `string` | `"alertmanager_config: |\n route:\n receiver: 'default'\n receivers:\n - name: 'default'\n"` | no |
87+
| <a name="input_cloudwatch_log_group_class"></a> [cloudwatch\_log\_group\_class](#input\_cloudwatch\_log\_group\_class) | Specified the log class of the log group. Possible values are: `STANDARD` or `INFREQUENT_ACCESS` | `string` | `null` | no |
88+
| <a name="input_cloudwatch_log_group_kms_key_id"></a> [cloudwatch\_log\_group\_kms\_key\_id](#input\_cloudwatch\_log\_group\_kms\_key\_id) | If a KMS Key ARN is set, this key will be used to encrypt the corresponding log group. Please be sure that the KMS Key has an appropriate key policy (https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/encrypt-log-data-kms.html) | `string` | `null` | no |
89+
| <a name="input_cloudwatch_log_group_name"></a> [cloudwatch\_log\_group\_name](#input\_cloudwatch\_log\_group\_name) | Custom name of CloudWatch log group for a service associated with the container definition | `string` | `null` | no |
90+
| <a name="input_cloudwatch_log_group_retention_in_days"></a> [cloudwatch\_log\_group\_retention\_in\_days](#input\_cloudwatch\_log\_group\_retention\_in\_days) | Number of days to retain log events. Set to `0` to keep logs indefinitely | `number` | `30` | no |
91+
| <a name="input_cloudwatch_log_group_use_name_prefix"></a> [cloudwatch\_log\_group\_use\_name\_prefix](#input\_cloudwatch\_log\_group\_use\_name\_prefix) | Determines whether the log group name should be used as a prefix | `bool` | `false` | no |
8692
| <a name="input_create"></a> [create](#input\_create) | Determines whether a resources will be created | `bool` | `true` | no |
8793
| <a name="input_create_alert_manager"></a> [create\_alert\_manager](#input\_create\_alert\_manager) | Controls whether an Alert Manager definition is created along with the AMP workspace | `bool` | `true` | no |
8894
| <a name="input_create_workspace"></a> [create\_workspace](#input\_create\_workspace) | Determines whether a workspace will be created or to use an existing workspace | `bool` | `true` | no |
8995
| <a name="input_kms_key_arn"></a> [kms\_key\_arn](#input\_kms\_key\_arn) | The ARN of the KMS Key to for encryption at rest | `string` | `null` | no |
90-
| <a name="input_logging_configuration"></a> [logging\_configuration](#input\_logging\_configuration) | The logging configuration of the prometheus workspace. | `map(string)` | `{}` | no |
91-
| <a name="input_rule_group_namespaces"></a> [rule\_group\_namespaces](#input\_rule\_group\_namespaces) | A map of one or more rule group namespace definitions | `map(any)` | `{}` | no |
96+
| <a name="input_logging_configuration"></a> [logging\_configuration](#input\_logging\_configuration) | The logging configuration of the prometheus workspace. | <pre>object({<br/> create_log_group = optional(bool, true)<br/> logging_configuration = optional(string)<br/> })</pre> | `null` | no |
97+
| <a name="input_region"></a> [region](#input\_region) | Region where the resource(s) will be managed. Defaults to the Region set in the provider configuration | `string` | `null` | no |
98+
| <a name="input_rule_group_namespaces"></a> [rule\_group\_namespaces](#input\_rule\_group\_namespaces) | A map of one or more rule group namespace definitions | <pre>map(object({<br/> name = string<br/> data = string<br/> }))</pre> | `null` | no |
9299
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
93100
| <a name="input_workspace_alias"></a> [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 |
94101
| <a name="input_workspace_id"></a> [workspace\_id](#input\_workspace\_id) | The ID of an existing workspace to use when `create_workspace` is `false` | `string` | `""` | no |

examples/complete/README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ Configuration in this directory creates:
1111
To run this example you need to execute:
1212

1313
```bash
14-
$ terraform init
15-
$ terraform plan
16-
$ terraform apply
14+
terraform init
15+
terraform plan
16+
terraform apply
1717
```
1818

1919
Note that this example may create resources which will incur monetary charges on your AWS bill. Run `terraform destroy` when you no longer need these resources.
@@ -23,14 +23,12 @@ Note that this example may create resources which will incur monetary charges on
2323

2424
| Name | Version |
2525
|------|---------|
26-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
27-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.32 |
26+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5.7 |
27+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.0 |
2828

2929
## Providers
3030

31-
| Name | Version |
32-
|------|---------|
33-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.32 |
31+
No providers.
3432

3533
## Modules
3634

@@ -42,9 +40,7 @@ Note that this example may create resources which will incur monetary charges on
4240

4341
## Resources
4442

45-
| Name | Type |
46-
|------|------|
47-
| [aws_cloudwatch_log_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource |
43+
No resources.
4844

4945
## Inputs
5046

examples/complete/main.tf

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ provider "aws" {
44

55
locals {
66
region = "us-east-1"
7-
name = "amp-ex-${replace(basename(path.cwd), "_", "-")}"
7+
name = "amp-ex-${basename(path.cwd)}"
88
}
99

1010
################################################################################
@@ -16,7 +16,9 @@ module "prometheus" {
1616

1717
workspace_alias = local.name
1818
logging_configuration = {
19-
log_group_arn = "${aws_cloudwatch_log_group.this.arn}:*"
19+
create_log_group = true
20+
# To use externally created log group
21+
# log_group_arn = "${aws_cloudwatch_log_group.this.arn}:*"
2022
}
2123

2224
create_alert_manager = true
@@ -52,21 +54,14 @@ module "prometheus" {
5254
}
5355
}
5456

55-
module "disabled" {
56-
source = "../.."
57-
58-
create = false
59-
}
60-
6157
module "default" {
6258
source = "../.."
6359

6460
workspace_alias = "${local.name}-default"
6561
}
6662

67-
################################################################################
68-
# Supporting Resources
69-
################################################################################
70-
resource "aws_cloudwatch_log_group" "this" {
71-
name = "example-aws-managed-service-prometheus-complete"
63+
module "disabled" {
64+
source = "../.."
65+
66+
create = false
7267
}

examples/complete/versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
2-
required_version = ">= 1.3"
2+
required_version = ">= 1.5.7"
33

44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.32"
7+
version = ">= 6.0"
88
}
99
}
1010
}

main.tf

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,53 @@ locals {
99
resource "aws_prometheus_workspace" "this" {
1010
count = var.create && var.create_workspace ? 1 : 0
1111

12+
region = var.region
13+
1214
alias = var.workspace_alias
1315
kms_key_arn = var.kms_key_arn
1416

1517
dynamic "logging_configuration" {
16-
for_each = length(var.logging_configuration) > 0 ? [var.logging_configuration] : []
18+
for_each = var.logging_configuration != null ? [var.logging_configuration] : []
1719

1820
content {
19-
log_group_arn = logging_configuration.value.log_group_arn
21+
log_group_arn = logging_configuration.value.create_log_group ? "${aws_cloudwatch_log_group.this[0].arn}:*" : logging_configuration.value.log_group_arn
2022
}
2123
}
2224

2325
tags = var.tags
2426
}
2527

28+
################################################################################
29+
# Cloudwatch Log Group
30+
################################################################################
31+
32+
locals {
33+
log_group_name = try(coalesce(var.cloudwatch_log_group_name, "/aws/prometheus/${var.workspace_alias}"), "")
34+
}
35+
36+
resource "aws_cloudwatch_log_group" "this" {
37+
count = var.create && var.create_workspace && try(coalesce(var.logging_configuration.create_log_group), true) ? 1 : 0
38+
39+
region = var.region
40+
41+
name = var.cloudwatch_log_group_use_name_prefix ? null : local.log_group_name
42+
name_prefix = var.cloudwatch_log_group_use_name_prefix ? "${local.log_group_name}-" : null
43+
log_group_class = var.cloudwatch_log_group_class
44+
retention_in_days = var.cloudwatch_log_group_retention_in_days
45+
kms_key_id = var.cloudwatch_log_group_kms_key_id
46+
47+
tags = var.tags
48+
}
49+
2650
################################################################################
2751
# Alert Manager Definition
2852
################################################################################
2953

3054
resource "aws_prometheus_alert_manager_definition" "this" {
3155
count = var.create && var.create_alert_manager ? 1 : 0
3256

57+
region = var.region
58+
3359
workspace_id = local.workspace_id
3460
definition = var.alert_manager_definition
3561
}
@@ -39,7 +65,9 @@ resource "aws_prometheus_alert_manager_definition" "this" {
3965
################################################################################
4066

4167
resource "aws_prometheus_rule_group_namespace" "this" {
42-
for_each = var.create ? var.rule_group_namespaces : {}
68+
for_each = var.create && var.rule_group_namespaces != null ? var.rule_group_namespaces : {}
69+
70+
region = var.region
4371

4472
name = each.value.name
4573
workspace_id = local.workspace_id

outputs.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
output "workspace_arn" {
66
description = "Amazon Resource Name (ARN) of the workspace"
7-
value = try(aws_prometheus_workspace.this[0].arn, "")
7+
value = try(aws_prometheus_workspace.this[0].arn, null)
88
}
99

1010
output "workspace_id" {
1111
description = "Identifier of the workspace"
12-
value = try(aws_prometheus_workspace.this[0].id, "")
12+
value = try(aws_prometheus_workspace.this[0].id, null)
1313
}
1414

1515
output "workspace_prometheus_endpoint" {
1616
description = "Prometheus endpoint available for this workspace"
17-
value = try(aws_prometheus_workspace.this[0].prometheus_endpoint, "")
17+
value = try(aws_prometheus_workspace.this[0].prometheus_endpoint, null)
1818
}

variables.tf

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ variable "create" {
44
default = true
55
}
66

7+
variable "region" {
8+
description = "Region where the resource(s) will be managed. Defaults to the Region set in the provider configuration"
9+
type = string
10+
default = null
11+
}
12+
713
variable "tags" {
814
description = "A map of tags to add to all resources"
915
type = map(string)
@@ -34,8 +40,11 @@ variable "workspace_alias" {
3440

3541
variable "logging_configuration" {
3642
description = "The logging configuration of the prometheus workspace."
37-
type = map(string)
38-
default = {}
43+
type = object({
44+
create_log_group = optional(bool, true)
45+
logging_configuration = optional(string)
46+
})
47+
default = null
3948
}
4049

4150
variable "kms_key_arn" {
@@ -44,6 +53,40 @@ variable "kms_key_arn" {
4453
default = null
4554
}
4655

56+
################################################################################
57+
# CloudWatch Log Group
58+
################################################################################
59+
60+
variable "cloudwatch_log_group_name" {
61+
description = "Custom name of CloudWatch log group for a service associated with the container definition"
62+
type = string
63+
default = null
64+
}
65+
66+
variable "cloudwatch_log_group_use_name_prefix" {
67+
description = "Determines whether the log group name should be used as a prefix"
68+
type = bool
69+
default = false
70+
}
71+
72+
variable "cloudwatch_log_group_class" {
73+
description = "Specified the log class of the log group. Possible values are: `STANDARD` or `INFREQUENT_ACCESS`"
74+
type = string
75+
default = null
76+
}
77+
78+
variable "cloudwatch_log_group_retention_in_days" {
79+
description = "Number of days to retain log events. Set to `0` to keep logs indefinitely"
80+
type = number
81+
default = 30
82+
}
83+
84+
variable "cloudwatch_log_group_kms_key_id" {
85+
description = "If a KMS Key ARN is set, this key will be used to encrypt the corresponding log group. Please be sure that the KMS Key has an appropriate key policy (https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/encrypt-log-data-kms.html)"
86+
type = string
87+
default = null
88+
}
89+
4790
################################################################################
4891
# Alert Manager Definition
4992
################################################################################
@@ -72,6 +115,9 @@ variable "alert_manager_definition" {
72115

73116
variable "rule_group_namespaces" {
74117
description = "A map of one or more rule group namespace definitions"
75-
type = map(any)
76-
default = {}
118+
type = map(object({
119+
name = string
120+
data = string
121+
}))
122+
default = null
77123
}

versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
2-
required_version = ">= 1.3"
2+
required_version = ">= 1.5.7"
33

44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.32"
7+
version = ">= 6.0"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)