-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
134 lines (113 loc) · 3.41 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#This Terraform Code Deploys Basic VPC Infra.
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "${var.aws_region}"
}
resource "aws_vpc" "default" {
cidr_block = "${var.vpc_cidr}"
enable_dns_hostnames = true
tags = {
Name = "${var.vpc_name}"
Owner = "Sree"
}
}
resource "aws_internet_gateway" "default" {
vpc_id = "${aws_vpc.default.id}"
tags = {
Name = "${var.IGW_name}"
}
}
resource "aws_subnet" "subnet1-public" {
vpc_id = "${aws_vpc.default.id}"
cidr_block = "${var.public_subnet1_cidr}"
availability_zone = "us-east-1a"
tags = {
Name = "${var.public_subnet1_name}"
}
}
resource "aws_subnet" "subnet2-public" {
vpc_id = "${aws_vpc.default.id}"
cidr_block = "${var.public_subnet2_cidr}"
availability_zone = "us-east-1b"
tags = {
Name = "${var.public_subnet2_name}"
}
}
resource "aws_subnet" "subnet3-public" {
vpc_id = "${aws_vpc.default.id}"
cidr_block = "${var.public_subnet3_cidr}"
availability_zone = "us-east-1c"
tags = {
Name = "${var.public_subnet3_name}"
}
}
resource "aws_route_table" "terraform-public" {
vpc_id = "${aws_vpc.default.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.default.id}"
}
tags = {
Name = "${var.Main_Routing_Table}"
}
}
resource "aws_route_table_association" "terraform-public" {
subnet_id = "${aws_subnet.subnet1-public.id}"
route_table_id = "${aws_route_table.terraform-public.id}"
}
resource "aws_security_group" "allow_all" {
name = "allow_all"
description = "Allow all inbound traffic"
vpc_id = "${aws_vpc.default.id}"
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
# data "aws_ami" "my_ami" {
# most_recent = true
# #name_regex = "^mavrick"
# owners = ["721834156908"]
# }
resource "aws_instance" "web-1" {
ami = "ami-05e16100b6f337dda"
#ami = "ami-0d857ff0f5fc4e03b"
availability_zone = "us-east-1a"
instance_type = "t2.micro"
key_name = "mackey"
subnet_id = "${aws_subnet.subnet1-public.id}"
vpc_security_group_ids = ["${aws_security_group.allow_all.id}"]
associate_public_ip_address = true
tags = {
Name = "Server-1"
Env = "Prod"
Owner = "Sree"
CostCenter = "ABCD"
}
}
##output "ami_id" {
# value = "${data.aws_ami.my_ami.id}"
#}
#!/bin/bash
# echo "Listing the files in the repo."
# ls -al
# echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++"
# echo "Running Packer Now...!!"
# packer build -var=aws_access_key=AAAAAAAAAAAAAAAAAA -var=aws_secret_key=BBBBBBBBBBBBB packer.json
#packer validate --var-file creds.json packer.json
#packer build --var-file creds.json packer.json
#packer.exe build --var-file creds.json -var=aws_access_key=AAAAAAAAAAAAAAAAAA -var=aws_secret_key=BBBBBBBBBBBBB packer.json
# echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++"
# echo "Running Terraform Now...!!"
# terraform init
# terraform apply --var-file terraform.tfvars -var="aws_access_key=AAAAAAAAAAAAAAAAAA" -var="aws_secret_key=BBBBBBBBBBBBB" --auto-approve
#https://discuss.devopscube.com/t/how-to-get-the-ami-id-after-a-packer-build/36