Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

03_04 solutions #209

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
12 changes: 6 additions & 6 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 4 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -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"
}