diff --git a/internal/services/apimanagement/api_management_diagnostic_resource.go b/internal/services/apimanagement/api_management_diagnostic_resource.go index 02aa56bbe4ef..e71c85e88fd6 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/2021-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)) }