Skip to content

Commit dcedbd5

Browse files
authored
Fix catalog validation (#423)
1 parent 7ca91c2 commit dcedbd5

File tree

9 files changed

+115
-0
lines changed

9 files changed

+115
-0
lines changed

.catalog-onboard-pipeline.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ offerings:
99
- name: security-enforced
1010
mark_ready: true
1111
install_type: fullstack
12+
pre_validation: "tests/scripts/pre-validate.sh solutions/security-enforced"
13+
post_validation: "tests/scripts/post-validate.sh"
1214
scc:
1315
instance_id: 1c7d5f78-9262-44c3-b779-b28fe4d88c37
1416
region: us-south
1517
scope_resource_group_var_name: existing_resource_group_name
1618
- name: fully-configurable
1719
mark_ready: true
1820
install_type: fullstack
21+
pre_validation: "tests/scripts/pre-validate.sh solutions/fully-configurable"
22+
post_validation: "tests/scripts/post-validate.sh"
1923
scc:
2024
instance_id: 1c7d5f78-9262-44c3-b779-b28fe4d88c37
2125
region: us-south

tests/new-rg/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The terraform code in this directory is used for by catalog pipeline

tests/new-rg/main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
##############################################################################
2+
# Resource Group
3+
##############################################################################
4+
5+
module "resource_group" {
6+
source = "terraform-ibm-modules/resource-group/ibm"
7+
version = "1.3.0"
8+
# if an existing resource group is not set (null) create a new one using prefix
9+
resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null
10+
existing_resource_group_name = var.resource_group
11+
}

tests/new-rg/outputs.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
##############################################################################
2+
# Outputs
3+
##############################################################################
4+
5+
output "resource_group_id" {
6+
value = module.resource_group.resource_group_id
7+
description = "Resource group ID."
8+
}
9+
10+
output "resource_group_name" {
11+
value = module.resource_group.resource_group_name
12+
description = "Resource group name."
13+
}

tests/new-rg/provider.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
provider "ibm" {
2+
ibmcloud_api_key = var.ibmcloud_api_key
3+
}

tests/new-rg/variables.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
variable "ibmcloud_api_key" {
2+
type = string
3+
description = "The IBM Cloud API Key."
4+
sensitive = true
5+
}
6+
7+
variable "prefix" {
8+
type = string
9+
description = "Prefix to append to all resources created by this example."
10+
default = "sm"
11+
}
12+
13+
variable "resource_group" {
14+
type = string
15+
description = "The name of an existing resource group to provision resources in. If not specified, a new resource group is created with the `prefix` variable."
16+
default = null
17+
}

tests/new-rg/version.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
terraform {
2+
required_version = ">= 1.9.0"
3+
required_providers {
4+
ibm = {
5+
source = "ibm-cloud/ibm"
6+
version = ">= 1.79.0"
7+
}
8+
}
9+
}

tests/scripts/post-validate.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#! /bin/bash
2+
3+
########################################################################################################################
4+
## This script is used by the catalog pipeline to destroy prerequisite resource required for catalog validation ##
5+
########################################################################################################################
6+
7+
set -e
8+
9+
TERRAFORM_SOURCE_DIR="tests/new-rg"
10+
TF_VARS_FILE="terraform.tfvars"
11+
12+
(
13+
cd ${TERRAFORM_SOURCE_DIR}
14+
echo "Destroying resource group .."
15+
terraform destroy -input=false -auto-approve -var-file=${TF_VARS_FILE} || exit 1
16+
rm -f "${TF_VARS_FILE}"
17+
18+
echo "Post-validation completed successfully"
19+
)

tests/scripts/pre-validate.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#! /bin/bash
2+
3+
############################################################################################################
4+
## This script is used by the catalog pipeline to provision a new resource group
5+
## (required to ensure auth policies don't clash in account)
6+
############################################################################################################
7+
8+
set -e
9+
10+
DA_DIR="${1}"
11+
TERRAFORM_SOURCE_DIR="tests/new-rg"
12+
JSON_FILE="${DA_DIR}/catalogValidationValues.json"
13+
TF_VARS_FILE="terraform.tfvars"
14+
15+
(
16+
cwd=$(pwd)
17+
cd ${TERRAFORM_SOURCE_DIR}
18+
echo "Provisioning new resource group .."
19+
terraform init || exit 1
20+
# $VALIDATION_APIKEY is available in the catalog runtime
21+
{
22+
echo "ibmcloud_api_key=\"${VALIDATION_APIKEY}\""
23+
echo "prefix=\"ocp-$(openssl rand -hex 2)\""
24+
} >> ${TF_VARS_FILE}
25+
terraform apply -input=false -auto-approve -var-file=${TF_VARS_FILE} || exit 1
26+
27+
rg_var_name="existing_resource_group_name"
28+
rg_value=$(terraform output -state=terraform.tfstate -raw resource_group_name)
29+
30+
echo "Appending '${rg_var_name}', input variable value to ${JSON_FILE}.."
31+
32+
cd "${cwd}"
33+
jq -r --arg rg_var_name "${rg_var_name}" \
34+
--arg rg_value "${rg_value}" \
35+
'. + {($rg_var_name): $rg_value}' "${JSON_FILE}" > tmpfile && mv tmpfile "${JSON_FILE}" || exit 1
36+
37+
echo "Pre-validation complete successfully"
38+
)

0 commit comments

Comments
 (0)