Skip to content

Commit 89ea824

Browse files
authored
feat: added way to skip zone creation (#273)
1 parent 75bc0e1 commit 89ea824

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

examples/fscloud/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This examples is designed to show case some of the key customization options for
1010

1111
Context: this examples covers a "pseudo" real-world scenario where:
1212
1. ICD Mongodb, and Postgresql instances are encrypted using keys storage in Key Protect.
13-
2. Schematics is used to execute terraform that create Key Protect keys and key ring over its public endpoint
14-
3. Operators used machines with a set list of public IPs to interact with Schematics
13+
2. Schematics is used to execute terraform that create Key Protect keys and key ring over its public endpoint.
14+
3. Operators use machines with a set list of public IPs to interact with Schematics.
1515
4. Applications are running the VPC and need access to PostgreSQL via the private endpoint - eg: a VPE.
16+
5. Skips creation of zones for these two service references ["user-management", "iam-groups"].

examples/fscloud/main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ module "cbr_account_level" {
5555
allow_vpcs_to_container_registry = var.allow_vpcs_to_container_registry
5656
allow_vpcs_to_cos = var.allow_vpcs_to_cos
5757

58+
# Demonstrates how zone creation will be skipped for these two service references ["user-management", "iam-groups"]
59+
skip_specific_services_for_zone_creation = ["user-management", "iam-groups"]
60+
5861
## Enable enforcement for key protect as an example
5962
## The other services not referenced here, are either report, or disabled (when not support report)
6063
target_service_details = {

modules/fscloud/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Important: In order to avoid unexpected breakage in the account against which th
5151
| <a name="input_existing_cbr_zone_vpcs"></a> [existing\_cbr\_zone\_vpcs](#input\_existing\_cbr\_zone\_vpcs) | Provide a existing zone id for VPC | <pre>object(<br> {<br> zone_id = string<br> })</pre> | `null` | no |
5252
| <a name="input_existing_serviceref_zone"></a> [existing\_serviceref\_zone](#input\_existing\_serviceref\_zone) | Provide a valid service reference and existing zone id | <pre>map(object(<br> {<br> zone_id = string<br> }))</pre> | `{}` | no |
5353
| <a name="input_prefix"></a> [prefix](#input\_prefix) | Prefix to append to all vpc\_zone\_list, service\_ref\_zone\_list and cbr\_rule\_description created by this submodule | `string` | n/a | yes |
54+
| <a name="input_skip_specific_services_for_zone_creation"></a> [skip\_specific\_services\_for\_zone\_creation](#input\_skip\_specific\_services\_for\_zone\_creation) | Provide a list of service references for which zone creation is not required | `list(string)` | `[]` | no |
5455
| <a name="input_target_service_details"></a> [target\_service\_details](#input\_target\_service\_details) | Details of the target service for which a rule is created. The key is the service name. | <pre>map(object({<br> target_rg = optional(string)<br> enforcement_mode = string<br> tags = optional(list(string))<br> }))</pre> | `{}` | no |
5556
| <a name="input_zone_service_ref_list"></a> [zone\_service\_ref\_list](#input\_zone\_service\_ref\_list) | (List) Service reference for the zone creation | `list(string)` | <pre>[<br> "cloud-object-storage",<br> "codeengine",<br> "containers-kubernetes",<br> "databases-for-cassandra",<br> "databases-for-elasticsearch",<br> "databases-for-enterprisedb",<br> "databases-for-etcd",<br> "databases-for-mongodb",<br> "databases-for-mysql",<br> "databases-for-postgresql",<br> "databases-for-redis",<br> "directlink",<br> "iam-groups",<br> "is",<br> "messagehub",<br> "messages-for-rabbitmq",<br> "schematics",<br> "secrets-manager",<br> "server-protect",<br> "user-management",<br> "apprapp",<br> "compliance",<br> "event-notifications"<br>]</pre> | no |
5657
| <a name="input_zone_vpc_crn_list"></a> [zone\_vpc\_crn\_list](#input\_zone\_vpc\_crn\_list) | (List) VPC CRN for the zones | `list(string)` | n/a | yes |

modules/fscloud/main.tf

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,19 @@ locals {
9494
}
9595

9696
target_service_details = merge(local.target_service_details_default, var.target_service_details)
97+
98+
zone_final_service_ref_list = [
99+
for service in var.zone_service_ref_list : service if !contains(var.skip_specific_services_for_zone_creation, service)
100+
]
97101
}
98102

99103
###############################################################################
100104
# Pre-create coarse grained CBR zones for each service
101105
###############################################################################
102106

103107
locals {
104-
service_ref_zone_list = (length(var.zone_service_ref_list) > 0) ? [
105-
for serviceref in var.zone_service_ref_list : {
108+
service_ref_zone_list = (length(local.zone_final_service_ref_list) > 0) ? [
109+
for serviceref in local.zone_final_service_ref_list : {
106110
name = "${var.prefix}-${serviceref}-service-zone"
107111
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
108112
zone_description = "Single zone for service ${serviceref}."
@@ -118,7 +122,7 @@ locals {
118122
]
119123
}] : []
120124

121-
service_ref_zone_map_pre_check = zipmap(var.zone_service_ref_list, local.service_ref_zone_list)
125+
service_ref_zone_map_pre_check = zipmap(local.zone_final_service_ref_list, local.service_ref_zone_list)
122126

123127
service_ref_zone_map_check = merge(local.service_ref_zone_map_pre_check, var.existing_serviceref_zone)
124128

modules/fscloud/variables.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,24 @@ variable "existing_cbr_zone_vpcs" {
155155
description = "Provide a existing zone id for VPC"
156156
default = null
157157
}
158+
159+
variable "skip_specific_services_for_zone_creation" {
160+
type = list(string)
161+
validation {
162+
condition = alltrue([
163+
for service_ref in var.skip_specific_services_for_zone_creation :
164+
contains(["cloud-object-storage", "codeengine", "containers-kubernetes",
165+
"databases-for-cassandra", "databases-for-elasticsearch", "databases-for-enterprisedb",
166+
"databases-for-etcd", "databases-for-mongodb",
167+
"databases-for-mysql", "databases-for-postgresql",
168+
"databases-for-redis", "directlink",
169+
"iam-groups", "is", "messagehub",
170+
"messages-for-rabbitmq", "schematics", "secrets-manager", "server-protect", "user-management",
171+
"apprapp", "compliance", "event-notifications"],
172+
service_ref)
173+
])
174+
error_message = "Provide a valid service reference for zone creation"
175+
}
176+
description = "Provide a list of service references for which zone creation is not required"
177+
default = []
178+
}

0 commit comments

Comments
 (0)