Refer my [**SO thread answer**](https://stackoverflow.com/questions/76549059/azure-function-app-configure-deployment-center-with-terraform/76555151#76555151) here for the same ask. By default - [azurerm_linux_function_app](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_function_app) does not contain source_control block it is available in [azurerm_function_app](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/function_app) which is now deprecated but you can still use it for your terraform deployment.
***Below code referred from my SO thread answer:-***
```hcl
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.59.0"
}
}
}
provider "azurerm" {
subscription_id = "xxxxx2a7"
tenant_id = "xxxxed-axxx"
client_id = "xxxxxxb"
client_secret = "xxxxxxx-xxxxLE"
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
resource "azurerm_resource_group" "example" {
name = "azure-functions-example-rgsiddhesh"
location = "West Europe"
}
resource "azurerm_storage_account" "example" {
name = "examlpesasiliconstrg32"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
depends_on = [ azurerm_resource_group.example ]
}
resource "azurerm_app_service_plan" "example" {
name = "azure-functions-example-sp-siliconweb"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
kind = "Linux"
reserved = true
depends_on = [ azurerm_resource_group.example ]
sku {
tier = "Dynamic"
size = "Y1"
}
lifecycle {
ignore_changes = [
kind
]
}
}
resource "azurerm_function_app" "example" {
name = "example-azure-function-siliconfunc65"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
app_service_plan_id = azurerm_app_service_plan.example.id
storage_account_name = azurerm_storage_account.example.name
storage_account_access_key = azurerm_storage_account.example.primary_access_key
os_type = "linux"
version = "~4"
depends_on = [ azurerm_storage_account.example ]
app_settings = {
"FUNCTIONS_WORKER_RUNTIME" = "python",
"AzureWebJobsDisableHomepage" = "true",
"SCM_DO_BUILD_DURING_DEPLOYMENT" = "true"
}
site_config {
linux_fx_version = "python|3.10"
}
source_control {
repo_url = "https://github.com/sid24desai/funchttp"
branch = "main"
}
}
```

As a workaround you can use **`az cli`** command to deploy the function with remote/local git or directly via git repository refer the code below:-
**Script reference:-**
```hcl
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.59.0"
}
}
}
provider "azurerm" {
subscription_id = "0151c365-f598-44d6-b4fd-e2b6e97cb2a7"
tenant_id = "xxxxaf90xxxx"
client_id = "xxxxxa31435cb"
client_secret = "xxxxxxx"
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
resource "azurerm_resource_group" "example" {
name = "siliconrgsid09"
location = "West Europe"
}
resource "azurerm_storage_account" "example" {
name = "linuxfuncsilicon63"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
depends_on = [ azurerm_resource_group.example ]
}
resource "azurerm_service_plan" "example" {
name = "silicon-appsrvc92"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
os_type = "Linux"
sku_name = "Y1"
depends_on = [ azurerm_resource_group.example ]
}
resource "azurerm_linux_function_app" "example" {
name = "silicon-funcapp94"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
storage_account_name = azurerm_storage_account.example.name
storage_account_access_key = azurerm_storage_account.example.primary_access_key
service_plan_id = azurerm_service_plan.example.id
depends_on = [ azurerm_storage_account.example ]
app_settings = {
"FUNCTIONS_WORKER_RUNTIME" = "python",
"AzureWebJobsDisableHomepage" = "true",
"SCM_DO_BUILD_DURING_DEPLOYMENT" = "true"
}
site_config {
application_stack {
python_version = "3.10"
}
}
}
resource "null_resource" "run_az_cli" {
provisioner "local-exec" {
command = "az functionapp deployment source config --branch main --manual-integration --name ${azurerm_linux_function_app.example.name} --repo-url https://github.com/sid24desai/functionpyhttp --resource-group ${azurerm_resource_group.example.name}"
}
}
```
As a workaround you can my another [SO thread answer](https://stackoverflow.com/questions/76432127/azures-function-app-not-being-able-to-access-storage-account/76437214#76437214) to Deploy Function trigger inside Function app via Storage account.
There's no direct, way to configure SCM or Source control in [**azurerm_windows_function_app**](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/windows_function_app) terraform provider. The Source control block is present in [**azurerm_function_app**](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/function_app#example-usage-python-in-a-consumption-plan) provider.
You can refer my [**SO thread answer**](https://stackoverflow.com/questions/76432127/azures-function-app-not-being-able-to-access-storage-account/76437214#76437214) to deploy Function Code via Storage account as zip via storage account URL.
My main.tf:-
```hcl
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.59.0"
}
}
}
provider "azurerm" {
subscription_id = "xxxx4fd-e2b6e97cb2a7"
tenant_id = "xxxxce4-99ed-af9038592395"
client_id = "xxxxx8-6d26a31435cb"
client_secret = "xxxxxRt8313-CS0ifbLE"
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
resource "azurerm_resource_group" "example" {
name = "azure-functions-example-rgsiddhesh"
location = "West Europe"
}
resource "azurerm_storage_account" "example" {
name = "examlpesasiliconstrg32"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
depends_on = [ azurerm_resource_group.example ]
}
resource "azurerm_app_service_plan" "example" {
name = "azure-functions-example-sp-siliconweb"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
kind = "Linux"
reserved = true
depends_on = [ azurerm_resource_group.example ]
sku {
tier = "Dynamic"
size = "Y1"
}
lifecycle {
ignore_changes = [
kind
]
}
}
resource "azurerm_function_app" "example" {
name = "example-azure-function-siliconfunc65"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
app_service_plan_id = azurerm_app_service_plan.example.id
storage_account_name = azurerm_storage_account.example.name
storage_account_access_key = azurerm_storage_account.example.primary_access_key
os_type = "linux"
version = "~4"
depends_on = [ azurerm_storage_account.example ]
app_settings = {
"FUNCTIONS_WORKER_RUNTIME" = "python",
"AzureWebJobsDisableHomepage" = "true",
"SCM_DO_BUILD_DURING_DEPLOYMENT" = "true"
}
site_config {
linux_fx_version = "python|3.10"
}
source_control {
repo_url = "https://github.com/username/functionrepo"
branch = "main"
}
}
```
You can also create a github action workflow via Azure CLI command from [here](https://learn.microsoft.com/en-us/cli/azure/functionapp/deployment/github-actions?view=azure-cli-latest) like below:-
Command:-
```bash
az functionapp deployment github-actions add --repo "sid24desai/funchttp" --branch main -g siliconrg5 -n siliconfunc32 --token github_pat_xxxxxxxxYA5UEkAZqq
```
**Output:-**

You can run the same command in your terraform script like below:-
```hcl
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.62.1"
}
}
}
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "example" {
name = "azure-functions-example-rgsiddhesh"
location = "West Europe"
}
resource "azurerm_storage_account" "example" {
name = "eeeesasiliconstrg32"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
depends_on = [ azurerm_resource_group.example ]
}
resource "azurerm_app_service_plan" "example" {
name = "eeesiliconweb"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
kind = "Linux"
reserved = true
depends_on = [ azurerm_resource_group.example ]
sku {
tier = "Dynamic"
size = "Y1"
}
lifecycle {
ignore_changes = [
kind
]
}
}
resource "azurerm_function_app" "example" {
name = "eesiliconfunc65"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
app_service_plan_id = azurerm_app_service_plan.example.id
storage_account_name = azurerm_storage_account.example.name
storage_account_access_key = azurerm_storage_account.example.primary_access_key
os_type = "linux"
version = "~4"
depends_on = [ azurerm_storage_account.example ]
app_settings = {
"FUNCTIONS_WORKER_RUNTIME" = "python",
"AzureWebJobsDisableHomepage" = "true",
"SCM_DO_BUILD_DURING_DEPLOYMENT" = "true"
}
site_config {
linux_fx_version = "python|3.10"
}
}
resource "null_resource" "run_az_cli" {
provisioner "local-exec" {
command = "az functionapp deployment github-actions add --repo sid24desai/funchttp --branch main -g resourcegroupname -n function-name --token github_pat_xxxxxxxxA5UEkAZqq"
}
}
```
This command will create a new workflow file in your repository, Just replace the Function app name with your Function and run the workflow:-

