Skip to content

Instantly share code, notes, and snippets.

@calum-github
Created November 30, 2018 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calum-github/866487f370bed4e6e0bf1bc2157b8a14 to your computer and use it in GitHub Desktop.
Save calum-github/866487f370bed4e6e0bf1bc2157b8a14 to your computer and use it in GitHub Desktop.
example using count in TF
# define the network interfaces in a count block for the vm's you want to assign them to
resource "azurerm_network_interface" "network-interface" {
name = "interface-number-${count.index}"
count = 3
# ...
}
# The above resource will generate three network interfaces
# Now create a resource block for 3 vm's and when we get to defining the network interface id's
# we use element to select the interface id from the above resource block
resource "azurerm_virtual_machine" "foo" {
# ...
count = 3
network_interface_ids = ["${element(azurerm_network_interface.network-interface.*.id, count.index)}"]
# ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment