How to configure a web app service backup using terraform

Hector Huerta Tricolor 106 Reputation points
2022-11-22T19:55:43.147+00:00

We need to know how to configure web app backup using terraform , looks like the below is not working

resource "azurerm_app_service" "apptftest1" {
name = var.web_app_name
location = data.azurerm_app_service_plan.sp.location
resource_group_name = data.azurerm_resource_group.rg.name
app_service_plan_id = data.azurerm_app_service_plan.sp.id

enable_backup = true
storage_account_name = "stdiagfortesting1"
backup_settings = {
enabled = true
name = var.web_app_name
frequency_interval = 1
frequency_unit = "Day"
retention_period_in_days = 30
}

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,931 questions
0 comments No comments
{count} votes

Accepted answer
  1. VenkateshDodda-MSFT 24,951 Reputation points Microsoft Employee Moderator
    2022-11-23T13:22:55.96+00:00

    @Hector Huerta Tricolor Thank you for reaching out to Microsoft Q&A. Apologize for the inconvenience caused on this. Based on the shared information I have understood that you are trying to create Web App and also enabling the custom backup to it using Terraform.

    I have created the below Terraform script which create a Webapp, storage account and also it enables the custom backup using the existing app service plan and I have tested this it is working fine I would suggest to validate from your end as well.

    Here is the sample terraform script :

    provider "azurerm" {  
      features {}  
    }  
      
    data "azurerm_resource_group" "rggroup" {  
      name = "<ResourceGroupName>"  
        
    }  
      
    data "azurerm_service_plan" "appplan"{  
        name= "<AppServicePlan>"  
        resource_group_name=data.azurerm_resource_group.rggroup.name  
    }  
      
    variable "app_name"{  
        type=string  
        default="<WebAppName>"  
      
    }  
      
    variable "storage_name"{  
        type=string  
        default="<StorageAccountName"  
    }  
      
      
    resource "azurerm_storage_account" "backupaccount" {  
        name= var.storage_name  
        location = data.azurerm_resource_group.rggroup.location  
        resource_group_name = data.azurerm_resource_group.rggroup.name  
        access_tier = "Hot"  
        account_tier = "Standard"  
        account_replication_type = "LRS"  
        account_kind = "BlobStorage"  
    }  
    resource "azurerm_storage_container" "backupcontainer" {  
      name ="<ContainerName>"  
      storage_account_name = azurerm_storage_account.backupaccount.name  
      container_access_type = "container"  
    }  
      
    data "azurerm_storage_account_blob_container_sas" "containersas"{  
      connection_string = azurerm_storage_account.backupaccount.primary_connection_string  
      container_name = azurerm_storage_container.backupcontainer.name  
      https_only = true  
      start = "2022-11-23T12:20:23Z"  
      expiry = "2022-11-24T00:00:00Z"  
      permissions {  
        read   = true  
        add    = true  
        create = true  
        write  = true  
        delete = true  
        list   = true  
      }  
       
    }  
      
    resource "azurerm_windows_web_app" "config" {  
        name = var.app_name  
        location = data.azurerm_resource_group.rggroup.location  
        resource_group_name = data.azurerm_resource_group.rggroup.name  
        service_plan_id = data.azurerm_service_plan.appplan.id  
        site_config {  
        always_on                 = true  
        ftps_state                = "FtpsOnly"  
        managed_pipeline_mode     = "Integrated"  
        use_32_bit_worker = false  
        application_stack {  
          current_stack = "dotnet"  
          dotnet_version= "v6.0"  
        }  
          
        }  
        backup{  
          name = "testbackup"  
          schedule{  
            frequency_interval =1  
            frequency_unit ="Day"  
            retention_period_days = 30  
            start_time = "2022-11-23T10:33:28.000Z"  
          }  
          storage_account_url = "https://${resource.azurerm_storage_account.backupaccount.name}.blob.core.windows.net/${resource.azurerm_storage_container.backupcontainer.name}${data.azurerm_storage_account_blob_container_sas.containersas.sas}"  
        }  
    }  
    

    Here is the sample output for your reference:

    263491-image.png

    Feel free to reach back to me if you have any further questions on this.


1 additional answer

Sort by: Most helpful
  1. Hector Huerta Tricolor 106 Reputation points
    2022-11-24T16:47:55.02+00:00

    264032-screenshot-2022-11-24-104306.png

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.