'Run terrform in azure functions powershell

We are developing an azure function which should run terraform cmdlets like init, plan and apply.

when we run above commands in powershell, we are getting below error.

Error checking configuration: <nil>: Failed to read module directory; Module directory C:\home\site\wwwroot\databricks-user-sync-modules does not exist or cannot be read

My run.ps1 file includes below sinppet

write-output (terraform --version)
Write-Output ((Get-ChildItem).Name)
Get-Content -Path main.tf
write-output (terraform init)
terraform plan -var-file dev.tfvars

How to run terraform in azure functions.



Solution 1:[1]

The error message you are receiving may or may not be related to your attempt to use terraform in Azure Functions.

I'd initially ask whether Azure Functions is the ideal solution to the problem you're trying to solve?

Based on the fact that the functions runtime doesn't include the terraform binary in order to run tf cli commands. You may have more success using Azure Devops pipelines or Github Actions to deploy your terraform code.

Both AzDo and Github can trigger CI/CD operations via a webhook.

https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#repository_dispatch

and

https://docs.microsoft.com/en-us/azure/devops/release-notes/2020/pipelines/sprint-172-update

Unless I am missing something obvious, you may have to provide more context around why you're using Azure Functions for this scenario

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BrettMiller