Created
November 14, 2019 23:45
-
-
Save 8bitnz/e32081881155e8d1bd5dc048e7d7432b to your computer and use it in GitHub Desktop.
Nelson VMUG vcloud director example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The provider is the system we are connecting to or managing. In this case | |
# the provider is 'vcd'. For the vcd provider, we need to provide the following. | |
# The vcd Provider supports both provider and tenants, in this instance we are assigning an Org, | |
# the credentials provided are local to that tenant | |
provider "vcd" { | |
user = "youruser" | |
password = "YourSecurePassword" | |
org = "ACME" | |
vdc = "VDC3" | |
url = "https://yourvcd.local/api" | |
allow_unverified_ssl = false | |
} | |
# In this example, we are creating a new network to place the VM on. The Routed network resource | |
# needs to know which edge to connect to, as well as IP details for the network. | |
resource "vcd_network_routed" "net" { | |
org = "ACME" | |
vdc = "VDC3" | |
name = "terraform_net" | |
edge_gateway = "Test-Gateway" | |
gateway = "192.168.27.1" | |
dns1 = "8.8.8.8" | |
dhcp_pool { | |
start_address = "192.168.27.2" | |
end_address = "192.168.27.50" | |
} | |
static_ip_pool { | |
start_address = "192.168.27.51" | |
end_address = "192.168.27.100" | |
} | |
} | |
# Once the network is created, we can create the vApp container for the VM to reside in. We need the network | |
# object to exist before we attempt to assign it to the vApp, so we use the 'depends_on' feature here. | |
resource "vcd_vapp" "vapp" { | |
name = "terraform_vapp" | |
depends_on = ["vcd_network_routed.net"] | |
} | |
# Finally we can create the VM. The below VM is deployed from a template in the 'shared public' catalog. | |
# We can assign a name, the size and connect it to the network deployed above. As with the network, we | |
# need the vApp to exist, so we set this as a dependency. | |
resource "vcd_vapp_vm" "vapp" { | |
vapp_name = "terraform_vapp" | |
name = "terraform_vm01" | |
catalog_name = "Shared Public" | |
template_name = "centos-7x" | |
memory = 1024 | |
cpus = 2 | |
network { | |
type = "org" | |
name = "terraform_net" | |
ip = "192.168.27.101" | |
ip_allocation_mode = "MANUAL" | |
} | |
depends_on = ["vcd_vapp.vapp"] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment