Commit 487e5be1 authored by Adrian Horrocks's avatar Adrian Horrocks

Merge branch 'elb-logs-to-s3' into 'master'

Elb logs to s3

See merge request !3
parents 3a4f81b5 8f11e255
......@@ -5,4 +5,4 @@ module "elb" {
security_groups = ["${aws_security_group.elb.id}"]
health_check_target = "HTTP:80/healthcheck.php"
ssl_certificate_id = "arn:aws:acm:eu-west-1:745249840871:certificate/b6ad625c-d0b8-4359-bcb6-326b309e90e8"
}
\ No newline at end of file
}
......@@ -67,6 +67,14 @@ variable "health_check_interval" {
default = "30"
}
variable "logs_enabled" {
default = "false"
}
variable "logs_interval" {
default = "5"
}
#############################################################################################################
# Security Group
#############################################################################################################
......@@ -129,6 +137,12 @@ resource "aws_elb" "main" {
instance_protocol = "${var.service_protocol}"
}
access_logs {
enabled = "${var.logs_enabled}"
bucket = "${var.name}-${random_string.bucket_name.result}-elb-logs"
interval = "${var.logs_interval}"
}
health_check {
healthy_threshold = "${var.health_check_healthy_threshold}"
unhealthy_threshold = "${var.health_check_unhealthy_threshold}"
......@@ -138,6 +152,45 @@ resource "aws_elb" "main" {
}
}
#############################################################################################################
# S3 Bucket for Log Exports
#############################################################################################################
resource "random_string" "bucket_name" {
length = 8
special = false
upper = false
}
data "aws_elb_service_account" "main" {}
resource "aws_s3_bucket" "elb_logs" {
count = "${var.logs_enabled == "true" ? 1 : 0}"
bucket = "${var.name}-${random_string.bucket_name.result}-elb-logs"
acl = "private"
policy = <<POLICY
{
"Id": "Policy",
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:PutObject"
],
"Effect": "Allow",
"Resource": "arn:aws:s3:::${var.name}-${random_string.bucket_name.result}-elb-logs/AWSLogs/*",
"Principal": {
"AWS": [
"${data.aws_elb_service_account.main.arn}"
]
}
}
]
}
POLICY
}
#############################################################################################################
# Outputs
#############################################################################################################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment