-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
150 lines (111 loc) · 4.56 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
module "acm" {
source = "terraform-aws-modules/acm/aws"
version = "5.1.1"
create_certificate = var.domain_name != "" ? true : false
validation_method = "DNS"
domain_name = var.dns_subdomain
zone_id = data.aws_route53_zone.selected[0].zone_id
subject_alternative_names = var.subject_alternative_names
zones = local.validation_zone_mapping
tags = var.tags
}
module "application" {
source = "cloudposse/elastic-beanstalk-application/aws"
# Cloud Posse recommends pinning every module to a specific version
version = "0.12.0"
name = var.application_name
description = "Test Elastic Beanstalk application"
tags = var.tags
}
module "environment" {
source = "cloudposse/elastic-beanstalk-environment/aws"
version = "0.51.2"
depends_on = [
aws_elastic_beanstalk_application_version.default,
module.acm,
]
name = var.application_name
description = var.description
region = var.region
keypair = var.keypair
version_label = aws_elastic_beanstalk_application_version.default.id
elastic_beanstalk_application_name = var.application_name
autoscale_min = var.autoscale_min
autoscale_max = var.autoscale_max
autoscale_measure_name = var.autoscale_measure_name
autoscale_statistic = var.autoscale_statistic
autoscale_unit = var.autoscale_unit
autoscale_lower_bound = var.autoscale_lower_bound
autoscale_lower_increment = var.autoscale_lower_increment
autoscale_upper_bound = var.autoscale_upper_bound
autoscale_upper_increment = var.autoscale_upper_increment
vpc_id = var.vpc_id
availability_zone_selector = var.availability_zone_selector
application_subnets = var.private_subnet_ids
loadbalancer_subnets = var.public_subnet_ids
loadbalancer_type = var.loadbalancer_type
loadbalancer_certificate_arn = module.acm.acm_certificate_arn
loadbalancer_ssl_policy = var.loadbalancer_ssl_policy
instance_type = var.instance_type
root_volume_type = var.root_volume_type
root_volume_size = var.root_volume_size
healthcheck_url = var.healthcheck_url
healthcheck_interval = var.healthcheck_interval
healthcheck_timeout = var.healthcheck_timeout
health_streaming_enabled = var.health_streaming_enabled
health_streaming_delete_on_terminate = var.health_streaming_delete_on_terminate
health_streaming_retention_in_days = var.health_streaming_retention_in_days
allow_all_egress = true
additional_security_group_rules = var.additional_security_group_rules
solution_stack_name = data.aws_elastic_beanstalk_solution_stack.this.name
env_vars = var.env_vars
prefer_legacy_ssm_policy = false
prefer_legacy_service_policy = false
dns_zone_id = var.domain_name != "" ? data.aws_route53_zone.selected.*.id[0] : var.dns_zone_id
dns_subdomain = var.dns_subdomain
force_destroy = true
enable_stream_logs = var.enable_stream_logs
logs_delete_on_terminate = var.logs_delete_on_terminate
logs_retention_in_days = var.logs_retention_in_days
additional_settings = var.additional_settings
managed_actions_enabled = var.managed_actions_enabled
preferred_start_time = var.preferred_start_time
update_level = var.update_level
instance_refresh_enabled = var.instance_refresh_enabled
tags = var.tags
}
data "aws_iam_policy_document" "minimal_s3_permissions" {
statement {
sid = "AllowS3OperationsOnElasticBeanstalkBuckets"
actions = [
"s3:ListAllMyBuckets",
"s3:GetBucketLocation"
]
resources = ["*"]
}
}
resource "aws_s3_object" "deployment" {
bucket = var.deployment_bucket
key = "${var.application_name}-${var.deployment_version}-${var.deployment_file_path}"
content = var.deployment_definition
}
resource "aws_elastic_beanstalk_application_version" "default" {
depends_on = [module.application]
name = "${var.application_name}-${var.deployment_version}"
application = var.application_name
description = "application version created by terraform"
bucket = var.deployment_bucket
key = aws_s3_object.deployment.id
}
resource "aws_route53_record" "additional" {
depends_on = [module.environment]
count = length(var.subject_alternative_names)
zone_id = data.aws_route53_zone.additional[count.index].zone_id
name = var.subject_alternative_names[count.index]
type = "A"
alias {
name = module.environment.endpoint
zone_id = module.environment.elb_zone_id
evaluate_target_health = true
}
}