-
Notifications
You must be signed in to change notification settings - Fork 1
/
main .tf
94 lines (84 loc) · 1.96 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
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
backend "s3" {
bucket = "XXXXXXx" #your bucket name
key = "backend/tf-backend-jenkins.tfstate"
region = "us-east-1"
}
}
provider "aws" {
region = "us-east-1"
}
variable "tags" {
default = ["postgresql", "nodejs", "react"]
}
variable "user" {
default = "clarusway"
}
resource "aws_instance" "managed_nodes" {
ami = "ami-016eb5d644c333ccb"
count = 3
instance_type = "t2.micro"
key_name = "XXXXXXXXX" # change with your pem file
vpc_security_group_ids = [aws_security_group.tf-sec-gr.id]
iam_instance_profile = "XXXXXXXXXXXXXXX-${var.user}" # we created this with jenkins server
tags = {
Name = "ansible_${element(var.tags, count.index )}"
stack = "ansible_project"
environment = "development"
}
user_data = <<-EOF
#! /bin/bash
dnf update -y
EOF
}
resource "aws_security_group" "tf-sec-gr" {
name = "project-sec-gr-${var.user}"
tags = {
Name = "project-sec-gr"
}
ingress {
from_port = 22
protocol = "tcp"
to_port = 22
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 5000
protocol = "tcp"
to_port = 5000
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 3000
protocol = "tcp"
to_port = 3000
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 5432
protocol = "tcp"
to_port = 5432
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
protocol = -1
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
}
output "react_ip" {
value = "http://${aws_instance.managed_nodes[2].public_ip}:3000"
}
output "node_public_ip" {
value = aws_instance.managed_nodes[1].public_ip
}
output "postgre_private_ip" {
value = aws_instance.managed_nodes[0].private_ip
}