Skip to content

Commit 2344427

Browse files
committed
Add support for SSH
1 parent b17a363 commit 2344427

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

terraform-example/main.tf

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ resource "aws_instance" "example_rails_app" {
77
instance_type = "t2.micro"
88
security_groups = ["${aws_security_group.example_rails_app.name}"]
99
user_data = "${template_file.user_data.rendered}"
10+
key_name = "${var.key_pair_name}"
1011

1112
tags {
1213
Name = "Example Rails App"
@@ -33,6 +34,14 @@ resource "aws_security_group" "example_rails_app" {
3334
cidr_blocks = ["0.0.0.0/0"]
3435
}
3536

37+
# Inbound SSH from anywhere
38+
ingress {
39+
from_port = 22
40+
to_port = 22
41+
protocol = "tcp"
42+
cidr_blocks = ["0.0.0.0/0"]
43+
}
44+
3645
# Outbound everything
3746
egress {
3847
from_port = 0

terraform-example/terraform.tfvars.sample

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@
77
#
88

99
# The ID of the AMI created by the packer-example
10-
ami = ""
10+
ami = ""
11+
12+
# The name of a Key Pair that you've created in AWS and have saved on your computer. You will be able to use this Key Pair to SSH to the EC2 instance.
13+
key_pair_name = ""

terraform-example/vars.tf

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ variable "ami" {
22
description = "The ID of the AMI that has Ruby on Rails installed and contains the code from the example-rails-app"
33
}
44

5+
variable "key_pair_name" {
6+
description = "The name of a Key Pair that you've created in AWS and have saved on your computer. You will be able to use this Key Pair to SSH to the EC2 instance."
7+
}
8+
59
variable "port" {
610
description = "The port the Ruby on Rails app should listen on for HTTP requests"
711
default = 8080

0 commit comments

Comments
 (0)