Reputation: 25
I'm trying to IaC my API Gateway using Terraform. I did all configurations normally, such as backend, products and policies. But reading the documentation, I didn't find any way to set a Tag to API, only create a new one.
resource "azurerm_api_management_api" "test" {
name = "test*******"
display_name = "Test*******"
api_management_name = data.azurerm_api_management.example.name
resource_group_name = data.azurerm_api_management.example.resource_group_name
revision = "1"
protocols = ["https"]
subscription_required = true
path = "test****"
subscription_key_parameter_names {
header = "Ocp-Apim-Subscription-Key"
query = "subscription-key"
}
}
Am I missing something? Does Terraform support this feature? Is it better to use ARM templates or Powershell in this case?
Upvotes: 0
Views: 912
Reputation: 1098
We were missing this feature as well.
Luckily, it got added to the azurerm Terraform provider in version 0.92.0 recently: azurerm_api_management_api_tag
You can use the new resource to assign an existing tag to an API:
resource "azurerm_api_management_api" "example" {
name = "example-api"
resource_group_name = azurerm_resource_group.example.name
api_management_name = azurerm_api_management.example.name
revision = "1"
}
resource "azurerm_api_management_tag" "example" {
api_management_id = data.azurerm_api_management.example.id
name = "example-tag"
display_name = "Example Tag"
}
resource "azurerm_api_management_api_tag" "example" {
api_id = azurerm_api_management_api.example.id
name = "example-tag"
}
Upvotes: 0
Reputation: 3137
I have tested in my environment
As per the azurerm_api_management_api | Resources | hashicorp/azurerm | Terraform Registry document, there is no option to set a tag to an API in Azure API Management using Terraform.
We can create an API tag for Azure API Management using terraform using below code :
resource "azurerm_api_management_tag" "example" {
api_management_id = "resource id of azure-api-management"
name = "tag-name"
}
Now, we can use this powershell command to set the above tag for an API in Azure API Management :
New-AzResource -ResourceGroupName "Resource-Group-Name" -ResourceType Microsoft.ApiManagement/service/apis/tags -ResourceName "api-management-name/api-name/tag-name" -Force
Upvotes: 2