I am testing creating resources with Terraform on Azure. I have tried to force one AZ per public ip and I ran the following code:
# Create public IPs
resource "azurerm_public_ip" "external_ip" {
count = length(var.wp_test_instance_location)
name = "external_ip-0${count.index}"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
allocation_method = "Dynamic"
zones = tolist([var.wp_test_instance_location[count.index], ])
tags = {
environment = "test"
terraform = "Y"
}
}
Then I ran into the following error message:
Error: creating/updating Public Ip Address: (Name "external_ip-01" / Resource Group "rg-bright-liger"): network.PublicIPAddressesClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="ZonesNotAllowedInBasicSkuResource" Message="Request for resource /subscriptions/[MASKED]/resourceGroups/rg-bright-liger/providers/Microsoft.Network/publicIPAddresses/external_ip-01 is invalid as it is Basic sku and in an Availability Zone which is a deprecated configuration. Please change your resource to Standard sku for Availability Zone support." Details=[]
The issue is that the SKU setting for the public IP has to be Standard instead of Basic ( which is the default and I didn’t set it before ). Also the allocation_method parmaters has to be changed from Dynamic to Static. The corrected code looks like:
# Create public IPs
resource "azurerm_public_ip" "external_ip" {
count = length(var.wp_test_instance_location)
name = "external_ip-0${count.index}"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
allocation_method = "Static"
zones = tolist([var.wp_test_instance_location[count.index], ])
sku = "Standard"
tags = {
environment = "test"
terraform = "Y"
}
}