Skip to content

Commit 9586187

Browse files
feat: added support to create service credentials + fixed bug in fscloud submodule (#312)
1 parent 731401e commit 9586187

File tree

17 files changed

+160
-65
lines changed

17 files changed

+160
-65
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ You need the following permissions to run this module.
123123
| [ibm_event_streams_topic.es_topic](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/event_streams_topic) | resource |
124124
| [ibm_iam_authorization_policy.kms_policy](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
125125
| [ibm_resource_instance.es_instance](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/resource_instance) | resource |
126+
| [ibm_resource_key.service_credentials](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/resource_key) | resource |
126127
| [time_sleep.wait_for_authorization_policy](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
127128

128129
### Inputs
@@ -140,6 +141,7 @@ You need the following permissions to run this module.
140141
| <a name="input_region"></a> [region](#input\_region) | The region where the Event Streams are created. | `string` | `"us-south"` | no |
141142
| <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 |
142143
| <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 |
144+
| <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 streams. | `map(string)` | `{}` | no |
143145
| <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 |
144146
| <a name="input_skip_iam_authorization_policy"></a> [skip\_iam\_authorization\_policy](#input\_skip\_iam\_authorization\_policy) | Set to true to skip the creation of an IAM authorization policy that permits all Event Streams database instances in the resource group to read the encryption key from the KMS instance. If set to false, pass in a value for the KMS instance in the existing\_kms\_instance\_guid variable. In addition, no policy is created if var.kms\_encryption\_enabled is set to false. | `bool` | `false` | no |
145147
| <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 |
@@ -158,6 +160,8 @@ You need the following permissions to run this module.
158160
| <a name="output_kafka_broker_version"></a> [kafka\_broker\_version](#output\_kafka\_broker\_version) | The Kafka version |
159161
| <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 |
160162
| <a name="output_kafka_http_url"></a> [kafka\_http\_url](#output\_kafka\_http\_url) | The API endpoint to interact with Event Streams REST API |
163+
| <a name="output_service_credentials_json"></a> [service\_credentials\_json](#output\_service\_credentials\_json) | The service credentials JSON map. |
164+
| <a name="output_service_credentials_object"></a> [service\_credentials\_object](#output\_service\_credentials\_object) | The service credentials object. |
161165
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
162166
<!-- BEGIN CONTRIBUTING HOOK -->
163167

examples/complete/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ This example uses the IBM Cloud Terraform provider to create the following infra
77
- A new resource group, if one is not passed in.
88
- A sample virtual private cloud (VPC).
99
- A instance of Event Streams in the provided resource group and region. You can identify topics and schemas to apply to the instance.
10-
- A context-based restriction rule to allow Event Streams to be accessible only from within the VPC.

examples/complete/main.tf

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,6 @@ module "resource_group" {
1010
existing_resource_group_name = var.resource_group
1111
}
1212

13-
##############################################################################
14-
# Get Cloud Account ID
15-
##############################################################################
16-
17-
data "ibm_iam_account_settings" "iam_account_settings" {
18-
}
19-
20-
##############################################################################
21-
# VPC
22-
##############################################################################
23-
resource "ibm_is_vpc" "example_vpc" {
24-
name = "${var.prefix}-vpc"
25-
resource_group = module.resource_group.resource_group_id
26-
tags = var.resource_tags
27-
}
28-
29-
resource "ibm_is_subnet" "testacc_subnet" {
30-
name = "${var.prefix}-subnet"
31-
vpc = ibm_is_vpc.example_vpc.id
32-
zone = "${var.region}-1"
33-
total_ipv4_address_count = 256
34-
resource_group = module.resource_group.resource_group_id
35-
}
36-
37-
##############################################################################
38-
# Create CBR Zone
39-
##############################################################################
40-
module "cbr_zone" {
41-
source = "terraform-ibm-modules/cbr/ibm//modules/cbr-zone-module"
42-
version = "1.27.0"
43-
name = "${var.prefix}-VPC-network-zone"
44-
zone_description = "CBR Network zone representing VPC"
45-
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
46-
addresses = [{
47-
type = "vpc", # to bind a specific vpc to the zone
48-
value = ibm_is_vpc.example_vpc.crn,
49-
}]
50-
}
51-
5213
##############################################################################
5314
# Events-streams-instance
5415
##############################################################################
@@ -60,22 +21,9 @@ module "event_streams" {
6021
schemas = var.schemas
6122
tags = var.resource_tags
6223
topics = var.topics
63-
cbr_rules = [
64-
{
65-
description = "${var.prefix}-event stream access only from vpc"
66-
enforcement_mode = "enabled"
67-
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
68-
rule_contexts = [{
69-
attributes = [
70-
{
71-
"name" : "endpointType",
72-
"value" : "private"
73-
},
74-
{
75-
name = "networkZoneId"
76-
value = module.cbr_zone.zone_id
77-
}]
78-
}]
79-
}
80-
]
24+
service_credential_names = {
25+
"es_writer" : "Writer",
26+
"es_reader" : "Reader",
27+
"es_manager" : "Manager"
28+
}
8129
}

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/fscloud/main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ module "event_streams" {
6262
tags = var.resource_tags
6363
topics = var.topics
6464
existing_kms_instance_guid = var.existing_kms_instance_guid
65+
service_credential_names = {
66+
"es_writer" : "Writer",
67+
"es_reader" : "Reader",
68+
"es_manager" : "Manager"
69+
}
6570
cbr_rules = [
6671
{
6772
description = "${var.prefix}-event stream access only from vpc"

examples/fscloud/outputs.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,15 @@ output "kafka_http_url" {
3131
description = "The API endpoint to interact with Event Streams REST API"
3232
value = module.event_streams.kafka_http_url
3333
}
34+
35+
output "service_credentials_json" {
36+
description = "Service credentials json map"
37+
value = module.event_streams.service_credentials_json
38+
sensitive = true
39+
}
40+
41+
output "service_credentials_object" {
42+
description = "Service credentials object"
43+
value = module.event_streams.service_credentials_object
44+
sensitive = true
45+
}

main.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,24 @@ module "cbr_rule" {
123123
]
124124
}]
125125
}
126+
127+
resource "ibm_resource_key" "service_credentials" {
128+
for_each = var.service_credential_names
129+
name = each.key
130+
role = each.value
131+
resource_instance_id = ibm_resource_instance.es_instance.id
132+
}
133+
134+
locals {
135+
service_credentials_json = length(var.service_credential_names) > 0 ? {
136+
for service_credential in ibm_resource_key.service_credentials :
137+
service_credential["name"] => service_credential["credentials_json"]
138+
} : null
139+
140+
service_credentials_object = length(var.service_credential_names) > 0 ? {
141+
credentials = {
142+
for service_credential in ibm_resource_key.service_credentials :
143+
service_credential["name"] => service_credential["credentials"]
144+
}
145+
} : null
146+
}

modules/fscloud/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ No resources.
3333
| <a name="input_region"></a> [region](#input\_region) | The region where the Event Streams are created. | `string` | `"us-south"` | no |
3434
| <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 |
3535
| <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 |
36+
| <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 streams. | `map(string)` | `{}` | no |
3637
| <a name="input_tags"></a> [tags](#input\_tags) | The list of tags associated with the Event Steams instance. | `list(string)` | `[]` | no |
3738
| <a name="input_topics"></a> [topics](#input\_topics) | The list of topics to apply to resources. Only one topic is allowed for Lite plan instances. | <pre>list(object(<br/> {<br/> name = string<br/> partitions = number<br/> config = object({})<br/> }<br/> ))</pre> | `[]` | no |
3839

@@ -46,4 +47,6 @@ No resources.
4647
| <a name="output_kafka_broker_version"></a> [kafka\_broker\_version](#output\_kafka\_broker\_version) | The Kafka version |
4748
| <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 |
4849
| <a name="output_kafka_http_url"></a> [kafka\_http\_url](#output\_kafka\_http\_url) | The API endpoint to interact with Event Streams REST API |
50+
| <a name="output_service_credentials_json"></a> [service\_credentials\_json](#output\_service\_credentials\_json) | Service credentials json map |
51+
| <a name="output_service_credentials_object"></a> [service\_credentials\_object](#output\_service\_credentials\_object) | Service credentials object |
4952
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

modules/fscloud/main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ module "event_streams" {
1111
topics = var.topics
1212
service_endpoints = "private"
1313
cbr_rules = var.cbr_rules
14+
service_credential_names = var.service_credential_names
15+
kms_encryption_enabled = true
16+
1417
}

modules/fscloud/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 = module.event_streams.kafka_broker_version
3333
}
34+
35+
output "service_credentials_json" {
36+
description = "Service credentials json map"
37+
value = module.event_streams.service_credentials_json
38+
sensitive = true
39+
}
40+
41+
output "service_credentials_object" {
42+
description = "Service credentials object"
43+
value = module.event_streams.service_credentials_object
44+
sensitive = true
45+
}

0 commit comments

Comments
 (0)