forked from cloudposse/terraform-aws-cloudwatch-flow-logs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
65 lines (58 loc) · 2.32 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
data "aws_region" "default" {}
module "log_group_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.1"
namespace = "${var.namespace}"
name = "${var.name}"
stage = "${var.stage}"
delimiter = "${var.delimiter}"
attributes = "${compact(concat(var.attributes, list("log")))}"
tags = "${var.tags}"
enabled = "${var.enabled}"
}
module "vpc_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.1"
namespace = "${var.namespace}"
name = "${var.name}"
stage = "${var.stage}"
delimiter = "${var.delimiter}"
attributes = "${compact(concat(var.attributes, list("vpc")))}"
tags = "${var.tags}"
enabled = "${var.enabled}"
}
module "subnet_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.1"
namespace = "${var.namespace}"
name = "${var.name}"
stage = "${var.stage}"
delimiter = "${var.delimiter}"
attributes = "${compact(concat(var.attributes, list("subnets")))}"
tags = "${var.tags}"
enabled = "${var.enabled}"
}
resource "aws_cloudwatch_log_group" "default" {
count = "${var.enabled == "true" ? 1 : 0}"
name = "${module.log_group_label.id}"
retention_in_days = "${var.retention_in_days}"
tags = "${module.log_group_label.tags}"
}
resource "aws_flow_log" "vpc" {
count = "${var.enabled == "true" ? 1 : 0}"
log_destination = "${aws_cloudwatch_log_group.default.arn}"
iam_role_arn = "${aws_iam_role.log.arn}"
vpc_id = "${var.vpc_id}"
traffic_type = "${var.traffic_type}"
}
resource "aws_flow_log" "subnets" {
count = "${var.enabled == "true" ? length(compact(var.subnet_ids)) : 0}"
log_destination = "${aws_cloudwatch_log_group.default.arn}"
iam_role_arn = "${aws_iam_role.log.arn}"
subnet_id = "${element(compact(var.subnet_ids), count.index)}"
traffic_type = "${var.traffic_type}"
}
resource "aws_flow_log" "eni" {
count = "${var.enabled == "true" ? length(compact(var.eni_ids)) : 0}"
log_destination = "${aws_cloudwatch_log_group.default.arn}"
iam_role_arn = "${aws_iam_role.log.arn}"
subnet_id = "${element(compact(var.eni_ids), count.index)}"
traffic_type = "${var.traffic_type}"
}