Skip to content

Commit f33c78b

Browse files
fix: split password file creation and deletion to ensure terraform fails on playbook failure
1 parent 2302bf7 commit f33c78b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

solutions/standard-openshift/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This example sets up an OpenShift Cluster on PowerVS following infrastructure:
1313
- KMS keys
1414
- Activity tracker
1515
- Optional Secrets Manager Instance Instance with private certificate.
16+
- Three application load balancers for internal OpenShift API, public OpenShift API, and OpenShift applications
1617

1718
- A local **transit gateway**
1819
- An IBM Cloud DNS Service Instance

solutions/standard-openshift/ansible/main.tf

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,16 @@ resource "terraform_data" "execute_playbooks" {
119119
]
120120
}
121121

122+
# Create the vault password_file to be used for decryption and encryption of ocp config
123+
provisioner "remote-exec" {
124+
inline = ["echo ${var.ansible_vault_password} > password_file"]
125+
}
126+
122127
# Decrypt ocp config if it already exists
123128
provisioner "remote-exec" {
124129
inline = [
125130
"if [ -f /root/.powervs/config.json ]; then",
126131
" if head -n 1 /root/.powervs/config.json | grep -q '^$ANSIBLE_VAULT'; then",
127-
" echo ${var.ansible_vault_password} > password_file",
128132
" ansible-vault decrypt /root/.powervs/config.json --vault-password-file password_file",
129133
" fi",
130134
"fi"
@@ -135,13 +139,16 @@ resource "terraform_data" "execute_playbooks" {
135139
# create password file so the script can encrypt the ocp config
136140
provisioner "remote-exec" {
137141
inline = [
138-
"echo ${var.ansible_vault_password} > password_file",
139142
"chmod +x ${local.dst_script_file_path}",
140-
"export IBMCLOUD_API_KEY=${local.ibmcloud_api_key} && ${local.dst_script_file_path}",
141-
"rm -f password_file"
143+
"export IBMCLOUD_API_KEY=${local.ibmcloud_api_key} && ${local.dst_script_file_path}"
142144
]
143145
}
144146

147+
# Again delete the password_file
148+
provisioner "remote-exec" {
149+
inline = ["rm -f password_file"]
150+
}
151+
145152
# Again delete private ssh key
146153
provisioner "remote-exec" {
147154
inline = [

0 commit comments

Comments
 (0)