my file,but im stuck.can anyone help me!
droplet-terraform.tfprovider "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"
]
}
}
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.