Last active
August 19, 2023 08:09
-
-
Save toshimaru/89bf5ab2d3c2c359f07bcdfc835154bb to your computer and use it in GitHub Desktop.
How to connect to server via SSH and use remote-exec provisioner.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "digitalocean_droplet" "web" { | |
image = "ubuntu-16-04-x64" | |
name = "web-1" | |
region = "sgp1" | |
size = "512mb" | |
ssh_keys = [12345] | |
connection { | |
type = "ssh" | |
user = "root" | |
private_key = "${file("~/.ssh/id_rsa")}" | |
} | |
provisioner "remote-exec" { | |
inline = [ | |
] | |
} | |
} |
2 years late to the party,
Following up on mkempster's code:
data "http" "icanhazip" {
url = "https://icanhazip.com/"
request_headers = {
Accept = "text/*"
}
}
# The IP Address of my laptop. Pass it to the Security Group ingress-rule, to restict SSH Access to the Instance
variable "my_ip" {
type = string
default = chomp(data.http.icanhazip.response_body)
}
resource "aws_security_group" "port_22_ingress_globally_accessible" {
name = "port_22_ingress_globally_accessible"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = [var.my_ip] // IP of my own laptop
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mkempster I have the same issue with you. And part of the solution was to open ssh traffic to all the internet. A not very secure aware move as you also wrote. Have you found any other alternative to that?