Looking at the error output, you can see that Terraform is attempting to connect via SSH to run the commands you’ve specified in your provisioner block, but it is hanging and eventually timing-out. This is because you have not provided a way for it to authenticate with the server.
digitaloceandroplet.terraform (remote-exec): Password: false
digitaloceandroplet.terraform (remote-exec): Private key: false
digitaloceandroplet.terraform (remote-exec): SSH Agent: false
It first tries a password, but one is not provided. Next an SSH key, and finally it looks for a cached SSH key from you local systems SSH agent.
There are two pieces you’ve missed. First, you must provide an SSH key as part of the Droplet resource. In the example bellow I’ve specified it using it’s finger print (generated with ssh-keygen -E md5 -lf ~/.ssh/id_rsa.pub
) but it can also be its ID from the DigitalOcean API. Secondly, you must also provide a connection block. Here I’ve told it to use the SSH agent, but you can also specify a specific key by its local file path.
Here’s a full example:
provider "digitalocean" {
token = "4xxxxxxxxxxxxxxxxxx3cc264"
}
resource "digitalocean_droplet" "terraform" {
image = "ubuntu-16-04-x64"
name = "terrform-droplet"
region = "blr1"
size = "2gb"
monitoring = true
ssh_keys = [
"60:e6:a4:d7:ff:52:d3:ea:4b:c4:6f:j6:37:92:0d:a8"
]
connection {
user = "root"
type = "ssh"
agent = "true"
timeout = "2m"
}
provisioner "remote-exec" {
inline = [
"export PATH=$PATH:/usr/bin",
# install java 8
"sudo add-apt-repository -y ppa:webupd8team/java",
"sudo apt-get update",
"sudo apt-get -y install oracle-java8-installer",
"export JAVA_HOME=/usr/lib/jvm/java-8-oracle",
"sudo apt-get update",
"echo $JAVA_HOME"
]
}
}
Also note that I added a -y
to the add-apt-repository
. Without it, it will hang waiting for user input.
For more info on using Terraform, check out:

by Mitchell Anicas
by Brian Hogan
Terraform is a tool for building and managing infrastructure in an organized way. In this tutorial, you'll install and use Terraform to create an infrastructure on DigitalOcean that consists of two Nginx servers that are load balanced by a DigitalOcean Load Balancer.
error
digitaloceandroplet.terraform: Still creating… (5m20s elapsed)
digitaloceandroplet.terraform (remote-exec): Connecting to remote host via SSH…
digitaloceandroplet.terraform (remote-exec): Host: 13x.xx.xx.xx4
digitaloceandroplet.terraform (remote-exec): User: root
digitaloceandroplet.terraform (remote-exec): Password: false
digitaloceandroplet.terraform (remote-exec): Private key: false
digitaloceandroplet.terraform (remote-exec): SSH Agent: false
digitaloceandroplet.terraform: Still creating… (5m30s elapsed)
Error: Error applying plan:
1 error(s) occurred:
digitalocean_droplet.terraform: 1 error(s) occurred:
timeout
Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
this is the output