Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .catalog-onboard-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ offerings:
- name: security-enforced
mark_ready: true
install_type: fullstack
pre_validation: "tests/scripts/pre-validate.sh solutions/security-enforced"
post_validation: "tests/scripts/post-validate.sh"
scc:
instance_id: 1c7d5f78-9262-44c3-b779-b28fe4d88c37
region: us-south
scope_resource_group_var_name: existing_resource_group_name
- name: fully-configurable
mark_ready: true
install_type: fullstack
pre_validation: "tests/scripts/pre-validate.sh solutions/fully-configurable"
post_validation: "tests/scripts/post-validate.sh"
scc:
instance_id: 1c7d5f78-9262-44c3-b779-b28fe4d88c37
region: us-south
Expand Down
1 change: 1 addition & 0 deletions tests/new-rg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The terraform code in this directory is used for by catalog pipeline
11 changes: 11 additions & 0 deletions tests/new-rg/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
##############################################################################
# Resource Group
##############################################################################

module "resource_group" {
source = "terraform-ibm-modules/resource-group/ibm"
version = "1.3.0"
# if an existing resource group is not set (null) create a new one using prefix
resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null
existing_resource_group_name = var.resource_group
}
13 changes: 13 additions & 0 deletions tests/new-rg/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
##############################################################################
# Outputs
##############################################################################

output "resource_group_id" {
value = module.resource_group.resource_group_id
description = "Resource group ID."
}

output "resource_group_name" {
value = module.resource_group.resource_group_name
description = "Resource group name."
}
3 changes: 3 additions & 0 deletions tests/new-rg/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "ibm" {
ibmcloud_api_key = var.ibmcloud_api_key
}
17 changes: 17 additions & 0 deletions tests/new-rg/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
variable "ibmcloud_api_key" {
type = string
description = "The IBM Cloud API Key."
sensitive = true
}

variable "prefix" {
type = string
description = "Prefix to append to all resources created by this example."
default = "sm"
}

variable "resource_group" {
type = string
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."
default = null
}
9 changes: 9 additions & 0 deletions tests/new-rg/version.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_version = ">= 1.9.0"
required_providers {
ibm = {
source = "ibm-cloud/ibm"
version = ">= 1.79.0"
}
}
}
19 changes: 19 additions & 0 deletions tests/scripts/post-validate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#! /bin/bash

########################################################################################################################
## This script is used by the catalog pipeline to destroy prerequisite resource required for catalog validation ##
########################################################################################################################

set -e

TERRAFORM_SOURCE_DIR="tests/new-rg"
TF_VARS_FILE="terraform.tfvars"

(
cd ${TERRAFORM_SOURCE_DIR}
echo "Destroying resource group .."
terraform destroy -input=false -auto-approve -var-file=${TF_VARS_FILE} || exit 1
rm -f "${TF_VARS_FILE}"

echo "Post-validation completed successfully"
)
38 changes: 38 additions & 0 deletions tests/scripts/pre-validate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#! /bin/bash

############################################################################################################
## This script is used by the catalog pipeline to provision a new resource group
## (required to ensure auth policies don't clash in account)
############################################################################################################

set -e

DA_DIR="${1}"
TERRAFORM_SOURCE_DIR="tests/new-rg"
JSON_FILE="${DA_DIR}/catalogValidationValues.json"
TF_VARS_FILE="terraform.tfvars"

(
cwd=$(pwd)
cd ${TERRAFORM_SOURCE_DIR}
echo "Provisioning new resource group .."
terraform init || exit 1
# $VALIDATION_APIKEY is available in the catalog runtime
{
echo "ibmcloud_api_key=\"${VALIDATION_APIKEY}\""
echo "prefix=\"ocp-$(openssl rand -hex 2)\""
} >> ${TF_VARS_FILE}
terraform apply -input=false -auto-approve -var-file=${TF_VARS_FILE} || exit 1

rg_var_name="existing_resource_group_name"
rg_value=$(terraform output -state=terraform.tfstate -raw resource_group_name)

echo "Appending '${rg_var_name}', input variable value to ${JSON_FILE}.."

cd "${cwd}"
jq -r --arg rg_var_name "${rg_var_name}" \
--arg rg_value "${rg_value}" \
'. + {($rg_var_name): $rg_value}' "${JSON_FILE}" > tmpfile && mv tmpfile "${JSON_FILE}" || exit 1

echo "Pre-validation complete successfully"
)