Skip to content

Commit 50d21db

Browse files
authored
chore: updated cbr enforcement mode (#251)
1 parent 44ce09a commit 50d21db

File tree

4 files changed

+112
-35
lines changed

4 files changed

+112
-35
lines changed

examples/complete/main.tf

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ resource "ibm_is_subnet" "testacc_subnet" {
8484
# Create CBR Zone
8585
##############################################################################
8686

87-
module "cbr_zone" {
87+
module "cbr_vpc_zone" {
8888
source = "terraform-ibm-modules/cbr/ibm//modules/cbr-zone-module"
8989
version = "1.23.0"
9090
name = "${var.prefix}-VPC-network-zone"
@@ -96,6 +96,21 @@ module "cbr_zone" {
9696
}]
9797
}
9898

99+
module "cbr_zone_schematics" {
100+
source = "terraform-ibm-modules/cbr/ibm//modules/cbr-zone-module"
101+
version = "1.23.0"
102+
name = "${var.prefix}-schematics-zone"
103+
zone_description = "CBR Network zone containing Schematics"
104+
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
105+
addresses = [{
106+
type = "serviceRef",
107+
ref = {
108+
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
109+
service_name = "schematics"
110+
}
111+
}]
112+
}
113+
99114
module "event_notification" {
100115
source = "../../"
101116
resource_group_id = module.resource_group.resource_group_id
@@ -117,7 +132,7 @@ module "event_notification" {
117132
cbr_rules = [
118133
{
119134
description = "${var.prefix}-event notification access only from vpc"
120-
enforcement_mode = "report"
135+
enforcement_mode = "enabled"
121136
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
122137
rule_contexts = [{
123138
attributes = [
@@ -127,7 +142,17 @@ module "event_notification" {
127142
},
128143
{
129144
name = "networkZoneId"
130-
value = module.cbr_zone.zone_id
145+
value = module.cbr_vpc_zone.zone_id
146+
}]
147+
}, {
148+
attributes = [
149+
{
150+
"name" : "endpointType",
151+
"value" : "public"
152+
},
153+
{
154+
name = "networkZoneId"
155+
value = module.cbr_zone_schematics.zone_id
131156
}]
132157
}]
133158
}

examples/fscloud/main.tf

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ resource "ibm_is_subnet" "testacc_subnet" {
3838
# Create CBR Zone
3939
##############################################################################
4040

41-
module "cbr_zone" {
41+
module "cbr_vpc_zone" {
4242
source = "terraform-ibm-modules/cbr/ibm//modules/cbr-zone-module"
4343
version = "1.23.0"
4444
name = "${var.prefix}-VPC-network-zone"
@@ -50,6 +50,21 @@ module "cbr_zone" {
5050
}]
5151
}
5252

53+
module "cbr_zone_schematics" {
54+
source = "terraform-ibm-modules/cbr/ibm//modules/cbr-zone-module"
55+
version = "1.23.0"
56+
name = "${var.prefix}-schematics-zone"
57+
zone_description = "CBR Network zone containing Schematics"
58+
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
59+
addresses = [{
60+
type = "serviceRef",
61+
ref = {
62+
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
63+
service_name = "schematics"
64+
}
65+
}]
66+
}
67+
5368
##############################################################################
5469
# Create COS Instance
5570
##############################################################################
@@ -117,7 +132,7 @@ module "event_notification" {
117132
cbr_rules = [
118133
{
119134
description = "${var.prefix}-event notification access only from vpc"
120-
enforcement_mode = "report"
135+
enforcement_mode = "enabled"
121136
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
122137
rule_contexts = [{
123138
attributes = [
@@ -127,7 +142,17 @@ module "event_notification" {
127142
},
128143
{
129144
name = "networkZoneId"
130-
value = module.cbr_zone.zone_id
145+
value = module.cbr_vpc_zone.zone_id
146+
}]
147+
}, {
148+
attributes = [
149+
{
150+
"name" : "endpointType",
151+
"value" : "private"
152+
},
153+
{
154+
name = "networkZoneId"
155+
value = module.cbr_zone_schematics.zone_id
131156
}]
132157
}]
133158
}

modules/fscloud/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module "event_notification" {
4040
cbr_rules = [
4141
{
4242
description = "Event notification access only from vpc"
43-
enforcement_mode = "report"
43+
enforcement_mode = "enabled"
4444
account_id = "defc0df06b644a9cabc6e44f55b3880s"
4545
rule_contexts = [{
4646
attributes = [

tests/pr_test.go

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -55,41 +55,36 @@ func setupOptions(t *testing.T, prefix string, dir string) *testhelper.TestOptio
5555
Region: validRegions[rand.Intn(len(validRegions))],
5656
})
5757

58-
if dir == fsExampleDir {
59-
options = testhelper.TestOptionsDefaultWithVars(&testhelper.TestOptions{
60-
Testing: t,
61-
TerraformDir: dir,
62-
Prefix: prefix,
63-
ResourceGroup: resourceGroup,
64-
Region: options.Region,
65-
TerraformVars: map[string]interface{}{
66-
"existing_kms_instance_crn": permanentResources["hpcs_south_crn"],
67-
"root_key_crn": permanentResources["hpcs_south_root_key_crn"],
68-
"kms_endpoint_url": permanentResources["hpcs_south_private_endpoint"],
69-
},
70-
})
71-
}
7258
return options
7359
}
7460

75-
func TestRunCompleteExample(t *testing.T) {
61+
func TestCompleteExampleInSchematics(t *testing.T) {
7662
t.Parallel()
7763

78-
options := setupOptions(t, "event-notification-complete", completeExampleDir)
79-
80-
output, err := options.RunTestConsistency()
81-
assert.Nil(t, err, "This should not have errored")
82-
assert.NotNil(t, output, "Expected some output")
83-
}
64+
var region = validRegions[rand.Intn(len(validRegions))]
8465

85-
func TestRunFSCloudExample(t *testing.T) {
86-
t.Parallel()
66+
options := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{
67+
Testing: t,
68+
Prefix: "en-complete",
69+
TarIncludePatterns: []string{
70+
"*.tf",
71+
completeExampleDir + "/*.tf",
72+
},
73+
ResourceGroup: resourceGroup,
74+
TemplateFolder: completeExampleDir,
75+
Tags: []string{"test-schematic"},
76+
DeleteWorkspaceOnFail: false,
77+
WaitJobCompleteMinutes: 60,
78+
})
8779

88-
options := setupOptions(t, "en-fs", fsExampleDir)
80+
options.TerraformVars = []testschematic.TestSchematicTerraformVar{
81+
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
82+
{Name: "prefix", Value: options.Prefix, DataType: "string"},
83+
{Name: "region", Value: region, DataType: "string"},
84+
}
8985

90-
output, err := options.RunTestConsistency()
86+
err := options.RunSchematicTest()
9187
assert.Nil(t, err, "This should not have errored")
92-
assert.NotNil(t, output, "Expected some output")
9388
}
9489

9590
func TestDAInSchematics(t *testing.T) {
@@ -104,7 +99,6 @@ func TestDAInSchematics(t *testing.T) {
10499
"*.tf",
105100
solutionDADir + "/*.tf",
106101
},
107-
ResourceGroup: resourceGroup,
108102
TemplateFolder: solutionDADir,
109103
Tags: []string{"test-schematic"},
110104
DeleteWorkspaceOnFail: false,
@@ -113,8 +107,8 @@ func TestDAInSchematics(t *testing.T) {
113107

114108
options.TerraformVars = []testschematic.TestSchematicTerraformVar{
115109
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
116-
{Name: "resource_group_name", Value: options.Prefix, DataType: "string"},
117110
{Name: "region", Value: region, DataType: "string"},
111+
{Name: "resource_group_name", Value: options.Prefix, DataType: "string"},
118112
{Name: "existing_kms_instance_crn", Value: permanentResources["hpcs_south_crn"], DataType: "string"},
119113
{Name: "kms_endpoint_url", Value: permanentResources["hpcs_south_private_endpoint"], DataType: "string"},
120114
{Name: "cross_region_location", Value: "us", DataType: "string"},
@@ -124,6 +118,39 @@ func TestDAInSchematics(t *testing.T) {
124118
assert.Nil(t, err, "This should not have errored")
125119
}
126120

121+
func TestFSCloudInSchematics(t *testing.T) {
122+
t.Parallel()
123+
124+
var region = validRegions[rand.Intn(len(validRegions))]
125+
126+
options := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{
127+
Testing: t,
128+
Prefix: "en-fs",
129+
TarIncludePatterns: []string{
130+
"*.tf",
131+
fsExampleDir + "/*.tf",
132+
"modules/fscloud/*.tf",
133+
},
134+
ResourceGroup: resourceGroup,
135+
TemplateFolder: fsExampleDir,
136+
Tags: []string{"test-schematic"},
137+
DeleteWorkspaceOnFail: false,
138+
WaitJobCompleteMinutes: 60,
139+
})
140+
141+
options.TerraformVars = []testschematic.TestSchematicTerraformVar{
142+
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
143+
{Name: "region", Value: region, DataType: "string"},
144+
{Name: "prefix", Value: options.Prefix, DataType: "string"},
145+
{Name: "existing_kms_instance_crn", Value: permanentResources["hpcs_south_crn"], DataType: "string"},
146+
{Name: "kms_endpoint_url", Value: permanentResources["hpcs_south_private_endpoint"], DataType: "string"},
147+
{Name: "root_key_crn", Value: permanentResources["hpcs_south_root_key_crn"], DataType: "string"},
148+
}
149+
150+
err := options.RunSchematicTest()
151+
assert.Nil(t, err, "This should not have errored")
152+
}
153+
127154
func TestRunUpgradeDASolution(t *testing.T) {
128155
t.Parallel()
129156

0 commit comments

Comments
 (0)