vmware / terraform-provider-vcd

Terraform VMware Cloud Director provider
https://www.terraform.io/docs/providers/vcd/
Mozilla Public License 2.0
149 stars 111 forks source link

retain_ip_mac_enabled does not retain ip address of vapp_template vms mac address #815

Open Prasaddiwalkar opened 2 years ago

Prasaddiwalkar commented 2 years ago

Hello,

Thank you for opening an issue. Please note that we try to keep the Terraform issue tracker reserved for bug reports and feature requests. For general usage questions, please see: https://www.terraform.io/community.html.

Terraform Version

Run terraform -v to show the version. If you are not running the latest version of Terraform, please upgrade because your issue may have already been fixed.

Affected Resource(s)

Please list the resources as a list, for example:

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

terraform {
  required_providers {
    vcd = {
      source = "vmware/vcd"
    }
  }
  required_version = ">= 0.13"
}

variable "vcd_user" {
    description = "vCloud user"
}
variable "vcd_pass" {
    description = "vCloud pass"
}
variable "vcd_allow_unverified_ssl" {
    default = true
}
variable "vcd_url" {}
variable "org_name" {}
variable "org_vdc" {}
variable "auth_type" {
default = "integrated"  
}

variable "vcd_max_retry_timeout" {
    default = 60
}

# Configure the VMware Cloud Director Provider
provider "vcd" {
  user                 = var.vcd_user
  password             = var.vcd_pass
  auth_type            = var.auth_type
  org                  = var.org_name
  vdc                  = var.org_vdc
  url                  = var.vcd_url
  max_retry_timeout    = 2
  allow_unverified_ssl = true

}

######################

data "vcd_catalog_item" "vapp_template" {
  org     = var.org_name
  catalog = "DEV_Public"
  name    = "SLCMV2_AES_TC133AW60_0123"
}

resource "vcd_vapp" "terraform_vapp" {
  name = "terraform_vapp"
  power_on = "true"
  description= "vApp using terraform"
  lease {
    runtime_lease_in_sec = 60 * 60 * 24 * 7 # extends the runtime lease to 7 days
    storage_lease_in_sec = 60 * 60 * 24 * 14  # extends the storage lease to 14 days
  }

  metadata = data.vcd_catalog_item.vapp_template.metadata
}

resource "vcd_vapp_network" "vapp-net" {
  name                  = "vAppNet-vApp_Network"
  vapp_name             = vcd_vapp.terraform_vapp.name
  org_network_name      = "New_Routed_Network"
  gateway               = "192.168.2.1"
  description           = "vAppNet-vApp_Network"
  guest_vlan_allowed    = false
  retain_ip_mac_enabled = true
  netmask               = "255.255.255.0"
  dns1 = "161.134.128.141"
  dns2 = "209.243.245.148"
  dns_suffix = "net.plm.eds.com"
  static_ip_pool {
    start_address = "192.168.2.100"
    end_address   = "192.168.2.150"
  }
  dhcp_pool {
    default_lease_time = 3600
    enabled = false
    max_lease_time = 7200
    start_address = "192.168.2.151"
    end_address = "192.168.2.200"
  }
}

# resource "vcd_vapp_vm" "terraform_lnx64_vm" {
#   vapp_name = vcd_vapp.terraform_vapp.name
#   name      = "terraform_lnx64_vm"

#   network {
#     type = "vapp"
#     adapter_type = "VMXNET3"
#     is_primary = true
#     ip_allocation_mode = "POOL"
#     name  = vcd_vapp_network.vapp-net.name
#   }
#   catalog_name  = "DEV_Public"
#   template_name = "RAD_Tc132AW52_linux_redhat_Foundation"
#   # template_name = "ARTWORK_TC141AW61_LNX_TEMPLATE"
#   # 
#   description= "vApp vm using terraform"
#   memory = 10240
#   cpus   = 2
#   depends_on = [vcd_vapp.terraform_vapp]

# }

resource "vcd_vapp_vm" "terraform_win_vm" {
  vapp_name = vcd_vapp.terraform_vapp.name
  name      = "terraform_win64_vm"

  network {
    type = "vapp"
    adapter_type = "VMXNET3"
    is_primary = true
    ip_allocation_mode = "POOL"
    name  = vcd_vapp_network.vapp-net.name
  }
  catalog_name  = "DEV_Public"
  template_name = "SLCMV2_AES_TC133AW60_0123"
  description= "vApp vm using terraform Windows"
  memory = 32768
  cpus   = 8

  depends_on = [vcd_vapp.terraform_vapp]
}

##########################

Debug Output

Please provide a link to GitHub Gist(s) containing complete debug output. You can enable debug by using the commands below:

export TF_LOG_PATH=tf.log            
export TF_LOG=TRACE                  
export GOVCD_LOG_FILE=go-vcloud-director.log
export GOVCD_LOG=true     

tf.log go-vcloud-director.log

Panic Output

Expected Behavior

Expected behavior when I set retain_ip_mac_enabled = true newly created vcd_vapp_vm should have same mac address of vcd_vatalog_items vm.

Actual Behavior

Always generate new mac address for newly spinned vm

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform init
  2. terraform plan
  3. terraform apply

User Access rights

Information about user used. Role and/or more exact rights if it is customized.

Important Factoids

Is there anything atypical about your accounts that we should know?

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

Prasaddiwalkar commented 2 years ago

Any updates?

vbauzys commented 2 years ago

Hi @Prasaddiwalkar Looks like this VCD this feature isn't what you expect: https://docs.vmware.com/en/VMware-Cloud-Director/9.7/com.vmware.vcloud.user.doc/GUID-249A5B8E-65C5-48F1-8BCB-AD0E08D97EF0.html

This feature allows the vApp to retain its assigned IP even after stopping and expiring the vApp

Prasaddiwalkar commented 2 years ago

Hi @Prasaddiwalkar Looks like this VCD this feature isn't what you expect: https://docs.vmware.com/en/VMware-Cloud-Director/9.7/com.vmware.vcloud.user.doc/GUID-249A5B8E-65C5-48F1-8BCB-AD0E08D97EF0.html

This feature allows the vApp to retain its assigned IP even after stopping and expiring the vApp

When I provision vApp from vApp_template using powershell it copies all the VM details from template.

How to achieve this behaviour using terraform?

Prasaddiwalkar commented 2 years ago

This is important to us, to migrate from our SDK base infrastructure provisioning tool to terraform. Can you please look into this issue?

vbauzys commented 2 years ago

Hi @Prasaddiwalkar we are currently quite busy with the last phase of release. I scanned the code and looks like that with current implementation there isn't a way to inherit network settings from the Vapp template.