forked from cloudposse/terraform-null-label
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
114 lines (93 loc) · 2.58 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
################################
# terraform-null-label example #
################################
module "label" {
source = "../../"
namespace = "eg"
stage = "prod"
name = "app"
tags = {
BusinessUnit = "Finance"
ManagedBy = "Terraform"
}
additional_tag_map = {
propagate_at_launch = "true"
}
}
#######################
# Launch template #
#######################
resource "aws_launch_template" "default" {
# terraform-null-label example used here: Set template name prefix
name_prefix = "${module.label.id}-"
image_id = data.aws_ami.amazon_linux.id
instance_type = "t2.micro"
instance_initiated_shutdown_behavior = "terminate"
vpc_security_group_ids = [data.aws_security_group.default.id]
monitoring {
enabled = false
}
# terraform-null-label example used here: Set tags on volumes
tag_specifications {
resource_type = "volume"
tags = module.label.tags
}
}
######################
# Autoscaling group #
######################
resource "aws_autoscaling_group" "default" {
# terraform-null-label example used here: Set ASG name prefix
name_prefix = "${module.label.id}-"
vpc_zone_identifier = data.aws_subnet_ids.all.ids
max_size = "1"
min_size = "1"
desired_capacity = "1"
launch_template {
id = aws_launch_template.default.id
version = "$Latest"
}
# terraform-null-label example used here: Set tags on ASG and EC2 Servers
tags = module.label.tags_as_list_of_maps
}
################################
# Provider #
################################
provider "aws" {
region = "eu-west-1"
# Make it faster by skipping unneeded checks here
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
skip_requesting_account_id = true
}
##############################################################
# Data sources to get VPC, subnets and security group details
##############################################################
data "aws_vpc" "default" {
default = true
}
data "aws_subnet_ids" "all" {
vpc_id = data.aws_vpc.default.id
}
data "aws_security_group" "default" {
vpc_id = data.aws_vpc.default.id
name = "default"
}
data "aws_ami" "amazon_linux" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = [
"amzn-ami-hvm-*-x86_64-gp2",
]
}
filter {
name = "owner-alias"
values = [
"amazon",
]
}
}