diff --git a/quickstart/101-attestation-provider/readme.md b/quickstart/101-attestation-provider/readme.md index f42ce260..41ff569a 100644 --- a/quickstart/101-attestation-provider/readme.md +++ b/quickstart/101-attestation-provider/readme.md @@ -12,8 +12,8 @@ This template deploys an [Attestation provider](/azure/attestation/overview) on | Name | Description | Default | |-|-|-| -| `resource_group_name_prefix` | (Optional) Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription.| rg | -| `resource_group_location` | (Optional) Azure Region in which to deploy these resources.| eastus | +| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg | +| `resource_group_location` | Location of the resource group. | eastus | | `attestation_provider_name` | Name of the Attestation provider | attestationprovider007 | ## Example diff --git a/quickstart/101-resource-group/readme.md b/quickstart/101-resource-group/readme.md index 84273e40..377234a3 100644 --- a/quickstart/101-resource-group/readme.md +++ b/quickstart/101-resource-group/readme.md @@ -9,10 +9,10 @@ This template deploys an Azure resource group with a random name beginning with ## Variables -| Name | Description | -|-|-| -| `resource_group_name_prefix` | (Optional) Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. Value defaults to: rg| -| `resource_group_location` | (Optional) Azure Region in which to deploy these resources. Value defaults to: eastus | +| Name | Description | Default | +|-|-|-| +| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg | +| `resource_group_location` | Location of the resource group. | eastus | ## Example diff --git a/quickstart/101-vm-with-infrastructure/main.tf b/quickstart/101-vm-with-infrastructure/main.tf new file mode 100644 index 00000000..978e5f06 --- /dev/null +++ b/quickstart/101-vm-with-infrastructure/main.tf @@ -0,0 +1,131 @@ +resource "random_pet" "rg_name" { + prefix = var.resource_group_name_prefix +} + +resource "azurerm_resource_group" "rg" { + location = var.resource_group_location + name = random_pet.rg_name.id +} + +# Create virtual network +resource "azurerm_virtual_network" "my_terraform_network" { + name = "myVnet" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name +} + +# Create subnet +resource "azurerm_subnet" "my_terraform_subnet" { + name = "mySubnet" + resource_group_name = azurerm_resource_group.rg.name + virtual_network_name = azurerm_virtual_network.my_terraform_network.name + address_prefixes = ["10.0.1.0/24"] +} + +# Create public IPs +resource "azurerm_public_ip" "my_terraform_public_ip" { + name = "myPublicIP" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + allocation_method = "Dynamic" +} + +# Create Network Security Group and rule +resource "azurerm_network_security_group" "my_terraform_nsg" { + name = "myNetworkSecurityGroup" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + + security_rule { + name = "SSH" + priority = 1001 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "22" + source_address_prefix = "*" + destination_address_prefix = "*" + } +} + +# Create network interface +resource "azurerm_network_interface" "my_terraform_nic" { + name = "myNIC" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + + ip_configuration { + name = "my_nic_configuration" + subnet_id = azurerm_subnet.my_terraform_subnet.id + private_ip_address_allocation = "Dynamic" + public_ip_address_id = azurerm_public_ip.my_terraform_public_ip.id + } +} + +# Connect the security group to the network interface +resource "azurerm_network_interface_security_group_association" "example" { + network_interface_id = azurerm_network_interface.my_terraform_nic.id + network_security_group_id = azurerm_network_security_group.my_terraform_nsg.id +} + +# Generate random text for a unique storage account name +resource "random_id" "random_id" { + keepers = { + # Generate a new ID only when a new resource group is defined + resource_group = azurerm_resource_group.rg.name + } + + byte_length = 8 +} + +# Create storage account for boot diagnostics +resource "azurerm_storage_account" "my_storage_account" { + name = "diag${random_id.random_id.hex}" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + account_tier = "Standard" + account_replication_type = "LRS" +} + +# Create (and display) an SSH key +resource "tls_private_key" "example_ssh" { + algorithm = "RSA" + rsa_bits = 4096 +} + +# Create virtual machine +resource "azurerm_linux_virtual_machine" "my_terraform_vm" { + name = "myVM" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + network_interface_ids = [azurerm_network_interface.my_terraform_nic.id] + size = "Standard_DS1_v2" + + os_disk { + name = "myOsDisk" + caching = "ReadWrite" + storage_account_type = "Premium_LRS" + } + + source_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "18.04-LTS" + version = "latest" + } + + computer_name = "myvm" + admin_username = "azureuser" + disable_password_authentication = true + + admin_ssh_key { + username = "azureuser" + public_key = tls_private_key.example_ssh.public_key_openssh + } + + boot_diagnostics { + storage_account_uri = azurerm_storage_account.my_storage_account.primary_blob_endpoint + } +} \ No newline at end of file diff --git a/quickstart/101-vm-with-infrastructure/outputs.tf b/quickstart/101-vm-with-infrastructure/outputs.tf new file mode 100644 index 00000000..545f6482 --- /dev/null +++ b/quickstart/101-vm-with-infrastructure/outputs.tf @@ -0,0 +1,12 @@ +output "resource_group_name" { + value = azurerm_resource_group.rg.name +} + +output "public_ip_address" { + value = azurerm_linux_virtual_machine.my_terraform_vm.public_ip_address +} + +output "tls_private_key" { + value = tls_private_key.example_ssh.private_key_pem + sensitive = true +} \ No newline at end of file diff --git a/quickstart/101-vm-with-infrastructure/providers.tf b/quickstart/101-vm-with-infrastructure/providers.tf new file mode 100644 index 00000000..0234a678 --- /dev/null +++ b/quickstart/101-vm-with-infrastructure/providers.tf @@ -0,0 +1,22 @@ +terraform { + required_version = ">=0.12" + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>2.0" + } + random = { + source = "hashicorp/random" + version = "~>3.0" + } + tls = { + source = "hashicorp/tls" + version = "~>4.0" + } + } +} + +provider "azurerm" { + features {} +} \ No newline at end of file diff --git a/quickstart/101-vm-with-infrastructure/readme.md b/quickstart/101-vm-with-infrastructure/readme.md new file mode 100644 index 00000000..02772c5e --- /dev/null +++ b/quickstart/101-vm-with-infrastructure/readme.md @@ -0,0 +1,30 @@ +# Azure resource group + +This template deploys a Linux virtual machine (VM) with infrastructure that includes a virtual network, subnet, public IP address, and more. + +## Terraform resource types + +- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) +- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) + +- [azurerm_virtual_network](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network) +- [azurerm_subnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet) +- [azurerm_public_ip](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip) +- [azurerm_network_security_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_group) +- [azurerm_network_interface](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface) +- [azurerm_network_interface_security_group_association](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface_security_group_association) +- [random_id](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) +- [azurerm_storage_account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account) +- [tls_private_key](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) +- [azurerm_linux_virtual_machine](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine) + +## Variables + +| Name | Description | Default | +|-|-| +| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg | +| `resource_group_location` | Location of the resource group. | eastus | + +## Example + +To see how to run this example, see [Quickstart: Configure a Linux virtual machine in Azure using Terraform](https://docs.microsoft.com/azure/developer/terraform/create-linux-virtual-machine-with-infrastructure). \ No newline at end of file diff --git a/quickstart/101-vm-with-infrastructure/variables.tf b/quickstart/101-vm-with-infrastructure/variables.tf new file mode 100644 index 00000000..e8396125 --- /dev/null +++ b/quickstart/101-vm-with-infrastructure/variables.tf @@ -0,0 +1,9 @@ +variable "resource_group_location" { + default = "eastus" + description = "Location of the resource group." +} + +variable "resource_group_name_prefix" { + default = "rg" + description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." +} \ No newline at end of file diff --git a/quickstart/201-mysql-fs-db/readme.md b/quickstart/201-mysql-fs-db/readme.md index bac940f1..286650fc 100644 --- a/quickstart/201-mysql-fs-db/readme.md +++ b/quickstart/201-mysql-fs-db/readme.md @@ -19,8 +19,8 @@ This template deploys an [Azure MySQL Flexible Server Database](https://registry | Name | Description | Default | |-|-|-| -| `resource_group_name_prefix` | (Optional) Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. Value defaults to: rg| -| `resource_group_location` | (Optional) Azure Region in which to deploy these resources. Value defaults to: eastus | +| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg | +| `resource_group_location` | Location of the resource group. | eastus | ## Example