From c82eba31b839bc95390b5684cf72d3757b9c1913 Mon Sep 17 00:00:00 2001 From: Andy Miles Date: Thu, 5 Dec 2024 07:24:24 -0800 Subject: [PATCH] adding ssh for debug --- terraform/main.tf | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/terraform/main.tf b/terraform/main.tf index 61d1428..d871c8a 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -2,10 +2,15 @@ provider "aws" { region = "us-west-2" } + resource "aws_key_pair" "deployer" { + key_name = "my-key-pair" # Set this to any descriptive name you prefer + public_key = file("~/.ssh/id_rsa.pub") # Path to your public key file + } + resource "aws_instance" "py_server" { ami = "ami-06946f6c9b153d494" instance_type = "t2.micro" - + key_name = aws_key_pair user_data = <<-EOF #!/bin/bash sudo apt-get update @@ -26,9 +31,29 @@ resource "aws_instance" "py_server" { Name = "FlaskAppInstance" } - vpc_security_group_ids = [aws_security_group.allow_http.id] + vpc_security_group_ids = [aws_security_group.allow_http.id, + aws_security_group.allow_ssh.id] } + resource "aws_security_group" "allow_ssh" { + name = "allow_ssh" + description = "Allow SSH inbound traffic" + + ingress { + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] # Be cautious with this setting; restrict to specific IPs if possible + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + } + resource "aws_security_group" "allow_http" { name = "allow_http_flask_web_app" description = "Allow inbound HTTP traffic"