Skip to content

Instantly share code, notes, and snippets.

@gowatana

gowatana/main.tf Secret

Last active June 12, 2025 15:47
Show Gist options
  • Select an option

  • Save gowatana/1f4a05d41758b85ff8c4e1d20e469f7c to your computer and use it in GitHub Desktop.

Select an option

Save gowatana/1f4a05d41758b85ff8c4e1d20e469f7c to your computer and use it in GitHub Desktop.
terraform {
required_providers {
nutanix = {
source = "nutanix/nutanix"
version = "2.2.0"
}
}
}
provider "nutanix" {
username = "admin"
password = "パスワード"
endpoint = "lab-nxpc-01.go-lab.jp"
port = 9440
insecure = true
wait_timeout = 10
foundation_endpoint = "0.0.0.0"
ndb_endpoint = "0.0.0.0"
ndb_username = "none"
ndb_password = "none"
}
data "nutanix_clusters_v2" "cluster1" {
filter = "name eq 'lab-nxce-10'"
}
resource "nutanix_subnet_v2" "ext-subnet1" {
name = "nw-vlan-21-extnat"
description = null
cluster_reference = data.nutanix_clusters_v2.cluster1.cluster_entities[0].ext_id
is_external = true
is_nat_enabled = true
network_id = 21
subnet_type = "VLAN"
ip_config {
ipv4 {
ip_subnet {
ip { value = "192.168.21.0" }
prefix_length = 24
}
default_gateway_ip { value = "192.168.21.1" }
pool_list {
start_ip { value = "192.168.21.10" }
end_ip { value = "192.168.21.29" }
}
}
}
}
resource "nutanix_vpc_v2" "vpc1" {
name = "vpc-11"
external_subnets {
subnet_reference = resource.nutanix_subnet_v2.ext-subnet1.ext_id
}
}
data "nutanix_route_tables_v2" "table1" {
filter = "vpcReference eq '${nutanix_vpc_v2.vpc1.ext_id}'"
}
resource "nutanix_routes_v2" "route1" {
name = "route1"
description = null
vpc_reference = resource.nutanix_vpc_v2.vpc1.ext_id
route_type = "STATIC"
route_table_ext_id = data.nutanix_route_tables_v2.table1.route_tables[0].ext_id
destination {
ipv4 {
ip { value = "0.0.0.0" }
prefix_length = 0
}
}
next_hop {
next_hop_type = "EXTERNAL_SUBNET"
next_hop_reference = resource.nutanix_subnet_v2.ext-subnet1.ext_id
}
}
resource "nutanix_subnet_v2" "overlay1" {
name = "overlay-11"
subnet_type = "OVERLAY"
vpc_reference = resource.nutanix_vpc_v2.vpc1.ext_id
description = null
ip_config {
ipv4 {
ip_subnet {
ip { value = "10.0.11.0" }
prefix_length = 24
}
default_gateway_ip { value = "10.0.11.1" }
pool_list {
start_ip { value = "10.0.11.10" }
end_ip { value = "10.0.11.19" }
}
}
}
dhcp_options {
domain_name_servers {
ipv4 { value = "192.168.1.101" }
}
domain_name_servers {
ipv4 { value = "192.168.1.102" }
}
search_domains = ["go-lab.jp"]
}
}
data "nutanix_images_v2" "image1" {
filter = "name eq 'OL9U5_x86_64-kvm-b253.qcow2'"
}
resource "nutanix_virtual_machine_v2" "vm1" {
name = "web-01"
description = null
cluster {
ext_id = data.nutanix_clusters_v2.cluster1.cluster_entities[0].ext_id
}
num_sockets = 1
num_cores_per_socket = 1
memory_size_bytes = (1024 * 1024 * 1024) * 1 # GiB
disks {
backing_info {
vm_disk {
data_source {
reference {
image_reference {
image_ext_id = data.nutanix_images_v2.image1.images[0].ext_id
}
}
}
}
}
}
nics {
network_info {
subnet { ext_id = resource.nutanix_subnet_v2.overlay1.ext_id }
}
}
boot_config {
legacy_boot {
boot_order = ["CDROM", "DISK"]
}
}
guest_customization {
config {
cloud_init {
cloud_init_script {
user_data {
value = <<EOF
I2Nsb3VkLWNvbmZpZwoKZGlzYWJsZV9yb290OiB0cnVlCnNzaF9wd2F1dGg6IHRydWUKcGFja2Fn
ZV91cGdyYWRlOiBmYWxzZQoKdXNlcnM6Ci0gbmFtZTogbnV0YW5peAogIHNoZWxsOiAvYmluL2Jh
c2gKICBsb2NrLXBhc3N3ZDogZmFsc2UKICBzdWRvOiBBTEw9KEFMTCkgTk9QQVNTV0Q6QUxMCgpj
aHBhc3N3ZDoKICBsaXN0OiB8CiAgICBudXRhbml4Om51dGFuaXgvNHUKICBleHBpcmU6IGZhbHNl
Cgp3cml0ZV9maWxlczoKLSBwYXRoOiAvZXRjL3N5c3RlbWQvc3lzdGVtL2RlbW8td2ViLnNlcnZp
Y2UKICBjb250ZW50OiB8CiAgICBbVW5pdF0KICAgIERlc2NyaXB0aW9uPURlbW8gV2ViIFNlcnZl
cgogICAgQWZ0ZXI9bmV0d29yay50YXJnZXQKICAgIFtTZXJ2aWNlXQogICAgRXhlY1N0YXJ0PS91
c3IvYmluL3B5dGhvbjMgLW0gaHR0cC5zZXJ2ZXIgODA4MCAtLWRpcmVjdG9yeSAvdG1wL3d3dwog
ICAgUmVzdGFydD1hbHdheXMKICAgIFVzZXI9cm9vdAogICAgW0luc3RhbGxdCiAgICBXYW50ZWRC
eT1tdWx0aS11c2VyLnRhcmdldAoKcnVuY21kOgogIC0gbWtkaXIgLXAgL3RtcC93d3cKICAtIGVj
aG8gIldlYiAkKGhvc3RuYW1lIC1JIHwgYXdrICd7cHJpbnQgJDF9JykiID4gL3RtcC93d3cvaW5k
ZXguaHRtbAogIC0gc3lzdGVtY3RsIGRhZW1vbi1yZWxvYWQKICAtIHN5c3RlbWN0bCBlbmFibGUg
LS1ub3cgZGVtby13ZWIKICAtIGZpcmV3YWxsLWNtZCAtLXBlcm1hbmVudCAtLWFkZC1wb3J0PTgw
ODAvdGNwCiAgLSBmaXJld2FsbC1jbWQgLS1yZWxvYWQKCg==
EOF
}
}
}
}
}
lifecycle {
ignore_changes = [
guest_customization,
cd_roms
]
}
}
resource "nutanix_floating_ip_v2" "fip1" {
name = "fip1"
description = null
external_subnet_reference = resource.nutanix_subnet_v2.ext-subnet1.ext_id
association {
vm_nic_association {
vm_nic_reference = nutanix_virtual_machine_v2.vm1.nics[0].ext_id
}
}
}
output "vm_ip" {
value = nutanix_virtual_machine_v2.vm1.nics[0].network_info[0].ipv4_config[0].ip_address[0].value
}
output "vm_fip" {
value = nutanix_floating_ip_v2.fip1.floating_ip[0].ipv4[0].value
}
@gowatana
Copy link
Author

gowatana commented May 22, 2025

下記の投稿むけ。

Terraform で FVN の NAT VPC を構成してみる。Part-03:VPC と仮想マシンの作成(tf ファイル集約)
https://blog.ntnx.jp/entry/2025/05/22/235926

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment