This step adds the automation to deploy an Apache server on the three workload virtual servers.
To implement this automation, we use the built-in Terraform remote-exec provisioner. The remote-exec provisioner connects to a remote resource and invokes a script on that computer.
We configure the remote-exec provisioner to run a script that installs the Apache server on a worker VSI. The remote-exec provisioner is configured to access the worker nodes through our management jump box that is publicly exposed. The same private SSH key is used to connect both to the jump box and to the worker VSIs.
You can find the code for this step in the app-install directory. The directory contains the following important files:
-
The main.tf file which contains the terraform logic calling the remote-exec provisioner with the ‘right’ parameters.
Notice the following settings in the
main.tf
file:- In the connection block, the
bastion_host
is set to the management server floating IP address that you will use as a jump host to connect to the workload server. - In the connection block, the
host
is set to the IP address of the workload server. - In the provisioner block, a list of the commands that will be executed on the workload server are listed.
resource "null_resource" "application-install" { count = var.number_vsi_workload connection { type = "ssh" user = "root" bastion_host = var.floating_ip_address host = local.workload_ip_list[count.index] private_key = var.ssh_private_key agent = false timeout = "15m" } provisioner "remote-exec" { inline = [ "apt-get install apache2 -y" ] } }
- In the connection block, the
To run the Terraform module in your local environment, follow these steps. These steps assume you ran the steps in (Executing the landing zone with a JSON definition).
-
Change to the
app-install
foldercd infra-to-app-with-landing-zone/app-install
-
Initialize Terraform.
terraform init
-
Generate a plan. The plan lists of resources that are going to be created.
terraform plan -var=region=eu-gb -var=ssh_private_key="$(cat ../custom-slz/lab2-key-tf)" -var=floating_ip_address=<The floating point IP address of the jump box> -var=vpc_id=<ID of the workload VPC>
ℹ️ Note:
The floating point IP address of the jump box
value can be retrieved by accessing the virtual server instances for VPC in the console. Please make sure the corresponding region that you provisioned your resources is selected in the dropdown.ID of the workload VPC
value can be retrieved by accessing the workload VPC in the Virtual private clouds list in the console. Please make sure the corresponding region that you provisioned your resources is selected in the dropdown.
-
(Optional) Apply the changes.
terraform apply -var=region=eu-gb -var=ssh_private_key="$(cat ./lab2-key-tf)" -var=floating_ip_address=<The floating point IP address of the jump box> -var=vpc_id=<ID of the workload VPC>