admin管理员组文章数量:1314308
When trying to create an azurerm_api_management_api_diagnostic resource within an existing APIM, an azurerm_api_management_logger
id is required.
Currently, Terraform only provides a resource block for the azurerm_api_management_logger
, which therefore presents a huge challenge for me and this is why. We already have an azurerm_api_management_logger
resource in APIM which I'd like to consume or reference.....instead of having to create brand new logger, using a Resource block.
Typically, if this was for some other Azure resource in a similar scenario, I would simply have used a Data block to reference the existing resource. Azurerm_api_management_logger however does not appear to support any Data blocks, meaning there is no way of me accessing or referencing the existing logger id required for my Terraform configuration.
Any suggestions on how I can get round this? The intent here is not to manage the existing logger but just reference it.
When trying to create an azurerm_api_management_api_diagnostic resource within an existing APIM, an azurerm_api_management_logger
id is required.
Currently, Terraform only provides a resource block for the azurerm_api_management_logger
, which therefore presents a huge challenge for me and this is why. We already have an azurerm_api_management_logger
resource in APIM which I'd like to consume or reference.....instead of having to create brand new logger, using a Resource block.
Typically, if this was for some other Azure resource in a similar scenario, I would simply have used a Data block to reference the existing resource. Azurerm_api_management_logger however does not appear to support any Data blocks, meaning there is no way of me accessing or referencing the existing logger id required for my Terraform configuration.
Any suggestions on how I can get round this? The intent here is not to manage the existing logger but just reference it.
Share Improve this question edited Feb 3 at 13:07 Jahnavi 8,0581 gold badge6 silver badges12 bronze badges Recognized by Microsoft Azure Collective asked Jan 30 at 12:47 hitman126hitman126 9511 gold badge27 silver badges59 bronze badges 4 |1 Answer
Reset to default 0Usually in Terraform, to reference existing resources and get their relevant properties one main approach is to use a data
block. But after a workaround on your issue, I too found that there is no data block existed for APIM service logger resource.
As a workaround, I figured out that data azapi_resource block helps out in this scenario as shown below.
data "azapi_resource" "logger" {
type = "Microsoft.ApiManagement/service/loggers@2024-06-01-preview"
name = "newloger"
parent_id = data.azurerm_api_management.example.id
response_export_values = ["id"]
}
output "logger_id" {
value = data.azapi_resource.logger.id
}
Also, thanks @Rui Jarimba for suggesting another workaround by declaring logger id under a variable
block.
Complete code using data azapi resource
:
terraform {
required_providers {
azapi = {
source = "Azure/azapi"
version = "2.2.0"
}
}
}
provider "azapi" {
# Configuration options
}
provider "azurerm" {
features {}
subscription_id="47xxxxb014"
}
data "azurerm_resource_group" "example" {
name = "Jahnavi"
}
data "azurerm_api_management" "example" {
name = "newapimjah"
resource_group_name = data.azurerm_resource_group.example.name
}
data "azapi_resource" "logger" {
type = "Microsoft.ApiManagement/service/loggers@2024-06-01-preview"
name = "newloger"
parent_id = data.azurerm_api_management.example.id
response_export_values = ["id"]
}
output "logger_id" {
value = data.azapi_resource.logger.id
}
resource "azurerm_application_insights" "example" {
name = "examplej-appinsightsnew"
location = data.azurerm_resource_group.example.location
resource_group_name = "newresources"
application_type = "web"
}
resource "azurerm_api_management_diagnostic" "example" {
identifier = "applicationinsights"
resource_group_name = "newresources"
api_management_name = "latestnewapimj"
api_management_logger_id = data.azapi_resource.logger.id
sampling_percentage = 10.0
always_log_errors = true
log_client_ip = true
verbosity = "verbose"
http_correlation_protocol = "W3C"
frontend_request {
body_bytes = 32
headers_to_log = [
"content-type",
"accept",
"origin",
]
}
frontend_response {
body_bytes = 32
headers_to_log = [
"content-type",
"content-length",
"origin",
]
}
backend_request {
body_bytes = 32
headers_to_log = [
"content-type",
"accept",
"origin",
]
}
backend_response {
body_bytes = 32
headers_to_log = [
"content-type",
"content-length",
"origin",
]
}
}
Output:
Reference: azurerm_api_management_diagnostic
本文标签: terraformReferencing an existing azurermapimanagementlogger in AzureStack Overflow
版权声明:本文标题:terraform - Referencing an existing azurerm_api_management_logger in Azure - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741964827a2407486.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
api_management_logger_id
and then go to the Azure Portal and grab the correspondent resource id and set the variable in a.tfvars
file? – Rui Jarimba Commented Jan 30 at 13:00az_api
data block to automate the deployment. @hitman126 – Jahnavi Commented Jan 31 at 11:11