This repository contains files for deploying virtual machines on a VMware vSphere environment. The deployment is customizable using variables that you can define in your defaults.tfvars
file or pass them through the command line when running Terraform commands.
- Terraform installed on your local machine
- VMware vSphere environment with necessary permissions to create resources
- VMware vSphere provider for Terraform (automatically installed when running
terraform init
)
-
Clone this repository or download the Terraform configuration files.
-
Create a
.tfvars
file in the same directory as the Terraform configuration files, or update the provideddefaults.tfvars
file with your custom values. -
Set the required variables in your
.tfvars
file or pass them as command line arguments when running Terraform commands. The required variables fordefaults.tfvars
are:vsphere_user
: The vSphere user with necessary permissions to create resourcesvsphere_password
: The password for the vSphere useradmin_user
: The username for the virtual machine's OSadmin_password
: The password for the virtual machine's OS uservm_name
: The hostname of the virtual machineip_addresses
: The IPv4 address of the virtual machine. Leave blank if using DHCP.
- Open a terminal and navigate to the directory containing the Terraform configuration files.
- Run
terraform init
to initialize the Terraform working directory and download the necessary provider plugins. - Run the following command to review the planned changes before applying them:
terraform plan
-var-file = <defaults.tfvars>
-var "vsphere_user = <vsphere_user>"
-var "vsphere_password = <vsphere_password>""
-var "admin_user = <admin_username>"
-var "admin_password = <password>"
-var "vm_name = <vm_name>"
-var "ip_addresses = [<list of ip addresses>]"
- If the plan output looks correct and you want to proceed with the deployment, run the following command to apply the changes:
terraform apply
-var-file = <defaults.tfvars>
-var "vsphere_user = <vsphere_user>"
-var "vsphere_password = <vsphere_password>"
-var "admin_user = <admin_user>"
-var "admin_password = <admin_password>"
-var "vm_name = <vm_name>"
-var "ip_addresses = [<list of ip addresses>]"
- Once the deployment is complete, you can verify the created resources in your vSphere environment.
To destroy the resources created by this Terraform configuration, run the following command:
terraform destroy
-var-file = <defaults.tfvars>
-var "vsphere_user = <vsphere_user>"
-var "vsphere_password = <vsphere_password>"
-var "admin_user = <admin_user>"
-var "admin_password = <admin_password>"
-var "vm_name = <vm_name>"
-var "ip_addresses = [<list of ip addresses>]"
Note: Destroying the resources will delete the virtual machines and associated resources from your vSphere environment. Be cautious when running this command.