-
Notifications
You must be signed in to change notification settings - Fork 112
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
Add support for network_dhcp_wait_seconds
invcd_vapp_vm
#436
Conversation
network_dhcp_wait_seconds
network_dhcp_wait_seconds
invcd_vapp_vm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First scroll :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Tried with BTW:
|
log.Printf("[DEBUG] [VM read] VM %s timed out waiting %d seconds "+ | ||
"to report DHCP IPs. You may want to increase 'network_dhcp_wait_seconds' or ensure "+ | ||
"your DHCP settings are correct.\n", vm.VM.Name, maxDhcpWaitSeconds) | ||
_, _ = fmt.Fprintf(getTerraformStdout(), "WARNING: VM %s timed out waiting %d seconds "+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to hit the timeout. It's nice that we get the WARNING inside the console. However, the further plan ended up running with a bunch of errors, because NAT+FW rules tried to use empty IP. Do we have any way to protect against that or workaround in the .tf
config itself?
vcd_vapp_vm.demo_vm_wordpress: Still creating... [4m50s elapsed]
WARNING: VM demo-vm-wordpress timed out waiting 60 seconds to report DHCP IPs. You may want to increase 'network_dhcp_wait_seconds' or ensure your DHCP settings are correct.
vcd_vapp_vm.demo_vm_wordpress: Creation complete after 4m52s [id=urn:vcloud:vm:5322ba15-9fc6-4e56-a193-6072f6c66129]
vcd_nsxv_dnat.demo_dnat_wordpress_ssh: Modifying... [id=196613]
vcd_nsxv_snat.web: Modifying... [id=196612]
vcd_nsxv_dnat.demo_dnat_wordpress_https: Modifying... [id=196614]
vcd_nsxv_firewall_rule.demo-nsxv-fw-rule-outbound: Modifying... [id=131079]
vcd_nsxv_dnat.demo_dnat_wordpress_https: Still modifying... [id=196614, 10s elapsed]
vcd_nsxv_firewall_rule.demo-nsxv-fw-rule-outbound: Still modifying... [id=131079, 10s elapsed]
vcd_nsxv_firewall_rule.demo-nsxv-fw-rule-outbound: Still modifying... [id=131079, 20s elapsed]
vcd_nsxv_firewall_rule.demo-nsxv-fw-rule-outbound: Modifications complete after 25s [id=131079]
Error: unable to update NAT rule with ID 196614: error while updating NAT rule : vShield Edge Invalid IP Address input /32 for field translatedAddress. (API error: 15012)
on xendi.tf line 393, in resource "vcd_nsxv_dnat" "demo_dnat_wordpress_https":
393: resource "vcd_nsxv_dnat" "demo_dnat_wordpress_https" {
Error: unable to update NAT rule with ID 196613: error while updating NAT rule : vShield Edge Invalid IP Address input /32 for field translatedAddress. (API error: 15012)
on xendi.tf line 411, in resource "vcd_nsxv_dnat" "demo_dnat_wordpress_ssh":
411: resource "vcd_nsxv_dnat" "demo_dnat_wordpress_ssh" {
Error: unable to update NAT rule with ID 196612: error while updating NAT rule : vShield Edge Invalid IP Address input /32 for field originalAddress. (API error: 15012)
on xendi.tf line 430, in resource "vcd_nsxv_snat" "web":
430: resource "vcd_nsxv_snat" "web" {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first thing that comes to my mind is actually returning an error during READ instead of warning. But there are a few problems and I believe this isn't good enough:
- READ is part of CREATE/UPDATE so creation could fail because of too small value.
- Because READ accesses the configuration from statefile, even changing the value to a higher one (say from 1 second to 300 seconds) would still at first try to READ with 1 second (because plan/apply triggers READ before UPDATE). If it fails immediately then the user never gets to 300 seconds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, looks like current behavior is actually correct. Given that VM does get created even though without IP address, we shouldn't report an error. In a sense, we're missing a special state in the Terraform state machine to model such incomplete executions. All in all, let's leave current implementation intact.
Tried one more time with Org VDC network with DHCP pool:
Now the IP assigned to VM was from this pool and the log said it got it after lease check (as opposed to guest tools):
And IP from the pool inside Terraform:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One very practical feature, LTGM now!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Closes https://github.com/terraform-providers/terraform-provider-vcd/issues/316
This PR adds a parameter
network_dhcp_wait_seconds
forvcd_vapp_vm
resource and data source. The parameter makes it possible to retrieveip
field innetwork
block on the firstapply
run whenip_allocation_mode=DHCP
. The drawback of it is that READ for the functions takes longer. For this function to work VM must be powered on and at least one of the following must be true:The feature got the current state after ruling out a few other options. I'm leaving it here to either avoid discussion of what is not possible or to spark some better ideas:
Problem 1: Changing the value of field
network_dhcp_wait_seconds
will actually show a change inplan
and an update although it will result in no opupdate
. The reason for this is that in READ functiond.Get("network_dhcp_wait_seconds")
actually gets the value not from.tf config
, but fromstatefile
. Apparently in the READ function there is no way to access value of.tf config
(open issue for that hashicorp/terraform-plugin-sdk#133). IfDiffSuppressFunc
is used - thend.Get("network_dhcp_wait_seconds")
always receives 0 (default TypeInt value).Problem 2: Initially I had idea to add this field to each of
network
block however there are a few issues about it:network
block definednetwork_dhcp_wait_seconds
value would cause wholenetwork
block to be reported as changed. It could confuse the user of updating network adapter itself (which is not the case here). Also it does not make sense to have different timings for each DHCP NIC as the lookup checks all of them at the same time (to save on API calls) and would still take as the longest time defined.Note. Test suite passed on 9.5.