Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_api_management_diagnostic - the operation_name_format property is only available for applicationinsights diagnostic #23736

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/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"
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 := ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, pre 4.0 we should still be defaulting this in the read.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

if !features.FourPointOh() {
format = string(diagnostic.OperationNameFormatName)
}
if props.OperationNameFormat != nil {
format = string(pointer.From(props.OperationNameFormat))
}
Expand Down
Loading