Skip to content

Commit 2bc63c8

Browse files
feat: added support to create CBR rules using new input cbr_rules (#142)
1 parent f7171ff commit 2bc63c8

File tree

5 files changed

+116
-2
lines changed

5 files changed

+116
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ statement instead the previous block.
9191

9292
### Modules
9393

94-
No modules.
94+
| Name | Source | Version |
95+
|------|--------|---------|
96+
| <a name="module_cbr_rule"></a> [cbr\_rule](#module\_cbr\_rule) | terraform-ibm-modules/cbr/ibm//modules/cbr-rule-module | 1.24.0 |
9597

9698
### Resources
9799

@@ -106,6 +108,7 @@ No modules.
106108
| Name | Description | Type | Default | Required |
107109
|------|-------------|------|---------|:--------:|
108110
| <a name="input_access_tags"></a> [access\_tags](#input\_access\_tags) | A list of access tags to apply to the SCC WP instance created by the module. For more information, see https://cloud.ibm.com/docs/account?topic=account-access-tags-tutorial. | `list(string)` | `[]` | no |
111+
| <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> tags = optional(list(object({<br> name = string<br> value = string<br> })), [])<br> rule_contexts = list(object({<br> attributes = optional(list(object({<br> name = string<br> value = string<br> }))) }))<br> enforcement_mode = string<br> }))</pre> | `[]` | no |
109112
| <a name="input_cloud_monitoring_instance_crn"></a> [cloud\_monitoring\_instance\_crn](#input\_cloud\_monitoring\_instance\_crn) | The CRN of an IBM Cloud Monitoring instance to connect to the SCC Workload Protection instance. | `string` | `null` | no |
110113
| <a name="input_name"></a> [name](#input\_name) | The name to give the SCC Workload Protection instance that will be provisioned by this module. | `string` | n/a | yes |
111114
| <a name="input_region"></a> [region](#input\_region) | IBM Cloud region where all resources will be deployed | `string` | `"us-south"` | no |

examples/advanced/main.tf

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,36 @@ module "cloud_monitoring" {
2222
instance_name = "${var.prefix}-cm"
2323
}
2424

25+
##############################################################################
26+
# Get Cloud Account ID
27+
##############################################################################
28+
29+
data "ibm_iam_account_settings" "iam_account_settings" {
30+
}
31+
32+
##############################################################################
33+
# VPC
34+
##############################################################################
35+
resource "ibm_is_vpc" "example_vpc" {
36+
name = "${var.prefix}-vpc"
37+
resource_group = module.resource_group.resource_group_id
38+
tags = var.resource_tags
39+
}
40+
41+
##############################################################################
42+
# Create CBR Zone
43+
##############################################################################
44+
module "cbr_zone" {
45+
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-cbr//cbr-zone-module?ref=v1.2.0"
46+
name = "${var.prefix}-VPC-network-zone"
47+
zone_description = "CBR Network zone representing VPC"
48+
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
49+
addresses = [{
50+
type = "vpc", # to bind a specific vpc to the zone
51+
value = ibm_is_vpc.example_vpc.crn,
52+
}]
53+
}
54+
2555
########################################################################################################################
2656
# SCC WP instance
2757
########################################################################################################################
@@ -34,4 +64,29 @@ module "scc_wp" {
3464
resource_tags = var.resource_tags
3565
access_tags = var.access_tags
3666
cloud_monitoring_instance_crn = module.cloud_monitoring.crn
67+
68+
cbr_rules = [
69+
{
70+
description = "${var.prefix}-SCC-WP access only from vpc"
71+
enforcement_mode = "enabled"
72+
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
73+
tags = [
74+
{
75+
name = "test-name"
76+
value = "test-value"
77+
}
78+
]
79+
rule_contexts = [{
80+
attributes = [
81+
{
82+
"name" : "endpointType",
83+
"value" : "private"
84+
},
85+
{
86+
name = "networkZoneId"
87+
value = module.cbr_zone.zone_id
88+
}]
89+
}]
90+
}
91+
]
3792
}

examples/basic/version.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
# Pin to the lowest provider version of the range defined in the main module's version.tf to ensure lowest version still works
55
ibm = {
66
source = "ibm-cloud/ibm"
7-
version = "1.58.1"
7+
version = "1.65.0"
88
}
99
}
1010
}

main.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,35 @@ resource "ibm_resource_tag" "scc_wp_access_tag" {
4141
tags = var.access_tags
4242
tag_type = "access"
4343
}
44+
45+
##############################################################################
46+
# Context Based Restrictions
47+
##############################################################################
48+
module "cbr_rule" {
49+
count = length(var.cbr_rules) > 0 ? length(var.cbr_rules) : 0
50+
source = "terraform-ibm-modules/cbr/ibm//modules/cbr-rule-module"
51+
version = "1.24.0"
52+
rule_description = var.cbr_rules[count.index].description
53+
enforcement_mode = var.cbr_rules[count.index].enforcement_mode
54+
rule_contexts = var.cbr_rules[count.index].rule_contexts
55+
resources = [{
56+
attributes = [
57+
{
58+
name = "accountId"
59+
value = var.cbr_rules[count.index].account_id
60+
operator = "stringEquals"
61+
},
62+
{
63+
name = "serviceInstance"
64+
value = ibm_resource_instance.scc_wp.guid
65+
operator = "stringEquals"
66+
},
67+
{
68+
name = "serviceName"
69+
value = "Security and Compliance Center Workload Protection"
70+
operator = "stringEquals"
71+
}
72+
],
73+
tags = var.cbr_rules[count.index].tags
74+
}]
75+
}

variables.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,27 @@ variable "cloud_monitoring_instance_crn" {
7272
description = "The CRN of an IBM Cloud Monitoring instance to connect to the SCC Workload Protection instance."
7373
default = null
7474
}
75+
76+
##############################################################
77+
# Context-based restriction (CBR)
78+
##############################################################
79+
80+
variable "cbr_rules" {
81+
type = list(object({
82+
description = string
83+
account_id = string
84+
tags = optional(list(object({
85+
name = string
86+
value = string
87+
})), [])
88+
rule_contexts = list(object({
89+
attributes = optional(list(object({
90+
name = string
91+
value = string
92+
}))) }))
93+
enforcement_mode = string
94+
}))
95+
description = "The list of context-based restriction rules to create."
96+
default = []
97+
# Validation happens in the rule module
98+
}

0 commit comments

Comments
 (0)