Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default system metadata is missing via bulk provisioing #1358

Open
JalenMak6 opened this issue Nov 22, 2024 · 1 comment
Open

Default system metadata is missing via bulk provisioing #1358

JalenMak6 opened this issue Nov 22, 2024 · 1 comment

Comments

@JalenMak6
Copy link

Hi Team,

I'm working on a bulk provisioning setup using the Terraform VCD provider, where multiple VMs are being provisioned simultaneously. However, I’ve encountered an issue: only the first VM that is provisioned via Terraform is able to retrieve the default system metadata and also get configured, such as vm.origin.name, vm.origin.type, and vm.origin.id. The subsequent VMs do not have these default system metadata set up on the vm metadata section, even though custom system metadata can be applied correctly to all VMs.

Is this behavior a bug in the VCD provider, or is there a specific configuration or workaround I can use to ensure that all VMs (not just the first one) obtain the default system metadata?

Any insights or suggestions to resolve this issue would be greatly appreciated.

Thank you!

terraform version:
terraform -v
Terraform v1.9.8
on windows_amd64

resource: vcd_vapp_vm
Here is my code

# provider.tf
    vcd = {
      source  = "vmware/vcd"
      version = "3.14.0"
    }
  }
}

provider "vcd" {
  user                 = var.vcd_user
  password             = var.vcd_pass
  auth_type            = "integrated"
  url                  = var.vcd_url
  org                  = var.vcd_org
  vdc                  = var.vcd_vdc
  max_retry_timeout    = var.vcd_max_retry_timeout
  allow_unverified_ssl = var.vcd_allow_unverified_ssl
}

# main.tf
# System administrator rights are required to connect external network

data "vcd_catalog" "my-catalog" {
  org  = var.vcd_org
  name = var.catalog_name
}

data "vcd_catalog_vapp_template" "rhel9" {
  org        = var.vcd_org
  catalog_id = data.vcd_catalog.my-catalog.id
  name       = var.image_name
}

resource "vcd_vapp" "new_vapp" {
  count = var.create_vapp ? 1 : 0 # Create only if the variable is true

  name = var.vapp_name

  metadata_entry {
    key         = "owner"
    value       = "myself"
    type        = "MetadataStringValue"
    user_access = "READWRITE"
    is_system   = false
  }
}

resource "vcd_vapp_org_network" "direct-network" {
  count            = var.create_vapp ? 1 : 0
  vapp_name        = vcd_vapp.new_vapp[count.index].name
  org_network_name = var.org_network_name
}


resource "vcd_vapp_vm" "new-vm" {
  for_each               = var.vm_configurations
  vapp_name              = var.vapp_name
  name                   = each.value.hostname 
  computer_name          = each.value.hostname
  vapp_template_id       = data.vcd_catalog_vapp_template.rhel9.id
  memory                 = each.value.memory    
  cpus                   = each.value.cpus     
  cpu_cores              = each.value.cpu_cores 
  memory_hot_add_enabled = true
  cpu_hot_add_enabled    = true
  description            = "Build via Terraform testing
  depends_on             = [vcd_vapp.new_vapp]
  #depends_on = [vcd_vapp_vm.new-vm[each.key]]

  metadata_entry {
    key         = var.metadata_entry.key
    value       = var.metadata_entry.value
    is_system   = var.metadata_entry.is_system
    user_access = var.metadata_entry.user_access
    type        = var.metadata_entry.type
  }


  network {
    type               = var.network.type
    adapter_type       = var.network.adapter_type
    name               = var.network.name
    ip_allocation_mode = var.network.ip_allocation_mode
    is_primary         = var.network.is_primary
    ip                 = each.value.ip
    connected          = var.network.connected
  }

  customization {
    change_sid                 = true
    allow_local_admin_password = true
    auto_generate_password     = false
    admin_password             = var.customization_local_admin_password
  }

  dynamic "disk" {
    for_each = var.create_independent_disk ? [vcd_independent_disk.myNewIndependentDisk[each.key].name] : []
    content {
      name        = disk.value
      bus_number  = 0
      unit_number = 2
    }
  }
}

# resource "vcd_independent_disk" "myNewIndependentDisk" {
#   count        = var.create_independent_disk ? 1 : 0
#   name         = var.additionaldisk_configuration.name
#   size_in_mb   = var.additionaldisk_configuration.size_in_mb
#   bus_type     = "SCSI"
#   bus_sub_type = "VirtualSCSI"
# }

resource "vcd_independent_disk" "myNewIndependentDisk" {
  for_each     = var.create_independent_disk ? var.vm_configurations : {}
  name         = "${each.key}-disk" # Disk name will be based on VM hostname (e.g., VM1-disk)
  size_in_mb   = var.additionaldisk_configuration.size_in_mb
  bus_type     = "SCSI"
  bus_sub_type = "VirtualSCSI"
}


# terraform.tfvars
# EduCloud connection credential
vcd_user = "myself"
vcd_pass = "myself_pass!"
vcd_org  = "myself-org"

#vapp info
# if you set create_vapp to force, it will not create 
# the vapp_name and org_network_name 
# instaed, it will use the value of vapp_name vairable
# and assign it to be the vapp
create_vapp      = false
vapp_name        = "myself-vapp-test"
org_network_name = "myself-network-p02"


# VM basic information
# A List of VM with arguments 
vm_configurations = {
  "myself-vm7" = {
    hostname  = "myself-vm7"
    ip        = "10.99.39.7"
    memory    = 4096
    cpus      = 4
    cpu_cores = 1
  },
  "myself-vm8" = {
    hostname  = "myself-vm8"
    ip        = "10.99.39.8"
    memory    = 4096
    cpus      = 4
    cpu_cores = 1
  }
}


# Metadata config
metadata_entry = {
  key         = "group_state"
  value       = "Group 1"
  is_system   = false
  user_access = "READWRITE"
  type        = "MetadataStringValue"
}


# Network config 
network = {
  type               = "org"
  adapter_type       = "VMXNET3"
  name               = "myself-network-p02"
  ip_allocation_mode = "MANUAL"
  is_primary         = true
  connected          = true
}

# Local admin password
customization_local_admin_password = "test_password"


# Determine if you need an additional disk
# if create_independent_disk is set to true
# Please uncomment the additionaldisk_configuration variable
create_independent_disk = false
additionaldisk_configuration = {
  name       = "disk5"
  size_in_mb = 20480 # Set your desired disk size here
}


@JalenMak6
Copy link
Author

JalenMak6 commented Nov 22, 2024

I also noticed that for a creating a VM in a new vapp, the default system metadata is generated on the VM. But for the existing vapp, it doesn't generate the default system metadata on VMs (except the first one).

The Issue:
New vApp:
Default system metadata (vm.origin.name, vm.origin.type, vm.origin.id) is generated correctly for all VMs.

Existing vApp:
Only the first VM receives the default system metadata, while subsequent VMs do not, although custom metadata is still applied successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant