terraformazure-web-app-serviceip-restrictions

Terraform Azure App Service - ip_restrictions


I am trying to set the IP restrictions block in my Azure App Service App

When performing the Terraform plan or apply, I receive the following error: Error: azurerm_app_service.app-service-1: : invalid or unknown key: ip_restriction

I used ip_restriction per Terraform Documentation for App Service (Web Apps) Resources

Here is the AppService deployment code i am using:

resource "azurerm_app_service" "app-service-1" {
  name                    = "${var.app_service_1}"
  location                = "${data.azurerm_resource_group.core-rg.location}"
  resource_group_name     = "${data.azurerm_resource_group.core-rg.name}"
  app_service_plan_id     = "${data.azurerm_app_service_plan.app-service-plan-1.id}"
  https_only              = "True"
  enabled                 = "True"
  client_affinity_enabled = "True"

  site_config {
    always_on                 = "True"
    #default_documents        = ""
    dotnet_framework_version  = "v4.0"
    #http2_enabled            = ""
    #ip_restriction           = ""
    #java_version             = ""
    #java_container           = ""
    #java_container_version   = ""
    managed_pipeline_mode     = "Integrated"
    min_tls_version           = "1.2"
    #php_version              = ""
    #python_version           = ""
    remote_debugging_enabled  = "False"
    #remote_debugging_version = ""
    scm_type                  = "None"
    use_32_bit_worker_process = "False"
    websockets_enabled        = "True"
    #ftps_state               = ""
  }

  app_settings {
    "KeyVaultURI" = ""
    "WEBSITE_NODE_DEFAULT_VERSION" = "6.9.1"
  }

  ip_restriction {
   "ip_address"     = ""
   }

Thank you


Solution

  • For those interested, here is the method to use ipRestrictions in Terraform

    ip Restrictions is part of the Site_Config {}

    See how to use below:

    AppService.tf:

    resource "azurerm_app_service" "app-service-1" {
      name                    = "${var.app_service_1}"
      location                = "${data.azurerm_resource_group.core-rg.location}"
      resource_group_name     = "${data.azurerm_resource_group.core-rg.name}"
      app_service_plan_id     = "${data.azurerm_app_service_plan.app-service-plan-1.id}"
      https_only              = "True"
      enabled                 = "True"
      client_affinity_enabled = "True"
      site_config {
        always_on                 = "True"
        #default_documents        = ""
        dotnet_framework_version  = "v4.0"
        #http2_enabled            = ""
        #ip_restriction           = ""
        #java_version             = ""
        #java_container           = ""
        #java_container_version   = ""
        managed_pipeline_mode     = "Integrated"
        min_tls_version           = "1.2"
        #php_version              = ""
        #python_version           = ""
        remote_debugging_enabled  = "False"
        #remote_debugging_version = ""
        scm_type                  = "None"
        use_32_bit_worker_process = "False"
        websockets_enabled        = "True"
        #ftps_state               = ""
        ip_restriction {
          ip_address  = "${var.ip_address_1}"
        }
        ip_restriction {
          ip_address  = "${var.ip_address_2}"
        }
        ip_restriction {
          ip_address  = "${var.ip_address_3}"
        }
      }
      app_settings {
        "KeyVaultURI" = ""
        "WEBSITE_NODE_DEFAULT_VERSION" = "6.9.1"
        }
      }