hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.6k stars 4.65k forks source link

Support for APIM Backend Headers Named Value #14575

Open Corendiel opened 2 years ago

Corendiel commented 2 years ago

Community Note

Description

Some Backend configurations are not possible via Terraform. Currently, it only supports a string value and doesn't support the Named Value option. Storing backend credentials in terraform script is not ideal Named Value opens the path to the Key Vault option.

New or Affected Resource(s)

Potential Terraform Configuration

resource "azurerm_api_management_backend" "example" {
  name                = "example-backend"
  resource_group_name = azurerm_resource_group.example.name
  api_management_name = azurerm_api_management.example.name
  protocol            = "http"
  url                 = "https://backend"
  credentials {
    header {
       name = Ocp-Apim-Subscription-Key
       named_value = azurerm_api_management_named_value.sub-key.name
    }
  }
}

References

https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_backend#header

mibo32 commented 2 years ago

@Corendiel Did you try this:

  credentials {
    header = {

      "x-functions-key" = "{{Named_value_name}}" 
    }
  }

It will automatically add it as a named value reference instead of a string value.

emocibob commented 1 year ago
  credentials {
    header = {

      "x-functions-key" = "{{Named_value_name}}" 
    }
  }

It will automatically add it as a named value reference instead of a string value.

In case someone stumbles on this issue, you can use string interpolation to reference an azurerm_api_management_named_value resource. Example:

  credentials {
    header = {
      "x-functions-key" = "{{${azurerm_api_management_named_value.example.name}}}"
    }
  }
TanveerShell commented 1 year ago

@emocibob If we use the below code in the backend credentials { header = { "x-functions-key" = "{{${azurerm_api_management_named_value.example.name}}}" } }

and refer the backend in the api operation , will the named-value secret get added in the function app host key as *"apim-" as this is auto populated when imported manually.