Skip to content

Instantly share code, notes, and snippets.

@andybaran
Created October 26, 2023 22:52
Show Gist options
  • Save andybaran/61703040a443f8b5c926d2b4c25f4c24 to your computer and use it in GitHub Desktop.
Save andybaran/61703040a443f8b5c926d2b4c25f4c24 to your computer and use it in GitHub Desktop.
Nutanix TF NIC IP
terraform{
required_providers{
nutanix = {
source = "nutanix/nutanix"
version = "1.3.0"
}
}
}
provider "nutanix" {
username = "admin"
password = "Nutanix/123456"
endpoint = "10.xx.xx.xx"
insecure = true
port = 9440
}
data "nutanix_clusters" "clusters" {
}
locals {
cluster1 = data.nutanix_clusters.clusters.entities[1].metadata.uuid
}
resource "nutanix_image" "cirros-034-disk" {
name = "cirros-034-disk"
#source_uri = "http://endor.dyn.nutanix.com/acro_images/DISKs/cirros-0.3.4-x86_64-disk.img"
source_uri = "http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img"
description = "heres a tiny linux image, not an iso, but a real disk!"
}
# ### Define Terraform Managed Subnets
resource "nutanix_subnet" "infra-managed-network-140" {
# What cluster will this VLAN live on?
cluster_uuid = local.cluster1
# General Information
name = "infra-managed-network-140"
vlan_id = 140
subnet_type = "VLAN"
# Provision a Managed L3 Network
# This bit is only needed if you intend to turn on AHV's IPAM
subnet_ip = "10.xx.xx.xx"
default_gateway_ip = "10.xx.xx.xx"
prefix_length = 24
dhcp_options = {
boot_file_name = "bootfile"
domain_name = "lab"
tftp_server_name = "10.xx.xx.xx"
}
dhcp_server_address = {
ip = "10.xx.xx.xx"
}
dhcp_domain_name_server_list = ["10.xx.xx.xx"]
dhcp_domain_search_list = ["ntnxlab.local"]
#ip_config_pool_list_ranges = ["10.xx.xx.xx 10.xx.xx.xx"]
}
resource "nutanix_virtual_machine" "demo-01-web" {
# General Information
name = "demo-01-web"
description = "demo Frontend Web Server"
num_vcpus_per_socket = 2
num_sockets = 1
memory_size_mib = 4096
cluster_uuid = local.cluster1
nic_list {
subnet_uuid = nutanix_subnet.infra-managed-network-140.id
}
disk_list {
data_source_reference = {
kind = "image"
uuid = nutanix_image.cirros-034-disk.id
}
device_properties {
disk_address = {
device_index = 0
adapter_type = "SCSI"
}
device_type = "DISK"
}
}
disk_list {
disk_size_mib = 100000
disk_size_bytes = 104857600000
}
}
resource "time_sleep" "wait_120_seconds" {
create_duration = "120s"
}
data "nutanix_virtual_machine" "demo-01-web-data" {
depends_on = [ time_sleep.wait_120_seconds ]
vm_id = nutanix_virtual_machine.demo-01-web.id
}
# Show IP address
output "ip_address" {
value = nutanix_virtual_machine.demo-01-web-data.nic_list_status[0].ip_endpoint_list[0].ip
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment