Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- Update this title with a descriptive name. Use sentence case. -->
# Terraform modules template project
# IBM Cloud Pak for Data deployment on OpenShift

<!--
Update status and "latest release" badges:
Expand All @@ -14,7 +14,7 @@ Update status and "latest release" badges:


This repository contains the following deployment an Red Hat OpenShift cluster:
- [IBM Cloud Cloud Pak for Data](./solutions/deploy)
- [IBM Cloud Pak for Data](./solutions/deploy)

**NB:** These solutions are not intended to be called by one or more other modules since they contain a provider configurations, meaning they are 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)

Expand Down
Empty file added examples/basic/README.md
Empty file.
File renamed without changes.
2 changes: 1 addition & 1 deletion solutions/deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ You need the following permissions to run this module:
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.66.0, < 2.0.0 |
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | 2.35.1 |
| <a name="requirement_null"></a> [null](#requirement\_null) | 3.2.2 |
| <a name="requirement_restapi"></a> [restapi](#requirement\_restapi) | 1.18.2 |
| <a name="requirement_shell"></a> [shell](#requirement\_shell) | 1.7.10 |

### Modules

Expand Down
2 changes: 1 addition & 1 deletion solutions/deploy/cloud-pak-deployer/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ resource "shell_script" "uninstall" {

lifecycle_commands {
create = ""
delete = file("${path.module}/scripts/uninstall.sh.tftpl")
delete = file("${path.module}/scripts/uninstall.sh")
}

environment = {
Expand Down
44 changes: 44 additions & 0 deletions solutions/deploy/cloud-pak-deployer/scripts/uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

${OC} create -f "${JOB_UNINSTALL_CPD_FILENAME}"
RC=$?
if [ "${RC}" -ne 0 ]; then echo "Unable to create job ${JOB_NAME}; exiting..." && exit 1; fi

timeout_seconds=1800 # 30 minutes
sleep_seconds=5
number_of_tries=$((timeout_seconds / sleep_seconds))
complete=false
failed=false

i=0
while [ $i -lt "${number_of_tries}" ]; do

echo "Running job ... $i"
${OC} get jobs -n "${NAMESPACE_NAME}"

${OC} wait --for=condition=complete job "${JOB_NAME}" -n "${NAMESPACE_NAME}" --timeout=0 2>/dev/null
RC=$?
if [ "${RC}" -eq 0 ]; then complete=true && break; fi

${OC} wait --for=condition=failed job "${JOB_NAME}" -n "${NAMESPACE_NAME}" --timeout=0 2>/dev/null
RC=$?
if [ "${RC}" -eq 0 ]; then failed=true && break; fi

i=$((i+1))

sleep "${sleep_seconds}"

done

${OC} describe pods -n "${NAMESPACE_NAME}"

if $failed; then
echo "Job ${JOB_NAME} failed"
exit 1
elif "${complete}"; then
echo "Job ${JOB_NAME} completed successfully"
${OC} delete -f "${JOB_UNINSTALL_CPD_FILENAME}"
RC=$?
if [ "${RC}" -ne 0 ]; then echo "Unable to delete job ${JOB_NAME}; exiting..." && exit 1; fi
exit 0
fi
40 changes: 0 additions & 40 deletions solutions/deploy/cloud-pak-deployer/scripts/uninstall.sh.tftpl

This file was deleted.

24 changes: 10 additions & 14 deletions solutions/deploy/cpd-image-build/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,15 @@ module "code_engine_build" {
depends_on = [module.code_engine]
}

resource "restapi_object" "buildrun" {
path = "/v2/projects/${module.code_engine.project_id}/build_runs"
data = jsonencode(
{
build_name = module.code_engine_build.name
}
)
}

resource "time_sleep" "wait_for_build" {
create_duration = "10m"
resource "shell_script" "build_run" {
lifecycle_commands {
create = file("${path.module}/scripts/image-build.sh")
delete = ""
update = ""
}

depends_on = [
restapi_object.buildrun
]
environment = {
REGION = var.region
PROJECT_ID = module.code_engine.project_id
}
}
38 changes: 38 additions & 0 deletions solutions/deploy/cpd-image-build/scripts/image-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

BUILD_OUTPUT=$(curl -X POST "https://api.${REGION}.codeengine.cloud.ibm.com/v2/projects/${PROJECT_ID}/build_runs" -H "Authorization: ${TOKEN}" -H "Content-Type: application/json" -d '{ "build_name": "cpd-build" }')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do create the project/build/etc through the code engine DA. The problem is executing a build run and checking for completion which there is no terraform for

RC=$?

BUILD_NAME=$(echo "${BUILD_OUTPUT}" | jq -r .name)

if [ $RC -ne 0 ] || [ "${BUILD_NAME}" == "null" ]; then
echo "Creation of build run failed with rc = ${RC}. Output = ${BUILD_OUTPUT}"
exit 1;
fi

SLEEP_SECONDS=60
NUMBER_OF_RETRIES=15
COMPLETE=false

i=0
while [ "${i}" -lt "${NUMBER_OF_RETRIES}" ]; do

echo "Running job ... $i"

BUILD_RUN_OUTPUT=$(curl -X GET "https://api.${REGION}.codeengine.cloud.ibm.com/v2/projects/${PROJECT_ID}/build_runs/${BUILD_NAME}" -H "Authorization: ${TOKEN}")
echo "${BUILD_RUN_OUTPUT}"

BUILD_STATUS=$(echo "${BUILD_RUN_OUTPUT}" | jq -r .status)
if [ "${BUILD_STATUS}" == "succeeded" ]; then COMPLETE=true && break; fi

i=$((i+1))

sleep "${SLEEP_SECONDS}"
done

if [ "${COMPLETE}" = false ]; then
echo "The build run did not complete in the alloted time. Output = ${BUILD_RUN_OUTPUT}"
exit 1;
fi

exit 0;
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ terraform {
source = "hashicorp/random"
version = ">= 3.4.3, < 4.0.0"
}
restapi = {
source = "Mastercard/restapi"
version = "1.18.2"
}
time = {
source = "hashicorp/time"
version = "0.12.1"
shell = {
source = "scottwinkler/shell"
version = "1.7.10"
}
}
}
9 changes: 3 additions & 6 deletions solutions/deploy/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ provider "kubernetes" {

data "ibm_iam_auth_token" "tokendata" {}

provider "restapi" {
uri = "https://api.${var.region}.codeengine.cloud.ibm.com/"
debug = true
write_returns_object = true
headers = {
Authorization = data.ibm_iam_auth_token.tokendata.iam_access_token
provider "shell" {
sensitive_environment = {
TOKEN = data.ibm_iam_auth_token.tokendata.iam_access_token
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ terraform {
source = "hashicorp/null"
version = "3.2.2"
}
restapi = {
source = "Mastercard/restapi"
version = "1.18.2"
shell = {
source = "scottwinkler/shell"
version = "1.7.10"
}
}
}