-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.tf
106 lines (86 loc) · 2.53 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
locals {
stack_name = "COS"
env_name = "playground"
}
provider "aws" {
profile = var.deploy_profile
region = var.aws_region
}
### obtaining default vpc, security group and subnet of the env
data "aws_vpc" "default" {
default = true
}
data "aws_subnet_ids" "all" {
vpc_id = data.aws_vpc.default.id
}
resource "aws_security_group" "sg_sample" {
name_prefix = "sg_sample_"
vpc_id = data.aws_vpc.default.id
lifecycle {
create_before_destroy = true
}
}
resource "aws_security_group_rule" "allow_all_inbound" {
type = "ingress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.sg_sample.id
}
resource "aws_security_group_rule" "allow_all_outbound" {
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.sg_sample.id
}
resource "aws_autoscaling_group" "asg_sample" {
launch_configuration = aws_launch_configuration.lc_sample.name
name_prefix = "asg-sample-"
vpc_zone_identifier = data.aws_subnet_ids.all.ids
min_size = "1"
max_size = "1"
}
resource "aws_launch_configuration" "lc_sample" {
name_prefix = "lc-sample-"
image_id = "ami-43a15f3e" # Ubuntu Server 16.04 LTS (HVM)
instance_type = "t2.micro"
user_data = data.template_file.user_data.rendered
key_name = var.ssh_key_name
associate_public_ip_address = true
security_groups = [aws_security_group.sg_sample.id]
lifecycle {
create_before_destroy = true
}
}
data "template_file" "user_data" {
template = file("${path.module}/user-data.sh")
vars = {
nomad_ui_port = 4646
consul_ui_port = 8500
fabio_ui_port = 9998
}
}
module "ui-access" {
source = "../../modules/ui-access"
## required parameters
vpc_id = data.aws_vpc.default.id
subnet_ids = data.aws_subnet_ids.all.ids
nomad_server_asg_name = aws_autoscaling_group.asg_sample.name
consul_server_asg_name = aws_autoscaling_group.asg_sample.name
fabio_server_asg_name = aws_autoscaling_group.asg_sample.name
## optional parameters
aws_region = var.aws_region
env_name = local.env_name
stack_name = local.stack_name
nomad_ui_port = 4646
consul_ui_port = 8500
fabio_ui_port = 9998
allowed_cidr_blocks_for_ui_alb = {
"all" = "0.0.0.0/0",
"another" = "10.10.0.0/16"
}
unique_postfix = ""
}