Giter VIP home page Giter VIP logo

Comments (10)

atif089 avatar atif089 commented on August 30, 2024 2

Update.

I think the reason for this nor working is that remote-exec is trying execution a bit too early. I fixed this by adding a workaround local-exec provisioner to wait for a few more seconds.

provisioner "local-exec" {
  command = "ping 127.0.0.1 -n 30 > nul"
  on_failure = "continue"
}

from terraform-provider-digitalocean.

danreeves avatar danreeves commented on August 30, 2024

I'm getting this issue and the suggested workaround doesn't help

from terraform-provider-digitalocean.

atif089 avatar atif089 commented on August 30, 2024

@danreeves are you on Linux. In that case, you would need

provisioner "local-exec" {
  command = "sleep 30"
  on_failure = "continue"
}

@andrewsomething Do you think this should be closed without fixing? Although the workaround works but I think it needs to be fixed so that we don't have to add this.

from terraform-provider-digitalocean.

danreeves avatar danreeves commented on August 30, 2024

@atif089 I tried that but the sleep 30 doesn't seem to block at all. Maybe I've got my file structured incorrectly?

resource "digitalocean_droplet" "www-1" {
  ...digital ocean setup...

  provisioner "local-exec" {
    command = "sleep 30"
    on_failure = "continue"
  }

  provisioner "remote-exec" {
    ...
  }

  connection {
    ...ssh stuff...
  }
}

from terraform-provider-digitalocean.

atif089 avatar atif089 commented on August 30, 2024

@danreeves Looks good to me. You can try removing the on_failure line. If there is any problem with the sleep command it should break before the remote-exec

You can also try adding a dummy remote-exec with an echo command or something which should timeout in 30 seconds.

from terraform-provider-digitalocean.

danreeves avatar danreeves commented on August 30, 2024

No difference. Here's what the output looks like for that part, as you can see sleep 30 doesn't block.

digitalocean_droplet.www-1: Still creating... (1m0s elapsed)
digitalocean_droplet.www-1: Provisioning with 'local-exec'...
digitalocean_droplet.www-1 (local-exec): Executing: ["/bin/sh" "-c" "sleep 30"]
digitalocean_droplet.www-1: Still creating... (1m10s elapsed)
digitalocean_droplet.www-1: Still creating... (1m20s elapsed)
digitalocean_droplet.www-1: Still creating... (1m30s elapsed)
digitalocean_droplet.www-1: Provisioning with 'remote-exec'...

from terraform-provider-digitalocean.

atif089 avatar atif089 commented on August 30, 2024

Try increasing the timeout. I'm assuming DO is taking more than 30 seconds to create the droplet. I can see sleep 30 executing fine

from terraform-provider-digitalocean.

danreeves avatar danreeves commented on August 30, 2024

Ah, you're totally right, I didn't understand the output. Upped the timeout and it worked. This really shouldn't be necessary though so I'd vote for re-opening the ticket.

Thanks for the help!

from terraform-provider-digitalocean.

andrewsomething avatar andrewsomething commented on August 30, 2024

Unfortunately, I don't think there is much we can do here from the provider side. All we do in the provider is set the IP address for use in the connection once the API reports the Droplet is ready:

https://github.com/terraform-providers/terraform-provider-digitalocean/blob/5f345954158b2bf86fae5369b1a75d5d1e30bba3/digitalocean/resource_digitalocean_droplet.go#L345

The connection and provisioner are part of upstream Terraform core.

I think Still creating... here is a bit misleading, as the resource is not considered "created" until the provisioner completes. So by the time you see Provisioning with 'remote-exec'... in the output, the Droplet has been created on the DigitalOcean side. So the root issue is something with the SSH connection to the Droplet.

@danreeves Are you also trying to use this with a One-Click app like @atif089's example? If so, can you reproduce with a standard Ubuntu image? Please wait while we get your droplet ready... leads me to believe that the One-Click is blocking SSH connections until it has completed its own internal provisioning scripts (e.g configuring Wordpress).

Another potential workaround for this that might be a bit more elegant is to provide the script you want to run in the Droplet's user_data attribute. That way, an SSH connection is not needed. See: https://www.digitalocean.com/docs/droplets/resources/metadata/

There is probably also a feature request to Terraform itself to allow setting a number of retries on thee remote-exec provisioner.

from terraform-provider-digitalocean.

danreeves avatar danreeves commented on August 30, 2024

Yeah I was using a One-click App image. It works perfectly with the plain debian-9-x64 image. I guess I'll do the installs and setup I need myself which is a shame but not a big deal. Thanks again!

from terraform-provider-digitalocean.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.