Skip to content

Commit 5291d06

Browse files
authored
Merge pull request #29 from rackspace-infrastructure-automation/gdv/MPCSUPENG-922
allow retention configuration on CWL for flow logs
2 parents fc8cf2c + cc9de0b commit 5291d06

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module "vpc" {
1212
}
1313
```
1414

15-
Full working references are available at [examples](examples)
15+
Full working references are available at [examples](examples)
1616
## Default Resources
1717

1818
By default only `vpc_name` is required to be set. Unless changed `aws_region` defaults to `us-west-2` and will need to be updated for other regions. `source` will also need to be declared depending on where the module lives. Given default settings the following resources are created:
@@ -47,12 +47,13 @@ The following module variables were updated to better meet current Rackspace sty
4747
| Name | Description | Type | Default | Required |
4848
|------|-------------|------|---------|:-----:|
4949
| az\_count | Number of AZs to utilize for the subnets | `number` | `2` | no |
50-
| build\_flow\_logs | Whether or not to build flow log components in cloud watch logs | `bool` | `false` | no |
50+
| build\_flow\_logs | Whether or not to build flow log components in Cloudwatch Logs | `bool` | `false` | no |
5151
| build\_igw | Whether or not to build an internet gateway. If disabled, no public subnets or route tables, internet gateway,<br>or NAT Gateways will be created. | `bool` | `true` | no |
5252
| build\_nat\_gateways | Whether or not to build a NAT gateway per AZ. if `build_igw` is set to false, this value is ignored. | `bool` | `true` | no |
5353
| build\_s3\_flow\_logs | Whether or not to build flow log components in s3 | `bool` | `false` | no |
5454
| build\_vpn | Whether or not to build a VPN gateway | `bool` | `false` | no |
5555
| cidr\_range | CIDR range for the VPC | `string` | `"172.18.0.0/19"` | no |
56+
| cloudwatch\_flowlog\_retention | The number of days to retain flowlogs in CLoudwatch Logs. Valid values are: [0, 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653]. A value of `0` will retain indefinitely. | `number` | `14` | no |
5657
| custom\_azs | A list of AZs that VPC resources will reside in | `list(string)` | `[]` | no |
5758
| default\_tenancy | Default tenancy for instances. Either multi-tenant (default) or single-tenant (dedicated) | `string` | `"default"` | no |
5859
| domain\_name | Custom domain name for the VPC | `string` | `""` | no |
@@ -64,9 +65,8 @@ The following module variables were updated to better meet current Rackspace sty
6465
| logging\_bucket\_encryption | Enable default bucket encryption. i.e. AES256 or aws:kms | `string` | `"AES256"` | no |
6566
| logging\_bucket\_encryption\_kms\_mster\_key | The AWS KMS master key ID used for the SSE-KMS encryption. This can only be used when you set the value of sse\_algorithm as aws:kms. | `string` | `""` | no |
6667
| logging\_bucket\_force\_destroy | Whether all objects should be deleted from the bucket so that the bucket can be destroyed without error. These objects are not recoverable. ie. true | `bool` | `false` | no |
67-
| logging\_bucket\_name | Bucket name to store s3 flow logs. If empty, to create random bucket name. In conjuction with build\_s3\_flow\_logs | `string` | `""` | no |
68+
| logging\_bucket\_name | Bucket name to store s3 flow logs. If empty, a random bucket name is generated. Use in conjuction with `build_s3_flow_logs` | `string` | `""` | no |
6869
| logging\_bucket\_prefix | The prefix for the location in the S3 bucket. If you don't specify a prefix, the access logs are stored in the root of the bucket. | `string` | `""` | no |
69-
| logging\_bucket\_retention | The number of days to retain load balancer logs. 0 to ratain forever. | `number` | `14` | no |
7070
| name | Name prefix for the VPC and related resources | `string` | n/a | yes |
7171
| private\_cidr\_ranges | An array of CIDR ranges to use for private subnets | `list(string)` | <pre>[<br> "172.18.16.0/22",<br> "172.18.20.0/22",<br> "172.18.24.0/22"<br>]<br></pre> | no |
7272
| private\_subnet\_names | Text that will be included in generated name for private subnets. Given the default value of `["Private"]`, subnet<br>names in the form \"<vpc\_name>-Private<count+1>\", e.g. \"MyVpc-Public2\" will be produced. Otherwise, given a<br>list of names with length the same as the value of `az_count`, the first `az_count` subnets will be named using<br>the first string in the list, the second `az_count` subnets will be named using the second string, and so on. | `list(string)` | <pre>[<br> "Private"<br>]<br></pre> | no |
@@ -76,6 +76,7 @@ The following module variables were updated to better meet current Rackspace sty
7676
| public\_subnet\_names | Text that will be included in generated name for public subnets. Given the default value of `["Public"]`, subnet<br>names in the form \"<vpc\_name>-Public<count+1>\", e.g. \"MyVpc-Public1\" will be produced. Otherwise, given a<br>list of names with length the same as the value of `az_count`, the first `az_count` subnets will be named using<br>the first string in the list, the second `az_count` subnets will be named using the second string, and so on. | `list(string)` | <pre>[<br> "Public"<br>]<br></pre> | no |
7777
| public\_subnet\_tags | A list of maps containing tags to be applied to public subnets. List should either be the same length as the number of AZs to apply different tags per set of subnets, or a length of 1 to apply the same tags across all public subnets. | `list(map(string))` | <pre>[<br> {}<br>]<br></pre> | no |
7878
| public\_subnets\_per\_az | Number of public subnets to create in each AZ. NOTE: This value, when multiplied by the value of `az_count`,<br>should not exceed the length of the `public_cidr_ranges` list! | `number` | `1` | no |
79+
| s3\_flowlog\_retention | The number of days to retain flowlogs in s3. A value of `0` will retain indefinitely. | `number` | `14` | no |
7980
| spoke\_vpc | Whether or not the VPN gateway is a spoke of a Transit VPC | `bool` | `false` | no |
8081
| tags | Optional tags to be applied on top of the base tags on all resources | `map(string)` | `{}` | no |
8182

main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ resource "aws_s3_bucket" "vpc_log_bucket" {
333333
prefix = var.logging_bucket_prefix
334334

335335
expiration {
336-
days = var.logging_bucket_retention
336+
days = var.s3_flowlog_retention
337337
}
338338
}
339339
}
@@ -350,7 +350,8 @@ resource "aws_flow_log" "cw_vpc_log" {
350350
resource "aws_cloudwatch_log_group" "flowlog_group" {
351351
count = var.build_flow_logs ? 1 : 0
352352

353-
name = "${var.name}-FlowLogs"
353+
name = "${var.name}-FlowLogs"
354+
retention_in_days = var.cloudwatch_flowlog_retention
354355
}
355356

356357
resource "aws_iam_role" "flowlog_role" {

variables.tf

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ variable "az_count" {
55
}
66

77
variable "build_flow_logs" {
8-
description = "Whether or not to build flow log components in cloud watch logs"
8+
description = "Whether or not to build flow log components in Cloudwatch Logs"
99
default = false
1010
type = bool
1111
}
@@ -44,6 +44,12 @@ variable "cidr_range" {
4444
default = "172.18.0.0/19"
4545
}
4646

47+
variable "cloudwatch_flowlog_retention" {
48+
description = "The number of days to retain flowlogs in CLoudwatch Logs. Valid values are: [0, 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653]. A value of `0` will retain indefinitely."
49+
type = number
50+
default = 14
51+
}
52+
4753
variable "custom_azs" {
4854
description = "A list of AZs that VPC resources will reside in"
4955
type = list(string)
@@ -111,7 +117,7 @@ variable "logging_bucket_force_destroy" {
111117
}
112118

113119
variable "logging_bucket_name" {
114-
description = "Bucket name to store s3 flow logs. If empty, to create random bucket name. In conjuction with build_s3_flow_logs"
120+
description = "Bucket name to store s3 flow logs. If empty, a random bucket name is generated. Use in conjuction with `build_s3_flow_logs`"
115121
type = string
116122
default = ""
117123
}
@@ -122,12 +128,6 @@ variable "logging_bucket_prefix" {
122128
default = ""
123129
}
124130

125-
variable "logging_bucket_retention" {
126-
description = "The number of days to retain load balancer logs. 0 to ratain forever."
127-
type = number
128-
default = 14
129-
}
130-
131131
variable "name" {
132132
description = "Name prefix for the VPC and related resources"
133133
type = string
@@ -213,6 +213,12 @@ EOF
213213
default = 1
214214
}
215215

216+
variable "s3_flowlog_retention" {
217+
description = "The number of days to retain flowlogs in s3. A value of `0` will retain indefinitely."
218+
type = number
219+
default = 14
220+
}
221+
216222
variable "spoke_vpc" {
217223
description = "Whether or not the VPN gateway is a spoke of a Transit VPC"
218224
type = bool

0 commit comments

Comments
 (0)