Terraform Template Overview
The following is a description of a typical Terraform template focusing on the elements which may be modified.
The following elements are considered:
- Variables - SSH keys
- Variables - Cloud specific
- Variables - Environment variables
- Variables - Pattern variables
- Variables - Image variables
- IBM-specific Terraform resources
Variables - SSH keys
SSH keys for injection and Pattern Manager remote control.
variable "user_public_ssh_key" {
type = "string"
description = "User defined public SSH key used to connect to the virtual machine, whose format is required to be the openSSH key format with optional comment"
default = "None"
}
Variables - Cloud specific
Cloud specific variables that may be different for each cloud type. Cloud specific variables are likely injected by Managed services and not exposed to the deployer. The following examples are for VMware-based cloud.
variable "vsphere_user" {
description = "vSphere user"
}
variable "vsphere_password" {
description = "vSphere password"
}
variable "vsphere_server" {
description = "vSphere server"
}
variable "ibm_pm_public_ssh_key" {
description = "Public CAMC SSH key value which is used to connect to a guest, used on VMware only"
}
variable "ibm_pm_private_ssh_key" {
description = "Private CAMC SSH key (base64 encoded) used to connect to the virtual guest"
}
variable "allow_unverified_ssl" {
description = "Communication with vSphere server with self-signed certificate"
default = "true"
}
Variables - Environment variables
Environment variables relate to the injected variables which relate to the selected Content Runtime, and are not exposed to the deployer. A typical set of variables is:
variable "vsphere_user" {
description = "vSphere user"
}
variable "vsphere_password" {
description = "vSphere password"
}
variable "vsphere_server" {
description = "vSphere server"
}
variable "ibm_pm_public_ssh_key" {
description = "Public CAMC SSH key value which is used to connect to a guest, used on VMware only"
}
variable "ibm_pm_private_ssh_key" {
description = "Private CAMC SSH key (base64 encoded) used to connect to the virtual guest"
}
variable "allow_unverified_ssl" {
description = "Communication with vSphere server with self-signed certificate"
default = "true"
}
Variables - Pattern variables
This set of variables contains the specific variables that relate to the software pattern. Variables are typically defined on a per-node basis and relate to specific software concepts such as ports, users and directories.
This type of variable is the most applicable for editing. You can create custom templates for specific situations and hide variables from the deployer if necessary. It is noteworthy that each of these parameters appears in the CAM Variables section and may be defaulted or hidden by CAM Variable modification.
##### centralnode variables #####
#Variable : centralnode_was_liberty_base_version
variable "centralnode_was_liberty_base_version" {
type = "string"
description = "The release and fixpack level for WebSphere Liberty to be installed. Example formats are 8.5.5.11 or 17.0.0.2"
default = "17.0.2"
}
#Variable : centralnode_was_liberty_edition
variable "centralnode_was_liberty_edition" {
type = "string"
description = "Indicates which Liberty offering should be installed. Valid values are: base, core, nd"
default = "base"
}
Variables - Image variables
A template describes one or more compute instances and other cloud resources. These resources are cloud specific and may include the definition of virtual machines, networks, disk or security groups. The templates have different resources for each cloud defined.
This category of variables may be extremely relevant for an administrator to modify, to ensure that template deployers do not have too many decisions to make at deploy time.
#########################################################
##### Resource : centralnode
#########################################################
variable "centralnode-os_password" {
type = "string"
description = "Operating System Password for the Operating System User to access virtual machine"
}
variable "centralnode_folder" {
description = "Target vSphere folder for virtual machine"
}
variable "centralnode_datacenter" {
description = "Target vSphere Datacenter for virtual machine creation"
}
variable "centralnode_number_of_vcpu" {
description = "Number of virtual CPU for the virtual machine, which is required to be a positive Integer"
default = "2"
}
It is noteworthy that these resources often use CAM Variables to set values at deploy time. For example, the amount of memory assigned to a virtual machine is defined as follows and may be modified by an administrator using CAM Variables.
IBM-specific Terraform resources
IBM has extended the standard Terraform provider to expose methods provided by the Pattern Manager which participate in software deployment. The following resources are exposed:
camc_bootstrap
camc_bootstrap
bootstraps the target node with a Chef client and register the client with the relevant Chef server. A Chef vault item is also created at this time to handle Pattern Secrets. Standard IBM Variables such as stack_id
and stack_name
are created as Node Attributes during camc_bootstrap
. An example of camc_bootstrap
is:
resource "camc_bootstrap" "centralnode_chef_bootstrap_comp" {
depends_on = ["camc_vaultitem.VaultItem","vsphere_virtual_machine.centralnode"]
name = "centralnode_chef_bootstrap_comp"
camc_endpoint = "${var.ibm_pm_service}/v1/bootstrap/chef"
access_token = "${var.ibm_pm_access_token}"
skip_ssl_verify = true
trace = true
data = <<EOT
{
"os_admin_user": "${var.centralnode-os_admin_user}",
"stack_id": "${random_id.stack_id.hex}",
"environment_name": "_default",
"host_ip": "${vsphere_virtual_machine.centralnode.network_interface.0.ipv4_address}",
"node_name": "${var.centralnode-name}",
"node_attributes": {
"ibm_internal": {
"stack_id": "${random_id.stack_id.hex}",
"stack_name": "${var.ibm_stack_name}",
"vault": {
"item": "secrets",
"name": "${random_id.stack_id.hex}"
}
}
}
}
EOT
}
camc_softwaredeploy
camc_softwaredeploy
instructs the Pattern Manager to execute a Chef role on the target node. An important facet of this operation is the creation of Node Attributes on the Chef node which are used when the Chef client is executed.
resource "camc_softwaredeploy" "centralnode_liberty_install" {
depends_on = ["camc_bootstrap.centralnode_chef_bootstrap_comp","camc_bootstrap.libertynode_chef_bootstrap_comp"]
name = "centralnode_liberty_install"
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.centralnode-os_admin_user}",
"stack_id": "${random_id.stack_id.hex}",
"environment_name": "_default",
"host_ip": "${vsphere_virtual_machine.centralnode.network_interface.0.ipv4_address}",
"node_name": "${var.centralnode-name}",
"runlist": "role[liberty_install]",
"node_attributes": {
"ibm": {
"im_repo": "${var.ibm_im_repo}",
"im_repo_user": "${var.ibm_im_repo_user}",
"sw_repo": "${var.ibm_sw_repo}",
"sw_repo_user": "${var.ibm_sw_repo_user}"
},
"ibm_internal": {
"roles": "[liberty_install]"
},
"was_liberty": {
"base_version": "${var.centralnode_was_liberty_base_version}",
"edition": "${var.centralnode_was_liberty_edition}",
"im_install_dir": "${var.centralnode_was_liberty_im_install_dir}",
"install_dir": "${var.centralnode_was_liberty_install_dir}",
"install_grp": "${var.centralnode_was_liberty_install_grp}",
"install_user": "${var.centralnode_was_liberty_install_user}",
"java_version": "${var.centralnode_was_liberty_java_version}",
"wlp_user_dir": "${var.centralnode_was_liberty_wlp_user_dir}"
}
},
"vault_content": {
"item": "secrets",
"values": {
"ibm": {
"im_repo_password": "${var.ibm_im_repo_password}",
"sw_repo_password": "${var.ibm_sw_repo_password}"
}
},
"vault": "${random_id.stack_id.hex}"
}
}
EOT
}
In the previous example, note the following items:
runlist
: The Chef Runlist to execute.host_ip
: The IP address of the node to execute the Chef client on.node_attributes
: A Chef structure list of node attributes to be created.-
vault_content
: Chef vault items to create.Note: A single Chef vault is created per template or stack. In this way, all nodes from the same template can share secrets and exclude nodes from other templates.