From 3cb3f0a4ed7d18b4412b0382ce9b6674e972ac3d Mon Sep 17 00:00:00 2001 From: Josh Samuelson Date: Tue, 6 Sep 2022 22:00:29 -0700 Subject: [PATCH 1/4] 03_07 solutions --- main.tf | 25 +++++++++++++++++++++---- outputs.tf | 12 ++++++------ variables.tf | 8 ++++---- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/main.tf b/main.tf index 9b32ce06bb..be8a0a4ad5 100644 --- a/main.tf +++ b/main.tf @@ -14,11 +14,28 @@ 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 = [module.blog_sg.security_group_id] tags = { - Name = "HelloWorld" + Name = "Learning Terraform" } } + +module "blog_sg" { + source = "terraform-aws-modules/security-group/aws" + version = "4.13.0" + + vpc_id = data.aws_vpc.default.id + name = "blog" + ingress_rules = ["https-443-tcp","http-80-tcp"] + ingress_cidr_blocks = ["0.0.0.0/0"] + egress_rules = ["all-all"] + egress_cidr_blocks = ["0.0.0.0/0"] +} diff --git a/outputs.tf b/outputs.tf index b35171bef1..7e9410b55c 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 c750667e0f..48b7a75904 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 df6909b557bfc1e629157921c25292821658f3ef Mon Sep 17 00:00:00 2001 From: Vladimir Smolenski Date: Sat, 14 Mar 2026 13:21:03 +0100 Subject: [PATCH 2/4] Blog_sg module --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index be8a0a4ad5..18dd578064 100644 --- a/main.tf +++ b/main.tf @@ -30,7 +30,7 @@ resource "aws_instance" "blog" { module "blog_sg" { source = "terraform-aws-modules/security-group/aws" - version = "4.13.0" + version = "5.3.1" vpc_id = data.aws_vpc.default.id name = "blog" From 6b1735825f2ca85434096c71430958a66eeccf99 Mon Sep 17 00:00:00 2001 From: Vladimir Smolenski Date: Sat, 14 Mar 2026 13:24:42 +0100 Subject: [PATCH 3/4] changes --- main.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/main.tf b/main.tf index 18dd578064..de19f29eaa 100644 --- a/main.tf +++ b/main.tf @@ -28,6 +28,7 @@ resource "aws_instance" "blog" { } } + module "blog_sg" { source = "terraform-aws-modules/security-group/aws" version = "5.3.1" From 6003e3f53d5f8f6b6833a00dca47bd0045b89058 Mon Sep 17 00:00:00 2001 From: Vladimir Smolenski Date: Sat, 14 Mar 2026 13:25:51 +0100 Subject: [PATCH 4/4] Update main.tf --- main.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/main.tf b/main.tf index de19f29eaa..18dd578064 100644 --- a/main.tf +++ b/main.tf @@ -28,7 +28,6 @@ resource "aws_instance" "blog" { } } - module "blog_sg" { source = "terraform-aws-modules/security-group/aws" version = "5.3.1"