Skip to content
This repository was archived by the owner on Apr 6, 2026. It is now read-only.

Commit a653a65

Browse files
authored
Migrate Dev Center Network Connection Module to AzAPI
- Updated the `dev_center_network_connection` module to use the `azapi` provider instead of `azurerm`. - Modified `module.tf` to replace `azurerm_dev_center_network_connection` with `azapi_resource`. - Adjusted output values in `output.tf` to reflect changes in resource type. - Updated `README.md` and `variables.tf` to align with the new provider and resource structure. - Enhanced configuration examples in `configuration.tfvars` for both enhanced and simple cases. - Ensured compatibility with existing module interfaces while improving internal implementation.
1 parent 43e7ea4 commit a653a65

File tree

9 files changed

+137
-87
lines changed

9 files changed

+137
-87
lines changed

CHANGES_SUMMARY.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,30 @@ This document summarizes the updates made to the Azure DevCenter module to imple
66

77
## Latest Changes (July 28, 2025)
88

9+
### Dev Center Network Connection Module - AzAPI Migration
10+
- **Updated**: Migrated `dev_center_network_connection` module from azurerm to azapi provider
11+
- **Classification**: Improvement
12+
- **Breaking Change**: NO - Module interface remains the same, only internal implementation changed
13+
- **Files Modified**:
14+
- `modules/dev_center_network_connection/module.tf`:
15+
- Replaced `azurerm` provider with `azapi` provider (version ~> 2.4.0)
16+
- Updated resource from `azurerm_dev_center_network_connection` to `azapi_resource`
17+
- Set resource type to `Microsoft.DevCenter/networkConnections@2025-02-01`
18+
- Added `azapi_client_config` data source for subscription ID
19+
- Restructured properties in `body` block following Azure REST API schema
20+
- Added `response_export_values = ["properties"]` for proper output handling
21+
- `modules/dev_center_network_connection/output.tf`:
22+
- Updated output references from `azurerm_dev_center_network_connection.this` to `azapi_resource.this`
23+
- Modified property access to use `azapi_resource.this.output.properties.*` pattern
24+
- Added new outputs: `provisioning_state` and `health_check_status`
25+
- Updated `resource_group_name` output to reference variable (azapi doesn't expose this)
26+
- `modules/dev_center_network_connection/README.md`:
27+
- Updated provider requirements to reference azapi instead of azurerm
28+
- Added new output descriptions for provisioning_state and health_check_status
29+
- Updated resource table to reflect azapi_resource usage
30+
- **Testing**: All examples remain compatible as module interface is unchanged
31+
- **Validation**: Terraform fmt and validate pass successfully
32+
933
### Dev Center Environment Type Module - Complete Implementation
1034
- **Created**: Full implementation of the `dev_center_environment_type` module
1135
- **Files Created**:

docs/conventions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Each resource module follows a consistent file structure:
1313
### Naming Conventions
1414

1515
1. **Resource Naming**
16-
- All resources use the Azure CAF naming module for consistent naming. This includes prefixing names with "azurerm_"
16+
- All resources use the Azure CAF naming module for consistent naming. **IMPORTANT: This includes prefixing names with "azurerm_".**
1717
- Standard prefixes are applied through global settings
1818
- Resources are named using a combination of prefixes, resource type, and custom name
1919

examples/dev_center_network_connection/enhanced_case/configuration.tfvars

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,31 @@ global_settings = {
1414
# Resource Group Configuration
1515
resource_groups = {
1616
"dev_center_network_connection" = {
17-
name = "enhanced-dev-center-network-connection"
18-
location = "East US 2"
17+
name = "enhanced-dev-center-network-connection"
18+
region = "eastus"
1919
tags = {
2020
Purpose = "DevCenter Network Connection Enhanced Demo"
2121
Tier = "Production"
2222
}
2323
}
2424
}
2525

26-
# Virtual Network Configuration
27-
virtual_networks = {
28-
"dev_center_vnet" = {
29-
name = "enhanced-dev-center-vnet"
30-
location = "East US 2"
31-
address_space = ["172.16.0.0/16"]
32-
}
33-
}
34-
35-
# Subnet Configuration
36-
subnets = {
37-
"dev_center_subnet" = {
38-
name = "dev-center-hybrid-subnet"
39-
address_prefixes = ["172.16.10.0/24"]
40-
virtual_network_name = "enhanced-dev-center-vnet"
41-
}
42-
}
43-
4426
# Dev Center Network Connection Configuration - Hybrid Azure AD Join
4527
dev_center_network_connections = {
4628
"enhanced_hybrid_connection" = {
4729
name = "enhanced-hybrid-network-connection"
4830
domain_join_type = "HybridAzureADJoin"
49-
# subnet_id will be populated at runtime
50-
domain_name = "corp.contoso.local"
51-
domain_username = "svc-devcenter@corp.contoso.local"
52-
# Note: In production, use Azure Key Vault for sensitive data
53-
domain_password = var.domain_password # Pass via environment variable
54-
organization_unit = "OU=DevBoxes,OU=Computers,DC=corp,DC=contoso,DC=local"
31+
subnet_id = "/subscriptions/33e81e94-c18c-4d5a-a613-897c92b35411/resourceGroups/rg-alz-connectivity/providers/Microsoft.Network/virtualNetworks/alz-hub-eastus2/subnets/Sandbox"
32+
resource_group = {
33+
key = "dev_center_network_connection"
34+
}
35+
domain_join = {
36+
domain_name = "corp.contoso.local"
37+
domain_username = "svc-devcenter@corp.contoso.local"
38+
organizational_unit_path = "OU=DevBoxes,OU=Computers,DC=corp,DC=contoso,DC=local"
39+
# Note: In production, use Azure Key Vault for domain_password_secret_id
40+
# domain_password_secret_id = "/subscriptions/.../vaults/vault/secrets/domain-password"
41+
}
5542
tags = {
5643
Purpose = "Production Development Environment"
5744
DomainJoin = "Hybrid"

examples/dev_center_network_connection/simple_case/configuration.tfvars

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,23 @@ global_settings = {
1212
# Resource Group Configuration
1313
resource_groups = {
1414
"dev_center_network_connection" = {
15-
name = "example-dev-center-network-connection"
16-
location = "West Europe"
15+
name = "example-dev-center-network-connection"
16+
region = "eastus"
1717
tags = {
1818
Purpose = "DevCenter Network Connection Demo"
1919
}
2020
}
2121
}
2222

23-
# Virtual Network Configuration
24-
virtual_networks = {
25-
"dev_center_vnet" = {
26-
name = "example-dev-center-vnet"
27-
location = "West Europe"
28-
address_space = ["10.0.0.0/16"]
29-
}
30-
}
31-
32-
# Subnet Configuration
33-
subnets = {
34-
"dev_center_subnet" = {
35-
name = "dev-center-subnet"
36-
address_prefixes = ["10.0.1.0/24"]
37-
virtual_network_name = "example-dev-center-vnet"
38-
}
39-
}
40-
4123
# Dev Center Network Connection Configuration
4224
dev_center_network_connections = {
4325
"example_connection" = {
4426
name = "example-network-connection"
4527
domain_join_type = "AzureADJoin"
46-
# subnet_id will be populated at runtime
28+
subnet_id = "/subscriptions/33e81e94-c18c-4d5a-a613-897c92b35411/resourceGroups/rg-alz-connectivity/providers/Microsoft.Network/virtualNetworks/alz-hub-eastus/subnets/Sandbox"
29+
resource_group = {
30+
key = "dev_center_network_connection"
31+
}
4732
tags = {
4833
Purpose = "Development Environment"
4934
}

modules/dev_center_network_connection/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Dev Center Network Connection Module
22

3-
This module manages an Azure Dev Center Network Connection using the `azurerm_dev_center_network_connection` resource.
3+
This module manages an Azure Dev Center Network Connection using the `azapi_resource` resource.
44

55
## Overview
66

@@ -82,14 +82,14 @@ module "dev_center_network_connection" {
8282
|------|---------|
8383
| terraform | >= 1.9.0 |
8484
| azurecaf | ~> 1.2.29 |
85-
| azurerm | ~> 4.0 |
85+
| azapi | ~> 2.4.0 |
8686

8787
## Providers
8888

8989
| Name | Version |
9090
|------|---------|
9191
| azurecaf | ~> 1.2.29 |
92-
| azurerm | ~> 4.0 |
92+
| azapi | ~> 2.4.0 |
9393

9494
## Inputs
9595

@@ -110,13 +110,16 @@ module "dev_center_network_connection" {
110110
| resource_group_name | The resource group name of the Dev Center Network Connection |
111111
| domain_join_type | The domain join type of the Dev Center Network Connection |
112112
| subnet_id | The subnet ID of the Dev Center Network Connection |
113+
| provisioning_state | The provisioning state of the Dev Center Network Connection |
114+
| health_check_status | The health check status of the Dev Center Network Connection |
113115

114116
## Resources
115117

116118
| Name | Type |
117119
|------|------|
118120
| azurecaf_name.dev_center_network_connection | resource |
119-
| azurerm_dev_center_network_connection.this | resource |
121+
| azapi_resource.this | resource |
122+
| azapi_client_config.current | data source |
120123

121124
## Notes
122125

modules/dev_center_network_connection/module.tf

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ terraform {
55
source = "aztfmod/azurecaf"
66
version = "~> 1.2.29"
77
}
8-
azurerm = {
9-
source = "hashicorp/azurerm"
10-
version = "~> 4.0"
8+
azapi = {
9+
source = "Azure/azapi"
10+
version = "~> 2.4.0"
1111
}
1212
}
1313
}
@@ -33,24 +33,43 @@ resource "azurecaf_name" "dev_center_network_connection" {
3333
use_slug = var.global_settings.use_slug
3434
}
3535

36-
resource "azurerm_dev_center_network_connection" "this" {
37-
name = local.network_connection_name
38-
resource_group_name = var.resource_group_name
39-
location = var.location
40-
domain_join_type = var.dev_center_network_connection.domain_join_type
41-
subnet_id = var.dev_center_network_connection.subnet_id
36+
resource "azapi_resource" "this" {
37+
type = "Microsoft.DevCenter/networkConnections@2025-02-01"
38+
name = local.network_connection_name
39+
location = var.location
40+
parent_id = "/subscriptions/${data.azapi_client_config.current.subscription_id}/resourceGroups/${var.resource_group_name}"
4241

43-
domain_name = try(var.dev_center_network_connection.domain_name, null)
44-
domain_password = try(var.dev_center_network_connection.domain_password, null)
45-
domain_username = try(var.dev_center_network_connection.domain_username, null)
46-
organization_unit = try(var.dev_center_network_connection.organization_unit, null)
42+
body = {
43+
properties = merge(
44+
{
45+
domainJoinType = var.dev_center_network_connection.domain_join_type
46+
subnetId = var.dev_center_network_connection.subnet_id
47+
},
48+
try(var.dev_center_network_connection.networking_resource_group_name, null) != null ? {
49+
networkingResourceGroupName = var.dev_center_network_connection.networking_resource_group_name
50+
} : {},
51+
try(var.dev_center_network_connection.domain_join.domain_name, null) != null ? {
52+
domainName = var.dev_center_network_connection.domain_join.domain_name
53+
} : {},
54+
try(var.dev_center_network_connection.domain_join.domain_username, null) != null ? {
55+
domainUsername = var.dev_center_network_connection.domain_join.domain_username
56+
} : {},
57+
try(var.dev_center_network_connection.domain_join.organizational_unit_path, null) != null ? {
58+
organizationUnit = var.dev_center_network_connection.domain_join.organizational_unit_path
59+
} : {}
60+
)
61+
}
4762

4863
tags = local.tags
4964

65+
response_export_values = ["properties"]
66+
5067
# Ignore changes to system-managed tags that Azure automatically adds
5168
lifecycle {
5269
ignore_changes = [
5370
tags["hidden-title"]
5471
]
5572
}
56-
}
73+
}
74+
75+
data "azapi_client_config" "current" {}
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
11
output "id" {
22
description = "The ID of the Dev Center Network Connection"
3-
value = azurerm_dev_center_network_connection.this.id
3+
value = azapi_resource.this.id
44
}
55

66
output "name" {
77
description = "The name of the Dev Center Network Connection"
8-
value = azurerm_dev_center_network_connection.this.name
8+
value = azapi_resource.this.name
99
}
1010

1111
output "location" {
1212
description = "The location of the Dev Center Network Connection"
13-
value = azurerm_dev_center_network_connection.this.location
13+
value = azapi_resource.this.location
1414
}
1515

1616
output "resource_group_name" {
1717
description = "The resource group name of the Dev Center Network Connection"
18-
value = azurerm_dev_center_network_connection.this.resource_group_name
18+
value = var.resource_group_name
1919
}
2020

2121
output "domain_join_type" {
2222
description = "The domain join type of the Dev Center Network Connection"
23-
value = azurerm_dev_center_network_connection.this.domain_join_type
23+
value = try(azapi_resource.this.output.properties.domainJoinType, null)
2424
}
2525

2626
output "subnet_id" {
2727
description = "The subnet ID of the Dev Center Network Connection"
28-
value = azurerm_dev_center_network_connection.this.subnet_id
28+
value = try(azapi_resource.this.output.properties.subnetId, null)
29+
}
30+
31+
output "provisioning_state" {
32+
description = "The provisioning state of the Dev Center Network Connection"
33+
value = try(azapi_resource.this.output.properties.provisioningState, null)
34+
}
35+
36+
output "health_check_status" {
37+
description = "The health check status of the Dev Center Network Connection"
38+
value = try(azapi_resource.this.output.properties.healthCheckStatus, null)
2939
}

modules/dev_center_network_connection/variables.tf

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,29 @@ variable "location" {
2222
variable "dev_center_network_connection" {
2323
description = "Configuration object for the Dev Center Network Connection"
2424
type = object({
25-
name = string
26-
domain_join_type = string
27-
subnet_id = string
28-
domain_name = optional(string)
29-
domain_password = optional(string)
30-
domain_username = optional(string)
31-
organization_unit = optional(string)
32-
tags = optional(map(string))
25+
name = string
26+
domain_join_type = string
27+
subnet_id = string
28+
dev_center_id = optional(string)
29+
dev_center = optional(object({
30+
key = string
31+
}))
32+
resource_group = optional(object({
33+
key = string
34+
}))
35+
domain_join = optional(object({
36+
domain_name = string
37+
domain_password_secret_id = optional(string)
38+
domain_username = string
39+
organizational_unit_path = optional(string)
40+
}))
41+
networking_resource_group_name = optional(string)
42+
tags = optional(map(string), {})
3343
})
3444

3545
validation {
36-
condition = contains(["AzureADJoin", "HybridAzureADJoin"], var.dev_center_network_connection.domain_join_type)
37-
error_message = "Domain join type must be either 'AzureADJoin' or 'HybridAzureADJoin'."
46+
condition = contains(["AzureADJoin", "HybridAzureADJoin", "None"], var.dev_center_network_connection.domain_join_type)
47+
error_message = "Domain join type must be one of: AzureADJoin, HybridAzureADJoin, None."
3848
}
3949

4050
validation {

variables.tf

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,22 +258,34 @@ variable "dev_center_environment_types" {
258258
variable "dev_center_network_connections" {
259259
description = "Dev Center Network Connections configuration objects"
260260
type = map(object({
261-
name = string
262-
dev_center_id = optional(string)
261+
name = string
262+
domain_join_type = string
263+
subnet_id = string
264+
dev_center_id = optional(string)
263265
dev_center = optional(object({
264266
key = string
265267
}))
266-
network_connection_resource_id = string
267-
subnet_resource_id = string
268+
resource_group = optional(object({
269+
key = string
270+
}))
268271
domain_join = optional(object({
269272
domain_name = string
270273
domain_password_secret_id = optional(string)
271274
domain_username = string
272275
organizational_unit_path = optional(string)
273276
}))
274-
tags = optional(map(string), {})
277+
networking_resource_group_name = optional(string)
278+
tags = optional(map(string), {})
275279
}))
276280
default = {}
281+
282+
validation {
283+
condition = alltrue([
284+
for k, v in var.dev_center_network_connections :
285+
contains(["AzureADJoin", "HybridAzureADJoin", "None"], v.domain_join_type)
286+
])
287+
error_message = "Domain join type must be one of: AzureADJoin, HybridAzureADJoin, None."
288+
}
277289
}
278290

279291
# tflint-ignore: terraform_unused_declarations

0 commit comments

Comments
 (0)