Skip to content

Commit 8532c3f

Browse files
authored
feat: added support to apply quotas using new input quotas. Feature is only valid for enterpirse plan instances. (#337)
1 parent 01ae6f3 commit 8532c3f

File tree

13 files changed

+61
-8
lines changed

13 files changed

+61
-8
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ You need the following permissions to run this module.
106106
| Name | Version |
107107
|------|---------|
108108
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
109-
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.70.0, <2.0.0 |
109+
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.71.0, <2.0.0 |
110110
| <a name="requirement_time"></a> [time](#requirement\_time) | >= 0.9.1 |
111111

112112
### Modules
@@ -119,6 +119,7 @@ You need the following permissions to run this module.
119119

120120
| Name | Type |
121121
|------|------|
122+
| [ibm_event_streams_quota.eventstreams_quotas](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/event_streams_quota) | resource |
122123
| [ibm_event_streams_schema.es_schema](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/event_streams_schema) | resource |
123124
| [ibm_event_streams_topic.es_topic](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/event_streams_topic) | resource |
124125
| [ibm_iam_authorization_policy.kms_policy](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
@@ -141,6 +142,7 @@ You need the following permissions to run this module.
141142
| <a name="input_kms_key_crn"></a> [kms\_key\_crn](#input\_kms\_key\_crn) | The root key CRN of the key management service (Key Protect or Hyper Protect Crypto Services) to use to encrypt the payload data. [Learn more](https://cloud.ibm.com/docs/EventStreams?topic=EventStreams-managing_encryption) about integrating Hyper Protect Crypto Services with Event Streams. | `string` | `null` | no |
142143
| <a name="input_metrics"></a> [metrics](#input\_metrics) | Enhanced metrics to activate, as list of strings. Only allowed for enterprise plans. Allowed values: 'topic', 'partition', 'consumers'. | `list(string)` | `[]` | no |
143144
| <a name="input_plan"></a> [plan](#input\_plan) | The plan for the Event Streams instance. Possible values: `lite`, `standard`, `enterprise-3nodes-2tb`. | `string` | `"standard"` | no |
145+
| <a name="input_quotas"></a> [quotas](#input\_quotas) | Quotas to be applied to the Event Streams instance. Entity may be 'default' to apply to all users, or an IAM ServiceID for a specific user. Rates are bytes/second, with -1 meaning no quota. | <pre>list(object({<br/> entity = string<br/> producer_byte_rate = optional(number, -1)<br/> consumer_byte_rate = optional(number, -1)<br/> }))</pre> | `[]` | no |
144146
| <a name="input_region"></a> [region](#input\_region) | The region where the Event Streams are created. | `string` | `"us-south"` | no |
145147
| <a name="input_resource_group_id"></a> [resource\_group\_id](#input\_resource\_group\_id) | The resource group ID where the Event Streams instance is created. | `string` | n/a | yes |
146148
| <a name="input_schemas"></a> [schemas](#input\_schemas) | The list of schema objects. Include the `schema_id` and the `type` and `name` of the schema in the `schema` object. | <pre>list(object(<br/> {<br/> schema_id = string<br/> schema = object({<br/> type = string<br/> name = string<br/> fields = optional(list(object({<br/> name = string<br/> type = string<br/> })))<br/> })<br/> }<br/> ))</pre> | `[]` | no |

examples/basic/version.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ terraform {
33
required_providers {
44
ibm = {
55
source = "IBM-Cloud/ibm"
6-
version = "= 1.70.0"
6+
version = "= 1.71.0"
77
}
88
}
99
}

examples/complete/main.tf

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module "event_streams" {
2323
access_tags = var.access_tags
2424
topics = var.topics
2525
metrics = []
26+
quotas = []
2627
service_credential_names = {
2728
"es_writer" : "Writer",
2829
"es_reader" : "Reader",

examples/complete/version.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
# Use latest version of provider in non-basic examples to verify latest version works with module
55
ibm = {
66
source = "IBM-Cloud/ibm"
7-
version = ">= 1.70.0"
7+
version = ">= 1.71.0"
88
}
99
}
1010
}

examples/fscloud/main.tf

+7
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ module "event_streams" {
6363
topics = var.topics
6464
existing_kms_instance_guid = var.existing_kms_instance_guid
6565
metrics = ["topic", "partition", "consumers"]
66+
quotas = [
67+
{
68+
"entity" = "iam-ServiceId-00000000-0000-0000-0000-000000000000",
69+
"producer_byte_rate" = 100000,
70+
"consumer_byte_rate" = 200000
71+
}
72+
]
6673
service_credential_names = {
6774
"es_writer" : "Writer",
6875
"es_reader" : "Reader",

examples/fscloud/version.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
# Use latest version of provider in non-basic examples to verify latest version works with module
55
ibm = {
66
source = "IBM-Cloud/ibm"
7-
version = ">= 1.70.1"
7+
version = ">= 1.71.1"
88
}
99
}
1010
}

main.tf

+14
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ locals {
2626
) : null
2727
# tflint-ignore: terraform_unused_declarations
2828
validate_metrics = var.plan != "enterprise-3nodes-2tb" && length(var.metrics) > 0 ? tobool("metrics are only supported for enterprise plan") : true
29+
# tflint-ignore: terraform_unused_declarations
30+
validate_quotas = var.plan != "enterprise-3nodes-2tb" && length(var.quotas) > 0 ? tobool("quotas are only supported for enterprise plan") : true
2931
}
3032

3133
# workaround for https://github.com/IBM-Cloud/terraform-provider-ibm/issues/4478
@@ -100,6 +102,18 @@ resource "ibm_resource_tag" "es_access_tag" {
100102
tag_type = "access"
101103
}
102104

105+
##############################################################################
106+
# QUOTAS - defining quotas for the resource instance
107+
##############################################################################
108+
109+
resource "ibm_event_streams_quota" "eventstreams_quotas" {
110+
count = length(var.quotas)
111+
resource_instance_id = ibm_resource_instance.es_instance.id
112+
entity = var.quotas[count.index].entity
113+
producer_byte_rate = var.quotas[count.index].producer_byte_rate
114+
consumer_byte_rate = var.quotas[count.index].consumer_byte_rate
115+
}
116+
103117
##############################################################################
104118
# IAM Authorization Policy
105119
##############################################################################

modules/fscloud/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The default values in this profile were scanned by [IBM Code Risk Analyzer (CRA)
1010
| Name | Version |
1111
|------|---------|
1212
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
13-
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.70.0, <2.0.0 |
13+
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.71.0, <2.0.0 |
1414

1515
### Modules
1616

@@ -32,6 +32,7 @@ No resources.
3232
| <a name="input_existing_kms_instance_guid"></a> [existing\_kms\_instance\_guid](#input\_existing\_kms\_instance\_guid) | The GUID of the Hyper Protect Crypto service in which the key specified in var.kms\_key\_crn is coming from | `string` | n/a | yes |
3333
| <a name="input_kms_key_crn"></a> [kms\_key\_crn](#input\_kms\_key\_crn) | The root key CRN of the key management service (Key Protect or Hyper Protect Crypto Services) to use to encrypt the payload data. | `string` | n/a | yes |
3434
| <a name="input_metrics"></a> [metrics](#input\_metrics) | Enhanced metrics to activate, as list of strings. Allowed values: 'topic', 'partition', 'consumers'. | `list(string)` | `[]` | no |
35+
| <a name="input_quotas"></a> [quotas](#input\_quotas) | Quotas to be applied to the Event Streams instance. Entity may be 'default' to apply to all users, or an IAM ServiceID for a specific user. Rates are bytes/second, with -1 meaning no quota. | <pre>list(object({<br/> entity = string<br/> producer_byte_rate = optional(number, -1)<br/> consumer_byte_rate = optional(number, -1)<br/> }))</pre> | `[]` | no |
3536
| <a name="input_region"></a> [region](#input\_region) | The region where the Event Streams are created. | `string` | `"us-south"` | no |
3637
| <a name="input_resource_group_id"></a> [resource\_group\_id](#input\_resource\_group\_id) | The resource group ID where the Event Streams instance is created. | `string` | n/a | yes |
3738
| <a name="input_schemas"></a> [schemas](#input\_schemas) | The list of schema objects. Include the `schema_id` and the `type` and `name` of the schema in the `schema` object. | <pre>list(object(<br/> {<br/> schema_id = string<br/> schema = object({<br/> type = string<br/> name = string<br/> fields = optional(list(object({<br/> name = string<br/> type = string<br/> })))<br/> })<br/> }<br/> ))</pre> | `[]` | no |

modules/fscloud/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ module "event_streams" {
1414
cbr_rules = var.cbr_rules
1515
service_credential_names = var.service_credential_names
1616
metrics = var.metrics
17+
quotas = var.quotas
1718
kms_encryption_enabled = true
18-
1919
}

modules/fscloud/variables.tf

+14
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,17 @@ variable "metrics" {
9999
description = "Enhanced metrics to activate, as list of strings. Allowed values: 'topic', 'partition', 'consumers'."
100100
default = []
101101
}
102+
103+
variable "quotas" {
104+
type = list(object({
105+
entity = string
106+
producer_byte_rate = optional(number, -1)
107+
consumer_byte_rate = optional(number, -1)
108+
}))
109+
description = "Quotas to be applied to the Event Streams instance. Entity may be 'default' to apply to all users, or an IAM ServiceID for a specific user. Rates are bytes/second, with -1 meaning no quota."
110+
default = []
111+
validation {
112+
condition = alltrue([for v in var.quotas : v.entity != "" && (v.producer_byte_rate >= 0 || v.consumer_byte_rate >= 0)])
113+
error_message = "The quota entity must be defined, and at least one of producer_byte_rate or consumer_byte_rate must be set to a non-negative value"
114+
}
115+
}

modules/fscloud/version.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ terraform {
77
# tflint-ignore: terraform_unused_required_providers
88
ibm = {
99
source = "IBM-Cloud/ibm"
10-
version = ">= 1.70.0, <2.0.0"
10+
version = ">= 1.71.0, <2.0.0"
1111
}
1212
}
1313
}

variables.tf

+14
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,17 @@ variable "metrics" {
201201
}
202202
default = []
203203
}
204+
205+
variable "quotas" {
206+
type = list(object({
207+
entity = string
208+
producer_byte_rate = optional(number, -1)
209+
consumer_byte_rate = optional(number, -1)
210+
}))
211+
description = "Quotas to be applied to the Event Streams instance. Entity may be 'default' to apply to all users, or an IAM ServiceID for a specific user. Rates are bytes/second, with -1 meaning no quota."
212+
default = []
213+
validation {
214+
condition = alltrue([for v in var.quotas : v.entity != "" && (v.producer_byte_rate >= 0 || v.consumer_byte_rate >= 0)])
215+
error_message = "The quota entity must be defined, and at least one of producer_byte_rate or consumer_byte_rate must be set to a non-negative value"
216+
}
217+
}

version.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
# Use "greater than or equal to" range in modules
55
ibm = {
66
source = "IBM-Cloud/ibm"
7-
version = ">= 1.70.0, <2.0.0"
7+
version = ">= 1.71.0, <2.0.0"
88
}
99
time = {
1010
source = "hashicorp/time"

0 commit comments

Comments
 (0)