skip to Main Content

I need to get access to a Function App staging slot in Terraform.

I can get it for its production slot:

data "azurerm_linux_function_app" "my_application" {
  name                = <app_name>
  resource_group_name = <resource_group_name>
}

resource "azurerm_role_assignment" "role_assignment" {
  scope               = <scope>
  role_definition_name = <role_name>
  principal_id        = data.azurerm_linux_function_app.my_application.identity.0.principal_id
}

For the staging slot, I would have expected to be able to do something similar:

data "azurerm_linux_function_app_slot" "my_app_staging" {
  name                = <app_name>
  resource_group_name = <resource_group_name>
  slot_name           = "staging"
}


resource "azurerm_role_assignment" "staging_role_assignment" {
  scope               = <scope>
  role_definition_name = <role_name>
  principal_id        = data.azurerm_linux_function_app_slot.my_app_staging.identity.0.principal_id
}

However I get the following error:

The provider hashicorp/azurerm does not support data source
"azurerm_linux_function_app_slot".

Question

How to get the principal_id of a Function App’s Staging slot in Terraform?

2

Answers


  1. There is no Support data source for "azurerm_linux_function_app_slot".

    these are the available data sources

    enter image description here

    You can try to import the Function Apps Deployment Slots using the resource id, e.g

    terraform import azurerm_linux_function_app_slot.example "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Web/sites/site1/slots/slot1" 
    

    Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_function_app_slot

    Hope this helps!

    Login or Signup to reply.
  2. That data source is not implemented in the provider as of 3.48.0.

    Alternatively, you could use User Assigned identity and use the data source for User Assigned Identity.

    https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/user_assigned_identity

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search