Skip to content

Commit 4060786

Browse files
feat: updated the target_service_details input in the fscloud submodule to support setting the geography option.<br>**NOTE:** Both region and geography cannot be set simultaneously for the container registry service. (#519)
1 parent d244b0a commit 4060786

File tree

6 files changed

+30
-7
lines changed

6 files changed

+30
-7
lines changed

examples/fscloud/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ This examples is designed to show case some of the key customization options for
77
2. Open up network traffic flow from Schematics to Key Protect private endpoints.
88
3. Open up network traffic flow from a block of IPs to the Schematics public endpoint.
99
4. Open up network traffic flow from the VPC created in this example to ICD postgresql private endpoints.
10-
5. Customize the rule description for `kms` and the zone name for `codeengine` and `cloud-object-storage`.
11-
6. Add optional locations to open traffic only from `au` and `tok` locations for the `codeengine` network zone and leave the flow closed in other locations.
12-
7. Add optional location to open traffic only from `fr` location for `server-protect` network zone and leave the flow closed in other locations.
10+
5. Customize the rules for `kms`, `cloud-object-storage`, `databases-for-postgresql`, `messagehub`, `IAM` and `container-registry`.
11+
6. Customize the zone name for `codeengine` and `cloud-object-storage`.
12+
7. Add optional locations to open traffic only from `au` and `tok` locations for the `codeengine` network zone and leave the flow closed in other locations.
13+
8. Add optional location to open traffic only from `eu` location for `server-protect` network zone and leave the flow closed in other locations.
1314

1415
Context: this examples covers a "pseudo" real-world scenario where:
1516
1. ICD Mongodb and Postgresql instances are encrypted using keys storage in Key Protect.

examples/fscloud/main.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,23 @@ module "cbr_account_level" {
100100
"enforcement_mode" = "report"
101101
"global_deny" = false
102102
}
103+
"container-registry" : {
104+
"enforcement_mode" : "enabled"
105+
"geography" : "global"
106+
}
103107
}
104108

105109
# Demonstrates how a customized name and an optional location can be set for the CBR serviceRef zones
106110
zone_service_ref_list = {
107111
codeengine = {
108-
zone_name = "codeengine-zone-example-of-customized-zone-name"
112+
zone_name = "${var.prefix}-codeengine-zone-example-of-customized-zone-name"
109113
serviceRef_location = ["au", "tok"]
110114
},
111115
server-protect = {
112116
serviceRef_location = ["eu"]
113117
},
114118
cloud-object-storage = {
115-
zone_name = "COS-zone-example-of-customized-zone-name"
119+
zone_name = "${var.prefix}-COS-zone-example-of-customized-zone-name"
116120
}
117121
}
118122

