Two Terraform Resources referencing eachother

Viewed 91

The goal is to set up two services, an Azure function app and a Cosmos DB. The Cosmos DB should allow traffic only from the function app, and the function app should use the key of the Cosmos DB to access it.

Relevant Terraform code

resource "azurerm_cosmosdb_account" "cosmosdb_account" {
  ...
  ip_range_filter     = azurerm_function_app.function_app.possible_outbound_ip_addresses
}

resource "azurerm_function_app" "function_app" {
  ...
  app_settings = {
    key = azurerm_cosmosdb_account.cosmosdb_account.primary_master_key
  }
}

Error

Error: Cycle: azurerm_cosmosdb_account.cosmosdb_account, azurerm_function_app.function_app

Is there any way to do this without null_resources or weird hacks?

0 Answers
Related