Skip to content

Commit e4af6f6

Browse files
committed
feat: add customer-gateway module
1 parent de45997 commit e4af6f6

File tree

6 files changed

+277
-0
lines changed

6 files changed

+277
-0
lines changed

modules/customer-gateway/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# customer-gateway
2+
3+
This module creates following resources.
4+
5+
- `aws_customer_gateway`
6+
7+
<!-- BEGIN_TF_DOCS -->
8+
## Requirements
9+
10+
| Name | Version |
11+
|------|---------|
12+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.9 |
13+
| <a name="requirement_assert"></a> [assert](#requirement\_assert) | >= 0.15 |
14+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.93 |
15+
16+
## Providers
17+
18+
| Name | Version |
19+
|------|---------|
20+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.93.0 |
21+
22+
## Modules
23+
24+
| Name | Source | Version |
25+
|------|--------|---------|
26+
| <a name="module_resource_group"></a> [resource\_group](#module\_resource\_group) | tedilabs/misc/aws//modules/resource-group | ~> 0.10.0 |
27+
28+
## Resources
29+
30+
| Name | Type |
31+
|------|------|
32+
| [aws_customer_gateway.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/customer_gateway) | resource |
33+
34+
## Inputs
35+
36+
| Name | Description | Type | Default | Required |
37+
|------|-------------|------|---------|:--------:|
38+
| <a name="input_ip_address"></a> [ip\_address](#input\_ip\_address) | (Required) The IPv4 address for the customer gateway device's outside interface. | `string` | n/a | yes |
39+
| <a name="input_name"></a> [name](#input\_name) | (Required) A name for the customer gateway. | `string` | n/a | yes |
40+
| <a name="input_asn"></a> [asn](#input\_asn) | (Optional) The ASN (Autonomous System Number) of the customer gateway device. Valid values are between `1` and `4294967295`. Defaults to `65000.` | `number` | `65000` | no |
41+
| <a name="input_certificate"></a> [certificate](#input\_certificate) | (Optional) The ARN (Amazon Resource Name) of the certificate for the customer gateway. | `string` | `null` | no |
42+
| <a name="input_device"></a> [device](#input\_device) | (Optional) A name for the customer gateway device. | `string` | `""` | no |
43+
| <a name="input_module_tags_enabled"></a> [module\_tags\_enabled](#input\_module\_tags\_enabled) | (Optional) Whether to create AWS Resource Tags for the module informations. | `bool` | `true` | no |
44+
| <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 |
45+
| <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 |
46+
| <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 |
47+
| <a name="input_tags"></a> [tags](#input\_tags) | (Optional) A map of tags to add to all resources. | `map(string)` | `{}` | no |
48+
49+
## Outputs
50+
51+
| Name | Description |
52+
|------|-------------|
53+
| <a name="output_arn"></a> [arn](#output\_arn) | The ARN (Amazon Resource Name) of the customer gateway. |
54+
| <a name="output_asn"></a> [asn](#output\_asn) | The ASN (Autonomous System Number) of the customer gateway device. |
55+
| <a name="output_certificate"></a> [certificate](#output\_certificate) | The ARN (Amazon Resource Name) of the certificate for the customer gateway. |
56+
| <a name="output_device"></a> [device](#output\_device) | The name for the customer gateway device. |
57+
| <a name="output_id"></a> [id](#output\_id) | The ID of the customer gateway. |
58+
| <a name="output_ip_address"></a> [ip\_address](#output\_ip\_address) | The IPv4 address for the customer gateway device's outside interface. |
59+
| <a name="output_name"></a> [name](#output\_name) | The name of the customer gateway. |
60+
| <a name="output_type"></a> [type](#output\_type) | The type of customer gateway. |
61+
<!-- END_TF_DOCS -->

modules/customer-gateway/main.tf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
locals {
2+
metadata = {
3+
package = "terraform-aws-vpn"
4+
version = trimspace(file("${path.module}/../../VERSION"))
5+
module = basename(path.module)
6+
name = var.name
7+
}
8+
module_tags = var.module_tags_enabled ? {
9+
"module.terraform.io/package" = local.metadata.package
10+
"module.terraform.io/version" = local.metadata.version
11+
"module.terraform.io/name" = local.metadata.module
12+
"module.terraform.io/full-name" = "${local.metadata.package}/${local.metadata.module}"
13+
"module.terraform.io/instance" = local.metadata.name
14+
} : {}
15+
}
16+
17+
18+
###################################################
19+
# Customer Gateway
20+
###################################################
21+
22+
resource "aws_customer_gateway" "this" {
23+
device_name = var.device
24+
ip_address = var.ip_address
25+
bgp_asn = var.asn >= 2147483648 ? null : var.asn
26+
bgp_asn_extended = var.asn >= 2147483648 ? var.asn : null
27+
28+
type = "ipsec.1"
29+
certificate_arn = var.certificate
30+
31+
tags = merge(
32+
{
33+
"Name" = local.metadata.name
34+
},
35+
local.module_tags,
36+
var.tags,
37+
)
38+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
output "id" {
2+
description = "The ID of the customer gateway."
3+
value = aws_customer_gateway.this.id
4+
}
5+
6+
output "arn" {
7+
description = "The ARN (Amazon Resource Name) of the customer gateway."
8+
value = aws_customer_gateway.this.arn
9+
}
10+
11+
output "name" {
12+
description = "The name of the customer gateway."
13+
value = local.metadata.name
14+
}
15+
16+
output "type" {
17+
description = "The type of customer gateway."
18+
value = aws_customer_gateway.this.type
19+
}
20+
21+
output "device" {
22+
description = "The name for the customer gateway device."
23+
value = aws_customer_gateway.this.device_name
24+
}
25+
26+
output "ip_address" {
27+
description = "The IPv4 address for the customer gateway device's outside interface."
28+
value = aws_customer_gateway.this.ip_address
29+
}
30+
31+
output "asn" {
32+
description = "The ASN (Autonomous System Number) of the customer gateway device."
33+
value = var.asn
34+
}
35+
36+
output "certificate" {
37+
description = "The ARN (Amazon Resource Name) of the certificate for the customer gateway."
38+
value = aws_customer_gateway.this.certificate_arn
39+
}
40+
41+
# output "debug" {
42+
# description = "For debug purpose"
43+
# value = {
44+
# for k, v in aws_customer_gateway.this :
45+
# k => v
46+
# if !contains(["device_name", "type", "ip_address", "tags", "tags_all", "arn", "id", "certificate_arn", "bgp_asn", "bgp_asn_extended"], k)
47+
# }
48+
# }
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
locals {
2+
resource_group_name = (var.resource_group_name != ""
3+
? var.resource_group_name
4+
: join(".", [
5+
local.metadata.package,
6+
local.metadata.module,
7+
replace(local.metadata.name, "/[^a-zA-Z0-9_\\.-]/", "-"),
8+
])
9+
)
10+
}
11+
12+
13+
module "resource_group" {
14+
source = "tedilabs/misc/aws//modules/resource-group"
15+
version = "~> 0.10.0"
16+
17+
count = (var.resource_group_enabled && var.module_tags_enabled) ? 1 : 0
18+
19+
name = local.resource_group_name
20+
description = var.resource_group_description
21+
22+
query = {
23+
resource_tags = local.module_tags
24+
}
25+
26+
module_tags_enabled = false
27+
tags = merge(
28+
local.module_tags,
29+
var.tags,
30+
)
31+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
variable "name" {
2+
description = "(Required) A name for the customer gateway."
3+
type = string
4+
nullable = false
5+
}
6+
7+
variable "device" {
8+
description = "(Optional) A name for the customer gateway device."
9+
type = string
10+
default = ""
11+
nullable = false
12+
}
13+
14+
variable "ip_address" {
15+
description = "(Required) The IPv4 address for the customer gateway device's outside interface."
16+
type = string
17+
nullable = false
18+
19+
validation {
20+
condition = provider::assert::ipv4(var.ip_address)
21+
error_message = "The value of `ip_address` is invalid IPv4 address."
22+
}
23+
}
24+
25+
variable "asn" {
26+
description = "(Optional) The ASN (Autonomous System Number) of the customer gateway device. Valid values are between `1` and `4294967295`. Defaults to `65000.`"
27+
type = number
28+
default = 65000
29+
nullable = false
30+
31+
validation {
32+
condition = alltrue([
33+
var.asn >= 1,
34+
var.asn <= 4294967295,
35+
])
36+
error_message = "Valid values are between `1` and `4294967295`."
37+
}
38+
}
39+
40+
variable "certificate" {
41+
description = "(Optional) The ARN (Amazon Resource Name) of the certificate for the customer gateway."
42+
type = string
43+
default = null
44+
nullable = true
45+
}
46+
47+
variable "tags" {
48+
description = "(Optional) A map of tags to add to all resources."
49+
type = map(string)
50+
default = {}
51+
nullable = false
52+
}
53+
54+
variable "module_tags_enabled" {
55+
description = "(Optional) Whether to create AWS Resource Tags for the module informations."
56+
type = bool
57+
default = true
58+
nullable = false
59+
}
60+
61+
62+
###################################################
63+
# Resource Group
64+
###################################################
65+
66+
variable "resource_group_enabled" {
67+
description = "(Optional) Whether to create Resource Group to find and group AWS resources which are created by this module."
68+
type = bool
69+
default = true
70+
nullable = false
71+
}
72+
73+
variable "resource_group_name" {
74+
description = "(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`."
75+
type = string
76+
default = ""
77+
nullable = false
78+
}
79+
80+
variable "resource_group_description" {
81+
description = "(Optional) The description of Resource Group."
82+
type = string
83+
default = "Managed by Terraform."
84+
nullable = false
85+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
required_version = ">= 1.9"
3+
4+
required_providers {
5+
assert = {
6+
source = "hashicorp/assert"
7+
version = ">= 0.15"
8+
}
9+
aws = {
10+
source = "hashicorp/aws"
11+
version = ">= 5.93"
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)