Template modification
Template modification is possible by cloning catalog items from within the Managed services user interface and directly modifying the Template inline.
Consider the following use cases:
- Hardcoding template parameters
- Template modification - BYO script
- Template modification - BYO Chef role
Hardcoding template parameters
At a template level, you can hardcode predefined parameters and set them within the template. The following changes must be made:
- Remove Terraform parameter.
- Hardcode value in the
camc_softwaredeploy
resource.
As an example, consider the following camc_softwaredeploy
resource and associated parameter, install_dir
:
#Variable : centralnode_was_liberty_install_dir
variable "centralnode_was_liberty_install_dir" {
type = "string"
description = "Liberty install dir"
default = "/opt/IBM/WebSphere/Liberty"
}
resource "camc_softwaredeploy" "centralnode_liberty_install" {
...
"runlist": "role[liberty_install]",
"node_attributes": {
"was_liberty": {
"install_dir": "${var.centralnode_was_liberty_install_dir}",
...
In the previous example, if you want to hardcode the value of the install_dir
parameter, you must first remove the variable and secondly modify the resource with the correct value as, for example, /opt/liberty
.
"node_attributes": {
"was_liberty": {
"install_dir": "/opt/liberty",
Subsequent deployments of the template ignore parameters injected, and instead always use your custom value.
Template modification - BYO script
The BYO script resource allows for the inclusion of a custom script into an existing template. To perform this modification, the Managed services user interface may be used.
Note that the addition of custom scripts uses the standard Terraform remote-exec
resource. The following sample shows how this may be used with standard IBM-provided variables.
-
Custom script snippet
Use the following Terraform snippet in a VMware based template to add a custom script to the template.
#########################################################
##### Resource : Sample Script
#########################################################
resource "null_resource" "NODENAME_Sample Script" {
depends_on = ["vsphere_virtual_machine.NODENAME"]
# Specify the ssh connection
connection {
user = "${var.NODENAME-os_admin_user == "" ? lookup(var.default_os_admin_user, var.NODENAME-image) : var.NODENAME-os_admin_user}"
private_key = "${base64decode(var.ibm_pm_private_ssh_key)}"
host = "${vsphere_virtual_machine.NODENAME.network_interface.0.ipv4_address}"
}
provisioner "file" {
destination = "NODENAME_Sample Script.properties"
content = <<EOF
export custom_property=""
EOF
}
provisioner "file" {
destination = "NODENAME_Sample Script.sh"
content = <<EOF
#!/bin/bash
++SCRIPTLINES++
EOF
# Execute the script remotely
provisioner "remote-exec" {
inline = [
"sudo bash -c 'chmod +x NODENAME_Sample Script.properties'",
"sudo bash -c '. ./NODENAME_Sample Script.properties'",
"sudo bash -c 'chmod +x NODENAME_Sample Script.sh'",
"sudo bash -c './NODENAME_Sample Script.sh >> centralnode_Sample Script.log 2>&1'",
"sudo bash -c 'rm NODENAME_Sample Script.properties'"
]
}
}
The following variables must be substituted:
NODENAME
: The logical name of the node within the Terraform template.SCRIPTLINES
: The injected script.
Template modification - BYO Chef role
The BYO Chef role provides the capability to insert a customer provided Chef role into the orchestration. The following snippet must be added to a Terraform template:
resource "camc_softwaredeploy" "NODENAME_ROLE" {
depends_on = ["vsphere_virtual_machine.NODENAME"]
name = "NODENAME_ROLE"
camc_endpoint = "${var.ibm_pm_service}/v1/software_deployment/chef"
access_token = "${var.ibm_pm_access_token}"
skip_ssl_verify = true
trace = true
data = <<EOT
{
"os_admin_user": "${var.NODENAME-os_admin_user}",
"stack_id": "${random_id.stack_id.hex}",
"environment_name": "_default",
"host_ip": "${vsphere_virtual_machine.NODENAME.network_interface.0.ipv4_address}",
"node_name": "${var.NODENAME-name}",
"runlist": "role[ROLE]",
"node_attributes": {
"ibm_internal": {
"roles": "[ROLE]"
}
}
}
EOT
}
The following variables must be substituted:
NODENAME
: The logical name of the node within the Terraform template.ROLE
: The name of the Chef role to be executed.