Skip to content

Commit

Permalink
Merge pull request #83 from jysaad/remove-enable-variable
Browse files Browse the repository at this point in the history
  • Loading branch information
lorengordon authored Sep 14, 2020
2 parents 9ca25a7 + 486f4da commit e9eac46
Show file tree
Hide file tree
Showing 11 changed files with 7 additions and 61 deletions.
3 changes: 1 addition & 2 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[bumpversion]
current_version = 1.1.0
current_version = 2.0.0
commit = True
message = Bumps version to {new_version}
tag = False
tag_name = {new_version}

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Terraform module to create a VPC Flow Log

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| create\_vpc\_flow\_log | Controls whether to create the VPC Flow Log | `bool` | `true` | no |
| iam\_role\_arn | (Optional) ARN for the IAM role to attach to the flow log. If blank, a minimal role will be created | `string` | `null` | no |
| log\_destination | (Optional) The ARN of the logging destination. | `string` | `null` | no |
| log\_destination\_type | Controls whether to create the VPC Flow Log with a `cloud-watch-logs` or `s3` bucket destination | `string` | `null` | no |
Expand Down
14 changes: 5 additions & 9 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
provider "aws" {
}

locals {
iam_role_name = "flow-log-${format("%v", var.vpc_id)}"
log_group_name = var.log_group_name == null ? "/aws/vpc/flow-log/${format("%v", var.vpc_id)}" : var.log_group_name
Expand All @@ -12,7 +9,7 @@ data "aws_partition" "current" {
}

data "aws_iam_policy_document" "role" {
count = var.create_vpc_flow_log && local.create_iam_role ? 1 : 0
count = local.create_iam_role ? 1 : 0

statement {
actions = [
Expand All @@ -31,7 +28,7 @@ data "aws_iam_policy_document" "role" {
}

data "aws_iam_policy_document" "trust" {
count = var.create_vpc_flow_log && local.create_iam_role ? 1 : 0
count = local.create_iam_role ? 1 : 0

statement {
actions = ["sts:AssumeRole"]
Expand All @@ -44,7 +41,6 @@ data "aws_iam_policy_document" "trust" {
}

resource "aws_flow_log" "this" {
count = var.create_vpc_flow_log ? 1 : 0

log_destination_type = var.log_destination_type
log_destination = var.log_destination_type == "s3" ? var.log_destination : join("", aws_cloudwatch_log_group.this.*.arn)
Expand All @@ -55,22 +51,22 @@ resource "aws_flow_log" "this" {
}

resource "aws_cloudwatch_log_group" "this" {
count = var.create_vpc_flow_log && var.log_destination_type == "cloud-watch-logs" ? 1 : 0
count = var.log_destination_type == "cloud-watch-logs" ? 1 : 0

name = local.log_group_name
tags = var.tags
}

resource "aws_iam_role" "this" {
count = var.create_vpc_flow_log && local.create_iam_role ? 1 : 0
count = local.create_iam_role ? 1 : 0

name = local.iam_role_name
assume_role_policy = data.aws_iam_policy_document.trust[0].json
tags = var.tags
}

resource "aws_iam_role_policy" "this" {
count = var.create_vpc_flow_log && local.create_iam_role ? 1 : 0
count = local.create_iam_role ? 1 : 0

name = local.iam_role_name
role = aws_iam_role.this[0].id
Expand Down
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# VPC Flow Log
output "flow_log_id" {
description = "The ID of the VPC Flow Log"
value = join("", aws_flow_log.this.*.id)
value = aws_flow_log.this.id
}

output "log_group_arn" {
Expand Down
1 change: 0 additions & 1 deletion tests/baseline_cloudwatch_logs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module "baseline_s3" {
aws = aws
}

create_vpc_flow_log = true
vpc_id = module.vpc.vpc_id
log_destination_type = "cloud-watch-logs"
}
1 change: 0 additions & 1 deletion tests/baseline_s3/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module "baseline_s3" {
aws = aws
}

create_vpc_flow_log = true
vpc_id = module.vpc.vpc_id
log_destination_type = "s3"
log_destination = aws_s3_bucket.this.arn
Expand Down
1 change: 0 additions & 1 deletion tests/baseline_s3_log_format/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module "baseline_s3_log_format" {
aws = aws
}

create_vpc_flow_log = true
vpc_id = module.vpc.vpc_id
log_destination_type = "s3"
log_destination = aws_s3_bucket.this.arn
Expand Down
23 changes: 0 additions & 23 deletions tests/no_create/README.md

This file was deleted.

12 changes: 0 additions & 12 deletions tests/no_create/main.tf

This file was deleted.

4 changes: 0 additions & 4 deletions tests/no_create/versions.tf

This file was deleted.

6 changes: 0 additions & 6 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
variable "create_vpc_flow_log" {
description = "Controls whether to create the VPC Flow Log"
type = bool
default = true
}

variable "log_destination_type" {
description = "Controls whether to create the VPC Flow Log with a `cloud-watch-logs` or `s3` bucket destination"
type = string
Expand Down

0 comments on commit e9eac46

Please sign in to comment.