Skip to content

Commit 4587921

Browse files
committed
upgrade azure modules and providers
1 parent 7f4041d commit 4587921

File tree

10 files changed

+81
-49
lines changed

10 files changed

+81
-49
lines changed

terraform/azure/azure-linux-vm/main.tf

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ locals {
1717
"--advertise-connector",
1818
"--advertise-exit-node",
1919
"--advertise-routes=${join(",", coalescelist(
20-
local.vpc_cidr_block,
20+
tolist(local.vpc_cidr_block),
2121
))}",
2222
]
2323

2424
// Modify these to use your own VPC
25+
resource_group_id = azurerm_resource_group.main.id
2526
resource_group_name = azurerm_resource_group.main.name
2627
location = azurerm_resource_group.main.location
2728

@@ -45,6 +46,7 @@ module "vpc" {
4546
tags = local.azure_tags
4647

4748
location = local.location
49+
resource_group_id = local.resource_group_id
4850
resource_group_name = local.resource_group_name
4951

5052
subnet_name_public = "public"
@@ -63,6 +65,18 @@ resource "tailscale_tailnet_key" "main" {
6365
tags = local.tailscale_acl_tags
6466
}
6567

68+
resource "azurerm_public_ip" "vm" {
69+
location = local.location
70+
resource_group_name = local.resource_group_name
71+
72+
name = "${local.resource_group_name}-vm"
73+
tags = local.azure_tags
74+
75+
sku = "Standard"
76+
allocation_method = "Static"
77+
zones = []
78+
}
79+
6680
module "tailscale_azure_linux_virtual_machine" {
6781
source = "../internal-modules/azure-linux-vm"
6882

@@ -72,6 +86,7 @@ module "tailscale_azure_linux_virtual_machine" {
7286
# public subnet
7387
primary_subnet_id = local.subnet_id
7488
network_security_group_id = local.network_security_group_id
89+
public_ip_address_id = azurerm_public_ip.vm.id
7590

7691
machine_name = local.name
7792
machine_size = local.instance_type

terraform/azure/azure-linux-vm/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
output "resource_name_prefix" {
2+
value = local.name
3+
}
4+
15
output "vpc_id" {
26
value = module.vpc.vnet_id
37
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
provider "azurerm" {
2-
skip_provider_registration = true
2+
resource_provider_registrations = "none"
33
features {
44
resource_group {
55
prevent_deletion_if_contains_resources = false
@@ -8,4 +8,6 @@ provider "azurerm" {
88
delete_os_disk_on_deletion = true
99
}
1010
}
11+
12+
# subscription_id = "00000000-0000-0000-0000-000000000000"
1113
}

terraform/azure/azure-linux-vm/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
tailscale = {
44
source = "tailscale/tailscale"
5-
version = ">= 0.13.13"
5+
version = ">= 0.24"
66
}
77
}
88
}

terraform/azure/internal-modules/azure-linux-vm/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ resource "azurerm_network_interface" "primary" {
1919
internal_dns_name_label = "${var.machine_name}-primary"
2020
ip_configuration {
2121
subnet_id = var.primary_subnet_id
22-
name = "internal"
22+
name = "primary"
2323
private_ip_address_allocation = "Dynamic"
2424
public_ip_address_id = var.public_ip_address_id
2525
}

terraform/azure/internal-modules/azure-linux-vm/versions.tf

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ terraform {
22
required_providers {
33
azurerm = {
44
source = "hashicorp/azurerm"
5-
version = ">= 3.0, < 4.0"
6-
}
7-
tailscale = {
8-
source = "tailscale/tailscale"
9-
version = ">= 0.13.13"
5+
version = ">= 4.0, < 5.0"
106
}
117
}
128
}

terraform/azure/internal-modules/azure-network/main.tf

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,49 @@ resource "random_integer" "vpc_cidr" {
1212
}
1313

1414
module "vpc" {
15-
# https://registry.terraform.io/modules/Azure/network/azurerm/latest
16-
source = "Azure/network/azurerm"
17-
version = ">= 5.0, < 6.0"
18-
19-
resource_group_location = var.location
20-
resource_group_name = var.resource_group_name
21-
22-
vnet_name = var.name
23-
tags = var.tags
24-
25-
address_spaces = local.cidrs
26-
subnet_prefixes = local.subnet_cidrs
27-
subnet_names = [
28-
var.subnet_name_public,
29-
var.subnet_name_private,
30-
var.subnet_name_private_dns_resolver,
31-
]
32-
33-
subnet_delegation = {
34-
"${var.subnet_name_private_dns_resolver}" = [
35-
{
15+
# https://registry.terraform.io/modules/Azure/avm-res-network-virtualnetwork/azurerm/latest
16+
source = "Azure/avm-res-network-virtualnetwork/azurerm"
17+
version = ">= 0.16, < 1.0"
18+
19+
location = var.location
20+
parent_id = var.resource_group_id
21+
22+
name = var.name
23+
tags = var.tags
24+
25+
address_space = local.cidrs
26+
subnets = {
27+
"public" = {
28+
name = var.subnet_name_public
29+
address_prefixes = [local.subnet_cidrs[0]]
30+
}
31+
"private" = {
32+
name = var.subnet_name_private
33+
address_prefixes = [local.subnet_cidrs[1]]
34+
nat_gateway = {
35+
id = azurerm_nat_gateway.nat.id
36+
}
37+
}
38+
"dns-inbound" = {
39+
name = var.subnet_name_private_dns_resolver
40+
address_prefixes = [local.subnet_cidrs[2]]
41+
delegations = [{
3642
name = "Microsoft.Network/dnsResolvers"
3743
service_delegation = {
3844
name = "Microsoft.Network/dnsResolvers"
3945
actions = [
4046
"Microsoft.Network/virtualNetworks/subnets/join/action",
4147
]
4248
}
43-
}
44-
]
49+
}]
50+
}
4551
}
46-
47-
use_for_each = true # https://github.com/Azure/terraform-azurerm-network#notice-to-contributor
4852
}
4953

5054
data "azurerm_subnet" "public" {
5155
resource_group_name = var.resource_group_name
5256

53-
virtual_network_name = module.vpc.vnet_name
57+
virtual_network_name = module.vpc.name
5458
name = var.subnet_name_public
5559

5660
depends_on = [module.vpc.vnet_subnets]
@@ -59,7 +63,7 @@ data "azurerm_subnet" "public" {
5963
data "azurerm_subnet" "private" {
6064
resource_group_name = var.resource_group_name
6165

62-
virtual_network_name = module.vpc.vnet_name
66+
virtual_network_name = module.vpc.name
6367
name = var.subnet_name_private
6468

6569
depends_on = [module.vpc.vnet_subnets]
@@ -68,7 +72,7 @@ data "azurerm_subnet" "private" {
6872
data "azurerm_subnet" "dns-inbound" {
6973
resource_group_name = var.resource_group_name
7074

71-
virtual_network_name = module.vpc.vnet_name
75+
virtual_network_name = module.vpc.name
7276
name = var.subnet_name_private_dns_resolver
7377

7478
depends_on = [module.vpc.vnet_subnets]
@@ -83,7 +87,7 @@ resource "azurerm_private_dns_resolver" "main" {
8387
name = var.name
8488
tags = var.tags
8589

86-
virtual_network_id = module.vpc.vnet_id
90+
virtual_network_id = module.vpc.resource_id
8791
}
8892

8993
resource "azurerm_private_dns_resolver_inbound_endpoint" "main" {
@@ -107,23 +111,30 @@ resource "azurerm_nat_gateway" "nat" {
107111
location = var.location
108112
resource_group_name = var.resource_group_name
109113

110-
name = var.name
114+
name = var.name
115+
tags = var.tags
116+
111117
sku_name = "Standard"
112118
idle_timeout_in_minutes = 10
113-
}
119+
zones = []
114120

115-
resource "azurerm_subnet_nat_gateway_association" "nat" {
116-
nat_gateway_id = azurerm_nat_gateway.nat.id
117-
subnet_id = data.azurerm_subnet.private.id
118121
}
119122

123+
# resource "azurerm_subnet_nat_gateway_association" "nat" {
124+
# nat_gateway_id = azurerm_nat_gateway.nat.id
125+
# subnet_id = data.azurerm_subnet.private.id
126+
# }
127+
120128
resource "azurerm_public_ip" "nat" {
121129
location = var.location
122130
resource_group_name = var.resource_group_name
123131

124-
name = "${var.name}-nat"
132+
name = "${var.name}-nat"
133+
tags = var.tags
134+
125135
sku = "Standard"
126136
allocation_method = "Static"
137+
zones = []
127138
}
128139

129140
resource "azurerm_nat_gateway_public_ip_association" "nat" {

terraform/azure/internal-modules/azure-network/outputs.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
output "vnet_id" {
2-
value = module.vpc.vnet_id
2+
value = module.vpc.resource_id
33
}
44
output "vnet_name" {
5-
value = module.vpc.vnet_name
5+
value = module.vpc.name
66
}
77
output "vnet_address_space" {
8-
value = module.vpc.vnet_address_space
8+
value = module.vpc.address_spaces
99
}
1010
output "vnet_subnets" {
11-
value = module.vpc.vnet_subnets
11+
value = module.vpc.subnets
1212
}
1313

1414
output "public_subnet_id" {

terraform/azure/internal-modules/azure-network/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#
22
# Variables for all resources
33
#
4+
variable "resource_group_id" {
5+
description = "ID of Resource Group for all resources"
6+
type = string
7+
}
48
variable "resource_group_name" {
59
description = "Name of Resource Group for all resources"
610
type = string

terraform/azure/internal-modules/azure-network/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
azurerm = {
44
source = "hashicorp/azurerm"
5-
version = ">= 3.0, < 4.0"
5+
version = ">= 4.0, < 5.0"
66
}
77
}
88
}

0 commit comments

Comments
 (0)