Skip to content

Commit

Permalink
feat: add functionality to pass a custom name for the vpe gateway (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewLemmond authored Aug 15, 2023
1 parent b06ff17 commit 3bf013b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ No modules.
| <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 |
| <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 |
| <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 |
| <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 |

### Outputs

Expand Down
1 change: 1 addition & 0 deletions examples/default/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ module "vpes" {
cloud_services = var.cloud_services
cloud_service_by_crn = local.cloud_service_by_crn
service_endpoints = var.service_endpoints
vpe_names = var.vpe_names
# See comments below (resource "time_sleep" "sleep_time") for explaination on why this is needed.
depends_on = [time_sleep.sleep_time]
}
Expand Down
6 changes: 6 additions & 0 deletions examples/default/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ variable "service_endpoints" {
}
}

variable "vpe_names" {
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."
type = map(string)
default = {}
}

variable "resource_tags" {
type = list(string)
description = "Optional list of tags to be added to created resources"
Expand Down
10 changes: 5 additions & 5 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ locals {
# Create object for each service
for service in var.cloud_services :
{
name = "${var.vpc_name}-${service}"
name = lookup(var.vpe_names, service, "${var.prefix}-${var.vpc_name}-${service}")
service = service
crn = null
}
],
[
for service in var.cloud_service_by_crn :
{
name = "${var.vpc_name}-${service.name}"
name = lookup(var.vpe_names, service.name, "${var.prefix}-${var.vpc_name}-${service.name}")
service = null
crn = service.crn
}
Expand All @@ -32,15 +32,15 @@ locals {
{
ip_name = "${subnet.name}-${service}-gateway-${replace(subnet.zone, "/${var.region}-/", "")}-ip"
subnet_id = subnet.id
gateway_name = "${var.prefix}-${var.vpc_name}-${service}"
gateway_name = lookup(var.vpe_names, service, "${var.prefix}-${var.vpc_name}-${service}")
}
],
[
for service in var.cloud_service_by_crn :
{
ip_name = "${subnet.name}-${service.name}-gateway-${replace(subnet.zone, "/${var.region}-/", "")}-ip"
subnet_id = subnet.id
gateway_name = "${var.prefix}-${var.vpc_name}-${service.name}"
gateway_name = lookup(var.vpe_names, service.name, "${var.prefix}-${var.vpc_name}-${service.name}")
}
])
])
Expand Down Expand Up @@ -106,7 +106,7 @@ resource "ibm_is_subnet_reserved_ip" "ip" {

resource "ibm_is_virtual_endpoint_gateway" "vpe" {
count = length(local.gateway_list)
name = "${var.prefix}-${local.gateway_list[count.index].name}"
name = local.gateway_list[count.index].name
vpc = var.vpc_id
resource_group = var.resource_group_id
security_groups = var.security_group_ids
Expand Down
21 changes: 11 additions & 10 deletions module-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,10 @@
"type": "string",
"description": "The prefix that you would like to append to your resources",
"default": "vpe",
"required": true,
"source": [
"ibm_is_virtual_endpoint_gateway.vpe.name"
],
"pos": {
"filename": "variables.tf",
"line": 11
},
"immutable": true,
"min_length": 1,
"max_length": 63,
"matches": "^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$"
}
},
"region": {
"name": "region",
Expand Down Expand Up @@ -126,6 +118,16 @@
"filename": "variables.tf",
"line": 17
}
},
"vpe_names": {
"name": "vpe_names",
"type": "map(string)",
"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.",
"default": {},
"pos": {
"filename": "variables.tf",
"line": 125
}
}
},
"outputs": {
Expand Down Expand Up @@ -175,7 +177,6 @@
"type": "ibm_is_virtual_endpoint_gateway",
"name": "vpe",
"attributes": {
"name": "prefix",
"resource_group": "resource_group_id",
"security_groups": "security_group_ids",
"vpc": "vpc_id"
Expand Down
7 changes: 7 additions & 0 deletions tests/pr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func setupOptions(t *testing.T, prefix string, dir string) *testhelper.TestOptio
"user-management",
}

vpeNames := map[string]string{
"cloud-object-storage": "custom-cos-name",
"kms": "custom-kms-name",
"postgresql": "custom-postgres-name",
}

options := testhelper.TestOptionsDefaultWithVars(&testhelper.TestOptions{
Testing: t,
TerraformDir: dir,
Expand All @@ -49,6 +55,7 @@ func setupOptions(t *testing.T, prefix string, dir string) *testhelper.TestOptio
TerraformVars: map[string]interface{}{
"region": region,
"cloud_services": cloudServices,
"vpe_names": vpeNames,
},
})
return options
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,10 @@ variable "service_endpoints" {
}
}

variable "vpe_names" {
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."
type = map(string)
default = {}
}

##############################################################################

0 comments on commit 3bf013b

Please sign in to comment.