-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
161 lines (133 loc) · 4.82 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
module "naming" {
source = "Azure/naming/azurerm"
version = "~> 0.4"
}
module "regions" {
source = "Azure/regions/azurerm"
version = "=0.8.1"
}
locals {
tags = {
scenario = "Default"
}
}
resource "random_integer" "region_index" {
max = length(module.regions.regions_by_name) - 1
min = 0
}
resource "random_integer" "zone_index" {
max = length(module.regions.regions_by_name[module.regions.regions[random_integer.region_index.result].name].zones)
min = 1
}
module "get_valid_sku_for_deployment_region" {
source = "./.terraform/modules/sku_selector"
deployment_region = module.regions.regions[random_integer.region_index.result].name
}
resource "azurerm_resource_group" "this_rg" {
location = module.regions.regions[random_integer.region_index.result].name
name = module.naming.resource_group.name_unique
tags = local.tags
}
resource "azurerm_virtual_network" "this_vnet" {
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.this_rg.location
name = module.naming.virtual_network.name_unique
resource_group_name = azurerm_resource_group.this_rg.name
tags = local.tags
}
resource "azurerm_subnet" "this_subnet_1" {
address_prefixes = ["10.0.1.0/24"]
name = "${module.naming.subnet.name_unique}-1"
resource_group_name = azurerm_resource_group.this_rg.name
virtual_network_name = azurerm_virtual_network.this_vnet.name
}
resource "azurerm_subnet" "this_subnet_2" {
address_prefixes = ["10.0.2.0/24"]
name = "${module.naming.subnet.name_unique}-2"
resource_group_name = azurerm_resource_group.this_rg.name
virtual_network_name = azurerm_virtual_network.this_vnet.name
}
/* Uncomment this section if you would like to include a bastion resource with this example.
resource "azurerm_subnet" "bastion_subnet" {
name = "AzureBastionSubnet"
resource_group_name = azurerm_resource_group.this_rg.name
virtual_network_name = azurerm_virtual_network.this_vnet.name
address_prefixes = ["10.0.3.0/24"]
}
resource "azurerm_public_ip" "bastionpip" {
name = module.naming.public_ip.name_unique
location = azurerm_resource_group.this_rg.location
resource_group_name = azurerm_resource_group.this_rg.name
allocation_method = "Static"
sku = "Standard"
}
resource "azurerm_bastion_host" "bastion" {
name = module.naming.bastion_host.name_unique
location = azurerm_resource_group.this_rg.location
resource_group_name = azurerm_resource_group.this_rg.name
ip_configuration {
name = "${module.naming.bastion_host.name_unique}-ipconf"
subnet_id = azurerm_subnet.bastion_subnet.id
public_ip_address_id = azurerm_public_ip.bastionpip.id
}
}
*/
data "azurerm_client_config" "current" {}
module "avm_res_keyvault_vault" {
source = "Azure/avm-res-keyvault-vault/azurerm"
version = "=0.7.1"
tenant_id = data.azurerm_client_config.current.tenant_id
name = module.naming.key_vault.name_unique
resource_group_name = azurerm_resource_group.this_rg.name
location = azurerm_resource_group.this_rg.location
network_acls = {
default_action = "Allow"
}
role_assignments = {
deployment_user_secrets = {
role_definition_id_or_name = "Key Vault Secrets Officer"
principal_id = data.azurerm_client_config.current.object_id
}
}
wait_for_rbac_before_secret_operations = {
create = "60s"
}
tags = local.tags
}
module "testvm" {
#source = "../../"
source = "Azure/avm-res-compute-virtualmachine/azurerm"
version = "0.15.1"
enable_telemetry = var.enable_telemetry
location = azurerm_resource_group.this_rg.location
resource_group_name = azurerm_resource_group.this_rg.name
os_type = "Linux"
name = module.naming.virtual_machine.name_unique
sku_size = module.get_valid_sku_for_deployment_region.sku
#sku_size = "Standard_DS1_v2"
zone = random_integer.zone_index.result
generated_secrets_key_vault_secret_config = {
key_vault_resource_id = module.avm_res_keyvault_vault.resource_id
}
source_image_reference = {
publisher = "Canonical"
offer = "0001-com-ubuntu-server-focal"
sku = "20_04-lts-gen2"
version = "latest"
}
network_interfaces = {
network_interface_1 = {
name = module.naming.network_interface.name_unique
ip_configurations = {
ip_configuration_1 = {
name = "${module.naming.network_interface.name_unique}-ipconfig1"
private_ip_subnet_resource_id = azurerm_subnet.this_subnet_1.id
}
}
}
}
tags = local.tags
depends_on = [
module.avm_res_keyvault_vault
]
}