-
-
Save ppanula/7d275086d6ba3492e92206122affbdcf to your computer and use it in GitHub Desktop.
main.tf
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
terraform { | |
required_providers { | |
nutanix = { | |
source = "nutanix/nutanix" | |
version = "1.7.1" | |
} | |
} | |
} | |
# provider authentication | |
provider "nutanix" { | |
username = var.prism_user | |
password = var.prism_password | |
endpoint = var.prism_server | |
insecure = true | |
wait_timeout = 60 | |
} | |
# region datasources | |
data "nutanix_cluster" "cluster" { | |
name = var.cluster_name | |
} | |
data "nutanix_subnet" "network" { | |
subnet_name = var.nutanix_network | |
} | |
data "nutanix_image" "image" { | |
image_name = var.nutanix_image | |
} | |
data "template_file" "cloud" { | |
count = var.vm_count | |
template = file("cloud-init") | |
vars = { | |
vm_user = var.vm_user | |
vm_name = "${var.vm_name}-${count.index + 1}" | |
vm_domain = var.vm_domain | |
vm_public_key = var.vm_public_key | |
vm_password = var.vm_password | |
} | |
} | |
resource "nutanix_virtual_machine" "vm" { | |
count = var.vm_count | |
name = "${var.vm_name}-${count.index + 1}" | |
num_vcpus_per_socket = var.vm_num_vcpus_per_socket | |
num_sockets = var.vm_cpu | |
memory_size_mib = var.vm_ram | |
cluster_uuid = data.nutanix_cluster.cluster.id | |
boot_type = "SECURE_BOOT" | |
machine_type = "Q35" | |
guest_customization_cloud_init_user_data = base64encode("${element(data.template_file.cloud.*.rendered,count.index)}") | |
nic_list { | |
subnet_uuid = data.nutanix_subnet.network.id | |
} | |
disk_list { | |
data_source_reference = { | |
kind = var.nutanix_image_source_reference | |
uuid = data.nutanix_image.image.id | |
} | |
} | |
disk_list { | |
disk_size_bytes = 0 | |
data_source_reference = {} | |
device_properties { | |
device_type = "CDROM" | |
disk_address = { | |
device_index = "1" | |
adapter_type = "SATA" | |
} | |
} | |
} | |
# disk_list { | |
# device_properties { | |
# disk_address = { | |
# device_index = var.vm_disk_devide_index | |
# adapter_type = var.vm_disk_adapter_type | |
# } | |
# device_type = var.vm_disk_type | |
# } | |
# disk_size_mib = (var.vm_disk_size_gb * 1024) | |
# } | |
nutanix_guest_tools = { | |
state = "ENABLED", | |
ngt_state = "INSTALLED", | |
# iso_mount_state = "MOUNTED" | |
} | |
ngt_enabled_capability_list = [ ] | |
} | |
# endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment