Skip to content

Commit

Permalink
feat(AZ-1088)!: module v8 structure and updates
Browse files Browse the repository at this point in the history
BREAKING CHANGES: AzureRM Provider v4+ and OpenTofu 1.8+
  • Loading branch information
Shr3ps committed Nov 6, 2024
1 parent e72f535 commit 36cdb0a
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 212 deletions.
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
variables:
TF_MIN_VERSION: "1.3"
AZURERM_PROVIDER_MIN_VERSION: "3.107"
TF_MIN_VERSION: "1.8"
AZURERM_PROVIDER_MIN_VERSION: "4.0"

include:
- project: "claranet/projects/cloud/azure/terraform/ci"
Expand Down
86 changes: 28 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,7 @@ More details about variables set by the `terraform-wrapper` available in the [do
[Hashicorp Terraform](https://github.com/hashicorp/terraform/). Instead, we recommend to use [OpenTofu](https://github.com/opentofu/opentofu/).

```hcl
module "azure_region" {
source = "claranet/regions/azurerm"
version = "x.x.x"
azure_region = var.azure_region
}
module "rg" {
source = "claranet/rg/azurerm"
version = "x.x.x"
location = module.azure_region.location
client_name = var.client_name
environment = var.environment
stack = var.stack
}
module "azure_network_vnet" {
source = "claranet/vnet/azurerm"
version = "x.x.x"
environment = var.environment
location = module.azure_region.location
location_short = module.azure_region.location_short
client_name = var.client_name
stack = var.stack
resource_group_name = module.rg.resource_group_name
vnet_cidr = ["10.0.1.0/24"]
}
module "azure_network_route_table" {
module "route_table" {
source = "claranet/route-table/azurerm"
version = "x.x.x"
Expand All @@ -74,10 +44,10 @@ module "azure_network_route_table" {
stack = var.stack
location = module.azure_region.location
location_short = module.azure_region.location_short
resource_group_name = module.rg.resource_group_name
resource_group_name = module.rg.name
}
module "azure_network_security_group" {
module "network_security_group" {
source = "claranet/nsg/azurerm"
version = "x.x.x"
Expand All @@ -86,10 +56,10 @@ module "azure_network_security_group" {
location = module.azure_region.location
location_short = module.azure_region.location_short
stack = var.stack
resource_group_name = module.rg.resource_group_name
resource_group_name = module.rg.name
}
module "azure_network_subnet" {
module "subnet" {
source = "claranet/subnet/azurerm"
version = "x.x.x"
Expand All @@ -98,9 +68,9 @@ module "azure_network_subnet" {
client_name = var.client_name
stack = var.stack
resource_group_name = module.rg.resource_group_name
resource_group_name = module.rg.name
virtual_network_name = module.azure_network_vnet.virtual_network_name
virtual_network_name = module.vnet.name
subnet_cidr_list = ["10.0.1.0/26"]
subnet_delegation = {
app-service-plan = [
Expand All @@ -111,9 +81,9 @@ module "azure_network_subnet" {
]
}
route_table_name = module.azure_network_route_table.route_table_name
route_table_name = module.route_table.name
network_security_group_name = module.azure_network_security_group.network_security_group_name
network_security_group_name = module.network_security_group.name
service_endpoints = ["Microsoft.Storage", "Microsoft.KeyVault", "Microsoft.ServiceBus", "Microsoft.Web"]
}
Expand All @@ -123,8 +93,8 @@ module "azure_network_subnet" {

| Name | Version |
|------|---------|
| azurecaf | ~> 1.2, >= 1.2.22 |
| azurerm | ~> 3.107 |
| azurecaf | ~> 1.2.28 |
| azurerm | ~> 4.0 |

## Modules

Expand All @@ -134,7 +104,7 @@ No modules.

| Name | Type |
|------|------|
| [azurerm_subnet.subnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet) | resource |
| [azurerm_subnet.main](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet) | resource |
| [azurerm_subnet_network_security_group_association.subnet_association](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet_network_security_group_association) | resource |
| [azurerm_subnet_route_table_association.route_table_association](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet_route_table_association) | resource |
| [azurecaf_name.subnet](https://registry.terraform.io/providers/claranet/azurecaf/latest/docs/data-sources/name) | data source |
Expand All @@ -144,39 +114,39 @@ No modules.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| client\_name | Client name/account used in naming | `string` | n/a | yes |
| custom\_subnet\_name | Optional custom subnet name | `string` | `null` | no |
| client\_name | Client name/account used in naming. | `string` | n/a | yes |
| custom\_subnet\_name | Optional custom subnet name. | `string` | `null` | no |
| default\_outbound\_access\_enabled | Enable or Disable default\_outbound\_access. See https://learn.microsoft.com/en-us/azure/virtual-network/ip-services/default-outbound-access | `bool` | `false` | no |
| environment | Project environment | `string` | n/a | yes |
| environment | Project environment. | `string` | n/a | yes |
| location\_short | Short string for Azure location. | `string` | n/a | yes |
| name\_prefix | Optional prefix for the generated name | `string` | `""` | no |
| name\_suffix | Optional suffix for the generated name | `string` | `""` | no |
| name\_prefix | Optional prefix for the generated name. | `string` | `""` | no |
| name\_suffix | Optional suffix for the generated name. | `string` | `""` | no |
| network\_security\_group\_name | The Network Security Group name to associate with the subnets. | `string` | `null` | no |
| network\_security\_group\_rg | The Network Security Group RG to associate with the subnet. Default is the same RG than the subnet. | `string` | `null` | no |
| private\_link\_endpoint\_enabled | Enable or disable network policies for the Private Endpoint on the subnet. | `bool` | `null` | no |
| private\_link\_service\_enabled | Enable or disable network policies for the Private Link Service on the subnet. | `bool` | `null` | no |
| resource\_group\_name | Resource group name | `string` | n/a | yes |
| resource\_group\_name | Resource group name. | `string` | n/a | yes |
| route\_table\_name | The Route Table name to associate with the subnet. | `string` | `null` | no |
| route\_table\_rg | The Route Table RG to associate with the subnet. Default is the same RG than the subnet. | `string` | `null` | no |
| service\_endpoint\_policy\_ids | The list of IDs of Service Endpoint Policies to associate with the subnet. | `list(string)` | `null` | no |
| service\_endpoints | The list of Service endpoints to associate with the subnet. | `list(string)` | `[]` | no |
| stack | Project stack name | `string` | n/a | yes |
| stack | Project stack name. | `string` | n/a | yes |
| subnet\_cidr\_list | The address prefix list to use for the subnet. | `list(string)` | n/a | yes |
| subnet\_delegation | Subnet delegations configuration. | <pre>map(list(object({<br/> name = string<br/> actions = list(string)<br/> })))</pre> | `{}` | no |
| use\_caf\_naming | Use the Azure CAF naming provider to generate default resource name. `custom_subnet_name` override this if set. Legacy default name is used if this is set to `false`. | `bool` | `true` | no |
| virtual\_network\_name | Virtual network name | `string` | n/a | yes |
| virtual\_network\_name | Virtual network name. | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| subnet\_cidr\_list | CIDR list of the created subnets. |
| subnet\_cidrs\_map | Map with names and CIDRs of the created subnets. |
| subnet\_id | ID of the created subnet. |
| subnet\_ips | The collection of IPs within this subnet. |
| subnet\_name | Name of the created subnet. |
| subnet\_nsg\_association\_id | Subnet network security group association ID. |
| subnet\_rt\_association\_id | Subnet route table association ID. |
| cidrs\_list | CIDR list of the created subnets. |
| cidrs\_map | Map with names and CIDRs of the created subnets. |
| id | ID of the created subnet. |
| ips | The collection of IPs within this subnet. |
| name | Name of the created subnet. |
| nsg\_association\_id | Subnet network security group association ID. |
| resource | Subnet resource object. |
| rt\_association\_id | Subnet route table association ID. |
<!-- END_TF_DOCS -->
## Related documentation

Expand Down
4 changes: 2 additions & 2 deletions r-naming.tf → d-naming.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ data "azurecaf_name" "subnet" {
name = var.stack
resource_type = "azurerm_subnet"
prefixes = var.name_prefix == "" ? null : [local.name_prefix]
suffixes = compact([var.client_name, var.location_short, var.environment, local.name_suffix, var.use_caf_naming ? "" : "subnet"])
use_slug = var.use_caf_naming
suffixes = compact([var.client_name, var.location_short, var.environment, local.name_suffix])
use_slug = true
clean_input = true
separator = "-"
}
31 changes: 31 additions & 0 deletions examples/main/base.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module "azure_region" {
source = "claranet/regions/azurerm"
version = "x.x.x"

azure_region = var.azure_region
}

module "rg" {
source = "claranet/rg/azurerm"
version = "x.x.x"

location = module.azure_region.location
location_short = module.azure_region.location_short

client_name = var.client_name
environment = var.environment
stack = var.stack
}
module "vnet" {
source = "claranet/vnet/azurerm"
version = "x.x.x"

environment = var.environment
location = module.azure_region.location
location_short = module.azure_region.location_short
client_name = var.client_name
stack = var.stack
resource_group_name = module.rg.resource_group_name

vnet_cidr = ["10.0.1.0/24"]
}
48 changes: 9 additions & 39 deletions examples/main/modules.tf
Original file line number Diff line number Diff line change
@@ -1,34 +1,4 @@
module "azure_region" {
source = "claranet/regions/azurerm"
version = "x.x.x"

azure_region = var.azure_region
}

module "rg" {
source = "claranet/rg/azurerm"
version = "x.x.x"

location = module.azure_region.location
client_name = var.client_name
environment = var.environment
stack = var.stack
}
module "azure_network_vnet" {
source = "claranet/vnet/azurerm"
version = "x.x.x"

environment = var.environment
location = module.azure_region.location
location_short = module.azure_region.location_short
client_name = var.client_name
stack = var.stack
resource_group_name = module.rg.resource_group_name

vnet_cidr = ["10.0.1.0/24"]
}

module "azure_network_route_table" {
module "route_table" {
source = "claranet/route-table/azurerm"
version = "x.x.x"

Expand All @@ -37,10 +7,10 @@ module "azure_network_route_table" {
stack = var.stack
location = module.azure_region.location
location_short = module.azure_region.location_short
resource_group_name = module.rg.resource_group_name
resource_group_name = module.rg.name
}

module "azure_network_security_group" {
module "network_security_group" {
source = "claranet/nsg/azurerm"
version = "x.x.x"

Expand All @@ -49,10 +19,10 @@ module "azure_network_security_group" {
location = module.azure_region.location
location_short = module.azure_region.location_short
stack = var.stack
resource_group_name = module.rg.resource_group_name
resource_group_name = module.rg.name
}

module "azure_network_subnet" {
module "subnet" {
source = "claranet/subnet/azurerm"
version = "x.x.x"

Expand All @@ -61,9 +31,9 @@ module "azure_network_subnet" {
client_name = var.client_name
stack = var.stack

resource_group_name = module.rg.resource_group_name
resource_group_name = module.rg.name

virtual_network_name = module.azure_network_vnet.virtual_network_name
virtual_network_name = module.vnet.name
subnet_cidr_list = ["10.0.1.0/26"]
subnet_delegation = {
app-service-plan = [
Expand All @@ -74,9 +44,9 @@ module "azure_network_subnet" {
]
}

route_table_name = module.azure_network_route_table.route_table_name
route_table_name = module.route_table.name

network_security_group_name = module.azure_network_security_group.network_security_group_name
network_security_group_name = module.network_security_group.name

service_endpoints = ["Microsoft.Storage", "Microsoft.KeyVault", "Microsoft.ServiceBus", "Microsoft.Web"]
}
27 changes: 16 additions & 11 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
output "subnet_id" {
output "resource" {
description = "Subnet resource object."
value = azurerm_subnet.main
}

output "id" {
description = "ID of the created subnet."
value = azurerm_subnet.subnet.id
value = azurerm_subnet.main.id
}

output "subnet_cidr_list" {
output "cidrs_list" {
description = "CIDR list of the created subnets."
value = azurerm_subnet.subnet.address_prefixes
value = azurerm_subnet.main.address_prefixes
}

output "subnet_cidrs_map" {
output "cidrs_map" {
description = "Map with names and CIDRs of the created subnets."
value = {
(azurerm_subnet.subnet.name) = azurerm_subnet.subnet.address_prefixes
(azurerm_subnet.main.name) = azurerm_subnet.main.address_prefixes
}
}

output "subnet_name" {
output "name" {
description = "Name of the created subnet."
value = azurerm_subnet.subnet.name
value = azurerm_subnet.main.name
}

output "subnet_ips" {
output "ips" {
description = "The collection of IPs within this subnet."
value = var.subnet_cidr_list[*]
}

output "subnet_nsg_association_id" {
output "nsg_association_id" {
description = "Subnet network security group association ID."
value = one(azurerm_subnet_network_security_group_association.subnet_association[*].id)
}

output "subnet_rt_association_id" {
output "rt_association_id" {
description = "Subnet route table association ID."
value = one(azurerm_subnet_route_table_association.route_table_association[*].id)
}
12 changes: 12 additions & 0 deletions providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 4.0"
}
azurecaf = {
source = "claranet/azurecaf"
version = "~> 1.2.28"
}
}
}
11 changes: 8 additions & 3 deletions r-subnet.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
resource "azurerm_subnet" "subnet" {
moved {
from = azurerm_subnet.main
to = azurerm_subnet.main
}

resource "azurerm_subnet" "main" {
name = local.subnet_name
resource_group_name = var.resource_group_name
virtual_network_name = var.virtual_network_name
Expand Down Expand Up @@ -30,14 +35,14 @@ resource "azurerm_subnet" "subnet" {
resource "azurerm_subnet_network_security_group_association" "subnet_association" {
count = var.network_security_group_name == null ? 0 : 1

subnet_id = azurerm_subnet.subnet.id
subnet_id = azurerm_subnet.main.id
network_security_group_id = local.network_security_group_id
}

resource "azurerm_subnet_route_table_association" "route_table_association" {
count = var.route_table_name == null ? 0 : 1

subnet_id = azurerm_subnet.subnet.id
subnet_id = azurerm_subnet.main.id
route_table_id = local.route_table_id
}

Expand Down
Loading

0 comments on commit 36cdb0a

Please sign in to comment.