Skip to content

Commit bd5da63

Browse files
Feature/add resource names v2 (#7)
* add support for resource names v2 * fix go tests
1 parent 5facd60 commit bd5da63

File tree

6 files changed

+73
-4
lines changed

6 files changed

+73
-4
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,16 @@ No providers.
120120
| Name | Source | Version |
121121
|------|--------|---------|
122122
| <a name="module_resource_names"></a> [resource\_names](#module\_resource\_names) | terraform.registry.launch.nttdata.com/module_library/resource_name/launch | ~> 1.0 |
123+
| <a name="module_resource_names_v2"></a> [resource\_names\_v2](#module\_resource\_names\_v2) | terraform.registry.launch.nttdata.com/module_library/resource_name/launch | ~> 2.0 |
123124
| <a name="module_resource_group"></a> [resource\_group](#module\_resource\_group) | terraform.registry.launch.nttdata.com/module_primitive/resource_group/azurerm | ~> 1.0 |
124125
| <a name="module_network"></a> [network](#module\_network) | terraform.registry.launch.nttdata.com/module_primitive/virtual_network/azurerm | ~> 3.0 |
125126
| <a name="module_subnets"></a> [subnets](#module\_subnets) | terraform.registry.launch.nttdata.com/module_primitive/virtual_network_subnet/azurerm | ~> 1.0 |
126127
| <a name="module_private_dns_zones"></a> [private\_dns\_zones](#module\_private\_dns\_zones) | terraform.registry.launch.nttdata.com/module_primitive/private_dns_zone/azurerm | ~> 1.0 |
127128
| <a name="module_private_dns_zone_vnet_links"></a> [private\_dns\_zone\_vnet\_links](#module\_private\_dns\_zone\_vnet\_links) | terraform.registry.launch.nttdata.com/module_primitive/private_dns_vnet_link/azurerm | ~> 1.0 |
128129
| <a name="module_private_endpoint_resource_names"></a> [private\_endpoint\_resource\_names](#module\_private\_endpoint\_resource\_names) | terraform.registry.launch.nttdata.com/module_library/resource_name/launch | ~> 1.0 |
130+
| <a name="module_private_endpoint_resource_names_v2"></a> [private\_endpoint\_resource\_names\_v2](#module\_private\_endpoint\_resource\_names\_v2) | terraform.registry.launch.nttdata.com/module_library/resource_name/launch | ~> 2.0 |
129131
| <a name="module_private_service_connection_resource_names"></a> [private\_service\_connection\_resource\_names](#module\_private\_service\_connection\_resource\_names) | terraform.registry.launch.nttdata.com/module_library/resource_name/launch | ~> 1.0 |
132+
| <a name="module_private_service_connection_resource_names_v2"></a> [private\_service\_connection\_resource\_names\_v2](#module\_private\_service\_connection\_resource\_names\_v2) | terraform.registry.launch.nttdata.com/module_library/resource_name/launch | ~> 2.0 |
130133
| <a name="module_private_endpoints"></a> [private\_endpoints](#module\_private\_endpoints) | terraform.registry.launch.nttdata.com/module_primitive/private_endpoint/azurerm | ~> 1.0 |
131134
| <a name="module_route_tables"></a> [route\_tables](#module\_route\_tables) | terraform.registry.launch.nttdata.com/module_primitive/route_table/azurerm | ~> 1.0 |
132135
| <a name="module_routes"></a> [routes](#module\_routes) | terraform.registry.launch.nttdata.com/module_primitive/route/azurerm | ~> 1.0 |
@@ -159,6 +162,7 @@ No resources.
159162
| <a name="input_routes"></a> [routes](#input\_routes) | A mapping of routes to create. | <pre>map(object({<br> name = string<br> route_table_alias = string<br> address_prefix = string<br> next_hop_type = string<br> next_hop_in_ip_address = optional(string, null)<br> }))</pre> | `{}` | no |
160163
| <a name="input_tags"></a> [tags](#input\_tags) | Tags to be applied to all resources that are created by this module. | `map(string)` | `{}` | no |
161164
| <a name="input_resource_names_map"></a> [resource\_names\_map](#input\_resource\_names\_map) | A map of key to resource\_name that will be used by tf-launch-module\_library-resource\_name to generate resource names | <pre>map(object({<br> name = string<br> max_length = optional(number, 60)<br> }))</pre> | <pre>{<br> "monitor_private_link_scope": {<br> "max_length": 80,<br> "name": "ampls"<br> },<br> "monitor_private_link_scope_private_endpoint": {<br> "max_length": 80,<br> "name": "amplspe"<br> },<br> "resource_group": {<br> "max_length": 80,<br> "name": "rg"<br> },<br> "virtual_network": {<br> "max_length": 80,<br> "name": "vnet"<br> }<br>}</pre> | no |
165+
| <a name="input_resource_names_version"></a> [resource\_names\_version](#input\_resource\_names\_version) | Major version of the resource names module to use | `string` | `"1"` | no |
162166
| <a name="input_environment"></a> [environment](#input\_environment) | Environment in which the resource should be provisioned like dev, qa, prod etc. | `string` | `"sandbox"` | no |
163167
| <a name="input_class_env"></a> [class\_env](#input\_class\_env) | Environment where resource is going to be deployed. For example. dev, qa, uat | `string` | `null` | no |
164168
| <a name="input_environment_number"></a> [environment\_number](#input\_environment\_number) | The environment count for the respective environment. Defaults to 000. Increments in value of 1 | `string` | `"000"` | no |

locals.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ locals {
44
}
55
tags = merge(local.default_tags, var.tags)
66

7-
resource_group_name = module.resource_names["resource_group"].standard
8-
virtual_network_name = module.resource_names["virtual_network"].standard
7+
use_v2_resource_names = (var.resource_names_version == "2")
8+
9+
resource_group_name = local.use_v2_resource_names ? module.resource_names_v2["resource_group"].standard : module.resource_names["resource_group"].standard
10+
virtual_network_name = local.use_v2_resource_names ? module.resource_names_v2["virtual_network"].standard : module.resource_names["virtual_network"].standard
911

1012
transformed_subnets = {
1113
for subnet_alias, subnet_definition in var.subnets :

main.tf

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@ module "resource_names" {
2727
use_azure_region_abbr = true
2828
}
2929

30+
module "resource_names_v2" {
31+
source = "terraform.registry.launch.nttdata.com/module_library/resource_name/launch"
32+
version = "~> 2.0"
33+
34+
for_each = local.use_v2_resource_names ? var.resource_names_map : {}
35+
36+
region = join("", split("-", var.location))
37+
class_env = coalesce(var.class_env, var.environment)
38+
cloud_resource_type = each.value.name
39+
instance_env = coalesce(var.instance_env, var.environment_number)
40+
instance_resource = coalesce(var.instance_resource, var.resource_number)
41+
maximum_length = each.value.max_length
42+
logical_product_family = var.logical_product_family
43+
logical_product_service = var.logical_product_service
44+
use_azure_region_abbr = true
45+
}
46+
3047
module "resource_group" {
3148
source = "terraform.registry.launch.nttdata.com/module_primitive/resource_group/azurerm"
3249
version = "~> 1.0"
@@ -124,6 +141,23 @@ module "private_endpoint_resource_names" {
124141
use_azure_region_abbr = true
125142
}
126143

144+
module "private_endpoint_resource_names_v2" {
145+
source = "terraform.registry.launch.nttdata.com/module_library/resource_name/launch"
146+
version = "~> 2.0"
147+
148+
for_each = local.use_v2_resource_names ? var.private_endpoints : {}
149+
150+
region = join("", split("-", var.location))
151+
class_env = var.environment
152+
cloud_resource_type = var.private_endpoint_resource_names_map["private_endpoint"].name
153+
instance_env = var.environment_number
154+
instance_resource = var.resource_number
155+
maximum_length = var.private_endpoint_resource_names_map["private_endpoint"].max_length
156+
logical_product_family = var.logical_product_family
157+
logical_product_service = each.key
158+
use_azure_region_abbr = true
159+
}
160+
127161
module "private_service_connection_resource_names" {
128162
source = "terraform.registry.launch.nttdata.com/module_library/resource_name/launch"
129163
version = "~> 1.0"
@@ -141,17 +175,34 @@ module "private_service_connection_resource_names" {
141175
use_azure_region_abbr = true
142176
}
143177

178+
module "private_service_connection_resource_names_v2" {
179+
source = "terraform.registry.launch.nttdata.com/module_library/resource_name/launch"
180+
version = "~> 2.0"
181+
182+
for_each = local.use_v2_resource_names ? var.private_endpoints : {}
183+
184+
region = join("", split("-", var.location))
185+
class_env = var.environment
186+
cloud_resource_type = var.private_endpoint_resource_names_map["private_service_connection"].name
187+
instance_env = var.environment_number
188+
instance_resource = var.resource_number
189+
maximum_length = var.private_endpoint_resource_names_map["private_service_connection"].max_length
190+
logical_product_family = var.logical_product_family
191+
logical_product_service = each.key
192+
use_azure_region_abbr = true
193+
}
194+
144195
module "private_endpoints" {
145196
source = "terraform.registry.launch.nttdata.com/module_primitive/private_endpoint/azurerm"
146197
version = "~> 1.0"
147198

148199
for_each = var.private_endpoints
149200

150201
region = var.location
151-
endpoint_name = module.private_endpoint_resource_names[each.key].standard
202+
endpoint_name = local.use_v2_resource_names ? module.private_endpoint_resource_names_v2[each.key].standard : module.private_endpoint_resource_names[each.key].standard
152203
is_manual_connection = false
153204
resource_group_name = module.resource_group.name
154-
private_service_connection_name = module.private_service_connection_resource_names[each.key].standard
205+
private_service_connection_name = local.use_v2_resource_names ? module.private_service_connection_resource_names_v2[each.key].standard : module.private_service_connection_resource_names[each.key].standard
155206
private_connection_resource_id = each.value.target_resource_id
156207
subresource_names = each.value.private_link_subresource_names
157208
subnet_id = module.subnets[each.value.subnet_name].id

tests/post_deploy_functional/main_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ func TestVnetModule(t *testing.T) {
3838
"with_private_endpoint": {
3939
"IS_TERRAFORM_IDEMPOTENT_APPLY": false,
4040
},
41+
"with_private_link_scope": {
42+
"IS_TERRAFORM_IDEMPOTENT_APPLY": false,
43+
},
4144
}).
4245
Build()
4346

tests/post_deploy_functional_readonly/main_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ func TestVnetModule(t *testing.T) {
3838
"with_private_endpoint": {
3939
"IS_TERRAFORM_IDEMPOTENT_APPLY": false,
4040
},
41+
"with_private_link_scope": {
42+
"IS_TERRAFORM_IDEMPOTENT_APPLY": false,
43+
},
4144
}).
4245
Build()
4346

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ variable "resource_names_map" {
204204
}
205205
}
206206

207+
variable "resource_names_version" {
208+
description = "Major version of the resource names module to use"
209+
type = string
210+
default = "1"
211+
}
212+
207213
// TODO: remove this in favor of `class_env` next major release
208214
variable "environment" {
209215
description = "Environment in which the resource should be provisioned like dev, qa, prod etc."

0 commit comments

Comments
 (0)