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

r\application_insights fix workspace_id case that force recreation #19325

Merged
merged 4 commits into from
Nov 21, 2022
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 @@ -11,7 +11,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/preview/alertsmanagement/mgmt/2019-06-01-preview/alertsmanagement"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2020-08-01/workspaces"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/applicationinsights/migration"
Expand Down Expand Up @@ -79,7 +79,7 @@ func resourceApplicationInsights() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: azure.ValidateResourceIDOrEmpty,
ValidateFunc: workspaces.ValidateWorkspaceID,
},

"retention_in_days": {
Expand Down Expand Up @@ -228,7 +228,11 @@ func resourceApplicationInsightsCreateUpdate(d *pluginsdk.ResourceData, meta int
}

if workspaceRaw, hasWorkspaceId := d.GetOk("workspace_id"); hasWorkspaceId {
applicationInsightsComponentProperties.WorkspaceResourceID = utils.String(workspaceRaw.(string))
workspaceID, err := workspaces.ParseWorkspaceID(workspaceRaw.(string))
if err != nil {
return err
}
applicationInsightsComponentProperties.WorkspaceResourceID = utils.String(workspaceID.ID())
}

if v, ok := d.GetOk("retention_in_days"); ok {
Expand Down Expand Up @@ -370,9 +374,15 @@ func resourceApplicationInsightsRead(d *pluginsdk.ResourceData, meta interface{}
d.Set("internet_query_enabled", resp.PublicNetworkAccessForQuery == insights.PublicNetworkAccessTypeEnabled)
d.Set("force_customer_storage_for_profiler", props.ForceCustomerStorageForProfiler)

workspaceId := ""
if v := props.WorkspaceResourceID; v != nil {
d.Set("workspace_id", v)
id, err := workspaces.ParseWorkspaceIDInsensitively(*v)
if err != nil {
return err
}
workspaceId = id.ID()
}
mgattei marked this conversation as resolved.
Show resolved Hide resolved
d.Set("workspace_id", workspaceId)

if v := props.RetentionInDays; v != nil {
d.Set("retention_in_days", v)
Expand Down