Skip to content

Instantly share code, notes, and snippets.

@ilmax
Created April 6, 2023 13:37
Show Gist options
  • Save ilmax/4799a5d3d25040be35d00eca6cc714a2 to your computer and use it in GitHub Desktop.
Save ilmax/4799a5d3d25040be35d00eca6cc714a2 to your computer and use it in GitHub Desktop.
terraform-workaround
## Get an access token using standard cli functionality
data "external" "token" {
program = ["az", "account", "get-access-token"]
}
## Put the access token in a local variable for ease of use
locals {
accessToken = data.external.token.result["accessToken"]
}
## Get the app settings for the function app, if the app doesn't exist, this will not fail/terminate the terraform apply
data "http" "resource" {
url = "https://management.azure.com/subscriptions/${var.subscription_id}/resourceGroups/${var.resource_group_name}/providers/Microsoft.Web/sites/${var.site_name}/config/appsettings/list?api-version=2022-03-01"
method = "POST"
request_headers = {
Accept = "application/json"
Authorization = "Bearer ${local.accessToken}"
}
}
# # Just for debug purposes
# output "result" {
# value = data.http.resource.response_body
# }
locals {
appsettings = data.http.resource.status_code == 200 ? jsondecode(data.http.resource.response_body)["properties"] : null
}
output "appsettings" {
value = local.appsettings
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment