Skip to content

Commit

Permalink
azurerm_api_management_diagnostic - the operation_name_format pro…
Browse files Browse the repository at this point in the history
…perty is only available for `applicationinsights` diagnostic (#23736)

* fix issue 19970

* update code

* simplify FourPointOh wrapping

---------

Co-authored-by: Steph <[email protected]>
  • Loading branch information
sinbai and stephybun authored Nov 1, 2023
1 parent 2f0b375 commit 1a075a9
Showing 1 changed file with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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))
}
Expand Down

0 comments on commit 1a075a9

Please sign in to comment.