Skip to content

Commit 78de6fb

Browse files
authored
feat: multiple refactoring (#158)
BREAKING CHANGE: If you were using the legacy input variable `allowlist` to restrict network to a specific IP range, you will need to migrate to using Context Based Restrictions (CBRs) for this. For more info see [Protecting Cloud Databases resources with context-based restrictions](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-cbr&interface=ui)
1 parent 15a1259 commit 78de6fb

26 files changed

+626
-406
lines changed

.secrets.baseline

Lines changed: 13 additions & 2 deletions
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": "2023-05-05T07:45:21Z",
6+
"generated_at": "2023-05-16T09:19:59Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"
@@ -76,7 +76,18 @@
7676
"name": "TwilioKeyDetector"
7777
}
7878
],
79-
"results": {},
79+
"results": {
80+
"README.md": [
81+
{
82+
"hashed_secret": "ff9ee043d85595eb255c05dfe32ece02a53efbb2",
83+
"is_secret": false,
84+
"is_verified": false,
85+
"line_number": 17,
86+
"type": "Secret Keyword",
87+
"verified_result": null
88+
}
89+
]
90+
},
8091
"version": "0.13.1+ibm.60.dss",
8192
"word_list": {
8293
"file": null,

README.md

Lines changed: 39 additions & 33 deletions
Large diffs are not rendered by default.

catalogValidationValues.json.template

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/basic/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Basic example
22

3-
An end-to-end example that uses the module's default variable values.
4-
5-
This example uses the IBM Cloud Terraform provider to create the following infrastructure:
3+
An end-to-end example that creates the following infrastructure:
64

75
- A resource group, if one is not passed in.
86
- An ICD MongoDB database instance.

examples/complete/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Complete example with encryption, autoscaling, and CBR rules
22

3-
This end-to-end example uses the IBM Cloud terraform provider to:
3+
An end-to-end example that uses the IBM Cloud Terraform provider to create the following infrastructure:
44

5-
- Create a new resource group if one is not passed in.
6-
- An ICD MongoDB database instance with autoscaling enabled (automatically increase resources).
7-
- Create Key Protect instance with root key.
8-
- Backend encryption using generated Key Protect key.
9-
- Create a Sample VPC.
10-
- Create Context Based Restriction(CBR) to only allow MongoDB to be accessible from the VPC.
5+
- A resource group, if one is not passed in.
6+
- A Key Protect instance with a root key.
7+
- An instance of Databases for MongoDB with BYOK encryption and autoscaling enabled (automatically increases resources).
8+
- Service credentials for the database instance.
9+
- A sample virtual private cloud (VPC).
10+
- A context-based restriction (CBR) rule to only allow MongoDB to be accessible from within the VPC.

examples/complete/main.tf

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ resource "ibm_is_subnet" "testacc_subnet" {
3131
##############################################################################
3232

3333
module "key_protect_all_inclusive" {
34-
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-key-protect-all-inclusive.git?ref=v4.0.0"
34+
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-key-protect-all-inclusive.git?ref=v4.1.0"
3535
resource_group_id = module.resource_group.resource_group_id
3636
# Note: Database instance and Key Protect must be created in the same region when using BYOK
3737
# See https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-key-protect&interface=ui#key-byok
@@ -41,26 +41,6 @@ module "key_protect_all_inclusive" {
4141
key_map = { "icd" = ["${var.prefix}-mongodb"] }
4242
}
4343

44-
# Create IAM Access Policy to allow Key protect to access Postgres instance
45-
resource "ibm_iam_authorization_policy" "policy" {
46-
source_service_name = "databases-for-mongodb"
47-
source_resource_group_id = module.resource_group.resource_group_id
48-
target_service_name = "kms"
49-
target_resource_instance_id = module.key_protect_all_inclusive.key_protect_guid
50-
roles = ["Reader"]
51-
}
52-
53-
##############################################################################
54-
# Service Credentials
55-
##############################################################################
56-
57-
resource "ibm_resource_key" "service_credentials" {
58-
count = length(var.service_credentials)
59-
name = var.service_credentials[count.index]
60-
resource_instance_id = module.mongodb.id
61-
tags = var.resource_tags
62-
}
63-
6444
##############################################################################
6545
# Get Cloud Account ID
6646
##############################################################################
@@ -83,23 +63,25 @@ module "cbr_zone" {
8363
}
8464

8565
##############################################################################
86-
# ICD mongodb database
66+
# ICD MongoDB instance
8767
##############################################################################
8868

8969
module "mongodb" {
90-
source = "../.."
91-
resource_group_id = module.resource_group.resource_group_id
92-
mongodb_version = var.mongodb_version
93-
instance_name = "${var.prefix}-mongodb"
94-
endpoints = "private"
95-
region = var.region
96-
kms_key_crn = module.key_protect_all_inclusive.keys["icd.${var.prefix}-mongodb"].crn
97-
tags = var.resource_tags
98-
auto_scaling = var.auto_scaling
70+
source = "../.."
71+
resource_group_id = module.resource_group.resource_group_id
72+
mongodb_version = var.mongodb_version
73+
instance_name = "${var.prefix}-mongodb"
74+
kms_encryption_enabled = true
75+
existing_kms_instance_guid = module.key_protect_all_inclusive.key_protect_guid
76+
region = var.region
77+
kms_key_crn = module.key_protect_all_inclusive.keys["icd.${var.prefix}-mongodb"].crn
78+
tags = var.resource_tags
79+
auto_scaling = var.auto_scaling
80+
service_credential_names = var.service_credential_names
9981
cbr_rules = [
10082
{
10183
description = "${var.prefix}-mongodb access only from vpc"
102-
enforcement_mode = var.enforcement_mode
84+
enforcement_mode = "enabled"
10385
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
10486
rule_contexts = [{
10587
attributes = [

examples/complete/outputs.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,15 @@ output "guid" {
1616
description = "mongodb instance guid"
1717
value = module.mongodb.guid
1818
}
19+
20+
output "service_credentials_json" {
21+
description = "Service credentials json map"
22+
value = module.mongodb.service_credentials_json
23+
sensitive = true
24+
}
25+
26+
output "service_credentials_object" {
27+
description = "Service credentials object"
28+
value = module.mongodb.service_credentials_object
29+
sensitive = true
30+
}

examples/complete/variables.tf

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,19 @@ variable "resource_tags" {
3030

3131
variable "mongodb_version" {
3232
type = string
33-
description = "Version of the mongodb instance. If left at null, the latest version is provisioned."
33+
description = "Version of the MongoDB instance. If no value is passed, the current preferred version of IBM Cloud Databases is used."
3434
default = null
3535
}
3636

37-
variable "service_credentials" {
38-
description = "A list of service credentials that you want to create for the database"
39-
type = list(string)
40-
default = ["mongodb_credential_microservices", "mongodb_credential_dev_1", "mongodb_credential_dev_2"]
41-
}
42-
43-
variable "enforcement_mode" {
44-
description = "whether or not enforce a rule upon creation and update the rule enforcement."
45-
type = string
46-
default = "enabled"
37+
variable "service_credential_names" {
38+
description = "Map of name, role for service credentials that you want to create for the database"
39+
type = map(string)
40+
default = {
41+
"mongodb_admin" : "Administrator",
42+
"mongodb_operator" : "Operator",
43+
"mongodb_viewer" : "Viewer",
44+
"mongodb_viewer" : "Editor",
45+
}
4746
}
4847

4948
variable "auto_scaling" {
@@ -75,7 +74,7 @@ variable "auto_scaling" {
7574
rate_units = optional(string)
7675
})
7776
})
78-
description = "Configure rules to allow your database to automatically increase its resources. Single block of autoscaling is allowed at once."
77+
description = "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-mongodb?topic=databases-for-mongodb-autoscaling&interface=cli#autoscaling-considerations in the IBM Cloud Docs."
7978
default = {
8079
cpu = {}
8180
disk = {

examples/fscloud/README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# Financial Services Cloud profile example
22

3-
## *Note:* This example is only deploying MongoDB in a compliant manner the other infrastructure is not necessarily compliant.
3+
An end-to-end example that uses the [Profile for IBM Cloud Framework for Financial Services](../../profiles/fscloud/) to deploy an instance of IBM Cloud Databases for MongoDB.
44

5-
### Requirements
6-
This example expects you have Hyper Protect Crypto Service instances in the region you wish to deploy your MongoDB instance.
5+
The example uses the IBM Cloud Terraform provider to create the following infrastructure:
76

8-
### Deploys
9-
An example using the fscloud profile to deploy a compliant MongoDB instance. This example uses the IBM Cloud terraform provider to:
7+
- A resource group, if one is not passed in.
8+
- An IAM authorization between all MongoDB database instances in the given resource group, and the Hyper Protect Crypto Services instance that is passed in.
9+
- An IBM Cloud Databases MongoDB database instance that is encrypted with the Hyper Protect Crypto Services root key that is passed in.
10+
- Service Credentials for the MongoDB database instance.
11+
- A sample virtual private cloud (VPC).
12+
- A context-based restriction (CBR) rule to only allow MongoDB to be accessible from within the VPC.
1013

11-
- Create a new resource group if one is not passed in.
12-
- Create a Key protect instance and generate backup encryption key.
13-
- Create an IAM Authorization between MongoDB instance resource group and Key Protect Instance for backup_encryption_key_crn as backup encryption key is not supported by Hyper Protect instances yet.
14-
- Create an IAM Authorization between MongoDB instance Resource group and HPSC permanent Instance.
15-
- Create a new ICD MongoDB instance and credentials that is encrypted using the Hyper Protect Crypto Service resources that are passed in.
16-
- Create a Sample VPC.
17-
- Create Context Based Restriction(CBR) to only allow MongoDB to be accessible from the VPC.
14+
:exclamation: **Important:** In this example, only the IBM Cloud Databases for MongoDB instance complies with the IBM Cloud Framework for Financial Services. Other parts of the infrastructure do not necessarily comply.
15+
16+
## Before you begin
17+
18+
- You need a Hyper Protect Crypto Services instance and root key available in the region that you want to deploy your MongoDB database instance to.

0 commit comments

Comments
 (0)