examples/fscloud/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ variable "ibmcloud_api_key" {
66

77
variable "prefix" {
88
type = string
9-
description = "Prefix to append to all vpc_zone_list, service_ref_zone_list and cbr_rule_description created by this submodule"
9+
description = "Prefix to append to all vpc_zone_list, zone_service_ref_list and cbr_rule_description created by this submodule"
1010
}
1111

1212
variable "region" {

modules/fscloud/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ module "cbr_fscloud" {
128128
| <a name="input_kms_service_targeted_by_prewired_rules"></a> [kms\_service\_targeted\_by\_prewired\_rules](#input\_kms\_service\_targeted\_by\_prewired\_rules) | IBM Cloud offers two distinct Key Management Services (KMS): Key Protect and Hyper Protect Crypto Services (HPCS). This variable determines the specific KMS service to which the pre-configured rules will be applied. Use the value 'key-protect' to specify the Key Protect service, and 'hs-crypto' for the Hyper Protect Crypto Services (HPCS). | `list(string)` | <pre>[<br> "hs-crypto"<br>]</pre> | no |
129129
| <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 |
130130
| <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 |
131-
| <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> description = optional(string)<br> target_rg = optional(string)<br> instance_id = optional(string)<br> enforcement_mode = string<br> tags = optional(list(string))<br> region = optional(string)<br> global_deny = optional(bool, true)<br> }))</pre> | `{}` | no |
131+
| <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> description = optional(string)<br> target_rg = optional(string)<br> instance_id = optional(string)<br> enforcement_mode = string<br> tags = optional(list(string))<br> region = optional(string)<br> geography = optional(string)<br> global_deny = optional(bool, true)<br> }))</pre> | `{}` | no |
132132
| <a name="input_zone_service_ref_list"></a> [zone\_service\_ref\_list](#input\_zone\_service\_ref\_list) | (Optional) Provide a valid service reference with the customized name of the zone and location where the context-based restriction zones are created. If no value is specified for `serviceRef_location`, the zones are not scoped to any location and if no value is specified for `zone_name` default zone name with the prefix will be created. | <pre>object({<br> cloud-object-storage = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> codeengine = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> containers-kubernetes = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> databases-for-cassandra = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> databases-for-elasticsearch = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> databases-for-enterprisedb = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> databases-for-etcd = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> databases-for-mongodb = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> databases-for-mysql = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> databases-for-postgresql = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> databases-for-redis = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> directlink = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> iam-groups = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> is = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> messagehub = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> messages-for-rabbitmq = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> schematics = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> secrets-manager = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> server-protect = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> user-management = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> apprapp = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> compliance = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> event-notifications = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> logdna = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> logdnaat = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> cloudantnosqldb = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> globalcatalog-collection = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> sysdig-monitor = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> sysdig-secure = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> toolchain = optional(object({<br> zone_name = optional(string)<br> serviceRef_location = optional(list(string))<br> }))<br><br> })</pre> | `{}` | no |
133133
| <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)` | `[]` | no |
134134

modules/fscloud/main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,11 @@ locals {
404404
name = "region",
405405
operator = "stringEquals",
406406
value = value.region
407+
} : {},
408+
try(value.geography, null) != null ? {
409+
name = "geography",
410+
operator = "stringEquals",
411+
value = value.geography
407412
} : {}
408413
] }
409414
}

modules/fscloud/variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,29 @@ variable "target_service_details" {
285285
enforcement_mode = string
286286
tags = optional(list(string))
287287
region = optional(string)
288+
geography = optional(string)
288289
global_deny = optional(bool, true)
289290
}))
290291
description = "Details of the target service for which a rule is created. The key is the service name."
292+
291293
validation {
292294
condition = alltrue([
293295
for target_service_name, _ in var.target_service_details :
294296
contains(["IAM", "apprapp", "cloud-object-storage", "codeengine", "compliance", "container-registry", "containers-kubernetes", "containers-kubernetes-cluster", "containers-kubernetes-management", "context-based-restrictions", "databases-for-cassandra", "databases-for-elasticsearch", "databases-for-enterprisedb", "databases-for-etcd", "databases-for-mongodb", "databases-for-mysql", "databases-for-postgresql", "databases-for-redis", "directlink", "dns-svcs", "event-notifications", "globalcatalog-collection", "hs-crypto", "iam-access-management", "iam-groups", "iam-identity", "is", "kms", "logdna", "logdnaat", "messagehub", "messages-for-rabbitmq", "mqcloud", "schematics", "secrets-manager", "sysdig-monitor", "sysdig-secure", "transit", "user-management"], target_service_name)
295297
])
296298
error_message = "Provide a valid target service name that is supported by context-based restrictions"
297299
}
300+
validation {
301+
condition = alltrue([
302+
for target_service_name, attributes in var.target_service_details : (
303+
target_service_name != "container-registry" || (
304+
contains(["container-registry"], target_service_name) &&
305+
!(attributes.region != null && attributes.geography != null)
306+
)
307+
)
308+
])
309+
error_message = "Both `region` and `geography` cannot be set simultaneously for the container registry service."
310+
}
298311
validation {
299312
condition = alltrue([
300313
for target_service_name, attributes in var.target_service_details :

0 commit comments

Comments
 (0)