Skip to content

Commit 1681fa0

Browse files
esolitosGowiem
andauthored
feat: add logging options (#26)
* feat: add logging options * feat: automatically create cloudwatch log group if required * feat: improve name and allow selecting retention period * chore: make Run: make init make readme make github/init * fix: do not applly logging option when not enabled * Apply suggestions from code review by @Gowiem Co-authored-by: Matt Gowie <[email protected]> * chore: force document updates as in main * chore: make readme * chore: make github/init * fix: missed in merge Co-authored-by: Matt Gowie <[email protected]> * chore: make readme --------- Co-authored-by: Matt Gowie <[email protected]>
1 parent 67cbc25 commit 1681fa0

File tree

7 files changed

+76
-4
lines changed

7 files changed

+76
-4
lines changed

.github/renovate.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"extends": [
33
"config:base",
4-
":preserveSemverRanges"
4+
":preserveSemverRanges",
5+
":rebaseStalePrs"
56
],
6-
"baseBranches": ["main", "master", "/^release\\/v\\d{1,2}$/"],
7+
"baseBranches": ["main"],
78
"labels": ["auto-update"],
89
"dependencyDashboardAutoclose": true,
910
"enabledManagers": ["terraform"],
1011
"terraform": {
11-
"ignorePaths": ["**/context.tf", "examples/**"]
12+
"ignorePaths": ["**/context.tf"]
1213
}
1314
}

.github/workflows/release-branch.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
- 'docs/**'
1111
- 'examples/**'
1212
- 'test/**'
13+
- 'README.*'
1314

1415
permissions:
1516
contents: write

.github/workflows/release-published.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ permissions:
1111

1212
jobs:
1313
terraform-module:
14-
uses: cloudposse/github-actions-workflows-terraform-module/.github/workflows/release.yml@main
14+
uses: cloudposse/github-actions-workflows-terraform-module/.github/workflows/release-published.yml@main

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ Available targets:
116116

