Search code examples
azureterraformterraform-provider-azureazure-storage-accountazure-front-door

Terraform - Get the Primary Static Website Endpoint of a Storage account


I want to deploy an Azure Front Door with a backend linked to the Static Website of a Storage Account. If I use Azure Portal there's no problem, but I can't get how to retrieve the Primary Static Website's Endpoint ?

Moreover, the Primary Endpoint goes out like https://saprodgamingfiles.z6.web.core.windows.net/ but for the backend host name we want saprodgamingfiles.z6.web.core.windows.net.

How to automate the creation of the Front Door backend related to the Storage Account's Static Website Primary Endpoint ?


Synthesis

I want to automate the following host_header and address from the Azure Front Door Terraform config...

backend {
     host_header = "saprodgamingfiles.z6.web.core.windows.net"
     address     = "saprodgamingfiles.z6.web.core.windows.net"
     http_port   = 80
     https_port  = 443
     priority    = 1
     weight      = 50
}

... related to the static website created as such with the Storage Account :

resource "azurerm_storage_account" "saprodgamingfiles" {
    name                = var.sa_name1
    resource_group_name = azurerm_resource_group.rg-prod-gaming.name

    # etc...

    # THIS : Pre-requisite for Azure Front Door
    static_website {}
}

I'm new to Terraform & Azure, but I searched a lot and I couldn't find a satisfying solution to my problem. I'm surprised it's not raised as much, maybe I'm just missing something ?

Best


Solution

  • You could use primary_web_host in the backend,

    enter image description here

    Output the value of

    output "primary_web_host" {
        value = data.azurerm_storage_account.example.primary_web_host
    }
    

    You will see

    enter image description here

    So the backend will like this:

    backend {
         host_header = azurerm_storage_account.saprodgamingfiles.primary_web_host
         address     = azurerm_storage_account.saprodgamingfiles.primary_web_host
         http_port   = 80
         https_port  = 443
         priority    = 1
         weight      = 50
    }