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

Wait for state "Ready" #163

Open
neic opened this issue Nov 18, 2024 · 0 comments
Open

Wait for state "Ready" #163

neic opened this issue Nov 18, 2024 · 0 comments

Comments

@neic
Copy link

neic commented Nov 18, 2024

Feature request

The documentation is lacking, but it is possible to change the state of an instance from "Running" to "Ready" from inside the instance with curl --unix-socket /dev/incus/sock -X PATCH -d '{"state": "Ready"}' incus/1.0. 1

The incus_instance resource currently have a wait_for_network that checks if a instance have an IPv4-address on any interface. It would be very useful to have something similar to wait for the state/status to be "Ready".

The startup script could set the state to ready when the services on the instance are running. Then terraform could wait for that and continue its work afterwards. In my case I want to contact kubernetes on the newly created instance from the kubectl terraform provider in the same terraform apply. It is currently not possible because terraform would see the incus_instance as done before the kubernetes cluster on it is running and fail to apply the resources with kubectl.

Bug

When setting the state to "Ready" with the above curl call, a subsequent terraform apply would show the following plan:

  # incus_instance.k8s-node[0] will be updated in-place
  ~ resource "incus_instance" "k8s-node" {
      ~ ipv4_address     = "10.60.0.100" -> (known after apply)
      + ipv6_address     = (known after apply)
      ~ mac_address      = "00:16:3e:8f:9c:43" -> (known after apply)
        name             = "k8s-node-0"
      ~ running          = false -> true
      ~ status           = "Ready" -> (known after apply)
      + target           = (known after apply)
        # (7 unchanged attributes hidden)
    }

And after confirming, would fail with:

│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to incus_instance.k8s-node[0], provider
│ "provider[\"registry.opentofu.org/lxc/incus\"]" produced an unexpected new value: .running: was
│ cty.True, but now cty.False.

My guess is that the line that sets the running-argument , should also consider api.Ready.

Alternative

From the CLI the cloud-init status can be checked by incus exec my-instance -- cloud-init status --wait. With the proposed exec from #86, I would expect terraform to wait for the exec block to finish before moving on. It would then be trivial to just do cloud-init status --wait in an exec block. Alternatively, I could just move all my functionality currently implemented with cloud-init to an exec.

Footnotes

  1. I found this out from these fragmented documentation bits: 1, 2, 3, 4

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

No branches or pull requests

1 participant