- 15 Nov 2021
- 3 Minutes to read
- Print
- DarkLight
Terraform with VDC
- Updated on 15 Nov 2021
- 3 Minutes to read
- Print
- DarkLight
Terraform with VDC
The Servers Australia Virtual Data Center (VDC) environment allows you to integrate with Terraform, an “Infrastructure as Code” utility to spin up, modify, and delete resources on the VDC platform.
We've provided a ready-to-go demo which you can find and follow along with, hosted on GitHub: https://github.com/ServersAU/vdc-terraform
This guide is intended to provide you with more context on the above demo and will show you a quick and easy way to get started with Terraform and your new environment. For our intended “environment”. Let’s say that we want the following:
This environment will contain:
- A vApp, which contains:
- app1, our application VM running Alma Linux 8.4. This can run on 20 GB of Tier 1 storage.
- db1, our database VM, which will also run Alma Linux 8.4/ This needs to run on 40 GB of Tier 1 storage.
- A vApp Network, which the vApp uses.
- The VDC Network. This is a network provided to you first provisioning on the network of 192.168.99.0/24.
- An NSX, which is the firewall/gateway/router appliance. This is also already provisioned for you on setup.
Logically, this may appear like:
Terraform is available on a number of operating systems.
We recommended referring to their documentation here: https://learn.hashicorp.com/tutorials/terraform/install-cli for your specific operating system.
From the command line, run the below init command to prepare terraform in the folder.
# terraform init
Starting Files
As noted above, navigate to our public repo which has your getting started files: https://github.com/ServersAU/vdc-terraform
Clone this to a local directory using git on your workstation, or download and extract the zip. You’ll see the following main files:
/main.tf: The main terraform file. In here, you establish the intended configuration, including VMs, Networks, and Firewall Rules.
/variables.tf: A supplementary file. In here, you set applicable variables for your environment, including CPU, RAM and IP information.
/secret.tfvars: This file holds your password for the vdc environment, along with the VM passwords. This is provided to assist with a "quick start" tutorial, never store your passwords in plaintext in a production environment. Variables have been left blank for you to fill in the passwords yourself.
Update your variables
Navigate to the variables.tf file.
At a minimum the following seven (7) variable sections must be updated in the "default" section:
- vcd_user: replace "cid-1234" with your Username (as shown in the MySAU Services portal)
- vcd_org: replace "cid-1234" with your Organisation name (as shown in the MySAU Services portal)
- vcd_vdc: replace "SAU-XXXXX-VD" with your Virtual Data Centre name (as shown in the MySAU Services portal)
- nsx_edge: Similar to above, replace "SAU-XXXXX-VD-nsx-edge" with your Virtual Data Centre name, appending -nsx-edge.
An example from the MySAU portal, VDC services page:
Set your Passwords
For production environments, it is recommended to use a secure form of password management. For now, we'll use a separate variables file and input our passwords. Define the following in secret.tfvars :
- vcd_pass: The password you set up for your login. This can be reset in the MySAU portal under "Reset Password".
- app1_os_password: A random string or set password you'll use for the app1 VM.
- db1_os_password: Another random string or set password you'll use for the db1 VM.
Planning the Configuration
# terraform plan -var-file="secret.tfvars"
Terraform will read your main.tf file, fill in the variables from your variable file and secret file, and present any planned additions, changes or deletions. We want to add five things:
- A new Routed Network (vcd_network_routed_v2.routed_network)
- A new vApp (vcd_vapp.terraform_vapp)
- An organisational network for the vApp (vcd_vapp_org_network.vapp_network)
- The app1 VM (vcd_vapp_vm.app1)
- The db1 VM (vcd_vapp_vm.db1)
You should see a line confirming these file items will be created:
Plan: 5 to add, 0 to change, 0 to destroy.
Applying the Configuration
If we are happy to proceed, run the below to begin:
# terraform apply -var-file="secret.tfvars"
<omitted for brevity>
Plan: 5 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
It will prompt for a final "yes" from you, then it will proceed to create the infrastructure.