Created
April 11, 2023 17:05
-
-
Save hrs/0fc70e5a2ef8b88672ddb162b6daedda to your computer and use it in GitHub Desktop.
Minimal Terraform configuration to create an SSH server on AWS.
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
# This builds a publicly available SSH server on EC2. | |
# | |
# Make sure to edit the path to your public SSH key. | |
# | |
# Log in: | |
# | |
# $ ssh ubuntu@$(terraform output -raw public_ip) | |
terraform { | |
required_providers { | |
aws = { | |
source = "hashicorp/aws" | |
version = "~> 4.16" | |
} | |
} | |
required_version = ">= 1.2.0" | |
} | |
provider "aws" { | |
region = "us-west-2" | |
} | |
resource "aws_security_group" "ssh" { | |
name = "allow-ssh" | |
description = "Allows inbound SSH traffic" | |
ingress { | |
from_port = 22 | |
to_port = 22 | |
protocol = "tcp" | |
cidr_blocks = [ | |
"0.0.0.0/0" | |
] | |
} | |
} | |
resource "aws_key_pair" "aws_key" { | |
public_key = file("~/.ssh/id_td_ed25519.pub") | |
} | |
resource "aws_instance" "ssh" { | |
ami = "ami-08d70e59c07c61a3a" | |
instance_type = "t2.micro" | |
key_name = aws_key_pair.aws_key.key_name | |
vpc_security_group_ids = [ | |
aws_security_group.ssh.id | |
] | |
} | |
output "public_ip" { | |
value = aws_instance.ssh.public_ip | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment