From 1a075a9b1623deb9d7ee3fc2fd4a7b6079c0675c Mon Sep 17 00:00:00 2001 From: Elena Xin <39109137+sinbai@users.noreply.github.com> Date: Wed, 1 Nov 2023 15:26:02 +0800 Subject: [PATCH] `azurerm_api_management_diagnostic` - the `operation_name_format` property is only available for `applicationinsights` diagnostic (#23736) * fix issue 19970 * update code * simplify FourPointOh wrapping --------- Co-authored-by: Steph --- .../api_management_diagnostic_resource.go | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/internal/services/apimanagement/api_management_diagnostic_resource.go b/internal/services/apimanagement/api_management_diagnostic_resource.go index 81ec5d4079c6..c3d128a53ce6 100644 --- a/internal/services/apimanagement/api_management_diagnostic_resource.go +++ b/internal/services/apimanagement/api_management_diagnostic_resource.go @@ -15,6 +15,7 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2022-08-01/logger" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/services/apimanagement/schemaz" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/set" @@ -114,7 +115,12 @@ func resourceApiManagementDiagnostic() *pluginsdk.Resource { "operation_name_format": { Type: pluginsdk.TypeString, Optional: true, - Default: string(diagnostic.OperationNameFormatName), + Default: func() interface{} { + if !features.FourPointOh() { + return string(diagnostic.OperationNameFormatName) + } + return nil + }(), ValidateFunc: validation.StringInSlice([]string{ string(diagnostic.OperationNameFormatName), string(diagnostic.OperationNameFormatUrl), @@ -147,11 +153,18 @@ func resourceApiManagementDiagnosticCreateUpdate(d *pluginsdk.ResourceData, meta parameters := diagnostic.DiagnosticContract{ Properties: &diagnostic.DiagnosticContractProperties{ - LoggerId: d.Get("api_management_logger_id").(string), - OperationNameFormat: pointer.To(diagnostic.OperationNameFormat(d.Get("operation_name_format").(string))), + LoggerId: d.Get("api_management_logger_id").(string), }, } + if d.Get("identifier") == "applicationinsights" { + if operationNameFormat, ok := d.GetOk("operation_name_format"); ok { + parameters.Properties.OperationNameFormat = pointer.To(diagnostic.OperationNameFormat(operationNameFormat.(string))) + } else if !features.FourPointOh() { + parameters.Properties.OperationNameFormat = pointer.To(diagnostic.OperationNameFormatName) + } + } + if samplingPercentage, ok := d.GetOk("sampling_percentage"); ok { parameters.Properties.Sampling = &diagnostic.SamplingSettings{ SamplingType: pointer.To(diagnostic.SamplingTypeFixed), @@ -259,7 +272,11 @@ func resourceApiManagementDiagnosticRead(d *pluginsdk.ResourceData, meta interfa d.Set("backend_request", nil) d.Set("backend_response", nil) } - format := string(diagnostic.OperationNameFormatName) + + format := "" + if !features.FourPointOh() { + format = string(diagnostic.OperationNameFormatName) + } if props.OperationNameFormat != nil { format = string(pointer.From(props.OperationNameFormat)) }