Skip to content

Commit 7628208

Browse files
feat: add storage delegation from SaaS DA for WatsonX project (#129)
1 parent d6549bb commit 7628208

File tree

4 files changed

+89
-3
lines changed

4 files changed

+89
-3
lines changed

modules/watson-machine-learning/main.tf

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,26 @@ module "cos" {
1010
cos_plan = "standard"
1111
}
1212

13+
module "storage_delegation" {
14+
providers = {
15+
ibm = ibm
16+
ibm.deployer = ibm
17+
restapi.restapi_watsonx_admin = restapi.restapi_watsonx_admin
18+
}
19+
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-watsonx-saas-da.git//storage_delegation?ref=v1.4.0"
20+
count = var.watsonx_project_delegated ? 1 : 0
21+
cos_kms_crn = var.cos_kms_crn
22+
cos_kms_key_crn = var.cos_kms_key_crn
23+
cos_kms_new_key_name = var.cos_kms_new_key_name
24+
cos_kms_ring_id = var.cos_kms_ring_id
25+
cos_guid = module.cos.cos_instance_guid
26+
}
27+
1328
## Use code from Watson SaaS directly to avoid "legacy module" issues
1429
## Note: passing a non-null delegated storage attribute may result in API errors
1530

16-
1731
resource "restapi_object" "configure_project" {
32+
depends_on = [module.storage_delegation]
1833
provider = restapi.restapi_watsonx_admin
1934
path = local.dataplatform_api
2035
read_path = "${local.dataplatform_api}{id}"

modules/watson-machine-learning/variables.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,37 @@ variable "cos_instance_name" {
88
type = string
99
}
1010

11+
variable "cos_kms_crn" {
12+
description = "KMS service instance CRN used to encrypt the COS buckets used by the watsonx projects."
13+
type = string
14+
default = null
15+
16+
validation {
17+
condition = anytrue([
18+
can(regex("^crn:(.*:){3}kms:(.*:){2}[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$", var.cos_kms_crn)),
19+
var.cos_kms_crn == null,
20+
])
21+
error_message = "Key Protect CRN validation failed."
22+
}
23+
}
24+
25+
variable "cos_kms_key_crn" {
26+
description = "KMS key CRN used to encrypt the COS buckets used by the watsonx projects. If not set, then the cos_kms_new_key_name must be specified."
27+
type = string
28+
default = null
29+
}
30+
31+
variable "cos_kms_new_key_name" {
32+
description = "Name of the KMS key to create for encrypting the COS buckets used by the watsonx projects."
33+
type = string
34+
}
35+
36+
variable "cos_kms_ring_id" {
37+
description = "The identifier of the KMS ring to create the cos_kms_new_key_name into. If it is not set, then the new key will be created in the default ring."
38+
type = string
39+
default = null
40+
}
41+
1142
variable "watson_ml_instance_crn" {
1243
description = "Watson Machine Learning instance CRN"
1344
type = string

solutions/banking/main.tf

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ locals {
33
use_watson_machine_learning = (var.watson_machine_learning_instance_guid != null) ? true : false
44
use_elastic_index = (var.elastic_instance_crn != null) ? true : false
55

6+
cos_instance_name = var.prefix != null ? "${var.prefix}-rag-sample-app-cos" : "gen-ai-rag-sample-app-cos"
7+
cos_kms_new_key_name = var.prefix != null ? "${var.prefix}-${var.cos_kms_new_key_name}" : var.cos_kms_new_key_name
68
watsonx_assistant_url = "//api.${var.watson_assistant_region}.assistant.watson.cloud.ibm.com/instances/${var.watson_assistant_instance_id}"
79
watson_discovery_url = local.use_watson_discovery ? "//api.${var.watson_discovery_region}.discovery.watson.cloud.ibm.com/instances/${var.watson_discovery_instance_id}" : null
810
watson_discovery_project_name = var.prefix != null ? "${var.prefix}-gen-ai-rag-sample-app-project" : "gen-ai-rag-sample-app-project"
@@ -106,18 +108,24 @@ resource "ibm_resource_instance" "cd_instance" {
106108

107109
module "configure_wml_project" {
108110
providers = {
111+
ibm = ibm.ibm_resources
109112
ibm.ibm_resources = ibm.ibm_resources
110113
restapi.restapi_watsonx_admin = restapi.restapi_watsonx_admin
111114
}
112115
count = local.use_watson_machine_learning ? 1 : 0
113116
source = "../../modules/watson-machine-learning"
117+
watsonx_project_delegated = var.cos_kms_crn != null ? true : false
114118
watson_ml_instance_guid = var.watson_machine_learning_instance_guid
115119
watson_ml_instance_crn = var.watson_machine_learning_instance_crn
116120
watson_ml_instance_resource_name = var.watson_machine_learning_instance_resource_name
117121
watson_ml_project_name = local.watson_ml_project_name
118122
resource_group_id = module.resource_group.resource_group_id
119-
cos_instance_name = "${var.prefix}-rag-sample-app-cos"
120-
location = var.watson_discovery_region # WatsonX services needs to be in the same region anyway
123+
cos_instance_name = local.cos_instance_name
124+
cos_kms_crn = var.cos_kms_crn
125+
cos_kms_key_crn = var.cos_kms_key_crn
126+
cos_kms_ring_id = var.cos_kms_ring_id
127+
cos_kms_new_key_name = local.cos_kms_new_key_name
128+
location = var.watson_assistant_region
121129
}
122130

123131
moved {

solutions/banking/variables.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,38 @@ variable "watson_machine_learning_instance_resource_name" {
100100
default = null # WML usage is optional, elastic can be used instead
101101
}
102102

103+
variable "cos_kms_crn" {
104+
description = "Key Protect service instance CRN used to encrypt the COS buckets used by the watsonx projects."
105+
type = string
106+
default = null
107+
108+
validation {
109+
condition = anytrue([
110+
can(regex("^crn:(.*:){3}kms:(.*:){2}[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$", var.cos_kms_crn)),
111+
var.cos_kms_crn == null,
112+
])
113+
error_message = "Key Protect CRN validation failed."
114+
}
115+
}
116+
117+
variable "cos_kms_key_crn" {
118+
description = "Key Protect key CRN used to encrypt the COS buckets used by the watsonx projects. If not set, then the cos_kms_new_key_name must be specified."
119+
type = string
120+
default = null
121+
}
122+
123+
variable "cos_kms_new_key_name" {
124+
description = "Name of the Key Protect key to create for encrypting the COS buckets used by the watsonx projects."
125+
type = string
126+
default = ""
127+
}
128+
129+
variable "cos_kms_ring_id" {
130+
description = "The identifier of the Key Protect ring to create the cos_kms_new_key_name into. If it is not set, then the new key will be created in the default ring."
131+
type = string
132+
default = null
133+
}
134+
103135
variable "elastic_instance_crn" {
104136
description = "Elastic ICD instance CRN"
105137
type = string

0 commit comments

Comments
 (0)