diff --git a/quickstart/101-dns_zone/main.tf b/quickstart/101-dns_zone/main.tf new file mode 100644 index 00000000..6c97556a --- /dev/null +++ b/quickstart/101-dns_zone/main.tf @@ -0,0 +1,29 @@ +resource "random_pet" "rg_name" { + prefix = var.resource_group_name_prefix +} + +resource "azurerm_resource_group" "rg" { + name = random_pet.rg_name.id + location = var.resource_group_location +} + +resource "random_string" "azurerm_dns_zone_name" { + length = 13 + lower = true + numeric = false + special = false + upper = false +} + +resource "azurerm_dns_zone" "zone" { + name = var.dns_zone_name != null ? var.dns_zone_name : "www.${random_string.azurerm_dns_zone_name.result}.azurequickstart.org" + resource_group_name = azurerm_resource_group.rg.name +} + +resource "azurerm_dns_a_record" "record" { + name = "www" + resource_group_name = azurerm_resource_group.rg.name + zone_name = azurerm_dns_zone.zone.name + ttl = var.dns_ttl + records = var.dns_records +} diff --git a/quickstart/101-dns_zone/outputs.tf b/quickstart/101-dns_zone/outputs.tf new file mode 100644 index 00000000..1cb40a57 --- /dev/null +++ b/quickstart/101-dns_zone/outputs.tf @@ -0,0 +1,11 @@ +output "resource_group_name" { + value = azurerm_resource_group.rg.name +} + +output "dns_zone_name" { + value = azurerm_dns_zone.zone.name +} + +output "name_servers" { + value = azurerm_dns_zone.zone.name_servers +} diff --git a/quickstart/101-dns_zone/providers.tf b/quickstart/101-dns_zone/providers.tf new file mode 100644 index 00000000..74326fc6 --- /dev/null +++ b/quickstart/101-dns_zone/providers.tf @@ -0,0 +1,16 @@ +terraform { + required_version = ">=1.0" + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>3.4" + } + random = { + source = "hashicorp/random" + version = "~>3.4" + } + } +} +provider "azurerm" { + features {} +} \ No newline at end of file diff --git a/quickstart/101-dns_zone/readme.md b/quickstart/101-dns_zone/readme.md new file mode 100644 index 00000000..1effc14d --- /dev/null +++ b/quickstart/101-dns_zone/readme.md @@ -0,0 +1,25 @@ +# Azure DNS zone and A record + +This template creates an Azure DNS zone and an 'A' record. + +## 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) +- [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) +- [azurerm_dns_zone](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/dns_zone) +- [azurerm_dns_a_record](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/dns_a_record) + +## 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 | +| `dns_zone_name` | Name of the DNS zone. | null | +| `dns_ttl` | Time To Live (TTL) of the DNS record (in seconds). | 3600 | +| `dns_records` | List of IPv4 addresses. | ["1.2.3.4", "1.2.3.5"] | + +## Example + +To see how to run this example, see [Create an Azure resource group using Terraform](https://docs.microsoft.com/azure/developer/terraform/create-resource-group). diff --git a/quickstart/101-dns_zone/variables.tf b/quickstart/101-dns_zone/variables.tf new file mode 100644 index 00000000..7fd6cc15 --- /dev/null +++ b/quickstart/101-dns_zone/variables.tf @@ -0,0 +1,29 @@ +variable "resource_group_location" { + type = string + default = "eastus" + description = "Location for all resources." +} + +variable "resource_group_name_prefix" { + type = string + default = "rg" + description = "Prefix of the resource group name that's combined with a random value so name is unique in your Azure subscription." +} + +variable "dns_zone_name" { + type = string + default = null + description = "Name of the DNS zone." +} + +variable "dns_ttl" { + type = number + default = 3600 + description = "Time To Live (TTL) of the DNS record (in seconds)." +} + +variable "dns_records" { + type = list(string) + default = ["1.2.3.4", "1.2.3.5"] + description = "List of IPv4 addresses." +}