File tree Expand file tree Collapse file tree 3 files changed +12
-6
lines changed Expand file tree Collapse file tree 3 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ module "example-server-linuxvm" {
5151 vmname = "example-server-linux"
5252 vmrp = "esxi/Resources - or name of a resource pool"
5353 network = {
54- "Name of the Port Group in vSphere" = ["10.13.113.2", "10.13.113.3"] # To use DHCP create Empty list ["",""]
54+ "Name of the Port Group in vSphere" = ["10.13.113.2", "10.13.113.3"] # To use DHCP create Empty list ["",""]; You can also use a CIDR annotation;
5555 }
5656 vmgateway = "10.13.113.1"
5757 dc = "Datacenter"
@@ -94,7 +94,7 @@ module "example-server-windowsvm-advanced" {
9494 vmnameformat = "%03d" #To use three decimal with leading zero vmnames will be AdvancedVM001,AdvancedVM002
9595 domain = "somedomain.com"
9696 network = {
97- "Name of the Port Group in vSphere" = ["10.13.113.2", "10.13.113.3"] # To use DHCP create Empty list ["",""]
97+ "Name of the Port Group in vSphere" = ["10.13.113.2", "10.13.113.3"] # To use DHCP create Empty list ["",""]; You can also use a CIDR annotation;
9898 "Second Network Card" = ["", ""]
9999 }
100100 ipv4submask = ["24", "8"]
Original file line number Diff line number Diff line change @@ -210,8 +210,14 @@ resource "vsphere_virtual_machine" "vm" {
210210 dynamic "network_interface" {
211211 for_each = keys (var. network )
212212 content {
213- ipv4_address = var. network [keys (var. network )[network_interface . key ]][count . index ]
214- ipv4_netmask = " %{ if length (var. ipv4submask ) == 1 } ${ var . ipv4submask [0 ]} %{ else } ${ var . ipv4submask [network_interface . key ]} %{ endif } "
213+ ipv4_address = split (" /" , var. network [keys (var. network )[network_interface . key ]][count . index ])[0 ]
214+ ipv4_netmask = var. network [keys (var. network )[network_interface . key ]][count . index ] == " " ? null : (
215+ length (split (" /" , var. network [keys (var. network )[network_interface . key ]][count . index ])) == 2 ? (
216+ split (" /" , var. network [keys (var. network )[network_interface . key ]][count . index ])[1 ]
217+ ) : (
218+ length (var. ipv4submask ) == 1 ? var. ipv4submask [0 ] : var. ipv4submask [network_interface . key ]
219+ )
220+ )
215221 }
216222 }
217223 dns_server_list = var. dns_server_list
Original file line number Diff line number Diff line change 11# Network Section
22variable "network" {
3- description = " Define PortGroup and IPs for each VM"
3+ description = " Define PortGroup and IPs/CIDR for each VM. If no CIDR provided, the subnet mask is taken from var.ipv4submask. "
44 type = map (list (string ))
55 default = {}
66}
@@ -12,7 +12,7 @@ variable "network_type" {
1212}
1313
1414variable "ipv4submask" {
15- description = " ipv4 Subnet mask."
15+ description = " ipv4 Subnet mask. Warning: The order must follow the alphabetic order from var.network. "
1616 type = list (any )
1717 default = [" 24" ]
1818}
You can’t perform that action at this time.
0 commit comments