From 56f6ff7f348e55399faec122be911dd89dd4e7dc Mon Sep 17 00:00:00 2001 From: Josh Samuelson Date: Tue, 6 Sep 2022 21:50:00 -0700 Subject: [PATCH 1/4] 03_04 solutions --- main.tf | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- outputs.tf | 12 ++++++------ variables.tf | 8 ++++---- 3 files changed, 56 insertions(+), 14 deletions(-) diff --git a/main.tf b/main.tf index 9b32ce06b..8429eccef 100644 --- a/main.tf +++ b/main.tf @@ -14,11 +14,53 @@ data "aws_ami" "app_ami" { owners = ["979382823631"] # Bitnami } -resource "aws_instance" "web" { - ami = data.aws_ami.app_ami.id - instance_type = "t3.nano" +data "aws_vpc" "default" { + default = true +} + +resource "aws_instance" "blog" { + ami = data.aws_ami.app_ami.id + instance_type = var.instance_type + vpc_security_group_ids = [aws_security_group.blog.id] tags = { - Name = "HelloWorld" + Name = "Learning Terraform" } } + +resource "aws_security_group" "blog" { + name = "blog" + tags = { + Terraform = "true" + } + vpc_id = data.aws_vpc.default.id +} + +resource "aws_security_group_rule" "blog_http_in" { + type = "ingress" + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + security_group_id = aws_security_group.blog.id +} + + +resource "aws_security_group_rule" "blog_https_in" { + type = "ingress" + from_port = 443 + to_port = 443 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + security_group_id = aws_security_group.blog.id +} + + +resource "aws_security_group_rule" "blog_everything_out" { + type = "egress" + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + security_group_id = aws_security_group.blog.id +} diff --git a/outputs.tf b/outputs.tf index b35171bef..7e9410b55 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,7 +1,7 @@ -#output "instance_ami" { -# value = aws_instance.web.ami -#} +output "instance_ami" { + value = aws_instance.blog.ami +} -#output "instance_arn" { -# value = aws_instance.web.arn -#} +output "instance_arn" { + value = aws_instance.blog.arn +} diff --git a/variables.tf b/variables.tf index c750667e0..48b7a7590 100644 --- a/variables.tf +++ b/variables.tf @@ -1,4 +1,4 @@ -#variable "instance_type" { -# description = "Type of EC2 instance to provision" -# default = "t3.nano" -#} +variable "instance_type" { + description = "Type of EC2 instance to provision" + default = "t3.nano" +} \ No newline at end of file From dc48cef17beedfddd8cfc03c45352686b6667cc8 Mon Sep 17 00:00:00 2001 From: Stefan <131394134+Kakaobaum@users.noreply.github.com> Date: Tue, 24 Sep 2024 23:09:30 +0200 Subject: [PATCH 2/4] initial commit --- main.tf | 2 +- outputs.tf | 12 ++++++------ variables.tf | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/main.tf b/main.tf index 9b32ce06b..6c8a886b2 100644 --- a/main.tf +++ b/main.tf @@ -16,7 +16,7 @@ data "aws_ami" "app_ami" { resource "aws_instance" "web" { ami = data.aws_ami.app_ami.id - instance_type = "t3.nano" + instance_type = "var.instance_type tags = { Name = "HelloWorld" diff --git a/outputs.tf b/outputs.tf index b35171bef..c429b19b4 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,7 +1,7 @@ -#output "instance_ami" { -# value = aws_instance.web.ami -#} +output "instance_ami" { + value = aws_instance.web.ami +} -#output "instance_arn" { -# value = aws_instance.web.arn -#} +output "instance_arn" { + value = aws_instance.web.arn +} diff --git a/variables.tf b/variables.tf index c750667e0..60856bc92 100644 --- a/variables.tf +++ b/variables.tf @@ -1,4 +1,4 @@ -#variable "instance_type" { -# description = "Type of EC2 instance to provision" -# default = "t3.nano" -#} +variable "instance_type" { + description = "Type of EC2 instance to provision" + default = "t3.nano" +} From 1bbd9859fc76c7b5e4ceb7549f3ad171ed341a11 Mon Sep 17 00:00:00 2001 From: Stefan <131394134+Kakaobaum@users.noreply.github.com> Date: Tue, 24 Sep 2024 23:12:08 +0200 Subject: [PATCH 3/4] initial commit --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 6c8a886b2..0bfc35451 100644 --- a/main.tf +++ b/main.tf @@ -16,7 +16,7 @@ data "aws_ami" "app_ami" { resource "aws_instance" "web" { ami = data.aws_ami.app_ami.id - instance_type = "var.instance_type + instance_type = var.instance_type tags = { Name = "HelloWorld" From d849880ed5fd6f5c44697dba40c08fc6f8689f27 Mon Sep 17 00:00:00 2001 From: Stefan <131394134+Kakaobaum@users.noreply.github.com> Date: Tue, 24 Sep 2024 23:32:29 +0200 Subject: [PATCH 4/4] create security group --- main.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/main.tf b/main.tf index 8429eccef..21ef484e4 100644 --- a/main.tf +++ b/main.tf @@ -30,6 +30,7 @@ resource "aws_instance" "blog" { resource "aws_security_group" "blog" { name = "blog" + description = "Allow http and https in. Allow anything out." tags = { Terraform = "true" }