Commit e3b32928 authored by Nicky White's avatar Nicky White

Terraform 0.12.29

parent abda3911
{
"archive": "2d74818e7deb7a1df699f3725399d058587c2bce45306360d7d210b871444d48",
"aws": "42f7948de981929bc60f1a6e1c83b14944a2556a3748fb3f5ea03dbc02bdefc6",
"template": "c141e1d7b44ba18a20d48dc1c4367422a1a14cffab3df43bfe5befeb3a20e89c"
}
\ No newline at end of file
resource "aws_cloudwatch_event_rule" "schedule" {
name = "${var.prefix}es-cleanup-execution-schedule"
description = "es-cleanup execution schedule"
schedule_expression = "${var.schedule}"
schedule_expression = var.schedule
}
resource "aws_cloudwatch_event_target" "es_cleanup" {
target_id = "${var.prefix}lambda-es-cleanup"
rule = "${aws_cloudwatch_event_rule.schedule.name}"
arn = "${aws_lambda_function.es_cleanup.arn}"
rule = aws_cloudwatch_event_rule.schedule.name
arn = aws_lambda_function.es_cleanup.arn
}
resource "aws_lambda_permission" "allow_cloudwatch" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = "${aws_lambda_function.es_cleanup.arn}"
function_name = aws_lambda_function.es_cleanup.arn
principal = "events.amazonaws.com"
source_arn = "${aws_cloudwatch_event_rule.schedule.arn}"
source_arn = aws_cloudwatch_event_rule.schedule.arn
}
data "template_file" "policy" {
template = "${file("${path.module}/files/es_policy.json")}"
template = file("${path.module}/files/es_policy.json")
}
resource "aws_iam_policy" "policy" {
name = "${var.prefix}es-cleanup"
path = "/"
description = "Policy for es-cleanup Lambda function"
policy = "${data.template_file.policy.rendered}"
policy = data.template_file.policy.rendered
}
resource "aws_iam_role" "role" {
......@@ -26,9 +26,11 @@ resource "aws_iam_role" "role" {
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "policy_attachment" {
role = "${aws_iam_role.role.name}"
policy_arn = "${aws_iam_policy.policy.arn}"
role = aws_iam_role.role.name
policy_arn = aws_iam_policy.policy.arn
}
......@@ -5,21 +5,22 @@ data "archive_file" "es_cleanup_lambda" {
}
resource "aws_lambda_function" "es_cleanup" {
filename = "${path.module}/es-cleanup.zip"
function_name = "${var.prefix}es-cleanup"
timeout = 300
runtime = "python${var.python_version}"
role = "${aws_iam_role.role.arn}"
handler = "es-cleanup.lambda_handler"
source_code_hash = "${data.archive_file.es_cleanup_lambda.output_base64sha256}"
filename = "${path.module}/es-cleanup.zip"
function_name = "${var.prefix}es-cleanup"
timeout = 300
runtime = "python${var.python_version}"
role = aws_iam_role.role.arn
handler = "es-cleanup.lambda_handler"
source_code_hash = data.archive_file.es_cleanup_lambda.output_base64sha256
environment {
variables = {
es_endpoint = "${var.es_endpoint}"
index = "${var.index}"
delete_after = "${var.delete_after}"
index_format = "${var.index_format}"
sns_alert = "${var.sns_alert}"
}
environment {
variables = {
es_endpoint = var.es_endpoint
index = var.index
delete_after = var.delete_after
index_format = var.index_format
sns_alert = var.sns_alert
}
}
}
variable "prefix" { default = "" }
variable "prefix" {
default = ""
}
variable "schedule" { default = "cron(0 3 * * ? *)" }
variable "schedule" {
default = "cron(0 3 * * ? *)"
}
variable "sns_alert" { default = "" }
variable "sns_alert" {
default = ""
}
variable "es_endpoint" {}
variable "es_endpoint" {
}
variable "index" {}
variable "index" {
}
variable "delete_after" { default = 7 }
variable "delete_after" {
default = 7
}
variable "index_format" {}
variable "index_format" {
}
variable "python_version" {
default = "2.7"
}
variable "python_version" { default = "2.7" }
terraform {
required_version = ">= 0.12"
}
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