-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
107 lines (90 loc) · 2.12 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
backend "s3" {
bucket = "terra-state-bucket-friday2"
key = "terraform.tfstate"
region = "us-west-2"
}
}
# Configure the AWS Provider
provider "aws" {
region = "us-west-2"
}
# Create a VPC
resource "aws_vpc" "myvpc" {
cidr_block = "10.0.0.0/16"
tags = {
"Name" = "Terraform VPC"
}
}
# Create a Public subnet in AZ1
resource "aws_subnet" "public_subnet" {
vpc_id = aws_vpc.myvpc.id
cidr_block = "10.0.0.0/24"
tags = {
"Name" = "Public subnet"
}
}
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.myvpc.id
}
resource "aws_route_table" "public_route_table" {
vpc_id = aws_vpc.myvpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.gw.id
}
tags = {
Name = "Public RT"
}
}
resource "aws_route_table_association" "public_subnet_association" {
subnet_id = aws_subnet.public_subnet.id
route_table_id = aws_route_table.public_route_table.id
}
resource "aws_security_group" "ssh_http_security" {
name = "allow_ssh"
vpc_id = aws_vpc.myvpc.id
ingress {
description = "SSH"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "HTTP"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
tags = {
Name = "Allow SSH and HTTP"
}
}
resource "aws_instance" "first_instance" {
ami = "ami-08e2d37b6a0129927"
instance_type = "t3.micro"
associate_public_ip_address = true
iam_instance_profile = "LabInstanceProfile"
subnet_id = aws_subnet.public_subnet.id
vpc_security_group_ids = [aws_security_group.ssh_http_security.id]
key_name = "vockey"
user_data = file("script.sh")
tags = {
Name = "Corona IAM instance"
}
}