117117
| Name | Source | Version |
118118
|------|--------|---------|
119+
| <a name="module_logs"></a> [logs](#module\_logs) | cloudposse/cloudwatch-logs/aws | 0.6.8 |
119120
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |
120121

121122
## Resources
@@ -163,9 +164,12 @@ Available targets:
163164
| <a name="input_transit_gateway_routes"></a> [transit\_gateway\_routes](#input\_transit\_gateway\_routes) | A map of transit gateway routes to create on the given TGW route table (via `transit_gateway_route_table_id`) for the created VPN Attachment. Use the key in the map to describe the route. | <pre>map(object({<br> blackhole = optional(bool, false)<br> destination_cidr_block = string<br> }))</pre> | `{}` | no |
164165
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The ID of the VPC to which the Virtual Private Gateway will be attached | `string` | `null` | no |
165166
| <a name="input_vpn_connection_local_ipv4_network_cidr"></a> [vpn\_connection\_local\_ipv4\_network\_cidr](#input\_vpn\_connection\_local\_ipv4\_network\_cidr) | The IPv4 CIDR on the customer gateway (on-premises) side of the VPN connection. | `string` | `"0.0.0.0/0"` | no |
167+
| <a name="input_vpn_connection_log_retention_in_days"></a> [vpn\_connection\_log\_retention\_in\_days](#input\_vpn\_connection\_log\_retention\_in\_days) | Specifies the number of days you want to retain log events. | `number` | `30` | no |
166168
| <a name="input_vpn_connection_remote_ipv4_network_cidr"></a> [vpn\_connection\_remote\_ipv4\_network\_cidr](#input\_vpn\_connection\_remote\_ipv4\_network\_cidr) | The IPv4 CIDR on the AWS side of the VPN connection. | `string` | `"0.0.0.0/0"` | no |
167169
| <a name="input_vpn_connection_static_routes_destinations"></a> [vpn\_connection\_static\_routes\_destinations](#input\_vpn\_connection\_static\_routes\_destinations) | List of CIDR blocks to be used as destination for static routes. Routes to destinations will be propagated to the route tables defined in `route_table_ids` | `list(string)` | `[]` | no |
168170
| <a name="input_vpn_connection_static_routes_only"></a> [vpn\_connection\_static\_routes\_only](#input\_vpn\_connection\_static\_routes\_only) | If set to `true`, the VPN connection will use static routes exclusively. Static routes must be used for devices that don't support BGP | `bool` | `false` | no |
171+
| <a name="input_vpn_connection_tunnel1_cloudwatch_log_enabled"></a> [vpn\_connection\_tunnel1\_cloudwatch\_log\_enabled](#input\_vpn\_connection\_tunnel1\_cloudwatch\_log\_enabled) | Enable or disable VPN tunnel logging feature for the tunnel | `bool` | `false` | no |
172+
| <a name="input_vpn_connection_tunnel1_cloudwatch_log_output_format"></a> [vpn\_connection\_tunnel1\_cloudwatch\_log\_output\_format](#input\_vpn\_connection\_tunnel1\_cloudwatch\_log\_output\_format) | Set log format for the tunnel. Default format is json. Possible values are: json and text | `string` | `"json"` | no |
169173
| <a name="input_vpn_connection_tunnel1_dpd_timeout_action"></a> [vpn\_connection\_tunnel1\_dpd\_timeout\_action](#input\_vpn\_connection\_tunnel1\_dpd\_timeout\_action) | The action to take after DPD timeout occurs for the first VPN tunnel. Specify restart to restart the IKE initiation. Specify clear to end the IKE session. Valid values are clear \| none \| restart. | `string` | `"clear"` | no |
170174
| <a name="input_vpn_connection_tunnel1_ike_versions"></a> [vpn\_connection\_tunnel1\_ike\_versions](#input\_vpn\_connection\_tunnel1\_ike\_versions) | The IKE versions that are permitted for the first VPN tunnel. Valid values are ikev1 \| ikev2. | `list(string)` | `[]` | no |
171175
| <a name="input_vpn_connection_tunnel1_inside_cidr"></a> [vpn\_connection\_tunnel1\_inside\_cidr](#input\_vpn\_connection\_tunnel1\_inside\_cidr) | The CIDR block of the inside IP addresses for the first VPN tunnel | `string` | `null` | no |
@@ -177,6 +181,8 @@ Available targets:
177181
| <a name="input_vpn_connection_tunnel1_phase2_integrity_algorithms"></a> [vpn\_connection\_tunnel1\_phase2\_integrity\_algorithms](#input\_vpn\_connection\_tunnel1\_phase2\_integrity\_algorithms) | One or more integrity algorithms that are permitted for the first VPN tunnel for phase 2 IKE negotiations. Valid values are SHA1 \| SHA2-256 \| SHA2-384 \| SHA2-512. | `list(string)` | `[]` | no |
178182
| <a name="input_vpn_connection_tunnel1_preshared_key"></a> [vpn\_connection\_tunnel1\_preshared\_key](#input\_vpn\_connection\_tunnel1\_preshared\_key) | The preshared key of the first VPN tunnel. The preshared key must be between 8 and 64 characters in length and cannot start with zero. Allowed characters are alphanumeric characters, periods(.) and underscores(\_) | `string` | `null` | no |
179183
| <a name="input_vpn_connection_tunnel1_startup_action"></a> [vpn\_connection\_tunnel1\_startup\_action](#input\_vpn\_connection\_tunnel1\_startup\_action) | The action to take when the establishing the tunnel for the first VPN connection. By default, your customer gateway device must initiate the IKE negotiation and bring up the tunnel. Specify start for AWS to initiate the IKE negotiation. Valid values are add \| start. | `string` | `"add"` | no |
184+
| <a name="input_vpn_connection_tunnel2_cloudwatch_log_enabled"></a> [vpn\_connection\_tunnel2\_cloudwatch\_log\_enabled](#input\_vpn\_connection\_tunnel2\_cloudwatch\_log\_enabled) | Enable or disable VPN tunnel logging feature for the tunnel | `bool` | `false` | no |
185+
| <a name="input_vpn_connection_tunnel2_cloudwatch_log_output_format"></a> [vpn\_connection\_tunnel2\_cloudwatch\_log\_output\_format](#input\_vpn\_connection\_tunnel2\_cloudwatch\_log\_output\_format) | Set log format for the tunnel. Default format is json. Possible values are: json and text | `string` | `"json"` | no |
180186
| <a name="input_vpn_connection_tunnel2_dpd_timeout_action"></a> [vpn\_connection\_tunnel2\_dpd\_timeout\_action](#input\_vpn\_connection\_tunnel2\_dpd\_timeout\_action) | The action to take after DPD timeout occurs for the second VPN tunnel. Specify restart to restart the IKE initiation. Specify clear to end the IKE session. Valid values are clear \| none \| restart. | `string` | `"clear"` | no |
181187
| <a name="input_vpn_connection_tunnel2_ike_versions"></a> [vpn\_connection\_tunnel2\_ike\_versions](#input\_vpn\_connection\_tunnel2\_ike\_versions) | The IKE versions that are permitted for the second VPN tunnel. Valid values are ikev1 \| ikev2. | `list(string)` | `[]` | no |
182188
| <a name="input_vpn_connection_tunnel2_inside_cidr"></a> [vpn\_connection\_tunnel2\_inside\_cidr](#input\_vpn\_connection\_tunnel2\_inside\_cidr) | The CIDR block of the inside IP addresses for the second VPN tunnel | `string` | `null` | no |

docs/terraform.md

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
| Name | Source | Version |
1818
|------|--------|---------|
19+
| <a name="module_logs"></a> [logs](#module\_logs) | cloudposse/cloudwatch-logs/aws | 0.6.8 |
1920
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |
2021

2122
## Resources
@@ -63,9 +64,12 @@
6364
| <a name="input_transit_gateway_routes"></a> [transit\_gateway\_routes](#input\_transit\_gateway\_routes) | A map of transit gateway routes to create on the given TGW route table (via `transit_gateway_route_table_id`) for the created VPN Attachment. Use the key in the map to describe the route. | <pre>map(object({<br> blackhole = optional(bool, false)<br> destination_cidr_block = string<br> }))</pre> | `{}` | no |
6465
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The ID of the VPC to which the Virtual Private Gateway will be attached | `string` | `null` | no |
6566
| <a name="input_vpn_connection_local_ipv4_network_cidr"></a> [vpn\_connection\_local\_ipv4\_network\_cidr](#input\_vpn\_connection\_local\_ipv4\_network\_cidr) | The IPv4 CIDR on the customer gateway (on-premises) side of the VPN connection. | `string` | `"0.0.0.0/0"` | no |
67+
| <a name="input_vpn_connection_log_retention_in_days"></a> [vpn\_connection\_log\_retention\_in\_days](#input\_vpn\_connection\_log\_retention\_in\_days) | Specifies the number of days you want to retain log events. | `number` | `30` | no |
6668
| <a name="input_vpn_connection_remote_ipv4_network_cidr"></a> [vpn\_connection\_remote\_ipv4\_network\_cidr](#input\_vpn\_connection\_remote\_ipv4\_network\_cidr) | The IPv4 CIDR on the AWS side of the VPN connection. | `string` | `"0.0.0.0/0"` | no |
6769
| <a name="input_vpn_connection_static_routes_destinations"></a> [vpn\_connection\_static\_routes\_destinations](#input\_vpn\_connection\_static\_routes\_destinations) | List of CIDR blocks to be used as destination for static routes. Routes to destinations will be propagated to the route tables defined in `route_table_ids` | `list(string)` | `[]` | no |
6870
| <a name="input_vpn_connection_static_routes_only"></a> [vpn\_connection\_static\_routes\_only](#input\_vpn\_connection\_static\_routes\_only) | If set to `true`, the VPN connection will use static routes exclusively. Static routes must be used for devices that don't support BGP | `bool` | `false` | no |
71+
| <a name="input_vpn_connection_tunnel1_cloudwatch_log_enabled"></a> [vpn\_connection\_tunnel1\_cloudwatch\_log\_enabled](#input\_vpn\_connection\_tunnel1\_cloudwatch\_log\_enabled) | Enable or disable VPN tunnel logging feature for the tunnel | `bool` | `false` | no |
72+
| <a name="input_vpn_connection_tunnel1_cloudwatch_log_output_format"></a> [vpn\_connection\_tunnel1\_cloudwatch\_log\_output\_format](#input\_vpn\_connection\_tunnel1\_cloudwatch\_log\_output\_format) | Set log format for the tunnel. Default format is json. Possible values are: json and text | `string` | `"json"` | no |
6973
| <a name="input_vpn_connection_tunnel1_dpd_timeout_action"></a> [vpn\_connection\_tunnel1\_dpd\_timeout\_action](#input\_vpn\_connection\_tunnel1\_dpd\_timeout\_action) | The action to take after DPD timeout occurs for the first VPN tunnel. Specify restart to restart the IKE initiation. Specify clear to end the IKE session. Valid values are clear \| none \| restart. | `string` | `"clear"` | no |
7074
| <a name="input_vpn_connection_tunnel1_ike_versions"></a> [vpn\_connection\_tunnel1\_ike\_versions](#input\_vpn\_connection\_tunnel1\_ike\_versions) | The IKE versions that are permitted for the first VPN tunnel. Valid values are ikev1 \| ikev2. | `list(string)` | `[]` | no |
7175
| <a name="input_vpn_connection_tunnel1_inside_cidr"></a> [vpn\_connection\_tunnel1\_inside\_cidr](#input\_vpn\_connection\_tunnel1\_inside\_cidr) | The CIDR block of the inside IP addresses for the first VPN tunnel | `string` | `null` | no |
@@ -77,6 +81,8 @@
7781
| <a name="input_vpn_connection_tunnel1_phase2_integrity_algorithms"></a> [vpn\_connection\_tunnel1\_phase2\_integrity\_algorithms](#input\_vpn\_connection\_tunnel1\_phase2\_integrity\_algorithms) | One or more integrity algorithms that are permitted for the first VPN tunnel for phase 2 IKE negotiations. Valid values are SHA1 \| SHA2-256 \| SHA2-384 \| SHA2-512. | `list(string)` | `[]` | no |
7882
| <a name="input_vpn_connection_tunnel1_preshared_key"></a> [vpn\_connection\_tunnel1\_preshared\_key](#input\_vpn\_connection\_tunnel1\_preshared\_key) | The preshared key of the first VPN tunnel. The preshared key must be between 8 and 64 characters in length and cannot start with zero. Allowed characters are alphanumeric characters, periods(.) and underscores(\_) | `string` | `null` | no |
7983
| <a name="input_vpn_connection_tunnel1_startup_action"></a> [vpn\_connection\_tunnel1\_startup\_action](#input\_vpn\_connection\_tunnel1\_startup\_action) | The action to take when the establishing the tunnel for the first VPN connection. By default, your customer gateway device must initiate the IKE negotiation and bring up the tunnel. Specify start for AWS to initiate the IKE negotiation. Valid values are add \| start. | `string` | `"add"` | no |
84+
| <a name="input_vpn_connection_tunnel2_cloudwatch_log_enabled"></a> [vpn\_connection\_tunnel2\_cloudwatch\_log\_enabled](#input\_vpn\_connection\_tunnel2\_cloudwatch\_log\_enabled) | Enable or disable VPN tunnel logging feature for the tunnel | `bool` | `false` | no |
85+
| <a name="input_vpn_connection_tunnel2_cloudwatch_log_output_format"></a> [vpn\_connection\_tunnel2\_cloudwatch\_log\_output\_format](#input\_vpn\_connection\_tunnel2\_cloudwatch\_log\_output\_format) | Set log format for the tunnel. Default format is json. Possible values are: json and text | `string` | `"json"` | no |
8086
| <a name="input_vpn_connection_tunnel2_dpd_timeout_action"></a> [vpn\_connection\_tunnel2\_dpd\_timeout\_action](#input\_vpn\_connection\_tunnel2\_dpd\_timeout\_action) | The action to take after DPD timeout occurs for the second VPN tunnel. Specify restart to restart the IKE initiation. Specify clear to end the IKE session. Valid values are clear \| none \| restart. | `string` | `"clear"` | no |
8187
| <a name="input_vpn_connection_tunnel2_ike_versions"></a> [vpn\_connection\_tunnel2\_ike\_versions](#input\_vpn\_connection\_tunnel2\_ike\_versions) | The IKE versions that are permitted for the second VPN tunnel. Valid values are ikev1 \| ikev2. | `list(string)` | `[]` | no |
8288
| <a name="input_vpn_connection_tunnel2_inside_cidr"></a> [vpn\_connection\_tunnel2\_inside\_cidr](#input\_vpn\_connection\_tunnel2\_inside\_cidr) | The CIDR block of the inside IP addresses for the second VPN tunnel | `string` | `null` | no |

main.tf

+28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
locals {
22
enabled = module.this.enabled
33

4+
logs_enabled = local.enabled && (var.vpn_connection_tunnel1_cloudwatch_log_enabled || var.vpn_connection_tunnel2_cloudwatch_log_enabled)
45
transit_gateway_enabled = local.enabled && var.transit_gateway_enabled
56

67
transit_gateway_attachment_id = join("", aws_vpn_connection.default[*].transit_gateway_attachment_id)
@@ -26,6 +27,17 @@ resource "aws_customer_gateway" "default" {
2627
tags = module.this.tags
2728
}
2829

30+
module "logs" {
31+
source = "cloudposse/cloudwatch-logs/aws"
32+
version = "0.6.8"
33+
enabled = local.logs_enabled
34+
iam_role_enabled = false
35+
retention_in_days = var.vpn_connection_log_retention_in_days
36+
37+
context = module.this.context
38+
}
39+
40+
2941
# https://www.terraform.io/docs/providers/aws/r/vpn_connection.html
3042
resource "aws_vpn_connection" "default" {
3143
count = local.enabled ? 1 : 0
@@ -50,6 +62,14 @@ resource "aws_vpn_connection" "default" {
5062
tunnel1_phase1_integrity_algorithms = var.vpn_connection_tunnel1_phase1_integrity_algorithms
5163
tunnel1_phase2_integrity_algorithms = var.vpn_connection_tunnel1_phase2_integrity_algorithms
5264

65+
tunnel1_log_options {
66+
cloudwatch_log_options {
67+
log_enabled = var.vpn_connection_tunnel1_cloudwatch_log_enabled
68+
log_group_arn = var.vpn_connection_tunnel1_cloudwatch_log_enabled ? module.logs.log_group_arn : null
69+
log_output_format = var.vpn_connection_tunnel1_cloudwatch_log_enabled ? var.vpn_connection_tunnel1_cloudwatch_log_output_format : null
70+
}
71+
}
72+
5373
tunnel2_dpd_timeout_action = var.vpn_connection_tunnel2_dpd_timeout_action
5474
tunnel2_ike_versions = var.vpn_connection_tunnel2_ike_versions
5575
tunnel2_inside_cidr = var.vpn_connection_tunnel2_inside_cidr
@@ -63,6 +83,14 @@ resource "aws_vpn_connection" "default" {
6383
tunnel2_phase1_integrity_algorithms = var.vpn_connection_tunnel2_phase1_integrity_algorithms
6484
tunnel2_phase2_integrity_algorithms = var.vpn_connection_tunnel2_phase2_integrity_algorithms
6585

86+
tunnel2_log_options {
87+
cloudwatch_log_options {
88+
log_enabled = var.vpn_connection_tunnel2_cloudwatch_log_enabled
89+
log_group_arn = var.vpn_connection_tunnel2_cloudwatch_log_enabled ? module.logs.log_group_arn : null
90+
log_output_format = var.vpn_connection_tunnel2_cloudwatch_log_enabled ? var.vpn_connection_tunnel2_cloudwatch_log_output_format : null
91+
}
92+
}
93+
6694
tags = module.this.tags
6795
}
6896

variables.tf

+30
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ variable "vpn_connection_remote_ipv4_network_cidr" {
5050
default = "0.0.0.0/0"
5151
}
5252

53+
variable "vpn_connection_log_retention_in_days" {
54+
type = number
55+
description = "Specifies the number of days you want to retain log events."
56+
default = 30
57+
}
58+
5359
variable "vpn_connection_tunnel1_dpd_timeout_action" {
5460
type = string
5561
description = "The action to take after DPD timeout occurs for the first VPN tunnel. Specify restart to restart the IKE initiation. Specify clear to end the IKE session. Valid values are clear | none | restart."
@@ -116,6 +122,18 @@ variable "vpn_connection_tunnel1_startup_action" {
116122
default = "add"
117123
}
118124

125+
variable "vpn_connection_tunnel1_cloudwatch_log_enabled" {
126+
type = bool
127+
description = "Enable or disable VPN tunnel logging feature for the tunnel"
128+
default = false
129+
}
130+
131+
variable "vpn_connection_tunnel1_cloudwatch_log_output_format" {
132+
type = string
133+
description = "Set log format for the tunnel. Default format is json. Possible values are: json and text"
134+
default = "json"
135+
}
136+
119137
variable "vpn_connection_tunnel2_dpd_timeout_action" {
120138
type = string
121139
description = "The action to take after DPD timeout occurs for the second VPN tunnel. Specify restart to restart the IKE initiation. Specify clear to end the IKE session. Valid values are clear | none | restart."
@@ -182,6 +200,18 @@ variable "vpn_connection_tunnel2_startup_action" {
182200
default = "add"
183201
}
184202

203+
variable "vpn_connection_tunnel2_cloudwatch_log_enabled" {
204+
type = bool
205+
description = "Enable or disable VPN tunnel logging feature for the tunnel"
206+
default = false
207+
}
208+
209+
variable "vpn_connection_tunnel2_cloudwatch_log_output_format" {
210+
type = string
211+
description = "Set log format for the tunnel. Default format is json. Possible values are: json and text"
212+
default = "json"
213+
}
214+
185215
variable "existing_transit_gateway_id" {
186216
type = string
187217
default = ""

0 commit comments

Comments
 (0)