Skip to content

Commit af5b76b

Browse files
committed
feat: Add workspace resource policy support
1 parent 5952bb7 commit af5b76b

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,18 @@ No modules.
7676
|------|------|
7777
| [aws_cloudwatch_log_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource |
7878
| [aws_prometheus_alert_manager_definition.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/prometheus_alert_manager_definition) | resource |
79+
| [aws_prometheus_resource_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/prometheus_resource_policy) | resource |
7980
| [aws_prometheus_rule_group_namespace.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/prometheus_rule_group_namespace) | resource |
8081
| [aws_prometheus_workspace.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/prometheus_workspace) | resource |
8182
| [aws_prometheus_workspace_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/prometheus_workspace_configuration) | resource |
83+
| [aws_iam_policy_document.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
8284

8385
## Inputs
8486

8587
| Name | Description | Type | Default | Required |
8688
|------|-------------|------|---------|:--------:|
8789
| <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 |
90+
| <a name="input_attach_policy"></a> [attach\_policy](#input\_attach\_policy) | Controls if Prometheus Workspace should have policy attached (set to `true` to use value of `policy` as Prometheus Workspace policy) | `bool` | `false` | no |
8891
| <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 |
8992
| <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 |
9093
| <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 |
@@ -96,6 +99,7 @@ No modules.
9699
| <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 |
97100
| <a name="input_limits_per_label_set"></a> [limits\_per\_label\_set](#input\_limits\_per\_label\_set) | Configuration block for setting limits on metrics with specific label sets | <pre>list(object({<br/> label_set = map(string)<br/> limits = object({<br/> max_series = number<br/> })<br/> }))</pre> | `null` | no |
98101
| <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 |
102+
| <a name="input_policy"></a> [policy](#input\_policy) | (Optional) A valid policy JSON document. Note that if the policy document is not specific enough (but still valid), Terraform may view the policy as constantly changing in a terraform plan. In this case, please make sure you use the verbose/specific version of the policy. For more information about building AWS IAM policy documents with Terraform, see the AWS IAM Policy Document Guide. | `string` | `null` | no |
99103
| <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 |
100104
| <a name="input_retention_period_in_days"></a> [retention\_period\_in\_days](#input\_retention\_period\_in\_days) | Number of days to retain metric data in the workspace | `number` | `null` | no |
101105
| <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 |

main.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ resource "aws_prometheus_workspace_configuration" "this" {
5454
}
5555
}
5656

57+
data "aws_iam_policy_document" "this" {
58+
count = var.create && var.create_workspace && var.attach_policy ? 1 : 0
59+
60+
source_policy_documents = compact([
61+
var.attach_policy ? var.policy : ""
62+
])
63+
}
64+
65+
resource "aws_prometheus_resource_policy" "this" {
66+
count = var.create && var.create_workspace && var.attach_policy ? 1 : 0
67+
68+
region = var.region
69+
70+
workspace_id = local.workspace_id
71+
policy_document = data.aws_iam_policy_document.this[0].json
72+
}
73+
5774
################################################################################
5875
# Cloudwatch Log Group
5976
################################################################################

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ variable "limits_per_label_set" {
7474
default = null
7575
}
7676

77+
variable "attach_policy" {
78+
description = "Controls if Prometheus Workspace should have policy attached (set to `true` to use value of `policy` as Prometheus Workspace policy)"
79+
type = bool
80+
default = false
81+
}
82+
83+
variable "policy" {
84+
description = "(Optional) A valid policy JSON document. Note that if the policy document is not specific enough (but still valid), Terraform may view the policy as constantly changing in a terraform plan. In this case, please make sure you use the verbose/specific version of the policy. For more information about building AWS IAM policy documents with Terraform, see the AWS IAM Policy Document Guide."
85+
type = string
86+
default = null
87+
}
88+
7789
################################################################################
7890
# CloudWatch Log Group
7991
################################################################################

0 commit comments

Comments
 (0)