Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot refresh state when deploying new azurerm_app_service_source_control resource. #25772

Open
1 task done
avinode-amagdy opened this issue Apr 26, 2024 · 2 comments
Open
1 task done

Comments

@avinode-amagdy
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment and review the contribution guide to help.

I'm trying to create an app resource to deploy an azure sample app from public github repository, the creation is done successfully with no issues but when I try to run terraform refresh or when I try to redeploy after updating the configurations (i.e. run terraform deploy) the deployment fails.

Terraform Version

1.2.6

AzureRM Provider Version

"> 3.78" , also tried with the latest version "> 3.101.0"

Affected Resource(s)/Data Source(s)

resource azurerm_app_service_source_control

Terraform Configuration Files

terraform {
  required_version = ">= 1.2.6"
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 3.101.0"
    }
  }
}

provider "azurerm" {
  subscription_id = "<subscription_id>"
  features {}
}

resource "azurerm_service_plan" "app_service_plan" {
  name                = "app-service-plan-test"
  resource_group_name = "resource_group_name"
  location            = "eastus"
  os_type             = "Windows"
  sku_name            = "F1"
  tags                   = var.default_tags
  zone_balancing_enabled = false
}

resource "azurerm_windows_web_app" "topic_viewer" {
  name                = "event-grid-test"
  resource_group_name = "resource_group_name"
  location            = "eastus"
  service_plan_id     = azurerm_service_plan.app_service_plan.id

  site_config {
    always_on                         = false
    ftps_state                        = "AllAllowed"
    websockets_enabled                = true
    worker_count                      = 1
    health_check_eviction_time_in_min = 5
    application_stack {
      current_stack  = "dotnet"
      dotnet_version = "v6.0"
    }
  }
}

resource "azurerm_app_service_source_control" "source_control" {
  app_id   = azurerm_windows_web_app.topic_viewer.id
  branch   = "main"
  repo_url = "https://github.com/Azure-Samples/azure-event-grid-viewer.git"

  # I tried the removing the following attributes, I get the same result.
  use_manual_integration = true
  use_mercurial = false
}

Debug Output/Panic Output

azurerm_app_service_source_control.source_control: Refreshing state... [id=/subscriptions/<subscription_id>/resourceGroups/resource_group_name/providers/Microsoft.Web/sites/event-grid-te
st-support]
╷
│ Error: reading Source Control for App Service (Subscription: "<subscription_id>"
│ Resource Group Name: "resource_group_name"
│ Site Name: "event-grid-test-support"): unexpected status 400 (400 Bad Request) with response: {"Code":"BadRe
quest","Message":"Repository 'GetSiteSourceControl' operation failed with System.Collections.Generic.KeyNotFou
ndException: The given key was not present in the dictionary.\r\n   at System.ThrowHelper.ThrowKeyNotFoundExce
ption()\r\n   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)\r\n   at Microsoft.Web.Hosting.Adm
inistration.ExternalSiteRepositoryProvider.<GetSiteSourceControl>d__4.MoveNext() in C:\\__w\\1\\s\\src\\Hostin
g\\AdministrationService\\Microsoft.Web.Hosting.Administration\\Providers\\ExternalSiteRepositoryProvider.cs:l
ine 36\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime
.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNo
nSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.Web.Hosting.Administration.WebCloudController.<>
c__DisplayClass377_0.<<GetSiteSourceControl>b__0>d.MoveNext() in C:\\__w\\1\\s\\src\\Hosting\\AdministrationSe
rvice\\Microsoft.Web.Hosting.Administration\\Controllers\\WebCloudController.cs:line 11368\r\n--- End of stack
 trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.Excepti
onDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotific
ation(Task task)\r\n   at Microsoft.Web.Hosting.AsyncHelper.RunSync[TResult](Func`1 func)\r\n   at Microsoft.W
eb.Hosting.Administration.WebCloudController.GetSiteSourceControl(String subscriptionName, String webspaceName
, String name).","Target":null,"Details":[{"Message":"Repository 'GetSiteSourceControl' operation failed with 
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.\r\n   at Sys
tem.ThrowHelper.ThrowKeyNotFoundException()\r\n   at System.Collections.Generic.Dictionary`2.get_Item(TKey key
)\r\n   at Microsoft.Web.Hosting.Administration.ExternalSiteRepositoryProvider.<GetSiteSourceControl>d__4.Move
Next() in C:\\__w\\1\\s\\src\\Hosting\\AdministrationService\\Microsoft.Web.Hosting.Administration\\Providers\
\ExternalSiteRepositoryProvider.cs:line 36\r\n--- End of stack trace from previous location where exception wa
s thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.C
ompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.Web.Hosting.
Administration.WebCloudController.<>c__DisplayClass377_0.<<GetSiteSourceControl>b__0>d.MoveNext() in C:\\__w\\
1\\s\\src\\Hosting\\AdministrationService\\Microsoft.Web.Hosting.Administration\\Controllers\\WebCloudControll
er.cs:line 11368\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at Syst
em.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaite
r.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.Web.Hosting.AsyncHelper.RunSync[TResul
t](Func`1 func)\r\n   at Microsoft.Web.Hosting.Administration.WebCloudController.GetSiteSourceControl(String s
ubscriptionName, String webspaceName, String name)."},{"Code":"BadRequest"},{"ErrorEntity":{"ExtendedCode":"05
007","MessageTemplate":"Repository '{0}' operation failed with {1}.","Parameters":["GetSiteSourceControl","Sys
tem.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.\r\n   at System
.ThrowHelper.ThrowKeyNotFoundException()\r\n   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)\r
\n   at Microsoft.Web.Hosting.Administration.ExternalSiteRepositoryProvider.<GetSiteSourceControl>d__4.MoveNex
t() in C:\\__w\\1\\s\\src\\Hosting\\AdministrationService\\Microsoft.Web.Hosting.Administration\\Providers\\Ex
ternalSiteRepositoryProvider.cs:line 36\r\n--- End of stack trace from previous location where exception was t
hrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.Comp
ilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.Web.Hosting.Adm
inistration.WebCloudController.<>c__DisplayClass377_0.<<GetSiteSourceControl>b__0>d.MoveNext() in C:\\__w\\1\\
s\\src\\Hosting\\AdministrationService\\Microsoft.Web.Hosting.Administration\\Controllers\\WebCloudController.
cs:line 11368\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.
Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.H
andleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.Web.Hosting.AsyncHelper.RunSync[TResult](
Func`1 func)\r\n   at Microsoft.Web.Hosting.Administration.WebCloudController.GetSiteSourceControl(String subs
criptionName, String webspaceName, String name)"],"Code":"BadRequest","Message":"Repository 'GetSiteSourceCont
rol' operation failed with System.Collections.Generic.KeyNotFoundException: The given key was not present in t
he dictionary.\r\n   at System.ThrowHelper.ThrowKeyNotFoundException()\r\n   at System.Collections.Generic.Dic
tionary`2.get_Item(TKey key)\r\n   at Microsoft.Web.Hosting.Administration.ExternalSiteRepositoryProvider.<Get
SiteSourceControl>d__4.MoveNext() in C:\\__w\\1\\s\\src\\Hosting\\AdministrationService\\Microsoft.Web.Hosting
.Administration\\Providers\\ExternalSiteRepositoryProvider.cs:line 36\r\n--- End of stack trace from previous 
location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(
)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n 
  at Microsoft.Web.Hosting.Administration.WebCloudController.<>c__DisplayClass377_0.<<GetSiteSourceControl>b__
0>d.MoveNext() in C:\\__w\\1\\s\\src\\Hosting\\AdministrationService\\Microsoft.Web.Hosting.Administration\\Co
ntrollers\\WebCloudController.cs:line 11368\r\n--- End of stack trace from previous location where exception w
as thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.
CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.Web.Hosting
.AsyncHelper.RunSync[TResult](Func`1 func)\r\n   at Microsoft.Web.Hosting.Administration.WebCloudController.Ge
tSiteSourceControl(String subscriptionName, String webspaceName, String name)."}}],"Innererror":null}

Expected Behaviour

Terraform command should end successfully, specially when no changes were done after the first deployment.

Actual Behaviour

the application fails with a traceback, the traceback shows windows file paths however the command is running on MacOS environment.

Steps to Reproduce

No response

Important Factoids

No response

References

No response

@avinode-amagdy avinode-amagdy changed the title Cannot refresh state when deploying new azurerm_service_app_source_control resource. Cannot refresh state when deploying new azurerm_app_service_source_control resource. Apr 26, 2024
@rcskosir rcskosir added the v/3.x label Apr 26, 2024
@xiaxyi
Copy link
Contributor

xiaxyi commented Apr 30, 2024

Thanks @avinode-amagdy for raising this issue, are you able to do the redeploy using azure cli (https://learn.microsoft.com/en-us/cli/azure/webapp/deployment/source?view=azure-cli-latest) after you updated the configuration file?

@avinode-amagdy
Copy link
Author

@xiaxyi
I tried to re-deploy the app using the command you provided a link to, and it works when after the first deployment but after terraform fails I get the following error in command line (using the command you referred to):

There was a conflict. Conflict with existing ScmType: ExternalGit

I really cannot get my hands on the pattern when it fails, the failure seems very random specially that now it's not failing after immediately after the creation, but I noticed that when terraform fails to read the source-control resource the portal also shows an error on retrieving the github repo info.

I believe that it's something in the backend that is failing not terraform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants