Skip to content

Commit 0067fb4

Browse files
Khuzaima05Khuzaima-Shakeelimprateekshmaheshwarishikha
authored
fix: enhance DA for improving user experience<br>- updated reference architecture diagram<br>- updated tile content<br>- updated some of the input variables(prefix, region, resource_tags, kms_endpoint_type) description and validations (#148)
* refactor: enhance DA for improving user experience * refactor: enhance DA for improving user experience * update PR * update kms validation * update existing resource test * updated existing test * updated existing test * updated existing test * updated kms logic * fix catalog.json * minor fix * fix minor issues * Update solutions/fully-configurable/main.tf Co-authored-by: prateek <sharma_prateek@outlook.com> * Update solutions/fully-configurable/main.tf Co-authored-by: prateek <sharma_prateek@outlook.com> * Update tests/resources/kp-cos-instance/outputs.tf Co-authored-by: prateek <sharma_prateek@outlook.com> * resolve review comments * updated dependency version * resolve review comments * testing * testing * update test * update cloud logs icon * reverted version * Update ibm_catalog.json Co-authored-by: prateek <sharma_prateek@outlook.com> * Skipping kms test * resolve review comments * resolve review comments * Update ibm_catalog.json Co-authored-by: prateek <sharma_prateek@outlook.com> * resolve review comment * enabled encryption * Update solutions/fully-configurable/variables.tf Co-authored-by: Shikha Maheshwari <maheshwari.shikha@gmail.com> * Update ibm_catalog.json Co-authored-by: Shikha Maheshwari <maheshwari.shikha@gmail.com> * Update ibm_catalog.json Co-authored-by: Shikha Maheshwari <maheshwari.shikha@gmail.com> * Update ibm_catalog.json Co-authored-by: Shikha Maheshwari <maheshwari.shikha@gmail.com> * Update ibm_catalog.json Co-authored-by: Shikha Maheshwari <maheshwari.shikha@gmail.com> * Update ibm_catalog.json Co-authored-by: Shikha Maheshwari <maheshwari.shikha@gmail.com> * minor fix --------- Co-authored-by: Khuzaima-Shakeel <Khuzaima.Shakeel@ibm.com> Co-authored-by: prateek <sharma_prateek@outlook.com> Co-authored-by: Shikha Maheshwari <maheshwari.shikha@gmail.com>
1 parent 3484171 commit 0067fb4

File tree

14 files changed

+145
-145
lines changed

14 files changed

+145
-145
lines changed

ibm_catalog.json

Lines changed: 78 additions & 77 deletions
Large diffs are not rendered by default.

reference-architecture/deployable-architecture-watsonx-ai.svg

Lines changed: 4 additions & 0 deletions
Loading

reference-architecture/watsonx-ai-da.svg

Lines changed: 0 additions & 4 deletions
This file was deleted.

solutions/fully-configurable/DA-watsonx_ai_new_project_members.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@ The `watsonx_ai_new_project_members` input variable allows you to specify additi
1414

1515
### Example New Project Members Variable
1616
This is an example of adding two new members, one as an admin and one as a viewer to the project:
17+
1718
```json
18-
"members": [
19-
{
20-
"email": "example@ibm.com",
21-
"iam_id": "IBMid-1111111111",
22-
"role": "admin"
23-
},
24-
{
25-
"email": "IBMid-1111111110",
26-
"iam_id": "IBMid-1111111110",
27-
"role": "viewer",
28-
"state": "ACTIVE",
29-
"type": "service"
30-
}
19+
[
20+
{
21+
"email": "example@ibm.com",
22+
"iam_id": "IBMid-1111111111",
23+
"role": "admin"
24+
},
25+
{
26+
"email": "IBMid-1111111110",
27+
"iam_id": "IBMid-1111111110",
28+
"role": "viewer",
29+
"state": "ACTIVE",
30+
"type": "service"
31+
}
3132
]
3233
```
Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
# IBM watsonx.ai deployable architecture
2-
3-
This deployable architecture supports provisioning the following resources:
4-
5-
- A new resource group if one is not passed in.
6-
- A watsonx.ai Studio instance.
7-
- A watsonx.ai Runtime instance.
8-
- A Cloud Object Storage instance.
9-
- A new key-ring and key in the KMS(Key Protect) instance, if an existing key is not provided.
10-
- Configure the watsonx profile for IBM Cloud user.
11-
- Create a KMS encryption enabled IBM watsonx.ai project.
12-
13-
![watsonx-ai-deployable-architecture](../../reference-architecture/watsonx-ai-da.svg)
1+
# Cloud automation for watsonx.ai (Fully configurable)
142

153
:exclamation: **Important:** This solution is not intended to be called by other modules because it contains a provider configuration and is not compatible with the `for_each`, `count`, and `depends_on` arguments. For more information, see [Providers Within Modules](https://developer.hashicorp.com/terraform/language/modules/develop/providers).

solutions/fully-configurable/main.tf

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ module "existing_kms_crn_parser" {
2727

2828
locals {
2929
# fetch KMS region from existing_kms_instance_crn if KMS resources are required and existing_cos_kms_key_crn is not provided
30-
kms_region = var.existing_cos_kms_key_crn == null && var.existing_kms_instance_crn != null ? module.existing_kms_crn_parser[0].region : null
31-
kms_key_ring_name = var.cos_key_ring_name != null ? "${local.prefix}${var.cos_key_ring_name}" : null
32-
kms_key_name = var.cos_key_name != null ? "${local.prefix}${var.cos_key_name}" : null
30+
kms_enabled_cos = var.enable_cos_kms_encryption && var.existing_kms_instance_crn != null
31+
kms_region = local.kms_enabled_cos ? module.existing_kms_instance_crn_parser[0].region : null
32+
kms_key_ring_name = "${local.prefix}${var.cos_key_ring_name}"
33+
kms_key_name = "${local.prefix}${var.cos_key_name}"
34+
create_kms_key = local.kms_enabled_cos && var.existing_cos_kms_key_crn == null
3335
}
3436

3537
module "kms" {
36-
count = (var.enable_cos_kms_encryption && var.existing_cos_kms_key_crn == null && var.existing_kms_instance_crn != null) ? 1 : 0 # no need to create any KMS resources if passing an existing key
38+
count = local.create_kms_key ? 1 : 0
3739
source = "terraform-ibm-modules/kms-all-inclusive/ibm"
38-
version = "5.1.11"
40+
version = "5.1.19"
3941
create_key_protect_instance = false
4042
region = local.kms_region
4143
existing_kms_instance_crn = var.existing_kms_instance_crn
@@ -66,10 +68,9 @@ module "kms" {
6668
########################################################################################################################
6769

6870
locals {
69-
cos_instance_crn = var.existing_cos_instance_crn
7071
cos_kms_key_crn = var.enable_cos_kms_encryption ? (var.existing_cos_kms_key_crn != null ? var.existing_cos_kms_key_crn : module.kms[0].keys[format("%s.%s", local.kms_key_ring_name, local.kms_key_name)].crn) : null
71-
cos_instance_guid = local.cos_instance_crn != null ? module.existing_cos_crn_parser[0].service_instance : null
72-
cos_account_id = local.cos_instance_crn != null ? module.existing_cos_crn_parser[0].account_id : null
72+
cos_instance_guid = var.existing_cos_instance_crn != null ? module.existing_cos_crn_parser[0].service_instance : null
73+
cos_account_id = var.existing_cos_instance_crn != null ? module.existing_cos_crn_parser[0].account_id : null
7374
kms_guid = var.enable_cos_kms_encryption ? (length(module.existing_kms_key_crn_parser) > 0 ? module.existing_kms_key_crn_parser[0].service_instance : module.existing_kms_instance_crn_parser[0].service_instance) : null
7475
kms_account_id = var.enable_cos_kms_encryption ? (length(module.existing_kms_key_crn_parser) > 0 ? module.existing_kms_key_crn_parser[0].account_id : module.existing_kms_instance_crn_parser[0].account_id) : null
7576
kms_service_name = var.enable_cos_kms_encryption ? (length(module.existing_kms_key_crn_parser) > 0 ? module.existing_kms_key_crn_parser[0].service_name : module.existing_kms_instance_crn_parser[0].service_name) : null
@@ -105,7 +106,7 @@ module "watsonx_ai" {
105106
project_tags = var.project_tags
106107
mark_as_sensitive = var.mark_project_as_sensitive
107108
enable_cos_kms_encryption = var.enable_cos_kms_encryption
108-
cos_instance_crn = local.cos_instance_crn
109+
cos_instance_crn = var.existing_cos_instance_crn
109110
cos_kms_key_crn = local.cos_kms_key_crn
110111
skip_iam_authorization_policy = local.create_cross_account_cos_kms_auth_policy || !local.create_cos_kms_iam_auth_policy
111112
}
@@ -174,7 +175,7 @@ module "existing_kms_key_crn_parser" {
174175
}
175176

176177
module "existing_kms_instance_crn_parser" {
177-
count = var.enable_cos_kms_encryption && var.existing_kms_instance_crn != null && var.existing_kms_instance_crn != "" ? 1 : 0
178+
count = local.kms_enabled_cos && var.existing_kms_instance_crn != "" ? 1 : 0
178179
source = "terraform-ibm-modules/common-utilities/ibm//modules/crn-parser"
179180
version = "1.2.0"
180181
crn = var.existing_kms_instance_crn

solutions/fully-configurable/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,8 @@ output "watsonx_ai_project_url" {
7474
value = module.watsonx_ai.watsonx_ai_project_url
7575
description = "The URL of the watsonx.ai project that is created."
7676
}
77+
78+
output "cos_kms_key_crn" {
79+
description = "The CRN of the key management service (Key Protect) key used to encrypt the Cloud Object Storage bucket that the solution creates."
80+
value = local.cos_kms_key_crn
81+
}

solutions/fully-configurable/variables.tf

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,34 @@ variable "existing_resource_group_name" {
2727

2828
variable "prefix" {
2929
type = string
30-
nullable = true
31-
description = "The prefix to be added to all resources created by this solution. To skip using a prefix, set this value to null or an empty string. The prefix must begin with a lowercase letter and may contain only lowercase letters, digits and hyphens ('-'). It should not exceed 16 characters, must not end with a hyphen ('-'), and can not contain consecutive hyphens ('--'). Example: wx-54-ai. [Learn more](https://terraform-ibm-modules.github.io/documentation/#/prefix.md)"
30+
description = "The prefix to be added to all resources created by this solution. To skip using a prefix, set this value to null or an empty string. The prefix must begin with a lowercase letter and may contain only lowercase letters, digits, and hyphens '-'. It should not exceed 16 characters, must not end with a hyphen('-'), and can not contain consecutive hyphens ('--'). Example: wx-0205-ai. [Learn more](https://terraform-ibm-modules.github.io/documentation/#/prefix.md)."
3231

3332
validation {
34-
condition = var.prefix == null || var.prefix == "" ? true : alltrue([
35-
can(regex("^[a-z][-a-z0-9]*[a-z0-9]$", var.prefix)), length(regexall("--", var.prefix)) == 0
36-
])
37-
error_message = "Prefix must begin with a lowercase letter and may contain only lowercase letters, digits, and hyphens ('-'). It must not end with a hyphen ('-'), and cannot contain consecutive hyphens ('--')."
33+
# - null and empty string is allowed
34+
# - Must not contain consecutive hyphens (--): length(regexall("--", var.prefix)) == 0
35+
# - Starts with a lowercase letter: [a-z]
36+
# - Contains only lowercase letters (a–z), digits (0–9), and hyphens (-)
37+
# - Must not end with a hyphen (-): [a-z0-9]
38+
condition = (var.prefix == null || var.prefix == "" ? true :
39+
alltrue([
40+
can(regex("^[a-z][-a-z0-9]*[a-z0-9]$", var.prefix)),
41+
length(regexall("--", var.prefix)) == 0
42+
])
43+
)
44+
error_message = "Prefix must begin with a lowercase letter and may contain only lowercase letters, digits, and hyphens '-'. It must not end with a hyphen('-'), and cannot contain consecutive hyphens ('--')."
3845
}
39-
4046
validation {
47+
# must not exceed 16 characters in length
4148
condition = var.prefix == null || var.prefix == "" ? true : length(var.prefix) <= 16
4249
error_message = "Prefix must not exceed 16 characters."
4350
}
4451
}
4552

53+
4654
variable "region" {
47-
default = "us-south"
48-
description = "Region where the watsonx.ai resources will be provisioned."
55+
description = "The region to provision all resources in. [Learn more](https://terraform-ibm-modules.github.io/documentation/#/region) about how to select different regions for different services."
4956
type = string
50-
51-
validation {
52-
condition = contains(["eu-de", "us-south", "eu-gb", "jp-tok"], var.region)
53-
error_message = "You must specify `eu-de`, `eu-gb`, `jp-tok` or `us-south` as the IBM Cloud region."
54-
}
57+
default = "us-south"
5558

5659
validation {
5760
condition = (var.enable_cos_kms_encryption && var.existing_cos_kms_key_crn == null) ? local.kms_region == var.region : true
@@ -60,8 +63,8 @@ variable "region" {
6063
}
6164

6265
variable "resource_tags" {
63-
description = "Optional list of tags to describe the watsonx_ai runtime and studio instances created by the module."
6466
type = list(string)
67+
description = "Optional list of tags to describe the newly created watsonx.ai instance."
6568
default = []
6669
}
6770

@@ -130,7 +133,7 @@ variable "watsonx_ai_runtime_service_endpoints" {
130133
}
131134

132135
variable "watsonx_ai_new_project_members" {
133-
description = "The list of new members the owner of the Watsonx.ai project would like to add to the project. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-watsonx-ai/tree/main/solutions/standard/DA-watsonx_ai_new_project_members.md)"
136+
description = "The list of new members the owner of the watsonx.ai project would like to add to the project. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-watsonx-ai/tree/main/solutions/standard/DA-watsonx_ai_new_project_members.md)"
134137
type = list(object({
135138
email = string
136139
iam_id = string
@@ -199,8 +202,8 @@ variable "kms_endpoint_type" {
199202
description = "The type of endpoint to use for communicating with the Key Protect instance. Possible values: `public`, `private`. Applies only if `existing_cos_kms_key_crn` is not specified."
200203
default = "private"
201204
validation {
202-
condition = can(regex("public|private", var.kms_endpoint_type))
203-
error_message = "Valid values for the `kms_endpoint_type_value` are `public` or `private`."
205+
condition = var.existing_cos_kms_key_crn != null || can(regex("^(public|private)$", var.kms_endpoint_type))
206+
error_message = "Valid values for `kms_endpoint_type` are `public` or `private`. Applies only if `existing_cos_kms_key_crn` is not specified."
204207
}
205208
}
206209

tests/pr_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func setupOptions(t *testing.T, prefix string, dir string) *testhelper.TestOptio
8484

8585
// Provision KMS - Key Protect to use in DA tests
8686
func setupKMSKeyProtect(t *testing.T, region string, prefix string) *terraform.Options {
87-
realTerraformDir := "./resources/kp-instance"
87+
realTerraformDir := "./resources/kp-cos-instance"
8888
tempTerraformDir, _ := files.CopyTerraformFolderToTemp(realTerraformDir, fmt.Sprintf(prefix+"-%s", strings.ToLower(random.UniqueId())))
8989

9090
checkVariable := "TF_VAR_ibmcloud_api_key"
@@ -136,7 +136,6 @@ func TestRunBasicExample(t *testing.T) {
136136

137137
func TestRunCompleteExample(t *testing.T) {
138138
t.Parallel()
139-
140139
options := setupOptions(t, "wxai-complete", completeExampleDir)
141140

142141
output, err := options.RunTestConsistency()
@@ -149,8 +148,8 @@ func TestRunStandardSolution(t *testing.T) {
149148
t.Parallel()
150149

151150
var region = validRegions[rand.Intn(len(validRegions))]
152-
prefixKMSKey := fmt.Sprintf("wxai-da-%s", strings.ToLower(random.UniqueId()))
153-
existingTerraformOptions := setupKMSKeyProtect(t, region, prefixKMSKey)
151+
prefixExistingRes := fmt.Sprintf("wxai-da-%s", strings.ToLower(random.UniqueId()))
152+
existingTerraformOptions := setupKMSKeyProtect(t, region, prefixExistingRes)
154153

155154
// Deploy watsonx.ai DA using existing KP details
156155
options := testhelper.TestOptionsDefault(&testhelper.TestOptions{
@@ -181,21 +180,22 @@ func TestRunStandardSolution(t *testing.T) {
181180
"existing_kms_instance_crn": terraform.Output(t, existingTerraformOptions, "key_protect_crn"),
182181
"kms_endpoint_type": "public",
183182
"existing_cos_instance_crn": terraform.Output(t, existingTerraformOptions, "cos_crn"),
183+
"enable_cos_kms_encryption": true,
184184
}
185185

186186
output, err := options.RunTestConsistency()
187187
assert.Nil(t, err, "This should not have errored")
188188
assert.NotNil(t, output, "Expected some output")
189189

190-
cleanupResources(t, existingTerraformOptions, prefixKMSKey)
190+
cleanupResources(t, existingTerraformOptions, prefixExistingRes)
191191
}
192192

193193
func TestRunStandardUpgradeSolution(t *testing.T) {
194194
t.Parallel()
195195

196196
var region = validRegions[rand.Intn(len(validRegions))]
197-
prefixKMSKey := fmt.Sprintf("wxai-da-%s", strings.ToLower(random.UniqueId()))
198-
existingTerraformOptions := setupKMSKeyProtect(t, region, prefixKMSKey)
197+
prefixExistingRes := fmt.Sprintf("wxai-da-%s", strings.ToLower(random.UniqueId()))
198+
existingTerraformOptions := setupKMSKeyProtect(t, region, prefixExistingRes)
199199

200200
// Deploy watsonx.ai DA using existing KP details
201201
options := testhelper.TestOptionsDefault(&testhelper.TestOptions{
@@ -226,6 +226,7 @@ func TestRunStandardUpgradeSolution(t *testing.T) {
226226
"existing_kms_instance_crn": terraform.Output(t, existingTerraformOptions, "key_protect_crn"),
227227
"kms_endpoint_type": "public",
228228
"existing_cos_instance_crn": terraform.Output(t, existingTerraformOptions, "cos_crn"),
229+
"enable_cos_kms_encryption": true,
229230
}
230231

231232
output, err := options.RunTestUpgrade()
@@ -234,5 +235,5 @@ func TestRunStandardUpgradeSolution(t *testing.T) {
234235
assert.NotNil(t, output, "Expected some output")
235236
}
236237

237-
cleanupResources(t, existingTerraformOptions, prefixKMSKey)
238+
cleanupResources(t, existingTerraformOptions, prefixExistingRes)
238239
}

tests/resources/kp-instance/main.tf renamed to tests/resources/kp-cos-instance/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
module "resource_group" {
22
source = "terraform-ibm-modules/resource-group/ibm"
3-
version = "1.2.1"
3+
version = "1.3.0"
44
resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null
55
existing_resource_group_name = var.resource_group
66
}
77

88
module "kms" {
99
source = "terraform-ibm-modules/kms-all-inclusive/ibm"
10-
version = "5.1.11"
10+
version = "5.1.19"
1111
create_key_protect_instance = true
1212
key_protect_instance_name = "${var.prefix}-kp"
1313
resource_group_id = module.resource_group.resource_group_id

0 commit comments

Comments
 (0)