Skip to content

Commit 9a5fc4f

Browse files
feat: added new FSCloud terraform submodule (profiles/fscloud) with example on how to consume + added support for Hyper Protect + added support for creating the KMS auth policy. key_protect_key_crn has been renamed kms_key_crn (#139)
1 parent 8d6f2d6 commit 9a5fc4f

File tree

19 files changed

+586
-47
lines changed

19 files changed

+586
-47
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
branches: [main]
88
pull_request:
99
branches: [main]
10+
types: [opened, synchronize, reopened, ready_for_review]
1011

1112
# Allows you to run this workflow manually from the Actions tab
1213
workflow_dispatch:
@@ -15,3 +16,8 @@ jobs:
1516
call-terraform-ci-pipeline:
1617
uses: terraform-ibm-modules/common-pipeline-assets/.github/workflows/[email protected]
1718
secrets: inherit
19+
with:
20+
craSCCv2: true
21+
craTarget: "examples/fscloud"
22+
craRuleIgnoreFile: "cra-tf-validate-ignore-rules.json"
23+
craEnvironmentVariables: "TF_VAR_existing_at_instance_crn=crn:v1:bluemix:public:logdnaat:eu-de:a/abac0df06b644a9cabc6e44f55b3880e:b1ef3365-dfbf-4d8f-8ac8-75f4f84d6f4a::,TF_VAR_existing_kms_instance_guid=${{ vars.HPCS_SOUTH_GUID }},TF_VAR_kms_key_crn=${{ vars.HPCS_SOUTH_KEY_CRN }} "

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ You need the following permissions to run this module.
4242
- [ Autoscale example](examples/autoscale)
4343
- [ Complete example with Encryption and CBR rules](examples/complete)
4444
- [ Default example](examples/default)
45+
- [ Financial Services Cloud profile example](examples/fscloud)
4546
<!-- END EXAMPLES HOOK -->
4647
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
4748
## Requirements
@@ -62,27 +63,30 @@ You need the following permissions to run this module.
6263
| Name | Type |
6364
|------|------|
6465
| [ibm_database.mongodb](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/database) | resource |
66+
| [ibm_iam_authorization_policy.kms_policy](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
6567

6668
## Inputs
6769

6870
| Name | Description | Type | Default | Required |
6971
|------|-------------|------|---------|:--------:|
7072
| <a name="input_allowlist"></a> [allowlist](#input\_allowlist) | (Optional, List of Objects) A list of allowed IP addresses for the database. | <pre>list(object({<br> address = string<br> description = string<br> }))</pre> | `[]` | no |
7173
| <a name="input_auto_scaling"></a> [auto\_scaling](#input\_auto\_scaling) | Configure rules to allow your database to automatically increase its resources. Single block of autoscaling is allowed at once. | <pre>object({<br> cpu = object({<br> rate_increase_percent = optional(number, 10)<br> rate_limit_count_per_member = optional(number, 20)<br> rate_period_seconds = optional(number, 900)<br> rate_units = optional(string, "count")<br> })<br> disk = object({<br> capacity_enabled = optional(bool, false)<br> free_space_less_than_percent = optional(number, 10)<br> io_above_percent = optional(number, 90)<br> io_enabled = optional(bool, false)<br> io_over_period = optional(string, "15m")<br> rate_increase_percent = optional(number, 10)<br> rate_limit_mb_per_member = optional(number, 3670016)<br> rate_period_seconds = optional(number, 900)<br> rate_units = optional(string, "mb")<br> })<br> memory = object({<br> io_above_percent = optional(number, 90)<br> io_enabled = optional(bool, false)<br> io_over_period = optional(string, "15m")<br> rate_increase_percent = optional(number, 10)<br> rate_limit_mb_per_member = optional(number, 114688)<br> rate_period_seconds = optional(number, 900)<br> rate_units = optional(string, "mb")<br> })<br> })</pre> | `null` | no |
72-
| <a name="input_backup_encryption_key_crn"></a> [backup\_encryption\_key\_crn](#input\_backup\_encryption\_key\_crn) | (Optional) The CRN of a key protect key, that you want to use for encrypting disk that holds deployment backups. If null, will use 'key\_protect\_key\_crn' as encryption key. If 'key\_protect\_key\_crn' is also null database is encrypted by using randomly generated keys. | `string` | `null` | no |
74+
| <a name="input_backup_encryption_key_crn"></a> [backup\_encryption\_key\_crn](#input\_backup\_encryption\_key\_crn) | (Optional) The CRN of a Key Protect Key to use for encrypting backups. If left null, the value passed for the 'kms\_key\_crn' variable will be used. Take note that Hyper Protect Crypto Services for IBM Cloud® Databases backups is not currently supported. | `string` | `null` | no |
7375
| <a name="input_cbr_rules"></a> [cbr\_rules](#input\_cbr\_rules) | (Optional, list) List of CBR rules to create | <pre>list(object({<br> description = string<br> account_id = string<br> rule_contexts = list(object({<br> attributes = optional(list(object({<br> name = string<br> value = string<br> }))) }))<br> enforcement_mode = string<br> }))</pre> | `[]` | no |
7476
| <a name="input_configuration"></a> [configuration](#input\_configuration) | Database Configuration in JSON format. | <pre>object({<br> maxmemory = optional(number)<br> maxmemory-policy = optional(string)<br> appendonly = optional(string)<br> maxmemory-samples = optional(number)<br> stop-writes-on-bgsave-error = optional(string)<br> })</pre> | `null` | no |
7577
| <a name="input_cpu_count"></a> [cpu\_count](#input\_cpu\_count) | Number of CPU cores available to the mongodb instance | `number` | `7` | no |
7678
| <a name="input_disk_mb"></a> [disk\_mb](#input\_disk\_mb) | Disk available to the mongodb instance | `number` | `20480` | no |
7779
| <a name="input_endpoints"></a> [endpoints](#input\_endpoints) | Endpoints available to the mongodb instance (public, private, public-and-private) | `string` | `"private"` | no |
80+
| <a name="input_existing_kms_instance_guid"></a> [existing\_kms\_instance\_guid](#input\_existing\_kms\_instance\_guid) | The GUID of the Hyper Protect or Key Protect instance in which the key specified in var.kms\_key\_crn is coming from. Only required if skip\_iam\_authorization\_policy is false | `string` | `null` | no |
7881
| <a name="input_instance_name"></a> [instance\_name](#input\_instance\_name) | Name of the MongoDB instance | `string` | n/a | yes |
79-
| <a name="input_key_protect_key_crn"></a> [key\_protect\_key\_crn](#input\_key\_protect\_key\_crn) | (Optional) The root key CRN of a Key Management Service like Key Protect or Hyper Protect Crypto Service (HPCS) that you want to use for disk encryption. If `null`, database is encrypted by using randomly generated keys. See https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-key-protect&interface=ui#key-byok for current list of supported regions for BYOK | `string` | `null` | no |
82+
| <a name="input_kms_key_crn"></a> [kms\_key\_crn](#input\_kms\_key\_crn) | (Optional) The root key CRN of a Key Management Service like Key Protect or Hyper Protect Crypto Service (HPCS) that you want to use for disk encryption. If `null`, database is encrypted by using randomly generated keys. See https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-key-protect&interface=ui#key-byok for current list of supported regions for BYOK | `string` | `null` | no |
8083
| <a name="input_members"></a> [members](#input\_members) | Allocated number of members | `number` | `3` | no |
8184
| <a name="input_memory_mb"></a> [memory\_mb](#input\_memory\_mb) | Memory available to the mongodb instance | `number` | `1024` | no |
8285
| <a name="input_mongodb_version"></a> [mongodb\_version](#input\_mongodb\_version) | The version of the mongodb to be provisioned | `string` | `null` | no |
8386
| <a name="input_plan"></a> [plan](#input\_plan) | The name of the service plan that you choose for your mongodb instance | `string` | `"standard"` | no |
84-
| <a name="input_region"></a> [region](#input\_region) | The IBM Cloud region where instance will be created | `string` | `"us-south"` | no |
87+
| <a name="input_region"></a> [region](#input\_region) | The region MongoDB is to be created on. The region must support BYOK region if Key Protect Key is used or KYOK region if Hyper Protect Crypto Service (HPCS) is used. | `string` | `"us-south"` | no |
8588
| <a name="input_resource_group_id"></a> [resource\_group\_id](#input\_resource\_group\_id) | The ID of the IMB Cloud resource group where you want to create the instance | `string` | n/a | yes |
89+
| <a name="input_skip_iam_authorization_policy"></a> [skip\_iam\_authorization\_policy](#input\_skip\_iam\_authorization\_policy) | Set to true to skip the creation of an IAM authorization policy that permits all MongoDB instances in the given Resource group to read the encryption key from the Hyper Protect or Key Protect instance in `existing_kms_instance_guid`. | `bool` | `true` | no |
8690
| <a name="input_tags"></a> [tags](#input\_tags) | A list of tags that you want to add to your instance | `list(any)` | `[]` | no |
8791

8892
## Outputs

cra-tf-validate-ignore-rules.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"scc_rules": [
3+
{
4+
"scc_rule_id": "rule-beb7b289-706b-4dc0-b01d-b1d15d4331e3",
5+
"description": "Check whether Databases for MongoDB network access is restricted to a specific IP range",
6+
"ignore_reason": "This module supports restricting network access using Context Based Restrictions (CBRs), however SCC does not yet support scanning for CBR rules, hence the rule currently fails. SCC CBR support is being tracked in AHA SCC-961",
7+
"is_valid": true
8+
},
9+
{
10+
"scc_rule_id": "rule-216e2449-27d7-4afc-929a-b66e196a9cf9",
11+
"description": "Check whether Flow Logs for VPC are enabled",
12+
"ignore_reason": "This rule is not relevant to the module itself, just the VPC resource is used in the example that is scanned",
13+
"is_valid": false
14+
}
15+
]
16+
}

examples/complete/main.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ module "cbr_zone" {
8787
##############################################################################
8888

8989
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-
key_protect_key_crn = module.key_protect_all_inclusive.keys["icd.${var.prefix}-mongodb"].crn
97-
tags = var.resource_tags
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
9898
cbr_rules = [
9999
{
100100
description = "${var.prefix}-mongodb access only from vpc"

examples/fscloud/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Financial Services Cloud profile example
2+
3+
## *Note:* This example is only deploying MongoDB in a compliant manner the other infrastructure is not necessarily compliant.
4+
5+
### Requirements
6+
This example expects you have Hyper Protect Crypto Service instances in the region you wish to deploy your MongoDB instance.
7+
8+
### Deploys
9+
An example using the fscloud profile to deploy a compliant MongoDB instance. This example uses the IBM Cloud terraform provider to:
10+
11+
- Create a new resource group if one is not passed in.
12+
- Create a Key protect instance and IAM Authorization between MongoDB instance resource group and Key Protect Instance.
13+
- Create an IAM Authorization between MongoDB instance Resource group and HPSC permanent Instance.
14+
- Create a new ICD MongoDB instance and credentials that is encrypted using the Hyper Protect Crypto Service resources that are passed in.
15+
- Create a Sample VPC.
16+
- Create Context Based Restriction(CBR) to only allow Postgresql to be accessible from the VPC.

examples/fscloud/main.tf

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
##############################################################################
2+
# Resource Group
3+
##############################################################################
4+
5+
module "resource_group" {
6+
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-resource-group.git?ref=v1.0.5"
7+
# if an existing resource group is not set (null) create a new one using prefix
8+
resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null
9+
existing_resource_group_name = var.resource_group
10+
}
11+
12+
##############################################################################
13+
# Key Protect All Inclusive
14+
##############################################################################
15+
16+
# Need Key Protect instance for backup_encryption_key_crn as backup encryption key is not supported by Hyper Protect instaces yet.
17+
module "key_protect_all_inclusive" {
18+
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-key-protect-all-inclusive.git?ref=v4.0.0"
19+
resource_group_id = module.resource_group.resource_group_id
20+
# Note: Database instance and Key Protect must be created in the same region when using BYOK
21+
# See https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-key-protect&interface=ui#key-byok
22+
region = var.region
23+
key_protect_instance_name = "${var.prefix}-kp"
24+
resource_tags = var.resource_tags
25+
key_map = { "icd-mongodb" = ["${var.prefix}-mongodb"] }
26+
}
27+
28+
# Create IAM Access Policy to allow Key protect to access MongoDB instance
29+
resource "ibm_iam_authorization_policy" "policy" {
30+
source_service_name = "databases-for-mongodb"
31+
source_resource_group_id = module.resource_group.resource_group_id
32+
target_service_name = "kms"
33+
target_resource_instance_id = module.key_protect_all_inclusive.key_protect_guid
34+
roles = ["Reader"]
35+
}
36+
37+
##############################################################################
38+
# Get Cloud Account ID
39+
##############################################################################
40+
41+
data "ibm_iam_account_settings" "iam_account_settings" {
42+
}
43+
44+
##############################################################################
45+
# VPC
46+
##############################################################################
47+
resource "ibm_is_vpc" "example_vpc" {
48+
name = "${var.prefix}-vpc"
49+
resource_group = module.resource_group.resource_group_id
50+
tags = var.resource_tags
51+
}
52+
53+
resource "ibm_is_subnet" "testacc_subnet" {
54+
name = "${var.prefix}-subnet"
55+
vpc = ibm_is_vpc.example_vpc.id
56+
zone = "${var.region}-1"
57+
total_ipv4_address_count = 256
58+
resource_group = module.resource_group.resource_group_id
59+
}
60+
61+
##############################################################################
62+
# Create CBR Zone
63+
##############################################################################
64+
module "cbr_zone" {
65+
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-cbr//cbr-zone-module?ref=v1.1.2"
66+
name = "${var.prefix}-VPC-network-zone"
67+
zone_description = "CBR Network zone containing VPC"
68+
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
69+
addresses = [{
70+
type = "vpc", # to bind a specific vpc to the zone
71+
value = ibm_is_vpc.example_vpc.crn,
72+
}]
73+
}
74+
75+
##############################################################################
76+
# ICD mongodb database
77+
##############################################################################
78+
79+
module "mongodb" {
80+
source = "../../profiles/fscloud"
81+
resource_group_id = module.resource_group.resource_group_id
82+
instance_name = "${var.prefix}-mongodb"
83+
region = var.region
84+
tags = var.resource_tags
85+
kms_key_crn = var.kms_key_crn
86+
existing_kms_instance_guid = var.existing_kms_instance_guid
87+
backup_encryption_key_crn = module.key_protect_all_inclusive.keys["icd-mongodb.${var.prefix}-mongodb"].crn
88+
cbr_rules = [
89+
{
90+
description = "${var.prefix}-mongodb access only from vpc"
91+
enforcement_mode = "enabled"
92+
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
93+
rule_contexts = [{
94+
attributes = [
95+
{
96+
"name" : "endpointType",
97+
"value" : "private"
98+
},
99+
{
100+
name = "networkZoneId"
101+
value = module.cbr_zone.zone_id
102+
}]
103+
}]
104+
}
105+
]
106+
}

examples/fscloud/outputs.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
##############################################################################
2+
# Outputs
3+
##############################################################################
4+
output "id" {
5+
description = "MongoDB instance id"
6+
value = module.mongodb.id
7+
}
8+
9+
output "guid" {
10+
description = "MongoDB instance guid"
11+
value = module.mongodb.guid
12+
}
13+
14+
output "version" {
15+
description = "MongoDB instance version"
16+
value = module.mongodb.version
17+
}

examples/fscloud/provider.tf

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+
}

examples/fscloud/variables.tf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
variable "ibmcloud_api_key" {
2+
type = string
3+
description = "The IBM Cloud API Key"
4+
sensitive = true
5+
}
6+
7+
variable "region" {
8+
type = string
9+
description = "Region to provision all resources created by this example"
10+
default = "us-south"
11+
}
12+
13+
variable "prefix" {
14+
type = string
15+
description = "Prefix to append to all resources created by this example"
16+
default = "fs-cloud"
17+
}
18+
19+
variable "resource_group" {
20+
type = string
21+
description = "An existing resource group name to use for this example, if unset a new resource group will be created"
22+
default = null
23+
}
24+
25+
variable "resource_tags" {
26+
type = list(string)
27+
description = "Optional list of tags to be added to created resources"
28+
default = []
29+
}
30+
31+
variable "existing_kms_instance_guid" {
32+
description = "The GUID of the Hyper Protect Crypto service in which the key specified in var.kms_key_crn is coming from"
33+
type = string
34+
}
35+
36+
variable "kms_key_crn" {
37+
type = string
38+
description = "The root key CRN of a Hyper Protect Crypto Service (HPCS) that you want to use for disk encryption. See https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-hpcs&interface=ui for more information on integrating HPCS with MongoDB instance."
39+
}

examples/fscloud/version.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.3.0"
3+
required_providers {
4+
# Pin to the lowest provider version of the range defined in the main module's version.tf to ensure lowest version still works
5+
ibm = {
6+
source = "IBM-Cloud/ibm"
7+
version = "1.49.0"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)