Skip to content

Commit

Permalink
azurerm_log_analytics_workspace - add state migration for sdk update
Browse files Browse the repository at this point in the history
  • Loading branch information
myc2h6o committed Feb 1, 2023
1 parent f7ba194 commit 08e565a
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ func resourceLogAnalyticsWorkspace() *pluginsdk.Resource {
return err
}),

SchemaVersion: 2,
SchemaVersion: 3,
StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{
0: migration.WorkspaceV0ToV1{},
1: migration.WorkspaceV1ToV2{},
2: migration.WorkspaceV2ToV3{},
}),

Timeouts: &pluginsdk.ResourceTimeout{
Expand Down
119 changes: 119 additions & 0 deletions internal/services/loganalytics/migration/workspace_v2_to_v3.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package migration

import (
"context"
"log"

"github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2020-08-01/workspaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
)

var _ pluginsdk.StateUpgrade = WorkspaceV2ToV3{}

type WorkspaceV2ToV3 struct{}

func (WorkspaceV2ToV3) Schema() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"allow_resource_only_permissions": {
Optional: true,
Type: pluginsdk.TypeBool,
},

"cmk_for_query_forced": {
Optional: true,
Type: pluginsdk.TypeBool,
},

"daily_quota_gb": {
Optional: true,
Type: pluginsdk.TypeFloat,
},

"internet_ingestion_enabled": {
Optional: true,
Type: pluginsdk.TypeBool,
},

"internet_query_enabled": {
Optional: true,
Type: pluginsdk.TypeBool,
},

"local_authentication_disabled": {
Optional: true,
Type: pluginsdk.TypeBool,
},

"location": {
ForceNew: true,
Required: true,
Type: pluginsdk.TypeString,
},

"name": {
ForceNew: true,
Required: true,
Type: pluginsdk.TypeString,
},

"primary_shared_key": {
Computed: true,
Type: pluginsdk.TypeString,
},

"reservation_capacity_in_gb_per_day": {
Computed: true,
Optional: true,
Type: pluginsdk.TypeInt,
},

"resource_group_name": {
ForceNew: true,
Required: true,
Type: pluginsdk.TypeString,
},

"retention_in_days": {
Computed: true,
Optional: true,
Type: pluginsdk.TypeInt,
},

"secondary_shared_key": {
Computed: true,
Type: pluginsdk.TypeString,
},

"sku": {
Computed: true,
Optional: true,
Type: pluginsdk.TypeString,
},

"tags": {
Elem: &pluginsdk.Schema{Type: pluginsdk.TypeString},
Optional: true,
Type: pluginsdk.TypeMap,
},

"workspace_id": {
Computed: true,
Type: pluginsdk.TypeString,
},
}
}

func (WorkspaceV2ToV3) UpgradeFunc() pluginsdk.StateUpgraderFunc {
return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
subscriptionId := meta.(*clients.Client).Account.SubscriptionId

log.Printf("[DEBUG] Migrating IDs to correct casing for Log Analytics Workspace")
name := rawState["name"].(string)
resourceGroup := rawState["resource_group_name"].(string)
id := workspaces.NewWorkspaceID(subscriptionId, resourceGroup, name)

rawState["id"] = id.ID()
return rawState, nil
}
}

0 comments on commit 08e565a

Please sign in to comment.