|
| 1 | +<!-- BEGIN_TF_DOCS --> |
| 2 | +<!-- Code generated by terraform-docs. DO NOT EDIT. --> |
| 3 | +# Default |
| 4 | + |
| 5 | +This example demonstrates the creation of a simple Ubuntu VM with the following features: |
| 6 | + |
| 7 | + - a single private IPv4 address |
| 8 | + - an auto-generated SSH key for an admin user named azureuser |
| 9 | + - password authentication disabled |
| 10 | + - a single default OS 128gb OS disk |
| 11 | + - deploys into a randomly selected region |
| 12 | + - bound to a single randomly selected availablity zone |
| 13 | + - a single ZRS data disk of 128gb |
| 14 | + |
| 15 | +It includes the following resources in addition to the VM resource: |
| 16 | + |
| 17 | + - A Vnet with two subnets |
| 18 | + - A keyvault for storing the login secrets |
| 19 | + - An optional subnet, public ip, and bastion which can be enabled by uncommenting the bastion resources when running the example. |
| 20 | + |
| 21 | +```hcl |
| 22 | +terraform { |
| 23 | + required_version = ">= 1.9, < 2.0" |
| 24 | +
|
| 25 | + required_providers { |
| 26 | + azapi = { |
| 27 | + source = "azure/azapi" |
| 28 | + version = "~> 2.0" |
| 29 | + } |
| 30 | + azurerm = { |
| 31 | + source = "hashicorp/azurerm" |
| 32 | + version = ">= 3.116, < 5.0" |
| 33 | + } |
| 34 | + random = { |
| 35 | + source = "hashicorp/random" |
| 36 | + version = "~> 3.7" |
| 37 | + } |
| 38 | + } |
| 39 | +} |
| 40 | +
|
| 41 | +# tflint-ignore: terraform_module_provider_declaration, terraform_output_separate, terraform_variable_separate |
| 42 | +provider "azurerm" { |
| 43 | + features { |
| 44 | + resource_group { |
| 45 | + prevent_deletion_if_contains_resources = false |
| 46 | + } |
| 47 | + key_vault { |
| 48 | + purge_soft_delete_on_destroy = true |
| 49 | + } |
| 50 | + } |
| 51 | +} |
| 52 | +
|
| 53 | +module "naming" { |
| 54 | + source = "Azure/naming/azurerm" |
| 55 | + version = "0.4.2" |
| 56 | +} |
| 57 | +
|
| 58 | +module "regions" { |
| 59 | + source = "Azure/avm-utl-regions/azurerm" |
| 60 | + version = "0.5.0" |
| 61 | +
|
| 62 | + availability_zones_filter = true |
| 63 | +} |
| 64 | +
|
| 65 | +locals { |
| 66 | + #deployment_region = module.regions.regions[random_integer.region_index.result].name |
| 67 | + deployment_region = "canadacentral" #temporarily pinning on single region |
| 68 | + tags = { |
| 69 | + scenario = "Default" |
| 70 | + } |
| 71 | +} |
| 72 | +
|
| 73 | +resource "random_integer" "region_index" { |
| 74 | + max = length(module.regions.regions_by_name) - 1 |
| 75 | + min = 0 |
| 76 | +} |
| 77 | +
|
| 78 | +resource "random_integer" "zone_index" { |
| 79 | + max = length(module.regions.regions_by_name[local.deployment_region].zones) |
| 80 | + min = 1 |
| 81 | +} |
| 82 | +
|
| 83 | +resource "azurerm_resource_group" "this_rg" { |
| 84 | + location = local.deployment_region |
| 85 | + name = module.naming.resource_group.name_unique |
| 86 | + tags = local.tags |
| 87 | +} |
| 88 | +
|
| 89 | +module "vm_sku" { |
| 90 | + source = "Azure/avm-utl-sku-finder/azapi" |
| 91 | + version = "0.3.0" |
| 92 | +
|
| 93 | + location = azurerm_resource_group.this_rg.location |
| 94 | + cache_results = true |
| 95 | + vm_filters = { |
| 96 | + min_vcpus = 2 |
| 97 | + max_vcpus = 2 |
| 98 | + encryption_at_host_supported = true |
| 99 | + accelerated_networking_enabled = true |
| 100 | + premium_io_supported = true |
| 101 | + location_zone = random_integer.zone_index.result |
| 102 | + } |
| 103 | +
|
| 104 | + depends_on = [random_integer.zone_index] |
| 105 | +} |
| 106 | +
|
| 107 | +module "natgateway" { |
| 108 | + source = "Azure/avm-res-network-natgateway/azurerm" |
| 109 | + version = "0.2.1" |
| 110 | +
|
| 111 | + location = azurerm_resource_group.this_rg.location |
| 112 | + name = module.naming.nat_gateway.name_unique |
| 113 | + resource_group_name = azurerm_resource_group.this_rg.name |
| 114 | + enable_telemetry = true |
| 115 | + public_ips = { |
| 116 | + public_ip_1 = { |
| 117 | + name = "nat_gw_pip1" |
| 118 | + } |
| 119 | + } |
| 120 | +} |
| 121 | +
|
| 122 | +module "vnet" { |
| 123 | + source = "Azure/avm-res-network-virtualnetwork/azurerm" |
| 124 | + version = "=0.8.1" |
| 125 | +
|
| 126 | + address_space = ["10.0.0.0/16"] |
| 127 | + location = azurerm_resource_group.this_rg.location |
| 128 | + resource_group_name = azurerm_resource_group.this_rg.name |
| 129 | + name = module.naming.virtual_network.name_unique |
| 130 | + subnets = { |
| 131 | + vm_subnet_1 = { |
| 132 | + name = "${module.naming.subnet.name_unique}-1" |
| 133 | + address_prefixes = ["10.0.1.0/24"] |
| 134 | + nat_gateway = { |
| 135 | + id = module.natgateway.resource_id |
| 136 | + } |
| 137 | + } |
| 138 | + vm_subnet_2 = { |
| 139 | + name = "${module.naming.subnet.name_unique}-2" |
| 140 | + address_prefixes = ["10.0.2.0/24"] |
| 141 | + nat_gateway = { |
| 142 | + id = module.natgateway.resource_id |
| 143 | + } |
| 144 | + } |
| 145 | + AzureBastionSubnet = { |
| 146 | + name = "AzureBastionSubnet" |
| 147 | + address_prefixes = ["10.0.3.0/24"] |
| 148 | + } |
| 149 | + } |
| 150 | +} |
| 151 | +
|
| 152 | +/* Uncomment this section if you would like to include a bastion resource with this example. |
| 153 | +resource "azurerm_public_ip" "bastionpip" { |
| 154 | + name = module.naming.public_ip.name_unique |
| 155 | + location = azurerm_resource_group.this_rg.location |
| 156 | + resource_group_name = azurerm_resource_group.this_rg.name |
| 157 | + allocation_method = "Static" |
| 158 | + sku = "Standard" |
| 159 | +} |
| 160 | +
|
| 161 | +resource "azurerm_bastion_host" "bastion" { |
| 162 | + name = module.naming.bastion_host.name_unique |
| 163 | + location = azurerm_resource_group.this_rg.location |
| 164 | + resource_group_name = azurerm_resource_group.this_rg.name |
| 165 | +
|
| 166 | + ip_configuration { |
| 167 | + name = "${module.naming.bastion_host.name_unique}-ipconf" |
| 168 | + subnet_id = module.vnet.subnets["AzureBastionSubnet"].resource_id |
| 169 | + public_ip_address_id = azurerm_public_ip.bastionpip.id |
| 170 | + } |
| 171 | +} |
| 172 | +*/ |
| 173 | +
|
| 174 | +data "azurerm_client_config" "current" {} |
| 175 | +
|
| 176 | +module "avm_res_keyvault_vault" { |
| 177 | + source = "Azure/avm-res-keyvault-vault/azurerm" |
| 178 | + version = "=0.10.0" |
| 179 | +
|
| 180 | + location = azurerm_resource_group.this_rg.location |
| 181 | + name = "${module.naming.key_vault.name_unique}-linux-default" |
| 182 | + resource_group_name = azurerm_resource_group.this_rg.name |
| 183 | + tenant_id = data.azurerm_client_config.current.tenant_id |
| 184 | + network_acls = { |
| 185 | + default_action = "Allow" |
| 186 | + } |
| 187 | + role_assignments = { |
| 188 | + deployment_user_secrets = { |
| 189 | + role_definition_id_or_name = "Key Vault Secrets Officer" |
| 190 | + principal_id = data.azurerm_client_config.current.object_id |
| 191 | + } |
| 192 | + } |
| 193 | + tags = local.tags |
| 194 | + wait_for_rbac_before_secret_operations = { |
| 195 | + create = "60s" |
| 196 | + } |
| 197 | +} |
| 198 | +
|
| 199 | +module "testvm" { |
| 200 | + source = "../../" |
| 201 | +
|
| 202 | + location = azurerm_resource_group.this_rg.location |
| 203 | + name = module.naming.virtual_machine.name_unique |
| 204 | + network_interfaces = { |
| 205 | + network_interface_1 = { |
| 206 | + name = module.naming.network_interface.name_unique |
| 207 | + ip_configurations = { |
| 208 | + ip_configuration_1 = { |
| 209 | + name = "${module.naming.network_interface.name_unique}-ipconfig1" |
| 210 | + private_ip_subnet_resource_id = module.vnet.subnets["vm_subnet_1"].resource_id |
| 211 | + } |
| 212 | + } |
| 213 | + } |
| 214 | + } |
| 215 | + resource_group_name = azurerm_resource_group.this_rg.name |
| 216 | + zone = random_integer.zone_index.result |
| 217 | + account_credentials = { |
| 218 | + key_vault_configuration = { |
| 219 | + resource_id = module.avm_res_keyvault_vault.resource_id |
| 220 | + } |
| 221 | + } |
| 222 | + enable_telemetry = var.enable_telemetry |
| 223 | + os_type = "Linux" |
| 224 | + sku_size = module.vm_sku.sku |
| 225 | + source_image_reference = { |
| 226 | + publisher = "Canonical" |
| 227 | + offer = "0001-com-ubuntu-server-focal" |
| 228 | + sku = "20_04-lts-gen2" |
| 229 | + version = "latest" |
| 230 | + } |
| 231 | + tags = local.tags |
| 232 | +
|
| 233 | + depends_on = [ |
| 234 | + module.avm_res_keyvault_vault |
| 235 | + ] |
| 236 | +} |
| 237 | +``` |
| 238 | + |
| 239 | +<!-- markdownlint-disable MD033 --> |
| 240 | +## Requirements |
| 241 | + |
| 242 | +The following requirements are needed by this module: |
| 243 | + |
| 244 | +- <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) (>= 1.9, < 2.0) |
| 245 | + |
| 246 | +- <a name="requirement_azapi"></a> [azapi](#requirement\_azapi) (~> 2.0) |
| 247 | + |
| 248 | +- <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) (>= 3.116, < 5.0) |
| 249 | + |
| 250 | +- <a name="requirement_random"></a> [random](#requirement\_random) (~> 3.7) |
| 251 | + |
| 252 | +## Resources |
| 253 | + |
| 254 | +The following resources are used by this module: |
| 255 | + |
| 256 | +- [azapi_update_resource.allow_drop_unencrypted_vnet](https://registry.terraform.io/providers/azure/azapi/latest/docs/resources/update_resource) (resource) |
| 257 | +- [azurerm_resource_group.this_rg](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) (resource) |
| 258 | +- [random_integer.region_index](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer) (resource) |
| 259 | +- [random_integer.zone_index](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer) (resource) |
| 260 | +- [azurerm_client_config.current](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/client_config) (data source) |
| 261 | + |
| 262 | +<!-- markdownlint-disable MD013 --> |
| 263 | +## Required Inputs |
| 264 | + |
| 265 | +No required inputs. |
| 266 | + |
| 267 | +## Optional Inputs |
| 268 | + |
| 269 | +The following input variables are optional (have default values): |
| 270 | + |
| 271 | +### <a name="input_enable_telemetry"></a> [enable\_telemetry](#input\_enable\_telemetry) |
| 272 | + |
| 273 | +Description: This variable controls whether or not telemetry is enabled for the module. |
| 274 | +For more information see https://aka.ms/avm/telemetryinfo. |
| 275 | +If it is set to false, then no telemetry will be collected. |
| 276 | + |
| 277 | +Type: `bool` |
| 278 | + |
| 279 | +Default: `true` |
| 280 | + |
| 281 | +## Outputs |
| 282 | + |
| 283 | +No outputs. |
| 284 | + |
| 285 | +## Modules |
| 286 | + |
| 287 | +The following Modules are called: |
| 288 | + |
| 289 | +### <a name="module_avm_res_keyvault_vault"></a> [avm\_res\_keyvault\_vault](#module\_avm\_res\_keyvault\_vault) |
| 290 | + |
| 291 | +Source: Azure/avm-res-keyvault-vault/azurerm |
| 292 | + |
| 293 | +Version: =0.10.0 |
| 294 | + |
| 295 | +### <a name="module_naming"></a> [naming](#module\_naming) |
| 296 | + |
| 297 | +Source: Azure/naming/azurerm |
| 298 | + |
| 299 | +Version: 0.4.2 |
| 300 | + |
| 301 | +### <a name="module_natgateway"></a> [natgateway](#module\_natgateway) |
| 302 | + |
| 303 | +Source: Azure/avm-res-network-natgateway/azurerm |
| 304 | + |
| 305 | +Version: 0.2.1 |
| 306 | + |
| 307 | +### <a name="module_regions"></a> [regions](#module\_regions) |
| 308 | + |
| 309 | +Source: Azure/avm-utl-regions/azurerm |
| 310 | + |
| 311 | +Version: 0.5.0 |
| 312 | + |
| 313 | +### <a name="module_testvm"></a> [testvm](#module\_testvm) |
| 314 | + |
| 315 | +Source: ../../ |
| 316 | + |
| 317 | +Version: |
| 318 | + |
| 319 | +### <a name="module_vm_sku"></a> [vm\_sku](#module\_vm\_sku) |
| 320 | + |
| 321 | +Source: Azure/avm-utl-sku-finder/azapi |
| 322 | + |
| 323 | +Version: 0.3.0 |
| 324 | + |
| 325 | +### <a name="module_vnet"></a> [vnet](#module\_vnet) |
| 326 | + |
| 327 | +Source: Azure/avm-res-network-virtualnetwork/azurerm |
| 328 | + |
| 329 | +Version: =0.8.1 |
| 330 | + |
| 331 | +<!-- markdownlint-disable-next-line MD041 --> |
| 332 | +## Data Collection |
| 333 | + |
| 334 | +The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft’s privacy statement. Our privacy statement is located at <https://go.microsoft.com/fwlink/?LinkID=824704>. You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices. |
| 335 | +<!-- END_TF_DOCS --> |
0 commit comments