Skip to content

Commit 8440284

Browse files
authored
feat: Added the ability to create Elasticsearch CBR rules in the DA using the input cbr_rules (#400)
1 parent 9480b9a commit 8440284

File tree

10 files changed

+110
-11
lines changed

10 files changed

+110
-11
lines changed

.secrets.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": "go.sum|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2025-02-05T07:22:24Z",
6+
"generated_at": "2025-02-13T14:40:55Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ You need the following permissions to run this module.
9595
| <a name="input_auto_scaling"></a> [auto\_scaling](#input\_auto\_scaling) | The rules to allow the database to increase resources in response to usage. Only a single autoscaling block is allowed. Make sure you understand the effects of autoscaling, especially for production environments. [Learn more](https://cloud.ibm.com/docs/databases-for-elasticsearch?topic=databases-for-elasticsearch-autoscaling&interface=cli#autoscaling-considerations). | <pre>object({<br/> disk = object({<br/> capacity_enabled = optional(bool, false)<br/> free_space_less_than_percent = optional(number, 10)<br/> io_above_percent = optional(number, 90)<br/> io_enabled = optional(bool, false)<br/> io_over_period = optional(string, "15m")<br/> rate_increase_percent = optional(number, 10)<br/> rate_limit_mb_per_member = optional(number, 3670016)<br/> rate_period_seconds = optional(number, 900)<br/> rate_units = optional(string, "mb")<br/> })<br/> memory = object({<br/> io_above_percent = optional(number, 90)<br/> io_enabled = optional(bool, false)<br/> io_over_period = optional(string, "15m")<br/> rate_increase_percent = optional(number, 10)<br/> rate_limit_mb_per_member = optional(number, 114688)<br/> rate_period_seconds = optional(number, 900)<br/> rate_units = optional(string, "mb")<br/> })<br/> })</pre> | `null` | no |
9696
| <a name="input_backup_crn"></a> [backup\_crn](#input\_backup\_crn) | The CRN of a backup resource to restore from. The backup is created by a database deployment with the same service ID. The backup is loaded after both provisioning is complete and the new deployment that uses that data starts. Specify a backup CRN is in the format `crn:v1:<...>:backup:`. If not specified, the database is provisioned empty. | `string` | `null` | no |
9797
| <a name="input_backup_encryption_key_crn"></a> [backup\_encryption\_key\_crn](#input\_backup\_encryption\_key\_crn) | The CRN of a Key Protect or Hyper Protect Crypto Services encryption key that you want to use for encrypting the disk that holds deployment backups. Applies only if `use_ibm_owned_encryption_key` is false and `use_same_kms_key_for_backups` is false. If no value is passed, and `use_same_kms_key_for_backups` is true, the value of `kms_key_crn` is used. Alternatively set `use_default_backup_encryption_key` to true to use the IBM Cloud Databases default encryption. Bare in mind that backups encryption is only available in certain regions. See [Bring your own key for backups](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-key-protect&interface=ui#key-byok) and [Using the HPCS Key for Backup encryption](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-hpcs#use-hpcs-backups). | `string` | `null` | no |
98-
| <a name="input_cbr_rules"></a> [cbr\_rules](#input\_cbr\_rules) | The list of context-based restriction rules to create. | <pre>list(object({<br/> description = string<br/> account_id = string<br/> rule_contexts = list(object({<br/> attributes = optional(list(object({<br/> name = string<br/> value = string<br/> }))) }))<br/> enforcement_mode = string<br/> }))</pre> | `[]` | no |
98+
| <a name="input_cbr_rules"></a> [cbr\_rules](#input\_cbr\_rules) | (Optional, list) List of context-based restrictions rules to create. | <pre>list(object({<br/> description = string<br/> account_id = string<br/> rule_contexts = list(object({<br/> attributes = optional(list(object({<br/> name = string<br/> value = string<br/> }))) }))<br/> enforcement_mode = string<br/> operations = optional(list(object({<br/> api_types = list(object({<br/> api_type_id = string<br/> }))<br/> })))<br/> }))</pre> | `[]` | no |
9999
| <a name="input_elasticsearch_version"></a> [elasticsearch\_version](#input\_elasticsearch\_version) | The version of Databases for Elasticsearch to deploy. Possible values: `8.7`, `8.10`, `8.12`, `8.15` which requires an Enterprise Platinum pricing plan. If no value is specified, the current preferred version for IBM Cloud Databases is used. | `string` | `null` | no |
100100
| <a name="input_elser_model_type"></a> [elser\_model\_type](#input\_elser\_model\_type) | Trained ELSER model to be used for Elastic's Natural Language Processing. Possible values: `.elser_model_1`, `.elser_model_2` and `.elser_model_2_linux-x86_64`. [Learn more](https://www.elastic.co/guide/en/machine-learning/current/ml-nlp-elser.html) | `string` | `".elser_model_2_linux-x86_64"` | no |
101101
| <a name="input_enable_elser_model"></a> [enable\_elser\_model](#input\_enable\_elser\_model) | Set it to true to install and start the Elastic's Natural Language Processing model. [Learn more](https://cloud.ibm.com/docs/databases-for-elasticsearch?topic=databases-for-elasticsearch-elser-embeddings-elasticsearch) | `bool` | `false` | no |

ibm_catalog.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@
376376
"value": "local"
377377
}
378378
]
379+
},
380+
{
381+
"key": "cbr_rules"
379382
}
380383
]
381384
}

modules/fscloud/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ No resources.
3535
| <a name="input_auto_scaling"></a> [auto\_scaling](#input\_auto\_scaling) | Optional rules to allow the database to increase resources in response to usage. Only a single autoscaling block is allowed. Make sure you understand the effects of autoscaling, especially for production environments. See https://cloud.ibm.com/docs/databases-for-elasticsearch?topic=databases-for-elasticsearch-autoscaling&interface=cli#autoscaling-considerations in the IBM Cloud Docs. | <pre>object({<br/> disk = object({<br/> capacity_enabled = optional(bool, false)<br/> free_space_less_than_percent = optional(number, 10)<br/> io_above_percent = optional(number, 90)<br/> io_enabled = optional(bool, false)<br/> io_over_period = optional(string, "15m")<br/> rate_increase_percent = optional(number, 10)<br/> rate_limit_mb_per_member = optional(number, 3670016)<br/> rate_period_seconds = optional(number, 900)<br/> rate_units = optional(string, "mb")<br/> })<br/> memory = object({<br/> io_above_percent = optional(number, 90)<br/> io_enabled = optional(bool, false)<br/> io_over_period = optional(string, "15m")<br/> rate_increase_percent = optional(number, 10)<br/> rate_limit_mb_per_member = optional(number, 114688)<br/> rate_period_seconds = optional(number, 900)<br/> rate_units = optional(string, "mb")<br/> })<br/> })</pre> | `null` | no |
3636
| <a name="input_backup_crn"></a> [backup\_crn](#input\_backup\_crn) | The CRN of a backup resource to restore from. The backup is created by a database deployment with the same service ID. The backup is loaded after provisioning and the new deployment starts up that uses that data. A backup CRN is in the format crn:v1:<…>:backup:. If omitted, the database is provisioned empty. | `string` | `null` | no |
3737
| <a name="input_backup_encryption_key_crn"></a> [backup\_encryption\_key\_crn](#input\_backup\_encryption\_key\_crn) | The CRN of a Key Protect or Hyper Protect Crypto Services encryption key that you want to use for encrypting the disk that holds deployment backups. Applies only if `use_ibm_owned_encryption_key` is false and `use_same_kms_key_for_backups` is false. If no value is passed, and `use_same_kms_key_for_backups` is true, the value of `kms_key_crn` is used. Alternatively set `use_default_backup_encryption_key` to true to use the IBM Cloud Databases default encryption. Bare in mind that backups encryption is only available in certain regions. See [Bring your own key for backups](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-key-protect&interface=ui#key-byok) and [Using the HPCS Key for Backup encryption](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-hpcs#use-hpcs-backups). | `string` | `null` | no |
38-
| <a name="input_cbr_rules"></a> [cbr\_rules](#input\_cbr\_rules) | (Optional, list) List of CBR rules to create | <pre>list(object({<br/> description = string<br/> account_id = string<br/> rule_contexts = list(object({<br/> attributes = optional(list(object({<br/> name = string<br/> value = string<br/> }))) }))<br/> enforcement_mode = string<br/> }))</pre> | `[]` | no |
38+
| <a name="input_cbr_rules"></a> [cbr\_rules](#input\_cbr\_rules) | (Optional, list) List of context-based restrictions rules to create. | <pre>list(object({<br/> description = string<br/> account_id = string<br/> rule_contexts = list(object({<br/> attributes = optional(list(object({<br/> name = string<br/> value = string<br/> }))) }))<br/> enforcement_mode = string<br/> operations = optional(list(object({<br/> api_types = list(object({<br/> api_type_id = string<br/> }))<br/> })))<br/> }))</pre> | `[]` | no |
3939
| <a name="input_elasticsearch_version"></a> [elasticsearch\_version](#input\_elasticsearch\_version) | Version of the Elasticsearch instance. If no value is passed, the current preferred version of IBM Cloud Databases is used. | `string` | `null` | no |
4040
| <a name="input_elser_model_type"></a> [elser\_model\_type](#input\_elser\_model\_type) | Trained ELSER model to be used for Elastic's Natural Language Processing. Possible values: `.elser_model_1`, `.elser_model_2` and `.elser_model_2_linux-x86_64`. [Learn more](https://www.elastic.co/guide/en/machine-learning/current/ml-nlp-elser.html) | `string` | `".elser_model_2_linux-x86_64"` | no |
4141
| <a name="input_enable_elser_model"></a> [enable\_elser\_model](#input\_enable\_elser\_model) | Set it to true to install and start the Elastic's Natural Language Processing model. [Learn more](https://cloud.ibm.com/docs/databases-for-elasticsearch?topic=databases-for-elasticsearch-elser-embeddings-elasticsearch) | `bool` | `false` | no |

modules/fscloud/variables.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,14 @@ variable "cbr_rules" {
195195
value = string
196196
}))) }))
197197
enforcement_mode = string
198+
operations = optional(list(object({
199+
api_types = list(object({
200+
api_type_id = string
201+
}))
202+
})))
198203
}))
199-
description = "(Optional, list) List of CBR rules to create"
204+
description = "(Optional, list) List of context-based restrictions rules to create."
200205
default = []
201-
# Validation happens in the rule module
202206
}
203207

204208
##############################################################

solutions/standard/DA-cbr_rules.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Configuring complex inputs for ICD Elastic Search in IBM Cloud projects
2+
3+
Several optional input variables in the IBM Cloud [ICD Elastic search Deployable Architecture](https://cloud.ibm.com/catalog#deployable_architecture) use complex object types. You specify these inputs when you configure deployable architecture.
4+
5+
* Context-Based Restrictions Rules (`cbr_rules`)
6+
7+
8+
## Rules For Context-Based Restrictions <a name="cbr_rules"></a>
9+
10+
The `cbr_rules` input variable allows you to provide a rule for the target service to enforce access restrictions for the service based on the context of access requests. Contexts are criteria that include the network location of access requests, the endpoint type from where the request is sent, etc.
11+
12+
- Variable name: `cbr_rules`.
13+
- Type: A list of objects. Allows only one object representing a rule for the target service
14+
- Default value: An empty list (`[]`).
15+
16+
### Options for cbr_rules
17+
18+
- `description` (required): The description of the rule to create.
19+
- `account_id` (required): The IBM Cloud Account ID
20+
- `rule_contexts` (required): (List) The contexts the rule applies to
21+
- `attributes` (optional): (List) Individual context attributes
22+
- `name` (required): The attribute name.
23+
- `value`(required): The attribute value.
24+
25+
- `enforcement_mode` (required): The rule enforcement mode can have the following values:
26+
- `enabled` - The restrictions are enforced and reported. This is the default.
27+
- `disabled` - The restrictions are disabled. Nothing is enforced or reported.
28+
- `report` - The restrictions are evaluated and reported, but not enforced.
29+
- `operations` (optional): The operations this rule applies to
30+
- `api_types`(required): (List) The API types this rule applies to.
31+
- `api_type_id`(required):The API type ID
32+
33+
34+
### Example Rule For Context-Based Restrictions Configuration
35+
36+
```hcl
37+
cbr_rules = [
38+
{
39+
"description" : "SCC Instance can be accessed from xyz"
40+
"account_id" : "defc0df06b644a9cabc6e44f55b3880s."
41+
"rule_contexts" : [{
42+
"attributes" : [
43+
{
44+
"name" : "endpointType",
45+
"value" : "private"
46+
},
47+
{
48+
"name" : "networkZoneId"
49+
"value" : "93a51a1debe2674193217209601dde6f" # pragma: allowlist secret
50+
}
51+
]
52+
}]
53+
"enforcement_mode" : "enabled"
54+
"operations" : [{
55+
"api_types" : [{
56+
"api_type_id" : "crn:v1:bluemix:public:context-based-restrictions::::api-type:"
57+
}]
58+
}]
59+
}
60+
]
61+
```

solutions/standard/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ module "elasticsearch" {
316316
service_credential_names = var.service_credential_names
317317
enable_elser_model = var.enable_elser_model
318318
elser_model_type = var.elser_model_type
319+
cbr_rules = var.cbr_rules
319320
}
320321

321322
locals {

solutions/standard/variables.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,3 +394,27 @@ variable "kibana_visibility" {
394394
error_message = "Valid values are 'local_public', 'local_private', or 'local'."
395395
}
396396
}
397+
398+
##############################################################
399+
# Context-based restriction (CBR)
400+
##############################################################
401+
402+
variable "cbr_rules" {
403+
type = list(object({
404+
description = string
405+
account_id = string
406+
rule_contexts = list(object({
407+
attributes = optional(list(object({
408+
name = string
409+
value = string
410+
}))) }))
411+
enforcement_mode = string
412+
operations = optional(list(object({
413+
api_types = list(object({
414+
api_type_id = string
415+
}))
416+
})))
417+
}))
418+
description = "(Optional, list) List of context-based restrictions rules to create. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-icd-elasticsearch/tree/main/solutions/standard/DA-cbr_rules.md)"
419+
default = []
420+
}

tests/pr_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ package test
33

44
import (
55
"fmt"
6+
"log"
7+
"math/rand"
8+
"os"
9+
"strings"
10+
"testing"
11+
612
"github.com/gruntwork-io/terratest/modules/files"
713
"github.com/gruntwork-io/terratest/modules/logger"
814
"github.com/gruntwork-io/terratest/modules/random"
@@ -13,11 +19,6 @@ import (
1319
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/common"
1420
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testhelper"
1521
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testschematic"
16-
"log"
17-
"math/rand"
18-
"os"
19-
"strings"
20-
"testing"
2122
)
2223

2324
const completeExampleTerraformDir = "examples/complete"

variables.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,13 @@ variable "cbr_rules" {
244244
value = string
245245
}))) }))
246246
enforcement_mode = string
247+
operations = optional(list(object({
248+
api_types = list(object({
249+
api_type_id = string
250+
}))
251+
})))
247252
}))
248-
description = "The list of context-based restriction rules to create."
253+
description = "(Optional, list) List of context-based restrictions rules to create."
249254
default = []
250255
# Validation happens in the rule module
251256
}

0 commit comments

Comments
 (0)