Skip to content

Commit f04cffd

Browse files
committed
Save router configuration to local file in dx-private-virtual-interface module
1 parent 4e6c05d commit f04cffd

File tree

5 files changed

+36
-14
lines changed

5 files changed

+36
-14
lines changed

modules/dx-private-virtual-interface/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ This module creates following resources.
1212
|------|---------|
1313
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
1414
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.60 |
15+
| <a name="requirement_local"></a> [local](#requirement\_local) | >= 2.4 |
1516

1617
## Providers
1718

1819
| Name | Version |
1920
|------|---------|
2021
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.61.0 |
22+
| <a name="provider_local"></a> [local](#provider\_local) | 2.4.0 |
2123

2224
## Modules
2325

@@ -31,6 +33,7 @@ This module creates following resources.
3133
|------|------|
3234
| [aws_dx_bgp_peer.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/dx_bgp_peer) | resource |
3335
| [aws_dx_private_virtual_interface.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/dx_private_virtual_interface) | resource |
36+
| [local_file.this](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
3437
| [aws_dx_router_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/dx_router_configuration) | data source |
3538

3639
## Inputs
@@ -47,7 +50,7 @@ This module creates following resources.
4750
| <a name="input_resource_group_description"></a> [resource\_group\_description](#input\_resource\_group\_description) | (Optional) The description of Resource Group. | `string` | `"Managed by Terraform."` | no |
4851
| <a name="input_resource_group_enabled"></a> [resource\_group\_enabled](#input\_resource\_group\_enabled) | (Optional) Whether to create Resource Group to find and group AWS resources which are created by this module. | `bool` | `true` | no |
4952
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | (Optional) The name of Resource Group. A Resource Group name can have a maximum of 127 characters, including letters, numbers, hyphens, dots, and underscores. The name cannot start with `AWS` or `aws`. | `string` | `""` | no |
50-
| <a name="input_router"></a> [router](#input\_router) | (Optional) The ID of the Router Type to get the sample router configuration. For example: `CiscoSystemsInc-2900SeriesRouters-IOS124` | `string` | `null` | no |
53+
| <a name="input_router_configuration"></a> [router\_configuration](#input\_router\_configuration) | (Optional) The configuration to retrieve a sample router configuration for the virtual interface. `router_configuration` as defined below.<br> (Optional) `router` - The ID of the Router Type to get the sample router configuration. For example: `CiscoSystemsInc-2900SeriesRouters-IOS124`.<br> (Optional) `output_path` - The path to save sample router configuration. | <pre>object({<br> router = optional(string)<br> output_path = optional(string)<br> })</pre> | `{}` | no |
5154
| <a name="input_sitelink_enabled"></a> [sitelink\_enabled](#input\_sitelink\_enabled) | (Optional) Indicate whether to enable SiteLink. Control direct connectivity between Direct Connect points of presence. Subject to additional charges. Defaults to `false`. | `bool` | `false` | no |
5255
| <a name="input_tags"></a> [tags](#input\_tags) | (Optional) A map of tags to add to all resources. | `map(string)` | `{}` | no |
5356

@@ -65,7 +68,7 @@ This module creates following resources.
6568
| <a name="output_jumbo_frame_enabled"></a> [jumbo\_frame\_enabled](#output\_jumbo\_frame\_enabled) | Whether jumbo frames (9001 MTU) are enabled. |
6669
| <a name="output_mtu"></a> [mtu](#output\_mtu) | The MTU of the virtual interface. |
6770
| <a name="output_name"></a> [name](#output\_name) | The name of the virtual interface. |
68-
| <a name="output_sample_configuration"></a> [sample\_configuration](#output\_sample\_configuration) | The sample router configuration for the virtual interface. |
71+
| <a name="output_router_configuration"></a> [router\_configuration](#output\_router\_configuration) | The sample router configuration for the virtual interface. |
6972
| <a name="output_sitelink_enabled"></a> [sitelink\_enabled](#output\_sitelink\_enabled) | Indicate whether to enable SiteLink. |
7073
| <a name="output_vlan"></a> [vlan](#output\_vlan) | The ID of the VLAN. |
7174
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

modules/dx-private-virtual-interface/main.tf

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,23 @@ resource "aws_dx_bgp_peer" "this" {
9595
###################################################
9696

9797
data "aws_dx_router_configuration" "this" {
98-
count = var.router != null ? 1 : 0
98+
count = var.router_configuration.router != null ? 1 : 0
9999

100100
virtual_interface_id = aws_dx_private_virtual_interface.this.id
101-
router_type_identifier = var.router
101+
router_type_identifier = var.router_configuration.router
102102

103103
lifecycle {
104104
precondition {
105-
condition = contains(local.router_ids, var.router)
106-
error_message = "Not supported router ID: ${var.router}."
105+
condition = contains(local.router_ids, var.router_configuration.router)
106+
error_message = "Not supported router ID: ${var.router_configuration.router}."
107107
}
108108
}
109109
}
110+
111+
resource "local_file" "this" {
112+
count = var.router_configuration.router != null ? 1 : 0
113+
114+
filename = coalesce(var.router_configuration.output_path,
115+
"${path.root}/outputs/${var.name}.${var.router_configuration.router}.conf")
116+
content = one(data.aws_dx_router_configuration.this[*].customer_router_config)
117+
}

modules/dx-private-virtual-interface/outputs.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ output "bgp_peerings" {
9494
)
9595
}
9696

97-
output "sample_configuration" {
97+
output "router_configuration" {
9898
description = "The sample router configuration for the virtual interface."
9999
value = {
100100
router = one([
101101
for router in local.routers :
102102
router
103-
if router.id == var.router
103+
if router.id == var.router_configuration.router
104104
])
105-
config = one(data.aws_dx_router_configuration.this[*].customer_router_config)
105+
output_path = var.router_configuration.output_path
106106
}
107107
}

modules/dx-private-virtual-interface/variables.tf

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,18 @@ variable "bgp_peerings" {
9999
}
100100
}
101101

102-
variable "router" {
103-
description = "(Optional) The ID of the Router Type to get the sample router configuration. For example: `CiscoSystemsInc-2900SeriesRouters-IOS124`"
104-
type = string
105-
default = null
106-
nullable = true
102+
variable "router_configuration" {
103+
description = <<EOF
104+
(Optional) The configuration to retrieve a sample router configuration for the virtual interface. `router_configuration` as defined below.
105+
(Optional) `router` - The ID of the Router Type to get the sample router configuration. For example: `CiscoSystemsInc-2900SeriesRouters-IOS124`.
106+
(Optional) `output_path` - The path to save sample router configuration.
107+
EOF
108+
type = object({
109+
router = optional(string)
110+
output_path = optional(string)
111+
})
112+
default = {}
113+
nullable = false
107114
}
108115

109116
variable "tags" {

modules/dx-private-virtual-interface/versions.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@ terraform {
66
source = "hashicorp/aws"
77
version = ">= 4.60"
88
}
9+
local = {
10+
source = "hashicorp/local"
11+
version = ">= 2.4"
12+
}
913
}
1014
}

0 commit comments

Comments
 (0)