Skip to content

Commit 3c9e11b

Browse files
feat: added support to create CBR rules using new input cbr_rules (#154)
1 parent 70e74a7 commit 3c9e11b

File tree

7 files changed

+120
-5
lines changed

7 files changed

+120
-5
lines changed

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ For more information on access and permissions, see <https://cloud.ibm.com/docs/
7979
| Name | Version |
8080
|------|---------|
8181
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
82-
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.49.0, < 2.0.0 |
82+
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.65.0, < 2.0.0 |
8383

8484
### Modules
8585

86-
No modules.
86+
| Name | Source | Version |
87+
|------|--------|---------|
88+
| <a name="module_cbr_rule"></a> [cbr\_rule](#module\_cbr\_rule) | terraform-ibm-modules/cbr/ibm//modules/cbr-rule-module | 1.24.0 |
8789

8890
### Resources
8991

@@ -101,6 +103,7 @@ No modules.
101103
| <a name="input_app_config_plan"></a> [app\_config\_plan](#input\_app\_config\_plan) | Plan for the App Configuration service instance, valid plans are lite, standardv2, and enterprise. | `string` | `"lite"` | no |
102104
| <a name="input_app_config_service_endpoints"></a> [app\_config\_service\_endpoints](#input\_app\_config\_service\_endpoints) | Service Endpoints for the App Configuration service instance, valid endpoints are public or public-and-private. | `string` | `"public-and-private"` | no |
103105
| <a name="input_app_config_tags"></a> [app\_config\_tags](#input\_app\_config\_tags) | Optional list of tags to be added to the App Config instance. | `list(string)` | `[]` | no |
106+
| <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 |
104107
| <a name="input_region"></a> [region](#input\_region) | The region to provision the App Configuration service, valid regions are us-south, us-east, eu-gb, and au-syd. | `string` | `"us-south"` | no |
105108
| <a name="input_resource_group_id"></a> [resource\_group\_id](#input\_resource\_group\_id) | The resource group ID where resources will be provisioned. | `string` | n/a | yes |
106109

examples/basic/version.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ terraform {
66
required_providers {
77
ibm = {
88
source = "IBM-Cloud/ibm"
9-
version = "1.49.0"
9+
version = "1.65.0"
1010
}
1111
}
1212
}

examples/complete/main.tf

+56
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,37 @@ module "resource_group" {
1414
existing_resource_group_name = var.resource_group
1515
}
1616

17+
##############################################################################
18+
# Get Cloud Account ID
19+
##############################################################################
20+
21+
data "ibm_iam_account_settings" "iam_account_settings" {
22+
}
23+
24+
##############################################################################
25+
# VPC
26+
##############################################################################
27+
resource "ibm_is_vpc" "example_vpc" {
28+
name = "${var.prefix}-vpc"
29+
resource_group = module.resource_group.resource_group_id
30+
tags = var.resource_tags
31+
}
32+
33+
##############################################################################
34+
# Create CBR Zone
35+
##############################################################################
36+
module "cbr_zone" {
37+
source = "terraform-ibm-modules/cbr/ibm//modules/cbr-zone-module"
38+
version = "1.27.0"
39+
name = "${var.prefix}-VPC-network-zone"
40+
zone_description = "CBR Network zone representing VPC"
41+
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
42+
addresses = [{
43+
type = "vpc", # to bind a specific vpc to the zone
44+
value = ibm_is_vpc.example_vpc.crn,
45+
}]
46+
}
47+
1748
########################################################################################################################
1849
# App Config
1950
########################################################################################################################
@@ -32,4 +63,29 @@ module "app_config" {
3263
description = "Collection for ${var.prefix}"
3364
}
3465
]
66+
67+
cbr_rules = [
68+
{
69+
description = "${var.prefix}-APP-CONF access only from vpc"
70+
enforcement_mode = "enabled"
71+
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
72+
tags = [
73+
{
74+
name = "test-name"
75+
value = "test-value"
76+
}
77+
]
78+
rule_contexts = [{
79+
attributes = [
80+
{
81+
"name" : "endpointType",
82+
"value" : "private"
83+
},
84+
{
85+
name = "networkZoneId"
86+
value = module.cbr_zone.zone_id
87+
}]
88+
}]
89+
}
90+
]
3591
}

examples/complete/version.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ terraform {
66
required_providers {
77
ibm = {
88
source = "IBM-Cloud/ibm"
9-
version = ">= 1.49.0, < 2.0.0"
9+
version = ">= 1.65.0, < 2.0.0"
1010
}
1111
}
1212
}

main.tf

+32
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,35 @@ resource "ibm_app_config_collection" "collections" {
2727
description = each.value.description
2828
tags = each.value.tags
2929
}
30+
31+
##############################################################################
32+
# Context Based Restrictions
33+
##############################################################################
34+
module "cbr_rule" {
35+
count = length(var.cbr_rules) > 0 ? length(var.cbr_rules) : 0
36+
source = "terraform-ibm-modules/cbr/ibm//modules/cbr-rule-module"
37+
version = "1.24.0"
38+
rule_description = var.cbr_rules[count.index].description
39+
enforcement_mode = var.cbr_rules[count.index].enforcement_mode
40+
rule_contexts = var.cbr_rules[count.index].rule_contexts
41+
resources = [{
42+
attributes = [
43+
{
44+
name = "accountId"
45+
value = var.cbr_rules[count.index].account_id
46+
operator = "stringEquals"
47+
},
48+
{
49+
name = "serviceInstance"
50+
value = ibm_resource_instance.app_config.guid
51+
operator = "stringEquals"
52+
},
53+
{
54+
name = "serviceName"
55+
value = "apprapp"
56+
operator = "stringEquals"
57+
}
58+
],
59+
tags = var.cbr_rules[count.index].tags
60+
}]
61+
}

variables.tf

+24
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,27 @@ variable "app_config_collections" {
6565
}))
6666
default = []
6767
}
68+
69+
##############################################################
70+
# Context-based restriction (CBR)
71+
##############################################################
72+
73+
variable "cbr_rules" {
74+
type = list(object({
75+
description = string
76+
account_id = string
77+
tags = optional(list(object({
78+
name = string
79+
value = string
80+
})), [])
81+
rule_contexts = list(object({
82+
attributes = optional(list(object({
83+
name = string
84+
value = string
85+
}))) }))
86+
enforcement_mode = string
87+
}))
88+
description = "The list of context-based restriction rules to create."
89+
default = []
90+
# Validation happens in the rule module
91+
}

version.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ terraform {
66
required_providers {
77
ibm = {
88
source = "IBM-Cloud/ibm"
9-
version = ">= 1.49.0, < 2.0.0"
9+
version = ">= 1.65.0, < 2.0.0"
1010
}
1111
}
1212
}

0 commit comments

Comments
 (0)