Scott Pulver
Scott Pulver

Reputation: 101

Can not get sample Terraform Azure App Service code to deploy

I am trying to deploy the sample App Service using Terraform from these instructions: https://learn.microsoft.com/en-us/azure/app-service/provision-resource-terraform

I keep getting a "GatewayTimeout" error when the code tries to deploy the sourcecontrol.

enter image description here

Anyone know why this is not working?

Tried a different GitHub repo but still same result. Tried to use version 3.57 of the hashicorp/azurerm but does not work. Triedd to change branch to 'main' instead of master. Expecting the sample code to work and function

Upvotes: 0

Views: 1091

Answers (1)

kavya Saraboju
kavya Saraboju

Reputation: 10871

Check the following:

resource "azurerm_service_plan" "appserviceplan" {
  name                = "webapp-asp-random"
  location              = data.azurerm_resource_group.example.location
  resource_group_name   = data.azurerm_resource_group.example.name
  os_type             = "Linux"
  sku_name            = "B1"
}

# Create the web app, pass in the App Service Plan ID
resource "azurerm_linux_web_app" "webapp" {
  name                  = "webapp-rand"
  location              = data.azurerm_resource_group.example.location
  resource_group_name   = data.azurerm_resource_group.example.name
  service_plan_id       = azurerm_service_plan.appserviceplan.id
  https_only            = true
  site_config { 
    minimum_tls_version = "1.2"
  }
}



Deploy code from a public GitHub reporesource
 "azurerm_app_service_source_control" "sourcecontrol" {
   app_id             = azurerm_linux_web_app.webapp.id
   repo_url           = "https://github.com/Azure-Samples/nodejs-docs-hello-world"
   branch             = "master"
   use_manual_integration = true
   use_mercurial      = false
 }

same error oocured with that github code.

Error: creating Source Control configuration for Web App: (Site Name "webapp-rand" / Resource Group "xx"): web.AppsClient#UpdateSourceControl: Failure responding to request: StatusCode=504 -- Original Error: autorest/azure: Service returned an error. Status=504 Code="GatewayTimeout" Message="The gateway did not receive a response from 'Microsoft.Web' within the specified time period."
│
│   with azurerm_app_service_source_control.sourcecontrol,
│   on main.tf line 86, in resource "azurerm_app_service_source_control" "sourcecontrol":
│   86: resource "azurerm_app_service_source_control" "sourcecontrol

enter image description here

Following code to deploy app service worked: Source code from azurerm_app_service_source_control | Resources | hashicorp/azurerm | Terraform Registry

main.tf

resource "azurerm_service_plan" "appserviceplan" {
  name                = "webapp-random"
  location              = data.azurerm_resource_group.example.location
  resource_group_name   = data.azurerm_resource_group.example.name
  os_type             = "Linux"
  sku_name            = "B1"
}

# Create the web app, pass in the App Service Plan ID
resource "azurerm_linux_web_app" "webapp" {
  name                  = "webapp-rand"
  location              = data.azurerm_resource_group.example.location
  resource_group_name   = data.azurerm_resource_group.example.name
  service_plan_id       = azurerm_service_plan.appserviceplan.id
  https_only            = true
  site_config { 
    minimum_tls_version = "1.2"
  }
}



resource "azurerm_app_service_source_control" "example" {
  app_id   = azurerm_linux_web_app.webapp.id
  repo_url = "https://github.com/Azure-Samples/python-docs-hello-world"
  branch   = "master"
 use_manual_integration = true
 use_mercurial      = false
}

I have following providers :

providers.tf:

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      //version = "=3.0.2"
      version = "=3.50.0"
    }

    azapi = {
      source  = "azure/azapi"
      version = "=1.2.0"
    }
    


    
    kubernetes = {
      source = "hashicorp/kubernetes"
          
    }
    
  

    docker = {
      source  = "kreuzwerker/docker"
      version = ">= 2.16.0"
    }


    

    azuread = {
      source  = "hashicorp/azuread"
     // version = "= 2.28.1"
     version = "2.30"
    }


    random = {
      source  = "hashicorp/random"
      version = "=3.1.2"
   // version = "3.0"
    }

  }
}

enter image description here

enter image description here

Check out constraints and limitations: Integrate your app with an Azure virtual network - Azure App Service | Microsoft Learn

Note :

If your app is in an App Service Environment, it's already integrated with a virtual network and doesn't require you to configure virtual network integration feature to reach resources in the same virtual network.

App and the Virtual network should be in the same region.

Upvotes: 1

Related Questions