-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
main.tf
121 lines (110 loc) · 4.4 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
#------------------------------------------------------------------------------
# Variables
#------------------------------------------------------------------------------
locals {
sonar_db_engine_version = var.db_engine_version
sonar_db_port = 5432
sonar_db_instance_size = var.db_instance_size
sonar_db_name = var.db_name
sonar_db_username = var.db_username
sonar_db_password = var.db_password == "" ? random_password.master_password.result : var.db_password
}
#------------------------------------------------------------------------------
# Random password for RDS
#------------------------------------------------------------------------------
resource "random_password" "master_password" {
length = 10
special = false
}
#------------------------------------------------------------------------------
# AWS Cloudwatch Logs
#------------------------------------------------------------------------------
module "aws_cw_logs" {
source = "cn-terraform/cloudwatch-logs/aws"
version = "1.0.12"
# source = "../terraform-aws-cloudwatch-logs"
create_kms_key = var.create_kms_key
log_group_kms_key_id = var.log_group_kms_key_id
log_group_retention_in_days = var.log_group_retention_in_days
logs_path = "/ecs/service/${var.name_prefix}-sonar"
tags = var.tags
}
#------------------------------------------------------------------------------
# ECS Fargate Service
#------------------------------------------------------------------------------
module "ecs_fargate" {
source = "cn-terraform/ecs-fargate/aws"
version = "2.0.52"
# source = "../terraform-aws-ecs-fargate"
name_prefix = "${var.name_prefix}-sonar"
vpc_id = var.vpc_id
public_subnets_ids = var.public_subnets_ids
private_subnets_ids = var.private_subnets_ids
container_name = "${var.name_prefix}-sonar"
container_image = var.sonarqube_image
container_cpu = var.container_cpu
container_memory = var.container_memory
container_memory_reservation = var.container_memory_reservation
enable_autoscaling = var.enable_autoscaling
ephemeral_storage_size = var.ephemeral_storage_size
volumes = var.volumes
mount_points = var.mount_points
permissions_boundary = var.permissions_boundary
# Deployment circuit breaker
deployment_circuit_breaker_enabled = var.deployment_circuit_breaker_enabled
deployment_circuit_breaker_rollback = var.deployment_circuit_breaker_rollback
# Application Load Balancer
custom_lb_arn = var.custom_lb_arn
lb_http_ports = var.lb_http_ports
lb_https_ports = var.lb_https_ports
lb_enable_cross_zone_load_balancing = var.lb_enable_cross_zone_load_balancing
lb_waf_web_acl_arn = var.lb_waf_web_acl_arn
default_certificate_arn = var.enable_ssl ? module.acm[0].acm_certificate_arn : null
# Application Load Balancer Logs
enable_s3_logs = var.enable_s3_logs
block_s3_bucket_public_access = var.block_s3_bucket_public_access
enable_s3_bucket_server_side_encryption = var.enable_s3_bucket_server_side_encryption
s3_bucket_server_side_encryption_sse_algorithm = var.s3_bucket_server_side_encryption_sse_algorithm
s3_bucket_server_side_encryption_key = var.s3_bucket_server_side_encryption_key
command = [
"-Dsonar.search.javaAdditionalOpts=-Dnode.store.allow_mmap=false"
]
ulimits = [
{
"name" : "nofile",
"softLimit" : 65535,
"hardLimit" : 65535
}
]
port_mappings = [
{
containerPort = 9000
hostPort = 9000
protocol = "tcp"
}
]
environment = [
{
name = "SONAR_JDBC_USERNAME"
value = local.sonar_db_username
},
{
name = "SONAR_JDBC_PASSWORD"
value = local.sonar_db_password
},
{
name = "SONAR_JDBC_URL"
value = "jdbc:postgresql://${aws_rds_cluster.aurora_db.endpoint}/${local.sonar_db_name}?sslmode=require"
},
]
log_configuration = {
logDriver = "awslogs"
options = {
"awslogs-region" = var.region
"awslogs-group" = "/ecs/service/${var.name_prefix}-sonar"
"awslogs-stream-prefix" = "ecs"
}
secretOptions = null
}
tags = var.tags
}