On a fresh DigitalOcean account (no pre-existing mitosis tag), tofu/terraform apply in deploy/do fails the first time with:
Error: Error creating firewall: POST https://api.digitalocean.com/v2/firewalls: 422 ... tag mitosis does not exist
digitalocean_firewall.mitosis attaches to tags = ["mitosis"] / source_tags = ["mitosis"], but the mitosis tag only comes into existence implicitly when digitalocean_droplet.leader (tagged ["mitosis"]) is created. There is no dependency between the firewall and the droplet, so they create in parallel and the firewall loses the race — the droplet takes ~30s to create while the firewall POSTs immediately.
Reproduction
Fresh DO account/token, no mitosis tag present.
cd deploy/do && tofu init && tofu apply -var "ssh_public_key=..."
First apply: firewall errors as above (droplet + ssh key succeed).
Re-running apply succeeds because the droplet (hence the tag) now exists.
Observed today on a single-droplet (ha=false) s-4vcpu-8gb / nyc3 deploy from origin/main (b0ea45d). Took two applies to converge.
Suggested fix
Declare the tag explicitly and depend on it, so it exists before either resource that references it:
resource "digitalocean_tag" "mitosis" {
name = "mitosis"
}
Then reference digitalocean_tag.mitosis.name in the droplet's tags and the firewall's tags/source_tags (or add depends_on = [digitalocean_droplet.leader] to the firewall as a minimal fix). An explicit digitalocean_tag resource is the cleaner, idempotent option and also makes destroy clean up the tag.
Impact
Cosmetic-but-confusing for first-time sovereign deploys: the apply looks like it failed, and the droplet is briefly live with no cloud firewall until the second apply attaches it. Worth fixing so the documented one-command deploy converges in a single apply.
What happens
On a fresh DigitalOcean account (no pre-existing
mitosistag),tofu/terraform applyindeploy/dofails the first time with:digitalocean_firewall.mitosisattaches totags = ["mitosis"]/source_tags = ["mitosis"], but themitosistag only comes into existence implicitly whendigitalocean_droplet.leader(tagged["mitosis"]) is created. There is no dependency between the firewall and the droplet, so they create in parallel and the firewall loses the race — the droplet takes ~30s to create while the firewall POSTs immediately.Reproduction
mitosistag present.cd deploy/do && tofu init && tofu apply -var "ssh_public_key=..."applysucceeds because the droplet (hence the tag) now exists.Observed today on a single-droplet (
ha=false)s-4vcpu-8gb/nyc3deploy fromorigin/main(b0ea45d). Took two applies to converge.Suggested fix
Declare the tag explicitly and depend on it, so it exists before either resource that references it:
Then reference
digitalocean_tag.mitosis.namein the droplet'stagsand the firewall'stags/source_tags(or adddepends_on = [digitalocean_droplet.leader]to the firewall as a minimal fix). An explicitdigitalocean_tagresource is the cleaner, idempotent option and also makesdestroyclean up the tag.Impact
Cosmetic-but-confusing for first-time sovereign deploys: the apply looks like it failed, and the droplet is briefly live with no cloud firewall until the second apply attaches it. Worth fixing so the documented one-command deploy converges in a single
apply.