Skip to content

Commit 92893c0

Browse files
authored
feat: refactored the VSI extension pattern in preperation for catalog release (#643)
1 parent 0f52f08 commit 92893c0

File tree

5 files changed

+41
-108
lines changed

5 files changed

+41
-108
lines changed

patterns/vsi-extension/README.md

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,11 @@
11
# Add a VSI to a landing zone VPC
22

3-
This logic creates a VSI to an existing landing zone VPC.
3+
This architecture creates virtual server instances (VSI) for VPC in some or all of the subnets of any existing landing zone VPC deployable architecture.
44

5-
This code creates and configures the following infrastructure:
6-
- Adds an SSH key to IBM Cloud or uses an existing one.
7-
- Adds a VSI in each subnet of the landing zone VPC.
5+
## Before you begin
86

9-
There are two ways through which a user can pass the VPC details for deploying the VSI, both the approaches are mutually exclusive.
7+
- You must have either the [VPC landing zone](https://cloud.ibm.com/catalog/architecture/deploy-arch-ibm-slz-vpc-9fc0fa64-27af-4fed-9dce-47b3640ba739-global) or [Red Hat OpenShift Container Platform on VPC landing zone](https://cloud.ibm.com/catalog/architecture/deploy-arch-ibm-slz-ocp-95fccffc-ae3b-42df-b6d9-80be5914d852-global) deployable architecture deployed.
8+
- The block storage to KMS auth policy must exist. This policy would have been created by one of the above deployable architectures if the `add_kms_block_storage_s2s` variable was set to `true`, which is default value.
9+
- You need the VPC ID, subnet names, and boot volume encryption key from your existing landing zone VPC deployable architecture. For information about finding these values, see [Adding a VSI to your VPC landing zone deployable architecture](https://cloud.ibm.com/docs/secure-infrastructure-vpc?topic=secure-infrastructure-vpc-ext-with-vsi).
1010

11-
## Using `vpc_id`
12-
13-
The VPC ID of the landing zone VPC can be assigned to the variable vpc_id in order to create a VSI within that specific VPC.
14-
15-
## Using `prerequisite_workspace_id` and `existing_vpc_name`
16-
17-
The user can specify the workspace ID associated with the deployment of the landing zone VPC when creating a new VSI.
18-
19-
Follow these steps to get the schematics workspace ID.
20-
21-
1. Click the Navigation menu icon, and then click Schematics > Workspaces.
22-
1. Select the Workspace that is associated with landing zone VPC.
23-
1. Click the Settings.
24-
1. In the Details section, you can find the Workspace ID.
25-
26-
Pass the Workspace ID to the `prerequisite_workspace_id` variable and pass the name of the VPC to the `existing_vpc_name` to choosse the name of the VPC to which the user wants to deploy the VSI.
27-
Please provide the Workspace ID for the prerequisite workspace and the name of the existing VPC to the `prerequisite_workspace_id` and `existing_vpc_name` variables respectively, to identify the VPC where you want to deploy the VSI.
11+
![Architecture diagram for adding a VSI to your VPC landing zone deployable architecture](https://raw.githubusercontent.com/terraform-ibm-modules/terraform-ibm-landing-zone/main/reference-architectures/vsi-extension.drawio.svg)

patterns/vsi-extension/main.tf

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,3 @@
1-
##############################################################################
2-
# Schematics Data
3-
##############################################################################
4-
5-
locals {
6-
# tflint-ignore: terraform_unused_declarations
7-
validate_vpc_vars = var.prerequisite_workspace_id == null && var.vpc_id == null ? tobool("var.prerequisite_workspace_id and var.vpc_id cannot be both set to null.") : true
8-
# tflint-ignore: terraform_unused_declarations
9-
validate_vpc_names = var.prerequisite_workspace_id != null && var.existing_vpc_name == null ? tobool("A value must be passed for var.existing_vpc_name to choose a VPC from the list of VPCs from the schematics workspace.") : true
10-
11-
location = var.prerequisite_workspace_id != null ? regex("^[a-z/-]+", var.prerequisite_workspace_id) : null
12-
fullstack_output = length(data.ibm_schematics_output.schematics_output) > 0 ? jsondecode(data.ibm_schematics_output.schematics_output[0].output_json) : null
13-
vpc_id = var.prerequisite_workspace_id != null ? [
14-
for vpc in local.fullstack_output[0].vpc_data.value :
15-
vpc.vpc_data.id if vpc.vpc_data.name == var.existing_vpc_name
16-
][0] : var.vpc_id
17-
}
18-
19-
data "ibm_schematics_workspace" "schematics_workspace" {
20-
count = var.prerequisite_workspace_id != null ? 1 : 0
21-
workspace_id = var.prerequisite_workspace_id
22-
location = local.location
23-
}
24-
25-
data "ibm_schematics_output" "schematics_output" {
26-
count = var.prerequisite_workspace_id != null ? 1 : 0
27-
workspace_id = var.prerequisite_workspace_id
28-
location = local.location
29-
template_id = data.ibm_schematics_workspace.schematics_workspace[0].runtime_data[0].id
30-
}
31-
321
##############################################################################
332
# Locals
343
##############################################################################
@@ -54,7 +23,7 @@ data "ibm_is_ssh_key" "ssh_key" {
5423
}
5524

5625
data "ibm_is_vpc" "vpc_by_id" {
57-
identifier = local.vpc_id
26+
identifier = var.vpc_id
5827
}
5928

6029
data "ibm_is_image" "image" {
@@ -74,19 +43,18 @@ module "vsi" {
7443
resource_group_id = data.ibm_is_vpc.vpc_by_id.resource_group
7544
create_security_group = true
7645
prefix = "${var.prefix}-vsi"
77-
vpc_id = local.vpc_id
46+
vpc_id = var.vpc_id
7847
subnets = var.subnet_names != null ? local.subnets : data.ibm_is_vpc.vpc_by_id.subnets
7948
tags = var.resource_tags
8049
access_tags = var.access_tags
8150
kms_encryption_enabled = true
82-
skip_iam_authorization_policy = var.skip_iam_authorization_policy
51+
skip_iam_authorization_policy = true
8352
user_data = var.user_data
8453
image_id = data.ibm_is_image.image.id
8554
boot_volume_encryption_key = var.boot_volume_encryption_key
86-
existing_kms_instance_guid = var.existing_kms_instance_guid
8755
security_group_ids = var.security_group_ids
8856
ssh_key_ids = [local.ssh_key_id]
89-
machine_type = var.machine_type
57+
machine_type = var.vsi_instance_profile
9058
vsi_per_subnet = var.vsi_per_subnet
9159
security_group = local.env.security_groups[0]
9260
load_balancers = var.load_balancers

patterns/vsi-extension/variables.tf

Lines changed: 25 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
variable "ibmcloud_api_key" {
2-
description = "The API key that's associated with the account to provision resources to"
2+
description = "The API key that's associated with the account to provision resources to."
33
type = string
44
sensitive = true
55
}
@@ -16,20 +16,19 @@ variable "prefix" {
1616
}
1717

1818
variable "vpc_id" {
19-
description = "The ID of the VPC where the VSI will be created."
19+
description = "The ID of the VPC where you want to deploy the VSI. [Learn more](https://cloud.ibm.com/docs/secure-infrastructure-vpc?topic=secure-infrastructure-vpc-ext-with-vsi)."
2020
type = string
21-
default = null
2221
}
2322

2423
variable "existing_ssh_key_name" {
25-
description = "The ID of the VPC where the VSI will be created."
24+
description = "The name of a public SSH key in the region where you want to deploy the VSI. [Learn more](https://cloud.ibm.com/docs/vpc?topic=vpc-ssh-keys). To create an SSH key, use the 'ssh_public_key' input instead."
2625
type = string
2726
default = null
2827
}
2928

3029

3130
variable "ssh_public_key" {
32-
description = "SSH keys to use to provision a VSI. Must be an RSA key with a key size of either 2048 bits or 4096 bits (recommended). If `public_key` is not provided, the named key will be looked up from data. See https://cloud.ibm.com/docs/vpc?topic=vpc-ssh-keys."
31+
description = "A public SSH key that does not exist in the region where you want to deploy the VSI. The key must be an RSA key with a key size of either 2048 bits or 4096 bits (recommended). [Learn more](https://cloud.ibm.com/docs/vpc?topic=vpc-ssh-keys). To use an existing key, specify a value in the `existing_ssh_key_name` input instead."
3332
type = string
3433

3534
validation {
@@ -39,75 +38,65 @@ variable "ssh_public_key" {
3938
}
4039

4140
variable "resource_tags" {
42-
description = "A list of tags to add to the VSI, block storage, security group, floating IP, and load balancer created by the module."
41+
description = "A list of resource tags to apply to resources created by this solution."
4342
type = list(string)
4443
default = []
4544
}
4645

4746
variable "access_tags" {
4847
type = list(string)
49-
description = "A list of access tags to apply to the VSI resources created by the module."
48+
description = "A list of access tags to apply to the VSI resources created by this solution."
5049
default = []
5150
}
5251

5352
variable "image_name" {
54-
description = "Image ID used for the VSI. Run the 'ibmcloud is images' CLI command to find available images. The IDs are different in each region."
53+
description = "The image ID used for the VSI. You can run the `ibmcloud is images` CLI command to find available images. The IDs are different in each region."
5554
type = string
56-
default = "ibm-ubuntu-22-04-2-minimal-amd64-1"
55+
default = "ibm-ubuntu-22-04-3-minimal-amd64-1"
5756
}
5857

59-
variable "machine_type" {
60-
description = "VSI machine type"
58+
variable "vsi_instance_profile" {
59+
description = "The VSI image profile. You can run the `ibmcloud is instance-profiles` CLI command to see available image profiles."
6160
type = string
62-
default = "cx2-2x4"
61+
default = "cx2-4x8"
6362
}
6463

6564
variable "user_data" {
66-
description = "User data to initialize VSI deployment."
65+
description = "The user data to transfer to the instance. [Learn more](https://cloud.ibm.com/docs/vpc?topic=vpc-user-data)."
6766
type = string
6867
default = null
6968
}
7069

7170
variable "boot_volume_encryption_key" {
72-
description = "The CRN of the boot volume encryption key."
71+
description = "The CRN of the boot volume encryption key. [Learn more](https://cloud.ibm.com/docs/secure-infrastructure-vpc?topic=secure-infrastructure-vpc-ext-with-vsi)."
7372
type = string
7473
}
7574

76-
variable "existing_kms_instance_guid" {
77-
description = "The GUID of the KMS instance that holds the key specified in `var.boot_volume_encryption_key`."
78-
type = string
79-
}
80-
81-
variable "skip_iam_authorization_policy" {
82-
type = bool
83-
description = "By default (true), the Landing Zone VPC creates an IAM authorization policy that permits all storage blocks to read the encryption key from the KMS instance. Set to false to create the authorization policy in a different KMS instance, and specify the GUID of the KMS instance in the existing_kms_instance_guid variable."
84-
default = true
85-
}
86-
8775
variable "vsi_per_subnet" {
88-
description = "The number of VSI instances for each subnet."
76+
description = "The number of virtual servers to create on each VSI subnet."
8977
type = number
9078
default = 1
9179
}
9280

9381
variable "subnet_names" {
94-
description = "The subnets to deploy the VSI instances to."
82+
description = "A list of subnet names where you want to deploy a VSI. If not specified, the VSI is deployed to all the subnets in the VPC. [Learn more](https://cloud.ibm.com/docs/secure-infrastructure-vpc?topic=secure-infrastructure-vpc-ext-with-vsi)."
9583
type = list(string)
96-
default = [
97-
"vpe-zone-1",
98-
"vpe-zone-2",
99-
"vpe-zone-3"
100-
]
84+
default = null
85+
86+
validation {
87+
error_message = "subnet_names cannot be an empty list."
88+
condition = var.subnet_names == null ? true : length(var.subnet_names) > 0 ? true : false
89+
}
10190
}
10291

10392
variable "security_group_ids" {
104-
description = "IDs of additional security groups to add to the VSI deployment primary interface. A VSI interface can have a maximum of 5 security groups."
93+
description = "The IDs of additional security groups to add to the VSI primary network interface (5 or fewer). [Learn more](https://cloud.ibm.com/docs/vpc?topic=vpc-using-security-groups)."
10594
type = list(string)
10695
default = []
10796
}
10897

10998
variable "block_storage_volumes" {
110-
description = "The list of block storage volumes to attach to each VSI."
99+
description = "The list of block storage volumes to attach to each VSI. [Learn more](https://cloud.ibm.com/docs/vpc?topic=vpc-creating-block-storage&interface=ui#create-from-vsi)."
111100
type = list(
112101
object({
113102
name = string
@@ -121,13 +110,13 @@ variable "block_storage_volumes" {
121110
}
122111

123112
variable "enable_floating_ip" {
124-
description = "Set to `true` to create a floating IP for each virtual server."
113+
description = "Whether to create a floating IP for each virtual server."
125114
type = bool
126115
default = false
127116
}
128117

129118
variable "placement_group_id" {
130-
description = "Unique Identifier of the Placement Group for restricting the placement of the instance, default behaviour is placement on any host"
119+
description = "Unique ID of the Placement Group for restricting the placement of the instance. If not specified (the default), the VSI are placed on any host. [Learn more](https://cloud.ibm.com/docs/vpc?topic=vpc-about-placement-groups-for-vpc)."
131120
type = string
132121
default = null
133122
}
@@ -183,15 +172,3 @@ variable "load_balancers" {
183172
)
184173
default = []
185174
}
186-
187-
variable "prerequisite_workspace_id" {
188-
type = string
189-
description = "IBM Cloud Schematics workspace ID of the prerequisite IBM VPC landing zone. If you do not have an existing deployment yet, create a new architecture using the same catalog tile."
190-
default = null
191-
}
192-
193-
variable "existing_vpc_name" {
194-
type = string
195-
description = "Name of the VPC to be used for deploying the VSI from the list of VPCs retrived from the IBM Cloud Schematics workspace."
196-
default = null
197-
}

reference-architectures/vsi-extension.drawio.svg

Lines changed: 4 additions & 0 deletions
Loading

tests/pr_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package test
33
import (
44
"encoding/json"
55
"fmt"
6-
tfjson "github.com/hashicorp/terraform-json"
76
"io/fs"
87
"log"
98
"os"
109
"path/filepath"
1110
"strings"
1211
"testing"
1312

13+
tfjson "github.com/hashicorp/terraform-json"
14+
1415
"github.com/gruntwork-io/terratest/modules/files"
1516
"github.com/gruntwork-io/terratest/modules/logger"
1617
"github.com/gruntwork-io/terratest/modules/random"
@@ -574,7 +575,6 @@ func TestRunVsiExtention(t *testing.T) {
574575
TerraformVars: map[string]interface{}{
575576
"prefix": prefix,
576577
"region": region,
577-
"existing_kms_instance_guid": terraform.Output(t, existingTerraformOptions, "key_management_guid"),
578578
"boot_volume_encryption_key": keyID,
579579
"vpc_id": managementVpcID,
580580
"ssh_public_key": sshPublicKey,

0 commit comments

Comments
 (0)