hashicorp / terraform-provider-vsphere

Terraform Provider for VMware vSphere
https://registry.terraform.io/providers/hashicorp/vsphere/
Mozilla Public License 2.0
622 stars 453 forks source link

creating a `vsphere_vapp_entity` for VMs, created with a count loop, requires two `terraform apply` runs #2141

Open erSitzt opened 8 months ago

erSitzt commented 8 months ago

Community Guidelines

Terraform

1.7.4

Terraform Provider

v2.6.1

VMware vSphere

v7.0.3

Description

The vsphere_vapp_entity settings are only created/set for a single VM in the loop. Maybe the first completed... not sure. A second run is needed to apply the settings for all VMs.

Affected Resources or Data Sources

resource/vsphere_vapp_entity

Terraform Configuration

This is my config. I create several (k8s-server-/k8s-agent-) VMs using a count loop.

resource "vsphere_vapp_entity" "vapp-entity-server-nodes" {
  for_each = { for idx, moid in vsphere_virtual_machine.rke-server-nodes.*.moid : idx => {"moid" = moid} }
  target_id    = each.value.moid
  container_id = "${vsphere_vapp_container.vapp_container.id}"
  start_action = "powerOn"
  stop_action  = "guestShutdown"
  start_order = 1
  start_delay = 30
  stop_delay = 30

  depends_on = [ vsphere_virtual_machine.rke-server-nodes ]
}

resource "vsphere_vapp_entity" "vapp-entity-agent-nodes" {
  for_each = { for idx, moid in vsphere_virtual_machine.rke-agent-nodes.*.moid : idx => {"moid" = moid} }
  target_id    = each.value.moid
  container_id = "${vsphere_vapp_container.vapp_container.id}"
  start_action = "powerOn"
  stop_action  = "guestShutdown"
  start_order = 2
  start_delay = 30
  stop_delay = 30

  depends_on = [ vsphere_virtual_machine.rke-agent-nodes ]
}

resource "vsphere_vapp_entity" "vapp-entity-rke-lb" {
  target_id    = "${vsphere_virtual_machine.rke-lb.moid}"
  container_id = "${vsphere_vapp_container.vapp_container.id}"
  start_action = "powerOn"
  stop_action  = "guestShutdown"
  start_order = 1
  start_delay = 30
  stop_delay = 30

  depends_on = [ vsphere_virtual_machine.rke-lb ]
}

Debug Output

I have removed everything after the vsphere provider exited.. https://gist.github.com/erSitzt/166b721cdad2605cab740269304996b5

Panic Output

No response

Expected Behavior

All settings in one go..

Actual Behavior

Two runs necessary to finish the configuration

Steps to Reproduce

Create vsphere_vapp_entity for a bunch of VMs created by using count

Environment Details

❯ terraform version
Terraform v1.7.4
on linux_amd64
+ provider registry.terraform.io/gitlabhq/gitlab v16.5.0
+ provider registry.terraform.io/hashicorp/dns v3.4.0
+ provider registry.terraform.io/hashicorp/external v2.3.3
+ provider registry.terraform.io/hashicorp/helm v2.12.1
+ provider registry.terraform.io/hashicorp/kubernetes v2.26.0
+ provider registry.terraform.io/hashicorp/local v2.4.1
+ provider registry.terraform.io/hashicorp/null v3.2.2
+ provider registry.terraform.io/hashicorp/template v2.2.0
+ provider registry.terraform.io/hashicorp/time v0.10.0
+ provider registry.terraform.io/hashicorp/vsphere v2.6.1
+ provider registry.terraform.io/rancher/rancher2 v3.1.1
+ provider registry.terraform.io/salrashid123/http-full v1.3.1

Screenshots

No response

References

No response

github-actions[bot] commented 8 months ago

Hello, erSitzt! 🖐

Thank you for submitting an issue for this provider. The issue will now enter into the issue lifecycle.

If you want to contribute to this project, please review the contributing guidelines and information on submitting pull requests.

erSitzt commented 6 months ago

Still an issue

❯ terraform version
Terraform v1.8.3
on linux_amd64
+ provider registry.terraform.io/gitlabhq/gitlab v16.5.0
+ provider registry.terraform.io/hashicorp/external v2.3.3
+ provider registry.terraform.io/hashicorp/helm v2.13.2
+ provider registry.terraform.io/hashicorp/kubernetes v2.30.0
+ provider registry.terraform.io/hashicorp/local v2.5.1
+ provider registry.terraform.io/hashicorp/null v3.2.2
+ provider registry.terraform.io/hashicorp/template v2.2.0
+ provider registry.terraform.io/hashicorp/time v0.11.1
+ provider registry.terraform.io/hashicorp/vault v4.2.0
+ provider registry.terraform.io/hashicorp/vsphere v2.8.1
+ provider registry.terraform.io/rancher/rancher2 v3.1.1
+ provider registry.terraform.io/salrashid123/http-full v1.3.1