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

Updates Metric Router validation condition #611

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ No resources.
| <a name="input_enable_platform_metrics"></a> [enable\_platform\_metrics](#input\_enable\_platform\_metrics) | Receive platform metrics in the provisioned IBM Cloud Monitoring instance. | `bool` | `true` | no |
| <a name="input_global_event_routing_settings"></a> [global\_event\_routing\_settings](#input\_global\_event\_routing\_settings) | Global settings for event routing | <pre>object({<br/> default_targets = optional(list(string), [])<br/> metadata_region_primary = string<br/> metadata_region_backup = optional(string)<br/> permitted_target_regions = list(string)<br/> private_api_endpoint_only = optional(bool, false)<br/> })</pre> | `null` | no |
| <a name="input_logs_routing_tenant_regions"></a> [logs\_routing\_tenant\_regions](#input\_logs\_routing\_tenant\_regions) | Pass a list of regions to create a tenant for that is targetted to the Cloud Logs instance created by this module. To manage platform logs that are generated by IBM Cloud® services in a region of IBM Cloud, you must create a tenant in each region that you operate. Leave the list empty if you don't want to create any tenants. | `list(any)` | `[]` | no |
| <a name="input_metrics_router_routes"></a> [metrics\_router\_routes](#input\_metrics\_router\_routes) | List of routes for IBM Metrics Router. | <pre>list(object({<br/> name = string<br/> rules = list(object({<br/> action = string<br/> targets = list(object({<br/> id = string<br/> }))<br/> inclusion_filters = list(object({<br/> operand = string<br/> operator = string<br/> values = list(string)<br/> }))<br/> }))<br/> }))</pre> | `[]` | no |
| <a name="input_metrics_router_settings"></a> [metrics\_router\_settings](#input\_metrics\_router\_settings) | Global settings for Metrics Routing. | <pre>object({<br/> default_targets = list(object({<br/> id = string<br/> }))<br/> permitted_target_regions = list(string)<br/> primary_metadata_region = string<br/> backup_metadata_region = string<br/> private_api_endpoint_only = bool<br/> })</pre> | `null` | no |
| <a name="input_metrics_router_targets"></a> [metrics\_router\_targets](#input\_metrics\_router\_targets) | List of Metrics Router targets to be created. | <pre>list(object({<br/> destination_crn = string<br/> target_name = string<br/> target_region = string<br/> skip_mrouter_sysdig_iam_auth_policy = optional(bool, false)<br/> }))</pre> | `[]` | no |
| <a name="input_metrics_router_routes"></a> [metrics\_router\_routes](#input\_metrics\_router\_routes) | List of routes for IBM Metrics Router. | <pre>list(object({<br/> name = string<br/> rules = list(object({<br/> action = optional(string, "send")<br/> targets = list(object({<br/> id = string<br/> }))<br/> inclusion_filters = list(object({<br/> operand = string<br/> operator = string<br/> values = list(string)<br/> }))<br/> }))<br/> }))</pre> | `[]` | no |
| <a name="input_metrics_router_settings"></a> [metrics\_router\_settings](#input\_metrics\_router\_settings) | Global settings for Metrics Routing. | <pre>object({<br/> default_targets = optional(list(object({<br/> id = string<br/> })))<br/> permitted_target_regions = optional(list(string))<br/> primary_metadata_region = optional(string)<br/> backup_metadata_region = optional(string)<br/> private_api_endpoint_only = optional(bool, false)<br/> })</pre> | `null` | no |
| <a name="input_metrics_router_targets"></a> [metrics\_router\_targets](#input\_metrics\_router\_targets) | List of Metrics Router targets to be created. | <pre>list(object({<br/> destination_crn = string<br/> target_name = string<br/> target_region = optional(string)<br/> skip_mrouter_sysdig_iam_auth_policy = optional(bool, false)<br/> }))</pre> | `[]` | no |
| <a name="input_region"></a> [region](#input\_region) | The IBM Cloud region where instances will be created. | `string` | `"us-south"` | no |
| <a name="input_resource_group_id"></a> [resource\_group\_id](#input\_resource\_group\_id) | The id of the IBM Cloud resource group where the instance(s) will be created. | `string` | `null` | no |
| <a name="input_skip_logs_routing_auth_policy"></a> [skip\_logs\_routing\_auth\_policy](#input\_skip\_logs\_routing\_auth\_policy) | Whether to create an IAM authorization policy that permits Logs Routing Sender access to the IBM Cloud Logs. | `bool` | `false` | no |
Expand Down
6 changes: 3 additions & 3 deletions modules/metrics_routing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ No modules.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_metrics_router_routes"></a> [metrics\_router\_routes](#input\_metrics\_router\_routes) | List of routes for IBM Metrics Router | <pre>list(object({<br/> name = string<br/> rules = list(object({<br/> action = string<br/> targets = optional(list(object({<br/> id = optional(string)<br/> })), [])<br/> inclusion_filters = list(object({<br/> operand = string<br/> operator = string<br/> values = list(string)<br/> }))<br/> }))<br/> }))</pre> | `[]` | no |
| <a name="input_metrics_router_settings"></a> [metrics\_router\_settings](#input\_metrics\_router\_settings) | Global settings for Metrics Routing | <pre>object({<br/> permitted_target_regions = list(string)<br/> primary_metadata_region = string<br/> backup_metadata_region = string<br/> private_api_endpoint_only = bool<br/> default_targets = optional(list(object({<br/> id = string<br/> })), [])<br/> })</pre> | `null` | no |
| <a name="input_metrics_router_targets"></a> [metrics\_router\_targets](#input\_metrics\_router\_targets) | List of Metrics Router targets to be created. | <pre>list(object({<br/> destination_crn = string<br/> target_name = string<br/> target_region = string<br/> skip_mrouter_sysdig_iam_auth_policy = optional(bool, false)<br/> }))</pre> | `[]` | no |
| <a name="input_metrics_router_routes"></a> [metrics\_router\_routes](#input\_metrics\_router\_routes) | List of routes for IBM Metrics Router | <pre>list(object({<br/> name = string<br/> rules = list(object({<br/> action = optional(string, "send")<br/> targets = list(object({<br/> id = string<br/> }))<br/> inclusion_filters = list(object({<br/> operand = string<br/> operator = string<br/> values = list(string)<br/> }))<br/> }))<br/> }))</pre> | `[]` | no |
| <a name="input_metrics_router_settings"></a> [metrics\_router\_settings](#input\_metrics\_router\_settings) | Global settings for Metrics Routing | <pre>object({<br/> permitted_target_regions = optional(list(string))<br/> primary_metadata_region = optional(string)<br/> backup_metadata_region = optional(string)<br/> private_api_endpoint_only = optional(bool, false)<br/> default_targets = optional(list(object({<br/> id = string<br/> })))<br/> })</pre> | `null` | no |
| <a name="input_metrics_router_targets"></a> [metrics\_router\_targets](#input\_metrics\_router\_targets) | List of Metrics Router targets to be created. | <pre>list(object({<br/> destination_crn = string<br/> target_name = string<br/> target_region = optional(string)<br/> skip_mrouter_sysdig_iam_auth_policy = optional(bool, false)<br/> }))</pre> | `[]` | no |

### Outputs

Expand Down
44 changes: 32 additions & 12 deletions modules/metrics_routing/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ variable "metrics_router_targets" {
type = list(object({
destination_crn = string
target_name = string
target_region = string
target_region = optional(string)
skip_mrouter_sysdig_iam_auth_policy = optional(bool, false)
}))
default = []
Expand All @@ -13,10 +13,10 @@ variable "metrics_router_routes" {
type = list(object({
name = string
rules = list(object({
action = string
targets = optional(list(object({
id = optional(string)
})), [])
action = optional(string, "send")
targets = list(object({
id = string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this right?

targets are required for all actions, whilst the new validation implies that targets are only required for send, thus optional for any other action.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason why I have removed the optional from target is because in terraform registry it is required but at the same time the target is only required when the action is send. If a user wants to drop the metrics then they don't need a target. The example in the terraform registry shows that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other way I could think of is to keep the target as optional but remove the empty list as default and since there is validation then it makes sure that whenever the action is send the user has to input targets.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made the target as optional & since there is validation for when the target is mandatory it makes sure the user inputs the target when required.

}))
inclusion_filters = list(object({
operand = string
operator = string
Expand All @@ -30,26 +30,46 @@ variable "metrics_router_routes" {
validation {
condition = length(var.metrics_router_routes) == 0 || alltrue([
for route in var.metrics_router_routes : (
length(route.rules) <= 4 &&
length(route.rules) <= 10 &&
alltrue([
for rule in route.rules : length(rule.inclusion_filters) <= 5
])
)
])
error_message = "The metrics_router_routes list can be empty or contain routes with up to 4 rules, and each rule's inclusion_filters must have less than 5 items."
error_message = "The 'metrics_router_routes' list can be empty or contain routes with up to 10 rules, and each rule's 'inclusion_filters' must have less than 5 items."
}
validation {
condition = length(var.metrics_router_routes) == 0 || alltrue([
for route in var.metrics_router_routes : alltrue([
for rule in route.rules :
rule.action != "send" || length(rule.targets) > 0
])
])
error_message = "Each rule with action 'send' must have at least one target defined in 'targets'."
}
}

variable "metrics_router_settings" {
type = object({
permitted_target_regions = list(string)
primary_metadata_region = string
backup_metadata_region = string
private_api_endpoint_only = bool
permitted_target_regions = optional(list(string))
primary_metadata_region = optional(string)
backup_metadata_region = optional(string)
private_api_endpoint_only = optional(bool, false)
default_targets = optional(list(object({
id = string
})), [])
})))
})
description = "Global settings for Metrics Routing"
default = null

validation {
error_message = "Valid regions for 'permitted_target_regions' are: us-south, eu-de, us-east, eu-es, eu-gb, au-syd, br-sao, ca-tor, jp-tok, jp-osa"
condition = (var.metrics_router_settings == null ?
true :
alltrue([
for region in var.metrics_router_settings.permitted_target_regions :
contains(["jp-osa", "au-syd", "jp-tok", "eu-de", "eu-gb", "eu-es", "us-south", "ca-tor", "us-east", "br-sao"], region)
])
)
}
}
16 changes: 8 additions & 8 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ variable "metrics_router_targets" {
type = list(object({
destination_crn = string
target_name = string
target_region = string
target_region = optional(string)
skip_mrouter_sysdig_iam_auth_policy = optional(bool, false)
}))
default = []
Expand All @@ -321,7 +321,7 @@ variable "metrics_router_routes" {
type = list(object({
name = string
rules = list(object({
action = string
action = optional(string, "send")
targets = list(object({
id = string
}))
Expand All @@ -338,13 +338,13 @@ variable "metrics_router_routes" {

variable "metrics_router_settings" {
type = object({
default_targets = list(object({
default_targets = optional(list(object({
id = string
}))
permitted_target_regions = list(string)
primary_metadata_region = string
backup_metadata_region = string
private_api_endpoint_only = bool
})))
permitted_target_regions = optional(list(string))
primary_metadata_region = optional(string)
backup_metadata_region = optional(string)
private_api_endpoint_only = optional(bool, false)
})
description = "Global settings for Metrics Routing."
default = null
Expand Down