my file,but im stuck.can anyone help me!
droplet-terraform.tf
provider "digitalocean" {
token = "4xxxxxxxxxxxxxxxxxx3cc264"
}
resource "digitalocean_droplet" "terraform" {
image = "ubuntu-16-04-x64"
name = "terrform-droplet"
region = "blr1"
size = "2gb"
monitoring = true
provisioner "remote-exec" {
inline = [
"export PATH=$PATH:/usr/bin",
# install java 8
"sudo add-apt-repository 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"
]
}
}
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
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:
This comment has been deleted
This comment has been deleted
Click below to sign up and get $100 of credit to try our products over 60 days!
this is the output
error digitalocean_droplet.terraform: Still creating… (5m20s elapsed) digitalocean_droplet.terraform (remote-exec): Connecting to remote host via SSH… digitalocean_droplet.terraform (remote-exec): Host: 13x.xx.xx.xx4 digitalocean_droplet.terraform (remote-exec): User: root digitalocean_droplet.terraform (remote-exec): Password: false digitalocean_droplet.terraform (remote-exec): Private key: false digitalocean_droplet.terraform (remote-exec): SSH Agent: false digitalocean_droplet.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.