Skip to content

Commit 4e058b7

Browse files
feat: create service credentials
1 parent f985565 commit 4e058b7

File tree

7 files changed

+78
-6
lines changed

7 files changed

+78
-6
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ You need the following permissions to run this module.
124124
| [ibm_event_streams_schema.es_schema](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/event_streams_schema) | resource |
125125
| [ibm_event_streams_topic.es_topic](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/event_streams_topic) | resource |
126126
| [ibm_resource_instance.es_instance](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/resource_instance) | resource |
127+
| [ibm_resource_key.service_credentials](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/resource_key) | resource |
127128

128129
### Inputs
129130

@@ -138,6 +139,7 @@ You need the following permissions to run this module.
138139
| <a name="input_region"></a> [region](#input\_region) | The region where the Event Streams are created. | `string` | `"us-south"` | no |
139140
| <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 |
140141
| <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 |
142+
| <a name="input_service_credential_names"></a> [service\_credential\_names](#input\_service\_credential\_names) | The mapping of names and roles for service credentials that you want to create for the Event Notifications streams. | `map(string)` | `{}` | no |
141143
| <a name="input_service_endpoints"></a> [service\_endpoints](#input\_service\_endpoints) | The type of service endpoints. Possible values: 'public', 'private', 'public-and-private'. | `string` | `"public"` | no |
142144
| <a name="input_storage_size"></a> [storage\_size](#input\_storage\_size) | Storage size of the Event Streams in GB. Applies only to Enterprise plan instances. Possible values: `2048`, `4096`, `6144`, `8192`, `10240`, `12288`. Storage capacity cannot be reduced after the instance is created. When the `throughput` input variable is set to `300`, storage size starts at 4096. When `throughput` is `450`, storage size starts starts at `6144`. | `number` | `"2048"` | no |
143145
| <a name="input_tags"></a> [tags](#input\_tags) | The list of tags associated with the Event Steams instance. | `list(string)` | `[]` | no |
@@ -155,6 +157,8 @@ You need the following permissions to run this module.
155157
| <a name="output_kafka_broker_version"></a> [kafka\_broker\_version](#output\_kafka\_broker\_version) | The Kafka version |
156158
| <a name="output_kafka_brokers_sasl"></a> [kafka\_brokers\_sasl](#output\_kafka\_brokers\_sasl) | (Array of Strings) Kafka brokers use for interacting with Kafka native API |
157159
| <a name="output_kafka_http_url"></a> [kafka\_http\_url](#output\_kafka\_http\_url) | The API endpoint to interact with Event Streams REST API |
160+
| <a name="output_service_credentials_json"></a> [service\_credentials\_json](#output\_service\_credentials\_json) | The service credentials JSON map. |
161+
| <a name="output_service_credentials_object"></a> [service\_credentials\_object](#output\_service\_credentials\_object) | The service credentials object. |
158162
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
159163
<!-- BEGIN CONTRIBUTING HOOK -->
160164

examples/complete/main.tf

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ module "cbr_zone" {
5454
##############################################################################
5555

5656
module "event_streams" {
57-
source = "../../"
58-
resource_group_id = module.resource_group.resource_group_id
59-
es_name = "${var.prefix}-es"
60-
schemas = var.schemas
61-
tags = var.resource_tags
62-
topics = var.topics
57+
source = "../../"
58+
resource_group_id = module.resource_group.resource_group_id
59+
es_name = "${var.prefix}-es"
60+
schemas = var.schemas
61+
tags = var.resource_tags
62+
topics = var.topics
63+
service_credential_names = var.service_credential_names
6364
cbr_rules = [
6465
{
6566
description = "${var.prefix}-event stream access only from vpc"

examples/complete/outputs.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,15 @@ output "kafka_broker_version" {
3535
description = "The Kafka version"
3636
value = module.event_streams.kafka_broker_version
3737
}
38+
39+
output "service_credentials_json" {
40+
description = "Service credentials json map"
41+
value = module.event_streams.service_credentials_json
42+
sensitive = true
43+
}
44+
45+
output "service_credentials_object" {
46+
description = "Service credentials object"
47+
value = module.event_streams.service_credentials_object
48+
sensitive = true
49+
}

examples/complete/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,14 @@ variable "topics" {
9999
}
100100
]
101101
}
102+
103+
variable "service_credential_names" {
104+
description = "Map of name, role for service credentials that you want to create for the event streams"
105+
type = map(string)
106+
default = {
107+
"en_writer" : "Writer",
108+
"en_reader" : "Reader",
109+
"en_manager" : "Manager",
110+
"en_none" : "None"
111+
}
112+
}

main.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,24 @@ module "cbr_rule" {
9090
]
9191
}]
9292
}
93+
94+
resource "ibm_resource_key" "service_credentials" {
95+
for_each = var.service_credential_names
96+
name = each.key
97+
role = each.value
98+
resource_instance_id = ibm_resource_instance.es_instance.id
99+
}
100+
101+
locals {
102+
service_credentials_json = length(var.service_credential_names) > 0 ? {
103+
for service_credential in ibm_resource_key.service_credentials :
104+
service_credential["name"] => service_credential["credentials_json"]
105+
} : null
106+
107+
service_credentials_object = length(var.service_credential_names) > 0 ? {
108+
credentials = {
109+
for service_credential in ibm_resource_key.service_credentials :
110+
service_credential["name"] => service_credential["credentials"]
111+
}
112+
} : null
113+
}

outputs.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,15 @@ output "kafka_broker_version" {
3131
description = "The Kafka version"
3232
value = ibm_resource_instance.es_instance.extensions.kafka_broker_version
3333
}
34+
35+
output "service_credentials_json" {
36+
description = "The service credentials JSON map."
37+
value = local.service_credentials_json
38+
sensitive = true
39+
}
40+
41+
output "service_credentials_object" {
42+
description = "The service credentials object."
43+
value = local.service_credentials_object
44+
sensitive = true
45+
}

variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,14 @@ variable "cbr_rules" {
156156
default = []
157157
# Validation happens in the rule module
158158
}
159+
160+
variable "service_credential_names" {
161+
description = "The mapping of names and roles for service credentials that you want to create for the Event Notifications streams."
162+
type = map(string)
163+
default = {}
164+
165+
validation {
166+
condition = alltrue([for name, role in var.service_credential_names : contains(["Writer", "Reader", "Manager", "None"], role)])
167+
error_message = "The specified service credential role is not valid. The following values are valid for service credential roles: 'Writer', 'Reader', 'Manager', 'None'"
168+
}
169+
}

0 commit comments

Comments
 (0)