Skip to content

Commit 3bf013b

Browse files
feat: add functionality to pass a custom name for the vpe gateway (#362)
1 parent b06ff17 commit 3bf013b

File tree

7 files changed

+37
-15
lines changed

7 files changed

+37
-15
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ No modules.
107107
| <a name="input_subnet_zone_list"></a> [subnet\_zone\_list](#input\_subnet\_zone\_list) | List of subnets in the VPC where gateways and reserved IPs will be provisioned. This value is intended to use the `subnet_zone_list` output from the Landing Zone VPC Subnet Module (https://github.com/terraform-ibm-modules/terraform-ibm-landing-zone-vpc) or from templates using that module for subnet creation. | <pre>list(<br> object({<br> name = string<br> id = string<br> zone = optional(string)<br> cidr = optional(string)<br> })<br> )</pre> | `[]` | no |
108108
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | ID of the VPC where the Endpoint Gateways will be created | `string` | `null` | no |
109109
| <a name="input_vpc_name"></a> [vpc\_name](#input\_vpc\_name) | Name of the VPC where the Endpoint Gateways will be created. This value is used to dynamically generate VPE names. | `string` | `"vpc"` | no |
110+
| <a name="input_vpe_names"></a> [vpe\_names](#input\_vpe\_names) | A map whose keys are the service(s) you are overriding the name of and the values are the names you want the gateways for those services to have. | `map(string)` | `{}` | no |
110111

111112
### Outputs
112113

examples/default/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ module "vpes" {
9393
cloud_services = var.cloud_services
9494
cloud_service_by_crn = local.cloud_service_by_crn
9595
service_endpoints = var.service_endpoints
96+
vpe_names = var.vpe_names
9697
# See comments below (resource "time_sleep" "sleep_time") for explaination on why this is needed.
9798
depends_on = [time_sleep.sleep_time]
9899
}

examples/default/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ variable "service_endpoints" {
9191
}
9292
}
9393

94+
variable "vpe_names" {
95+
description = "A Map to specify custom names for endpoint gateways whose keys are services and values are names to use for that service's endpoint gateway."
96+
type = map(string)
97+
default = {}
98+
}
99+
94100
variable "resource_tags" {
95101
type = list(string)
96102
description = "Optional list of tags to be added to created resources"

main.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ locals {
88
# Create object for each service
99
for service in var.cloud_services :
1010
{
11-
name = "${var.vpc_name}-${service}"
11+
name = lookup(var.vpe_names, service, "${var.prefix}-${var.vpc_name}-${service}")
1212
service = service
1313
crn = null
1414
}
1515
],
1616
[
1717
for service in var.cloud_service_by_crn :
1818
{
19-
name = "${var.vpc_name}-${service.name}"
19+
name = lookup(var.vpe_names, service.name, "${var.prefix}-${var.vpc_name}-${service.name}")
2020
service = null
2121
crn = service.crn
2222
}
@@ -32,15 +32,15 @@ locals {
3232
{
3333
ip_name = "${subnet.name}-${service}-gateway-${replace(subnet.zone, "/${var.region}-/", "")}-ip"
3434
subnet_id = subnet.id
35-
gateway_name = "${var.prefix}-${var.vpc_name}-${service}"
35+
gateway_name = lookup(var.vpe_names, service, "${var.prefix}-${var.vpc_name}-${service}")
3636
}
3737
],
3838
[
3939
for service in var.cloud_service_by_crn :
4040
{
4141
ip_name = "${subnet.name}-${service.name}-gateway-${replace(subnet.zone, "/${var.region}-/", "")}-ip"
4242
subnet_id = subnet.id
43-
gateway_name = "${var.prefix}-${var.vpc_name}-${service.name}"
43+
gateway_name = lookup(var.vpe_names, service.name, "${var.prefix}-${var.vpc_name}-${service.name}")
4444
}
4545
])
4646
])
@@ -106,7 +106,7 @@ resource "ibm_is_subnet_reserved_ip" "ip" {
106106

107107
resource "ibm_is_virtual_endpoint_gateway" "vpe" {
108108
count = length(local.gateway_list)
109-
name = "${var.prefix}-${local.gateway_list[count.index].name}"
109+
name = local.gateway_list[count.index].name
110110
vpc = var.vpc_id
111111
resource_group = var.resource_group_id
112112
security_groups = var.security_group_ids

module-metadata.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,10 @@
2929
"type": "string",
3030
"description": "The prefix that you would like to append to your resources",
3131
"default": "vpe",
32-
"required": true,
33-
"source": [
34-
"ibm_is_virtual_endpoint_gateway.vpe.name"
35-
],
3632
"pos": {
3733
"filename": "variables.tf",
3834
"line": 11
39-
},
40-
"immutable": true,
41-
"min_length": 1,
42-
"max_length": 63,
43-
"matches": "^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$"
35+
}
4436
},
4537
"region": {
4638
"name": "region",
@@ -126,6 +118,16 @@
126118
"filename": "variables.tf",
127119
"line": 17
128120
}
121+
},
122+
"vpe_names": {
123+
"name": "vpe_names",
124+
"type": "map(string)",
125+
"description": "A map whose keys are the service(s) you are overriding the name of and the values are the names you want the gateways for those services to have.",
126+
"default": {},
127+
"pos": {
128+
"filename": "variables.tf",
129+
"line": 125
130+
}
129131
}
130132
},
131133
"outputs": {
@@ -175,7 +177,6 @@
175177
"type": "ibm_is_virtual_endpoint_gateway",
176178
"name": "vpe",
177179
"attributes": {
178-
"name": "prefix",
179180
"resource_group": "resource_group_id",
180181
"security_groups": "security_group_ids",
181182
"vpc": "vpc_id"

tests/pr_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ func setupOptions(t *testing.T, prefix string, dir string) *testhelper.TestOptio
3636
"user-management",
3737
}
3838

39+
vpeNames := map[string]string{
40+
"cloud-object-storage": "custom-cos-name",
41+
"kms": "custom-kms-name",
42+
"postgresql": "custom-postgres-name",
43+
}
44+
3945
options := testhelper.TestOptionsDefaultWithVars(&testhelper.TestOptions{
4046
Testing: t,
4147
TerraformDir: dir,
@@ -49,6 +55,7 @@ func setupOptions(t *testing.T, prefix string, dir string) *testhelper.TestOptio
4955
TerraformVars: map[string]interface{}{
5056
"region": region,
5157
"cloud_services": cloudServices,
58+
"vpe_names": vpeNames,
5259
},
5360
})
5461
return options

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,10 @@ variable "service_endpoints" {
122122
}
123123
}
124124

125+
variable "vpe_names" {
126+
description = "A map whose keys are the service(s) you are overriding the name of and the values are the names you want the gateways for those services to have."
127+
type = map(string)
128+
default = {}
129+
}
130+
125131
##############################################################################

0 commit comments

Comments
 (0)