Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from asicsdigital/terraform12
Browse files Browse the repository at this point in the history
Update Module to Terraform 0.12.9
  • Loading branch information
Falpangaea authored Oct 1, 2019
2 parents b167c14 + 0e6c167 commit 2c01956
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .terraform-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.11.7
0.12.9
41 changes: 22 additions & 19 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
data "template_file" "json_config" {
vars {
rds_vpc_ids = "${jsonencode(var.rds_vpc_ids)}"
vars = {
rds_vpc_ids = jsonencode(var.rds_vpc_ids)
}

template = <<INPUT
{ "detail": {"vpc_ids": $${rds_vpc_ids} }}
INPUT

}

resource "aws_iam_role" "consul_rds" {
Expand All @@ -28,50 +29,51 @@ resource "aws_iam_role" "consul_rds" {
]
}
EOF

}

resource "aws_iam_role_policy_attachment" "xray_wo" {
role = "${aws_iam_role.consul_rds.name}"
role = aws_iam_role.consul_rds.name
policy_arn = "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess"
}

resource "aws_iam_role_policy_attachment" "vpc_exec" {
role = "${aws_iam_role.consul_rds.name}"
role = aws_iam_role.consul_rds.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
}

resource "aws_iam_role_policy_attachment" "ec2_ro" {
role = "${aws_iam_role.consul_rds.name}"
role = aws_iam_role.consul_rds.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess"
}

resource "aws_iam_role_policy_attachment" "rds_ro" {
role = "${aws_iam_role.consul_rds.name}"
role = aws_iam_role.consul_rds.name
policy_arn = "arn:aws:iam::aws:policy/AmazonRDSReadOnlyAccess"
}

resource "aws_iam_role_policy_attachment" "lambda_ro" {
role = "${aws_iam_role.consul_rds.name}"
role = aws_iam_role.consul_rds.name
policy_arn = "arn:aws:iam::aws:policy/AWSLambdaReadOnlyAccess"
}

resource "aws_iam_role_policy_attachment" "lambda_basic_exec" {
role = "${aws_iam_role.consul_rds.name}"
role = aws_iam_role.consul_rds.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}

resource "aws_lambda_function" "consulRdsCreateService" {
filename = "${path.module}/files/rds/consulRdsCreateService.zip"
function_name = "consulRdsCreateService-${var.env}" # env var
role = "${aws_iam_role.consul_rds.arn}"
function_name = "consulRdsCreateService-${var.env}" # env var
role = aws_iam_role.consul_rds.arn
handler = "consulRdsCreateService.lambda_handler"
source_code_hash = "${base64sha256(file("${path.module}/files/rds/consulRdsCreateService.zip"))}"
source_code_hash = filebase64sha256("${path.module}/files/rds/consulRdsCreateService.zip")
runtime = "python2.7"
timeout = "60"

vpc_config {
subnet_ids = ["${var.subnets}"]
security_group_ids = ["${var.rds_sg}"]
subnet_ids = var.subnets
security_group_ids = var.rds_sg
}

tracing_config {
Expand All @@ -82,21 +84,22 @@ resource "aws_lambda_function" "consulRdsCreateService" {
resource "aws_lambda_permission" "rds_allow_cloudwatch" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = "${aws_lambda_function.consulRdsCreateService.function_name}"
function_name = aws_lambda_function.consulRdsCreateService.function_name
principal = "events.amazonaws.com"
source_arn = "${aws_cloudwatch_event_rule.consul_rds.arn}"
source_arn = aws_cloudwatch_event_rule.consul_rds.arn
}

resource "aws_cloudwatch_event_rule" "consul_rds" {
name = "consulRdsCreateService-${var.env}"
description = "${var.env} Discover and Create RDS Services in Consul"
schedule_expression = "rate(5 minutes)"
role_arn = "${aws_iam_role.consul_rds.arn}"
role_arn = aws_iam_role.consul_rds.arn
}

resource "aws_cloudwatch_event_target" "consul_rds" {
target_id = "consulRdsCreateService-${var.env}"
rule = "${aws_cloudwatch_event_rule.consul_rds.name}"
arn = "${aws_lambda_function.consulRdsCreateService.arn}"
input = "${data.template_file.json_config.rendered}"
rule = aws_cloudwatch_event_rule.consul_rds.name
arn = aws_lambda_function.consulRdsCreateService.arn
input = data.template_file.json_config.rendered
}

10 changes: 6 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
variable "env" {}
variable "env" {
}

variable "subnets" {
type = "list"
type = list(string)
description = "List of VPC Subnets IDs used to do lambdas"
}

variable "rds_sg" {
type = "list"
type = list(string)
description = "List of Security Groups ID's to use for consulRdsCreateService lambda"
}

variable "rds_vpc_ids" {
type = "list"
type = list(string)
default = []
description = "List of VPC ID's the consulRdsCreateService lambda will attempt to discover RDS instances in. Defaults empty array"
}

0 comments on commit 2c01956

Please sign in to comment.