This repo contains sample infrastructure as code snippets to deploy, maintain and manage infrastructure on DCS using Terraform vCloud Director provider.
Terraform enables you to safely and predictably create, change, and improve infrastructure. It is an open source tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
Download Terraform based on your operating system to execute terraform code and plans.
Install Terraform by unzipping it and moving it to a directory included in your system's PATH.
-
Make sure that you have DCS contract and have your Contract Number/Pro-Number ready.
-
Create vCloud Director API User from DCS Self Service Portal.
-
Create Dynamic Data Center from DCS Self Service Portal.
-
config-values.tfvars This file is to pass configuration values to the terraform apply/destroy commands instead of passing values manually. Edit this file by exchanging the values as per your DCS environment setup.
-
main.tf This file is to define terraform provider for vCloud Director.
-
variables.tf This file defines all the needed variables that are referenced in this sample terraform script.
-
dcs-terraform-basic-sample.tf This sample terraform script shows how terraform can be used to write infrastructure as code in DCS with vCloud Director. This particular example will create a vDC Network,vApp and VM attached to the network.
- Open your shell change directory to
\terraform-dcs-demo
and executeterraform init
it will download vCloud Director provider and initialize terraform. - Run
terraform validate
to make sure the configuration is valid. - Run
terraform apply -var-file="config-values.tfvars"
to apply the changes required to reach the desired state of the configuration. This will start deploying resources in your DCS contract. - Run
terraform destroy -var-file="config-values.tfvars"
Infrastructure managed by Terraform will be destroyed. This will ask for confirmation before destroying. This will start destroying resources managed by Terraform in your DCS contract.