Currently source_control block only applies to localGit. There seems to be no way to configure source control for any other scm methods.
Using this module with scm_type set to other than None or LocalGit results in error:
Error making Read request on AzureRM App Service Source Control "example-app-test-service-unique": web.AppsClient#GetSourceControl: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="BadRequest" Message="Repository 'GetSiteSourceControl' operation failed with System.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.MoveNext()\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__DisplayClass305_1.<<GetSiteSourceControl>b__0>d.MoveNext()\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.AsyncHelper.RunSync[TResult](Func1 func)\r\n at Microsoft.Web.Hosting.Administration.WebCloudController.GetSiteSourceControl(String subscriptionName, String webspaceName, String name)." Details=[{"Message":"Repository 'GetSiteSourceControl' operation failed with System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.\r\n at System.ThrowHelper.ThrowKeyNotFoundException()\r\n at System.Collections.Generic.Dictionary2.get_Item(TKey key)\r\n at Microsoft.Web.Hosting.Administration.ExternalSiteRepositoryProvider.\u003cGetSiteSourceControl\u003ed__4.MoveNext()\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.\u003c\u003ec__DisplayClass305_1.\u003c\u003cGetSiteSourceControl\u003eb__0\u003ed.MoveNext()\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.AsyncHelper.RunSync[TResult](Func1 func)\r\n at Microsoft.Web.Hosting.Administration.WebCloudController.GetSiteSourceControl(String subscriptionName, String webspaceName, String name)."},{"Code":"BadRequest"},{"ErrorEntity":{"Code":"BadRequest","ExtendedCode":"05007","Message":"Repository 'GetSiteSourceControl' operation failed with System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.\r\n at System.ThrowHelper.ThrowKeyNotFoundException()\r\n at System.Collections.Generic.Dictionary2.get_Item(TKey key)\r\n at Microsoft.Web.Hosting.Administration.ExternalSiteRepositoryProvider.\u003cGetSiteSourceControl\u003ed__4.MoveNext()\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.\u003c\u003ec__DisplayClass305_1.\u003c\u003cGetSiteSourceControl\u003eb__0\u003ed.MoveNext()\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.AsyncHelper.RunSync[TResult](Func1 func)\r\n at Microsoft.Web.Hosting.Administration.WebCloudController.GetSiteSourceControl(String subscriptionName, String webspaceName, String name).","MessageTemplate":"Repository '{0}' operation failed with {1}.","Parameters":["GetSiteSourceControl","System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.\r\n at System.ThrowHelper.ThrowKeyNotFoundException()\r\n at System.Collections.Generic.Dictionary2.get_Item(TKey key)\r\n at Microsoft.Web.Hosting.Administration.ExternalSiteRepositoryProvider.\u003cGetSiteSourceControl\u003ed__4.MoveNext()\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.\u003c\u003ec__DisplayClass305_1.\u003c\u003cGetSiteSourceControl\u003eb__0\u003ed.MoveNext()\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.AsyncHelper.RunSync[TResult](Func1 func)\r\n at Microsoft.Web.Hosting.Administration.WebCloudController.GetSiteSourceControl(String subscriptionName, String webspaceName, String name)"]}}]
azurerm_app_service
site_config {
scm_type = "ExternalGit"
}
source_control {
repo_url = "https://github.com/azureappserviceoss/wordpress-azure"
branch = "master"
}
site_config {
scm_type = "GitHub"
}
source_control {
repo_url = "https://github.com/azureappserviceoss/wordpress-azure"
branch = "master"
}
This might happen even after you remove GitHub and go back to LocalGit
On top of this, after you run it with scm_type = "GitHub" and then you try to change it or even terraform destroy you always get the error. To remediate I have to manually remove entire app using azure portal and re-deploy with different setting like None and then using local exec to configure github.
I'm facing the same error with scm_type set to _BitbucketGit_
It seems that validation of other types of scm_type = "" have been added to the code but its missing underlying functionality.
Hi, we have been experimenting with support for App Service deployments for a while.
The following is already supported:
scm_type to LocalGit (within site_config block)LocalGit, then the repo_url (within source_control block) returns the URL for local Git deployment, and fields within site_credential block returns credentials that can be used to enable local Git (by using App Service credentials)We have been working on the following features:
repo_url and branch within source_control block. This implies is_manual_integration is false (which is the default).repo_url, branch and setting is_manual_integration to true within source_control blockAnd such we have been working on the following in Terraform AzureRM provider:
azurerm_app_service_source_control_token - for configuring App service deployment sources / source control tokensazurerm_app_service: support for setting repo_url, branch and other fields within the source_control block (they are read only currently)azurerm_app_service_source_control - for configuring App Service deployment / source controlClick to show Example configuration 1
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}
resource "azurerm_app_service_plan" "example" {
name = "example-app-service-plan"
location = "${azurerm_resource_group.example.location}"
resource_group_name = "${azurerm_resource_group.example.name}"
sku {
tier = "Standard"
size = "S1"
}
}
resource "azurerm_app_service" "example" {
name = "example-app-service"
location = "${azurerm_resource_group.example.location}"
resource_group_name = "${azurerm_resource_group.example.name}"
app_service_plan_id = "${azurerm_app_service_plan.example.id}"
site_config {
scm_type = "ExternalGit"
}
source_control {
repo_url = "https://github.com/Azure-Samples/app-service-web-html-get-started"
branch = "master"
}
}
Click to show example configuration 2
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}
resource "azurerm_app_service_plan" "example" {
name = "example-app-service-plan"
location = "${azurerm_resource_group.example.location}"
resource_group_name = "${azurerm_resource_group.example.name}"
sku {
tier = "Standard"
size = "S1"
}
}
resource "azurerm_app_service" "example" {
name = "example-app-service"
location = "${azurerm_resource_group.example.location}"
resource_group_name = "${azurerm_resource_group.example.name}"
app_service_plan_id = "${azurerm_app_service_plan.example.id}"
lifecycle {
ignore_changes = [site_config.0.scm_type]
}
}
resource "azurerm_app_service_source_control" "example" {
app_service_id = "${azurerm_app_service.example.id}"
repo_url = "https://github.com/Azure-Samples/app-service-web-html-get-started"
is_manual_integration = true
branch = "master"
}
Not sure what provides the best user experience in this case.
However there are some issues with adding support for setting repo_url, branch and other fields within the source_control block of azurerm_app_service resource without introducing any breaking changes.
For example:
scm_type (within site_config) supports the following values: BitbucketGit, BitbucketHg, CodePlexGit, CodePlexHg, Dropbox, ExternalGit, ExternalHg, GitHub, LocalGit, None, OneDrive, Tfs, VSO and VSTSRM.scm_type when using LocalGit or None.scm_type to BitbucketGit, BitbucketHg, Dropbox, ExternalGit, ExternalHg, GitHub or OneDrive, then fields within source_control block must be set first (like repo_url and branch). scm_type to BitbucketGit, BitbucketHg, Dropbox, GitHub or OneDrive, then a source control token must be set first.scm_type to Tfs, VSO and VSTSRM I have no idea what is supposed to happen. It feels like these values would only be needed in cases where someone imported old resource or configured something outside of Terraform (for example Azure portal), and these values would only be needed to fix configuration drift, but not expected to have any function within the AzureRM provider. In such case it's better to ignore changes to these fields in the Terraform configuration, and remove support for them in the provider. If anyone can provide any documentation about these values being officially supported, it would be most appreciated, as some of them seemingly don't work and results in error message.scm_type to CodePlexGit or CodePlexHg should be deprecated, because CodePlex was shut down Dec 2017.Because we can already set scm_type to all of these values in azurerm_app_service, and repo_url in source_control can either be local Git deployment URL or user specified repo URL, these features are hard to add without introducing breaking changes.
Any feedback is appreciated.
On top of this, after you run it with scm_type = "GitHub" and then you try to change it or even terraform destroy you always get the error. To remediate I have to manually remove entire app using azure portal and re-deploy with different setting like None and then using local exec to configure github.
You can fix this from resource explorer:
Head into "Subscriptions, resourceGroups, PICK_RESOURCE_GROUP, providers, Microsoft.Web, sites, YOUR_APP_SERVICE, config, web
Once there select "Read/Write" at the top by your account/name.
Click on Edit
Find: scmType
Change it from "Github" to "None"
Hit "Patch".
Now when you go back to the app service in Azure Portal, It won't just spin forever when you click Deployment Center, and you can setup Github manually again.
Hi, I think I have a problem related to this issue. I think due to changes on the repo_url its no longer accessible. When attempting to apply terraform complains that .repo_url doesn't exist even though when I inspect the state file it does. The other issue is the url that is given doesn't have the resource.git file appended to its path
${azurerm_app_service.this.source_control.repo_url} gives this error
Error: Unsupported attribute This value does not any attributes
```
resource "azurerm_app_service" "this" {
app_service_plan_id = azurerm_app_service_plan.this.id
location = var.location
name = "appservice-fddre"
resource_group_name = var.resource_group.name
site_config {
python_version = "3.4"
scm_type = "LocalGit"
websockets_enabled = "true"
}
provisioner "local-exec" {
command = "git remote add azure ${azurerm_app_service.this.source_control.repo_url}/appservice-fddre.git && git push azure master"
}
}
Are there any functional examples or samples with scm_typeusing anything other than "LocalGit"?
I'm experiencing a similar issue as @crumbling wherein I can no longer update existing app services set to LocalGit as it claims the RepoUrl (which was automatically generated) is invalid, and the only thing I can see about it is the missing repo.git on the end of the URL.
Adding a source_control block will not work as it conflicts with scm_type LocalGit, so we're basically dead in the water.
Most helpful comment
On top of this, after you run it with scm_type = "GitHub" and then you try to change it or even terraform destroy you always get the error. To remediate I have to manually remove entire app using azure portal and re-deploy with different setting like None and then using local exec to configure github.