Skip to content

Commit ffe4f02

Browse files
authored
Merge pull request #131 from drewmullen/flowlog-name-override
provide name override field for flowlog definition
2 parents ebb6422 + 68c05b2 commit ffe4f02

File tree

10 files changed

+53
-10
lines changed

10 files changed

+53
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ Please see our [developer documentation](https://github.com/aws-ia/terraform-aws
387387
| <a name="input_vpc_egress_only_internet_gateway"></a> [vpc\_egress\_only\_internet\_gateway](#input\_vpc\_egress\_only\_internet\_gateway) | Set to use the Egress-only Internet gateway for all IPv6 traffic going to the Internet. | `bool` | `false` | no |
388388
| <a name="input_vpc_enable_dns_hostnames"></a> [vpc\_enable\_dns\_hostnames](#input\_vpc\_enable\_dns\_hostnames) | Indicates whether the instances launched in the VPC get DNS hostnames. If enabled, instances in the VPC get DNS hostnames; otherwise, they do not. Disabled by default for nondefault VPCs. | `bool` | `true` | no |
389389
| <a name="input_vpc_enable_dns_support"></a> [vpc\_enable\_dns\_support](#input\_vpc\_enable\_dns\_support) | Indicates whether the DNS resolution is supported for the VPC. If enabled, queries to the Amazon provided DNS server at the 169.254.169.253 IP address, or the reserved IP address at the base of the VPC network range "plus two" succeed. If disabled, the Amazon provided DNS service in the VPC that resolves public DNS hostnames to IP addresses is not enabled. Enabled by default. | `bool` | `true` | no |
390-
| <a name="input_vpc_flow_logs"></a> [vpc\_flow\_logs](#input\_vpc\_flow\_logs) | Whether or not to create VPC flow logs and which type. Options: "cloudwatch", "s3", "none". By default creates flow logs to `cloudwatch`. Variable overrides null value types for some keys, defined in defaults.tf. | <pre>object({<br> log_destination = optional(string)<br> iam_role_arn = optional(string)<br> kms_key_id = optional(string)<br><br> log_destination_type = string<br> retention_in_days = optional(number)<br> tags = optional(map(string))<br> traffic_type = optional(string, "ALL")<br> destination_options = optional(object({<br> file_format = optional(string, "plain-text")<br> hive_compatible_partitions = optional(bool, false)<br> per_hour_partition = optional(bool, false)<br> }))<br> })</pre> | <pre>{<br> "log_destination_type": "none"<br>}</pre> | no |
390+
| <a name="input_vpc_flow_logs"></a> [vpc\_flow\_logs](#input\_vpc\_flow\_logs) | Whether or not to create VPC flow logs and which type. Options: "cloudwatch", "s3", "none". By default creates flow logs to `cloudwatch`. Variable overrides null value types for some keys, defined in defaults.tf. | <pre>object({<br> name_override = optional(string, "")<br> log_destination = optional(string)<br> iam_role_arn = optional(string)<br> kms_key_id = optional(string)<br><br> log_destination_type = string<br> retention_in_days = optional(number)<br> tags = optional(map(string))<br> traffic_type = optional(string, "ALL")<br> destination_options = optional(object({<br> file_format = optional(string, "plain-text")<br> hive_compatible_partitions = optional(bool, false)<br> per_hour_partition = optional(bool, false)<br> }))<br> })</pre> | <pre>{<br> "log_destination_type": "none"<br>}</pre> | no |
391391
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | VPC ID to use if not creating VPC. | `string` | `null` | no |
392392
| <a name="input_vpc_instance_tenancy"></a> [vpc\_instance\_tenancy](#input\_vpc\_instance\_tenancy) | The allowed tenancy of instances launched into the VPC. | `string` | `"default"` | no |
393393
| <a name="input_vpc_ipv4_ipam_pool_id"></a> [vpc\_ipv4\_ipam\_pool\_id](#input\_vpc\_ipv4\_ipam\_pool\_id) | Set to use IPAM to get an IPv4 CIDR block. | `string` | `null` | no |
@@ -407,6 +407,7 @@ Please see our [developer documentation](https://github.com/aws-ia/terraform-aws
407407
| <a name="output_core_network_attachment"></a> [core\_network\_attachment](#output\_core\_network\_attachment) | AWS Cloud WAN's core network attachment. Full output of aws\_networkmanager\_vpc\_attachment. |
408408
| <a name="output_core_network_subnet_attributes_by_az"></a> [core\_network\_subnet\_attributes\_by\_az](#output\_core\_network\_subnet\_attributes\_by\_az) | Map of all core\_network subnets containing their attributes.<br><br>Example:<pre>core_network_subnet_attributes_by_az = {<br> "us-east-1a" = {<br> "arn" = "arn:aws:ec2:us-east-1:<>:subnet/subnet-04a86315c4839b519"<br> "assign_ipv6_address_on_creation" = false<br> ...<br> <all attributes of subnet: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/subnet#attributes-reference><br> }<br> "us-east-1b" = {...)<br>}</pre> |
409409
| <a name="output_egress_only_internet_gateway"></a> [egress\_only\_internet\_gateway](#output\_egress\_only\_internet\_gateway) | Egress-only Internet gateway attributes. Full output of aws\_egress\_only\_internet\_gateway. |
410+
| <a name="output_flow_log_attributes"></a> [flow\_log\_attributes](#output\_flow\_log\_attributes) | Flow Log information. |
410411
| <a name="output_internet_gateway"></a> [internet\_gateway](#output\_internet\_gateway) | Internet gateway attributes. Full output of aws\_internet\_gateway. |
411412
| <a name="output_nat_gateway_attributes_by_az"></a> [nat\_gateway\_attributes\_by\_az](#output\_nat\_gateway\_attributes\_by\_az) | Map of nat gateway resource attributes by AZ.<br><br>Example:<pre>nat_gateway_attributes_by_az = {<br> "us-east-1a" = {<br> "allocation_id" = "eipalloc-0e8b20303eea88b13"<br> "connectivity_type" = "public"<br> "id" = "nat-0fde39f9550f4abb5"<br> "network_interface_id" = "eni-0d422727088bf9a86"<br> "private_ip" = "10.0.3.40"<br> "public_ip" = <><br> "subnet_id" = "subnet-0f11c92e439c8ab4a"<br> "tags" = tomap({<br> "Name" = "nat-my-public-us-east-1a"<br> })<br> "tags_all" = tomap({<br> "Name" = "nat-my-public-us-east-1a"<br> })<br> }<br> "us-east-1b" = { ... }<br>}</pre> |
412413
| <a name="output_natgw_id_per_az"></a> [natgw\_id\_per\_az](#output\_natgw\_id\_per\_az) | Map of nat gateway IDs for each resource. Will be duplicate ids if your var.subnets.public.nat\_gateway\_configuration = "single\_az".<br><br>Example:<pre>natgw_id_per_az = {<br> "us-east-1a" = {<br> "id" = "nat-0fde39f9550f4abb5"<br> }<br> "us-east-1b" = {<br> "id" = "nat-0fde39f9550f4abb5"<br> }<br>}</pre> |

data.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ locals {
116116
# VPC LATTICE ############################################################
117117
# If var.vpc_lattice is defined (default = {}), the VPC association is created.
118118
lattice_association = length(keys(var.vpc_lattice)) > 0
119+
120+
log_name = var.vpc_flow_logs.name_override == "" ? var.name : var.vpc_flow_logs.name_override
119121
}
120122

121123
data "aws_availability_zones" "current" {

examples/public_private_flow_logs/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,10 @@ At this point, only cloud-watch logs are support, pending: https://github.com/aw
3939

4040
## Outputs
4141

42-
No outputs.
42+
| Name | Description |
43+
|------|-------------|
44+
| <a name="output_log_name"></a> [log\_name](#output\_log\_name) | Name of the flow log. |
45+
| <a name="output_private_subnets"></a> [private\_subnets](#output\_private\_subnets) | Map of private subnet attributes grouped by az. |
46+
| <a name="output_private_subnets_tags_length"></a> [private\_subnets\_tags\_length](#output\_private\_subnets\_tags\_length) | Count of private subnet tags for a single az. |
47+
| <a name="output_public_subnets_tags_length"></a> [public\_subnets\_tags\_length](#output\_public\_subnets\_tags\_length) | Count of public subnet tags for a single az. |
4348
<!-- END_TF_DOCS -->

examples/public_private_flow_logs/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module "vpc1" {
2323
}
2424

2525
vpc_flow_logs = {
26+
name_override = "test"
2627
log_destination_type = "cloud-watch-logs"
2728
retention_in_days = 180
2829
}
@@ -46,4 +47,4 @@ module "vpc2" {
4647
file_format = "parquet"
4748
}
4849
}
49-
}
50+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,22 @@
11

2+
output "private_subnets" {
3+
description = "Map of private subnet attributes grouped by az."
4+
value = module.vpc1.private_subnet_attributes_by_az
5+
}
6+
7+
## Used for Testing, do not delete
8+
9+
output "public_subnets_tags_length" {
10+
description = "Count of public subnet tags for a single az."
11+
value = length(module.vpc1.public_subnet_attributes_by_az[data.aws_availability_zones.current.names[0]].tags)
12+
}
13+
14+
output "private_subnets_tags_length" {
15+
description = "Count of private subnet tags for a single az."
16+
value = length(module.vpc1.private_subnet_attributes_by_az["private/${data.aws_availability_zones.current.names[0]}"].tags)
17+
}
18+
19+
output "log_name" {
20+
description = "Name of the flow log."
21+
value = module.vpc1.flow_log_attributes.tags["Name"]
22+
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
variable "aws_region" {
22
description = "AWS Region."
33
type = string
4-
5-
default = "eu-west-1"
4+
default = "eu-west-1"
65
}

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ module "flow_logs" {
508508

509509
source = "./modules/flow_logs"
510510

511-
name = var.name
511+
name = local.log_name
512512
flow_log_definition = var.vpc_flow_logs
513513
vpc_id = local.vpc.id
514514

@@ -527,4 +527,4 @@ resource "aws_vpclattice_service_network_vpc_association" "vpc_lattice_service_n
527527
module.tags.tags_aws,
528528
module.vpc_lattice_tags.tags_aws
529529
)
530-
}
530+
}

outputs.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,9 @@ output "egress_only_internet_gateway" {
192192
output "vpc_lattice_service_network_association" {
193193
value = try(aws_vpclattice_service_network_vpc_association.vpc_lattice_service_network_association[0], null)
194194
description = "VPC Lattice Service Network VPC association. Full output of aws_vpclattice_service_network_vpc_association"
195-
}
195+
}
196+
197+
output "flow_log_attributes" {
198+
description = "Flow Log information."
199+
value = try(module.flow_logs[0].flow_log, null)
200+
}

test/examples_public_private_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package test
22

33
import (
44
"testing"
5-
5+
"github.com/stretchr/testify/assert"
66
"github.com/gruntwork-io/terratest/modules/terraform"
77
)
88

@@ -14,4 +14,12 @@ func TestExamplesPublicPrivateFlowLogs(t *testing.T) {
1414

1515
defer terraform.Destroy(t, terraformOptions)
1616
terraform.InitAndApply(t, terraformOptions)
17-
}
17+
terraform.ApplyAndIdempotent(t, terraformOptions)
18+
19+
log_name := terraform.Output(t, terraformOptions, "log_name")
20+
assert.Contains(t, "test", log_name)
21+
publicTagsLength := terraform.Output(t, terraformOptions, "public_subnets_tags_length")
22+
assert.Equal(t, "2", publicTagsLength)
23+
privateTagsLength := terraform.Output(t, terraformOptions, "private_subnets_tags_length")
24+
assert.Equal(t, "1", privateTagsLength)
25+
}

variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ variable "vpc_flow_logs" {
262262
description = "Whether or not to create VPC flow logs and which type. Options: \"cloudwatch\", \"s3\", \"none\". By default creates flow logs to `cloudwatch`. Variable overrides null value types for some keys, defined in defaults.tf."
263263

264264
type = object({
265+
name_override = optional(string, "")
265266
log_destination = optional(string)
266267
iam_role_arn = optional(string)
267268
kms_key_id = optional(string)

0 commit comments

Comments
 (0)