I am trying to retrieve the App Service publish profile so that I could save it to Azure Key Vault and retrieve it in a Github Actions workflow.
resource "null_resource" "get_publish_profile" {
provisioner "local-exec" {
working_dir = path.module
command = <<EOT
az webapp deployment list-publishing-profiles --name xxx --resource-group xxx --subscription xxx --xml >> ./output/publish_profile.xml
EOT
}
}
data "local_file" "publish_profile" {
depends_on = [null_resource.get_publish_profile]
filename = "./output/publish_profile.xml"
}
output "publish_profile_output" {
value = data.local_file.publish_profile.content
}
│ Error: Read local file data source error
│
│ with module.publish_profile.data.local_file.publish_profile,
│ on modules/null_resource/main.tf line 12, in data "local_file" "publish_profile":
│ 12: data "local_file" "publish_profile" {
│
│ The file at given path cannot be read.
│
│ +Original Error: open modules/null_resource/publish_profile.xml: no such
│ file or directory
I have tried checking the path where the xml is saved but I still get the error messages.
Any idea what I could try?
Thanks in advance!
I am trying to retrieve the App Service publish profile so that I could save it to Azure Key Vault and retrieve it in a Github Actions workflow.
resource "null_resource" "get_publish_profile" {
provisioner "local-exec" {
working_dir = path.module
command = <<EOT
az webapp deployment list-publishing-profiles --name xxx --resource-group xxx --subscription xxx --xml >> ./output/publish_profile.xml
EOT
}
}
data "local_file" "publish_profile" {
depends_on = [null_resource.get_publish_profile]
filename = "./output/publish_profile.xml"
}
output "publish_profile_output" {
value = data.local_file.publish_profile.content
}
│ Error: Read local file data source error
│
│ with module.publish_profile.data.local_file.publish_profile,
│ on modules/null_resource/main.tf line 12, in data "local_file" "publish_profile":
│ 12: data "local_file" "publish_profile" {
│
│ The file at given path cannot be read.
│
│ +Original Error: open modules/null_resource/publish_profile.xml: no such
│ file or directory
I have tried checking the path where the xml is saved but I still get the error messages.
Any idea what I could try?
Thanks in advance!
Share Improve this question asked Mar 10 at 13:06 NorbiNorbi 111 silver badge2 bronze badges 1 |1 Answer
Reset to default 0I tried the Terraform code below to retrieve the Azure App Service publish profile and it was successfully retrieved without any issues.
main.tf :
provider "azurerm" {
features {}
subscription_id = "<SubscriptionID>"
}
data "azurerm_resource_group" "rg" {
name = "<ResourceGroupName>"
}
data "azurerm_service_plan" "app_plan" {
name = "<AppServicePlanName>"
resource_group_name = data.azurerm_resource_group.rg.name
}
data "azurerm_windows_web_app" "app" {
name = "<AppServiceName>"
resource_group_name = data.azurerm_resource_group.rg.name
}
resource "null_resource" "fetch_publish_profile" {
provisioner "local-exec" {
interpreter = ["PowerShell", "-Command"]
command = <<EOT
$outputFolder = "output"
$outputFile = "$outputFolder/publish_profile.xml"
if (!(Test-Path -Path $outputFolder)) {
New-Item -ItemType Directory -Path $outputFolder
}
az webapp deployment list-publishing-profiles `
--name "<AppServiceName>" `
--resource-group "<ResourceGroupName>" `
--subscription "<SubscriptionID>" `
--xml | Out-File -FilePath $outputFile -Encoding utf8
if ($LASTEXITCODE -ne 0) {
Write-Output "Error fetching publishing profile"
exit $LASTEXITCODE
} else {
Write-Output "Publishing profile saved to $outputFile"
}
EOT
}
}
Output :
I successfully retrieved the Azure App Service publish profile using the Terraform code.
./output/
directory exists and use> ./output/publish_profile.xml
instead of>>
. – Dasari Kamali Commented Mar 11 at 3:33