Skip to content

Commit 287bf72

Browse files
nupurg-ibmNupur Goyal
andauthored
Custom image support for HPC solution (#187)
* Custom image support for HPC solution --------- Co-authored-by: Nupur Goyal <nupurgoyal@Nupurs-MacBook-Pro.local>
1 parent 6b758eb commit 287bf72

17 files changed

+1281
-141
lines changed

tools/image-builder/compute-rhel.sh

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

tools/image-builder/datasource.tf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
data "ibm_is_vpc" "existing_vpc" {
2+
count = var.vpc_name != null ? 1 : 0
3+
name = var.vpc_name
4+
}
5+
6+
data "ibm_is_vpc" "vpc" {
7+
name = local.vpc_name
8+
# Depends on creation of new VPC or look up of existing VPC based on value of var.vpc_name,
9+
depends_on = [module.landing_zone, data.ibm_is_vpc.existing_vpc]
10+
}
11+
12+
data "ibm_is_subnet" "existing_subnet" {
13+
count = (var.vpc_name != null && var.subnet_id != null) ? 1 : 0
14+
identifier = var.subnet_id
15+
}
16+
17+
data "ibm_resource_instance" "kms_instance" {
18+
count = (var.key_management == "key_protect" && var.kms_instance_name != null) ? 1 : 0
19+
name = var.kms_instance_name
20+
service = "kms"
21+
}
22+
23+
data "ibm_kms_key" "kms_key" {
24+
count = (var.key_management == "key_protect" && var.kms_key_name != null) ? 1 : 0
25+
instance_id = data.ibm_resource_instance.kms_instance[0].id
26+
key_name = var.kms_key_name
27+
}
28+
29+
data "ibm_is_image" "packer" {
30+
name = "ibm-redhat-8-8-minimal-amd64-6"
31+
}
32+
33+
data "ibm_is_ssh_key" "packer" {
34+
for_each = toset(var.ssh_keys)
35+
name = each.key
36+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
###################################################
2+
# Copyright (C) IBM Corp. 2023 All Rights Reserved.
3+
# Licensed under the Apache License v2.0
4+
###################################################
5+
6+
# This file contains the complete information on all the validations performed from the code during the generate plan process
7+
# Validations are performed to make sure, the appropriate error messages are displayed to user in-order to provide required input parameter
8+
9+
locals {
10+
# validation for the boot volume encryption toggling.
11+
validate_enable_customer_managed_encryption = anytrue([alltrue([var.kms_key_name != null, var.kms_instance_name != null]), (var.kms_key_name == null), (var.key_management != "key_protect")])
12+
validate_enable_customer_managed_encryption_msg = "Please make sure you are passing the kms_instance_name if you are passing kms_key_name."
13+
# tflint-ignore: terraform_unused_declarations
14+
validate_enable_customer_managed_encryption_chk = regex(
15+
"^${local.validate_enable_customer_managed_encryption_msg}$",
16+
(local.validate_enable_customer_managed_encryption ? local.validate_enable_customer_managed_encryption_msg : ""))
17+
18+
# validation for the boot volume encryption toggling.
19+
validate_null_customer_managed_encryption = anytrue([alltrue([var.kms_instance_name == null, var.key_management != "key_protect"]), (var.key_management == "key_protect")])
20+
validate_null_customer_managed_encryption_msg = "Please make sure you are setting key_management as key_protect if you are passing kms_instance_name, kms_key_name."
21+
# tflint-ignore: terraform_unused_declarations
22+
validate_null_customer_managed_encryption_chk = regex(
23+
"^${local.validate_null_customer_managed_encryption_msg}$",
24+
(local.validate_null_customer_managed_encryption ? local.validate_null_customer_managed_encryption_msg : ""))
25+
26+
# Validate existing packer subnet should be the subset of vpc_name entered
27+
validate_subnet_id_vpc_msg = "Provided packer subnet should be within the vpc entered."
28+
validate_subnet_id_vpc = anytrue([var.subnet_id == null, var.subnet_id != null && var.vpc_name != null ? alltrue([for subnet_id in [var.subnet_id] : contains(data.ibm_is_vpc.existing_vpc[0].subnets[*].id, subnet_id)]) : false])
29+
# tflint-ignore: terraform_unused_declarations
30+
validate_subnet_id_vpc_chk = regex("^${local.validate_subnet_id_vpc_msg}$",
31+
(local.validate_subnet_id_vpc ? local.validate_subnet_id_vpc_msg : ""))
32+
33+
# Validate existing packer subnet should be in the appropriate zone.
34+
validate_subnet_id_zone_msg = "Provided packer subnet should be in appropriate zone."
35+
validate_subnet_id_zone = anytrue([var.subnet_id == null, var.subnet_id != null && var.vpc_name != null ? alltrue([data.ibm_is_subnet.existing_subnet[0].zone == var.zones[0]]) : false])
36+
# tflint-ignore: terraform_unused_declarations
37+
validate_subnet_id_zone_chk = regex("^${local.validate_subnet_id_zone_msg}$",
38+
(local.validate_subnet_id_zone ? local.validate_subnet_id_zone_msg : ""))
39+
40+
# Validate existing packer subnet public gateways
41+
validate_subnet_name_pg_msg = "Provided existing packer subnet should have public gateway attached."
42+
validate_subnet_name_pg = anytrue([var.subnet_id == null, var.subnet_id != null && var.vpc_name != null ? (data.ibm_is_subnet.existing_subnet[0].public_gateway != "") : false])
43+
# tflint-ignore: terraform_unused_declarations
44+
validate_subnet_name_pg_chk = regex("^${local.validate_subnet_name_pg_msg}$",
45+
(local.validate_subnet_name_pg ? local.validate_subnet_name_pg_msg : ""))
46+
47+
# Validate existing vpc public gateways
48+
validate_existing_vpc_pgw_msg = "Provided existing vpc should have the public gateways created in the provided zones."
49+
validate_existing_vpc_pgw = anytrue([(var.vpc_name == null), alltrue([var.vpc_name != null, var.subnet_id != null]), alltrue([var.vpc_name != null, var.subnet_id == null, length(local.zone_1_pgw_ids) > 0])])
50+
# tflint-ignore: terraform_unused_declarations
51+
validate_existing_vpc_pgw_chk = regex("^${local.validate_existing_vpc_pgw_msg}$",
52+
(local.validate_existing_vpc_pgw ? local.validate_existing_vpc_pgw_msg : ""))
53+
54+
# Validate the subnet_id user input value
55+
validate_subnet_id_msg = "If the packer subnet_id is provided, the user should also provide the vpc_name."
56+
validate_subnet_id = anytrue([var.vpc_name != null && var.subnet_id != null, var.subnet_id == null])
57+
# tflint-ignore: terraform_unused_declarations
58+
validate_subnet_id_chk = regex("^${local.validate_subnet_id_msg}$",
59+
(local.validate_subnet_id ? local.validate_subnet_id_msg : ""))
60+
61+
# Validate security_group_id user input value
62+
validate_security_group_id_msg = "If existing security_group_id is provided, the user should also specify vpc_name that has that security group ID."
63+
validate_security_group_id = anytrue([var.vpc_name != null && var.security_group_id != "", var.security_group_id == ""])
64+
# tflint-ignore: terraform_unused_declarations
65+
validate_security_group_id_chk = regex("^${local.validate_security_group_id_msg}$",
66+
(local.validate_security_group_id ? local.validate_security_group_id_msg : ""))
67+
68+
}

0 commit comments

Comments
 (0)