Open lvirbalas opened 4 years ago
The field power_on
is not state. It's a directive for create and update.
If we want to detect state, we need to add a new field state
(and eventually state_text
) as we did for vApp.
The reason for such implementation is that the "powered on" corresponds to several status codes. If we tie the current power_on
field to status 4 (= POWERED_ON) we will get a mismatch when the VM is in intermediate states that are not OFF, but not ON either, and we will have a request to update while the VM is reaching the online state.
This is a (possibly incomplete) list of the statuses available to vApp and VM
-1: "FAILED_CREATION",
0: "UNRESOLVED",
1: "RESOLVED",
2: "DEPLOYED",
3: "SUSPENDED",
4: "POWERED_ON",
5: "WAITING_FOR_INPUT",
6: "UNKNOWN",
7: "UNRECOGNIZED",
8: "POWERED_OFF",
9: "INCONSISTENT_STATE",
10: "MIXED",
11: "DESCRIPTOR_PENDING",
12: "COPYING_CONTENTS",
13: "DISK_CONTENTS_PENDING",
14: "QUARANTINED",
15: "QUARANTINE_EXPIRED",
16: "REJECTED",
17: "TRANSFER_TIMEOUT",
18: "VAPP_UNDEPLOYED",
19: "VAPP_PARTIALLY_DEPLOYED",
If we map 1-to-1 the power_on
field to the VM status, most likely we get a state comparison failure, because the VM could be in an intermediate state before reaching the wanted one. Notice that the status field is overloaded by meanings that have nothing to do with the VM being online or not.
This is not similar to what happens when we modify,, say, the amount of memory. If we change the memory outside of Terraform, at the next read we will get the exact memory that is now assigned, not an intermediate value, and a reconciliation is immediately possible.
With the VM status, this is not feasible. If we make, for example, a wanted_status="POWERED_ON"
, the state comparison will return an error if the status is in an intermediate phase, meaning that it will eventually be online, but not just yet. If we act on such state discrepancy and try to force a power on operation, we would get a further error because we can't power on an already online VM.
I suggest two actions:
status
and status_text
like we have in vApppower_on
does not collect state, but is only a request for action.
Affected Resource(s)
Terraform Configuration Files
Steps to Reproduce
terraform plan
.Expected Behavior
The plan should show that the actual VM is powered off and suggest to reconcile the state (power it back on).
Actual Behavior
Terraform doesn't notice the change in VM:
References
Here's a similar example where it does work. Change VM CPU count in UI and run Terraform. It will reconcile the state: