-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
88 lines (85 loc) · 2.13 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
terraform {
required_version = "~> 0.15.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
backend "s3" {
bucket = "terraform-backend-tf03172021"
key = "terraform/stack01"
region = "us-east-1"
}
}
provider "aws" {
region = "us-east-1"
}
data "aws_ami" "windows_2016" {
most_recent = true
filter {
name = "name"
values = ["Windows_Server-2016-English-Full-Base-2021*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["amazon"] # Canonical
}
data "aws_ami" "linux" {
most_recent = true
filter {
name = "name"
values = ["amzn2-ami-hvm-2.0.20210427.0-x86_64-gp2"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["amazon"] # Canonical
}
data "aws_vpc" "default" {
default = true
}
data "aws_subnet_ids" "default"{
vpc_id = data.aws_vpc.default.id
}
module "AWS_VPC" {
source = "./modules/vpc/security_group"
tags = {}
}
module "AWS_EC2_windows" {
source = "./modules/aws/ec2/instance"
instance_names = ["web1","web2"]
instance_type = "t2.micro"
image_id = data.aws_ami.windows_2016.id
key_name = "m2c.class3"
security_groups = [module.AWS_VPC.security_group_id]
tags = {}
depends_on = [module.AWS_VPC.security_group_id]
user_data = templatefile("./modules/aws/ec2/instance/user_data/linux.sh",{} )
}
module "AWS_EC2_linux" {
source = "./modules/aws/ec2/instance"
instance_names = ["green","dot","rocks"]
instance_type = "t2.micro"
image_id = data.aws_ami.linux.id
key_name = "m2c.class3"
security_groups = [module.AWS_VPC.security_group_id]
tags = {}
depends_on = [module.AWS_VPC.security_group_id]
user_data = templatefile("./modules/aws/ec2/instance/user_data/linux.sh",{} )
}
module "AWS_EC2_elb" {
source = "./modules/aws/ec2/elb"
security_groups = [module.AWS_VPC.security_group_id]
tags = {}
instances = concat (
tolist([ for instance in module.AWS_EC2_windows.instances: instance.id]),
tolist([ for instance in module.AWS_EC2_linux.instances: instance.id])
)
}
output "security_group" {
value = module.AWS_VPC.security_group_id
}