Skip to content

Commit 3e25409

Browse files
authored
feat: added support to the cbr-zone-module to use existing zone using new inputs existing_zone_id and use_existing_cbr_zone (#530)
1 parent 4060786 commit 3e25409

File tree

25 files changed

+363
-62
lines changed

25 files changed

+363
-62
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ See in particular the [fscloud module](./modules/fscloud/) that enables creating
2525
* [Multi resource rule example](./examples/multi-resource-rule)
2626
* [Multi-zone example](./examples/multizone-rule)
2727
* [Pre-wired CBR configuration for FS Cloud example](./examples/fscloud)
28+
* [Zone example](./examples/update-existing-zone-addresses)
2829
* [Zone example](./examples/zone)
2930
* [Contributing](#contributing)
3031
<!-- END OVERVIEW HOOK -->
@@ -103,7 +104,7 @@ You need the following permissions to run this module.
103104
| Name | Version |
104105
|------|---------|
105106
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
106-
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.65.0, < 2.0.0 |
107+
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.69.0, < 2.0.0 |
107108

108109
### Modules
109110

@@ -136,12 +137,12 @@ You need the following permissions to run this module.
136137

137138
| Name | Description |
138139
|------|-------------|
139-
| <a name="output_rule_crn"></a> [rule\_crn](#output\_rule\_crn) | CBR rule resource instance crn |
140-
| <a name="output_rule_href"></a> [rule\_href](#output\_rule\_href) | CBR rule resource href |
141-
| <a name="output_rule_id"></a> [rule\_id](#output\_rule\_id) | CBR rule resource instance id |
142-
| <a name="output_zone_crn"></a> [zone\_crn](#output\_zone\_crn) | cbr\_zone resource instance crn |
143-
| <a name="output_zone_href"></a> [zone\_href](#output\_zone\_href) | cbr\_zone resource instance link |
144-
| <a name="output_zone_id"></a> [zone\_id](#output\_zone\_id) | cbr\_zone resource instance id |
140+
| <a name="output_rule_crn"></a> [rule\_crn](#output\_rule\_crn) | CBR rule crn |
141+
| <a name="output_rule_href"></a> [rule\_href](#output\_rule\_href) | CBR rule href |
142+
| <a name="output_rule_id"></a> [rule\_id](#output\_rule\_id) | CBR rule id |
143+
| <a name="output_zone_crn"></a> [zone\_crn](#output\_zone\_crn) | cbr\_zone crn |
144+
| <a name="output_zone_href"></a> [zone\_href](#output\_zone\_href) | cbr\_zone link |
145+
| <a name="output_zone_id"></a> [zone\_id](#output\_zone\_id) | cbr\_zone id |
145146
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
146147

147148
<!-- Leave this section as is so that your module has a link to local development environment set up steps for contributors to follow -->

examples/multi-service-profile/outputs.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
output "zone_ids" {
66
value = module.cbr_rule_multi_service_profile[*].zone_ids
7-
description = "CBR zone resource instance id(s)"
7+
description = "CBR zone id(s)"
88
}
99

1010
output "zone_crns" {
@@ -24,12 +24,12 @@ output "rule_ids" {
2424

2525
output "rule_crns" {
2626
value = module.cbr_rule_multi_service_profile[*].rule_crns
27-
description = "CBR rule resource instance crn(s)"
27+
description = "CBR rule crn(s)"
2828
}
2929

3030
output "rule_hrefs" {
3131
value = module.cbr_rule_multi_service_profile[*].rule_hrefs
32-
description = "CBR rule resource instance href(s)"
32+
description = "CBR rule href(s)"
3333
}
3434

3535
output "vpc_crn" {

examples/multi-service-profile/version.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ terraform {
55
# module's version.tf (zone or multi zone rule), and 1 example that will always use the latest provider version (fscloud multi service profile and multi resource rule).
66
ibm = {
77
source = "IBM-Cloud/ibm"
8-
version = ">= 1.65.0"
8+
version = ">= 1.69.0"
99

1010
}
1111
}

examples/multizone-rule/outputs.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
output "zone_id" {
66
value = module.cbr_zone[*].zone_id
7-
description = "CBR zone resource instance id"
7+
description = "CBR zone id"
88
}
99

1010
output "zone_crn" {
1111
value = module.cbr_zone[*].zone_crn
12-
description = "CBR zone resource instance crn"
12+
description = "CBR zone crn"
1313
}
1414

1515
output "zone_href" {
1616
value = module.cbr_zone[*].zone_href
17-
description = "CBR zone resource instance href"
17+
description = "CBR zone href"
1818
}
1919

2020
output "cos_guid" {
@@ -34,7 +34,7 @@ output "resource_group_id" {
3434

3535
output "rule_id" {
3636
value = module.cbr_rule.rule_id
37-
description = "CBR rule resource instance id"
37+
description = "CBR rule id"
3838
}
3939

4040
output "rule_description" {
@@ -44,10 +44,10 @@ output "rule_description" {
4444

4545
output "rule_crn" {
4646
value = module.cbr_rule.rule_crn
47-
description = "CBR rule resource instance crn"
47+
description = "CBR rule crn"
4848
}
4949

5050
output "rule_href" {
5151
value = module.cbr_rule.rule_href
52-
description = "CBR rule resource instance href"
52+
description = "CBR rule href"
5353
}

examples/multizone-rule/version.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ terraform {
55
# module's version.tf (zone or multi zone rule), and 1 example that will always use the latest provider version (fscloud multi service profile and multi resource rule).
66
ibm = {
77
source = "IBM-Cloud/ibm"
8-
version = "1.65.0"
8+
version = "1.69.0"
99
}
1010
}
1111
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Zone example
2+
3+
Example that creates a zone for context-based restrictions. This example uses the IBM Cloud Provider to automate the following infrastructure:
4+
5+
- Creates 2 VPCs.
6+
- Creates 2 Public Gateways.
7+
- Creates 2 VPC Subnets.
8+
- Creates a CBR Zone for the VPC.
9+
- Updates an existing CBR Zone created above with new addresses containing another VPC created above and a `compliance` serviceRef.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
##############################################################################
2+
# Get Cloud Account ID
3+
##############################################################################
4+
5+
data "ibm_iam_account_settings" "iam_account_settings" {
6+
}
7+
8+
##############################################################################
9+
# Resource Group
10+
##############################################################################
11+
12+
module "resource_group" {
13+
source = "terraform-ibm-modules/resource-group/ibm"
14+
version = "1.1.6"
15+
# if an existing resource group is not set (null) create a new one using prefix
16+
resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null
17+
existing_resource_group_name = var.resource_group
18+
}
19+
20+
##############################################################################
21+
# VPCs
22+
##############################################################################
23+
resource "ibm_is_vpc" "example_vpc" {
24+
name = "${var.prefix}-vpc"
25+
resource_group = module.resource_group.resource_group_id
26+
tags = var.resource_tags
27+
}
28+
29+
resource "ibm_is_public_gateway" "testacc_gateway" {
30+
name = "${var.prefix}-pgateway"
31+
vpc = ibm_is_vpc.example_vpc.id
32+
zone = "${var.region}-1"
33+
resource_group = module.resource_group.resource_group_id
34+
}
35+
36+
resource "ibm_is_subnet" "testacc_subnet" {
37+
name = "${var.prefix}-subnet"
38+
vpc = ibm_is_vpc.example_vpc.id
39+
zone = "${var.region}-1"
40+
public_gateway = ibm_is_public_gateway.testacc_gateway.id
41+
total_ipv4_address_count = 256
42+
resource_group = module.resource_group.resource_group_id
43+
}
44+
45+
resource "ibm_is_vpc" "example_new_vpc" {
46+
name = "${var.prefix}-new-vpc"
47+
resource_group = module.resource_group.resource_group_id
48+
tags = var.resource_tags
49+
}
50+
51+
resource "ibm_is_public_gateway" "testacc_new_gateway" {
52+
name = "${var.prefix}-new-pgateway"
53+
vpc = ibm_is_vpc.example_new_vpc.id
54+
zone = "${var.region}-1"
55+
resource_group = module.resource_group.resource_group_id
56+
}
57+
58+
resource "ibm_is_subnet" "testacc_new_subnet" {
59+
name = "${var.prefix}-new-subnet"
60+
vpc = ibm_is_vpc.example_new_vpc.id
61+
zone = "${var.region}-1"
62+
public_gateway = ibm_is_public_gateway.testacc_new_gateway.id
63+
total_ipv4_address_count = 256
64+
resource_group = module.resource_group.resource_group_id
65+
}
66+
67+
##############################################################################
68+
# CBR zone & rule creation
69+
##############################################################################
70+
71+
locals {
72+
zone_address_details = [{
73+
type = "vpc", # to bind a specific vpc to the zone
74+
value = resource.ibm_is_vpc.example_vpc.crn,
75+
}, {
76+
type = "serviceRef" # to bind a service reference type should be 'serviceRef'
77+
ref = {
78+
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
79+
service_name = "secrets-manager" # secrets manager service reference.
80+
}
81+
}]
82+
83+
new_zone_address_details = [{
84+
type = "vpc", # to bind a specific vpc to the zone
85+
value = resource.ibm_is_vpc.example_new_vpc.crn,
86+
}, {
87+
type = "serviceRef" # to bind a service reference type should be 'serviceRef'
88+
ref = {
89+
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
90+
service_name = "compliance" # SCC service reference.
91+
}
92+
}]
93+
}
94+
95+
module "ibm_cbr_zone" {
96+
source = "../../modules/cbr-zone-module"
97+
name = "${var.prefix}-cbr-zone"
98+
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
99+
zone_description = var.zone_description
100+
addresses = local.zone_address_details
101+
}
102+
103+
module "update_cbr_zone" {
104+
source = "../../modules/cbr-zone-module"
105+
use_existing_cbr_zone = true
106+
existing_zone_id = module.ibm_cbr_zone.zone_id
107+
addresses = local.new_zone_address_details
108+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# # ##############################################################################
2+
# # # Outputs
3+
# # ##############################################################################
4+
5+
output "vpc_id" {
6+
value = resource.ibm_is_vpc.example_vpc.id
7+
description = "VPC id"
8+
}
9+
10+
output "new_vpc_id" {
11+
value = resource.ibm_is_vpc.example_new_vpc.id
12+
description = "New VPC id"
13+
}
14+
15+
output "vpc_crn" {
16+
value = resource.ibm_is_vpc.example_vpc.crn
17+
description = "VPC crn"
18+
}
19+
20+
output "new_vpc_crn" {
21+
value = resource.ibm_is_vpc.example_new_vpc.crn
22+
description = "New VPC crn"
23+
}
24+
25+
output "account_id" {
26+
description = "account id"
27+
value = data.ibm_iam_account_settings.iam_account_settings.id
28+
}
29+
30+
output "zone_name" {
31+
value = module.ibm_cbr_zone.zone_names
32+
description = "cbr_zone name"
33+
}
34+
35+
output "zone_description" {
36+
value = module.ibm_cbr_zone.zone_description
37+
description = "cbr_zone description"
38+
}
39+
40+
output "zone_id" {
41+
value = module.ibm_cbr_zone.zone_id
42+
description = "cbr_zone id"
43+
}
44+
45+
output "zone_crn" {
46+
value = module.ibm_cbr_zone.zone_crn
47+
description = "cbr_zone crn"
48+
}
49+
50+
output "zone_href" {
51+
value = module.ibm_cbr_zone.zone_href
52+
description = "cbr_zone href"
53+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
provider "ibm" {
2+
ibmcloud_api_key = var.ibmcloud_api_key
3+
region = var.region
4+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
variable "ibmcloud_api_key" {
2+
type = string
3+
description = "The IBM Cloud API Key"
4+
sensitive = true
5+
}
6+
7+
variable "prefix" {
8+
type = string
9+
description = "Prefix to append to all resources created by this example"
10+
}
11+
12+
variable "region" {
13+
description = "Name of the Region to deploy into"
14+
type = string
15+
}
16+
17+
variable "resource_group" {
18+
type = string
19+
description = "An existing resource group name to use for this example, if unset a new resource group will be created"
20+
default = null
21+
}
22+
23+
variable "resource_tags" {
24+
type = list(string)
25+
description = "Optional list of tags to be added to created resources"
26+
default = []
27+
}
28+
29+
##############################################################
30+
# CBR
31+
##############################################################
32+
33+
variable "zone_description" {
34+
type = string
35+
description = "(Optional, String) The description of the zone"
36+
default = "Zone from automation"
37+
}

0 commit comments

Comments
 (0)