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 #220

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

03_04 #220

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
54 changes: 52 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,61 @@ data "aws_ami" "app_ami" {
owners = ["979382823631"] # Bitnami
}


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]
}

resource "aws_instance" "web" {
ami = data.aws_ami.app_ami.id
instance_type = "t3.nano"
instance_type = var.instance_type


tags = {
Name = "Learning Terraform"
}
}

resource "aws_security_group" "blog" {
name = "blog"
description = "Allow http and https in. Allow anything out."
tags = {
Name = "HelloWorld"
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
}
20 changes: 14 additions & 6 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#output "instance_ami" {
# value = aws_instance.web.ami
#}
output "instance_ami" {

#output "instance_arn" {
# value = aws_instance.web.arn
#}
value = aws_instance.blog.ami
}

output "instance_arn" {
value = aws_instance.blog.arn

value = aws_instance.web.ami
}

output "instance_arn" {
value = aws_instance.web.arn

}
11 changes: 7 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#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"

}
=======
}