Skip to content

Instantly share code, notes, and snippets.

@lawrencegripper
Last active July 26, 2022 17:45
Show Gist options
  • Save lawrencegripper/48cb08fe1c7952f1caf2a18828c6a357 to your computer and use it in GitHub Desktop.
Save lawrencegripper/48cb08fe1c7952f1caf2a18828c6a357 to your computer and use it in GitHub Desktop.
Terraform Azure functions keys
# Get the functions keys out of the app
resource "azurerm_template_deployment" "function_keys" {
name = "javafunckeys${var.random_name_ending}"
parameters = {
"functionApp" = "${azurerm_function_app.function-app.name}"
}
resource_group_name = "${var.resource_group_name}"
deployment_mode = "Incremental"
template_body = <<BODY
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"functionApp": {"type": "string", "defaultValue": ""}
},
"variables": {
"functionAppId": "[resourceId('Microsoft.Web/sites', parameters('functionApp'))]"
},
"resources": [
],
"outputs": {
"functionkey": {
"type": "string",
"value": "[listkeys(concat(variables('functionAppId'), '/host/default'), '2018-11-01').functionKeys.default]" }
}
}
BODY
}
output "func_keys" {
value = "${lookup(azurerm_template_deployment.function_keys.outputs, "functionkey")}"
}
// This is the response from the `listkeys` function in ARM so we use `.functionKeys.default` to reach into it and output
// the function key we need.
{
"functionKeys": {
"default": "KEYEHERE...qtocq1safFGhAwZkzPe1VdRflvg=="
},
"masterKey": "KEYEHERE......Ju1384KHUprI01kH5GIKH2uvrqew==",
"systemKeys": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment