-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9853 from terraform-providers/b/log-analytics-wor…
…kspace-state-migration r/log_analytics_workspace: force-upgrading the resource id's
- Loading branch information
Showing
4 changed files
with
138 additions
and
39 deletions.
There are no files selected for viewing
36 changes: 0 additions & 36 deletions
36
azurerm/internal/services/loganalytics/log_analytics_workspace_migrate.go
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
azurerm/internal/services/loganalytics/migration/workspace_v0_to_v1.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package migration | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/loganalytics/parse" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" | ||
) | ||
|
||
func WorkspaceV0ToV1() schema.StateUpgrader { | ||
return schema.StateUpgrader{ | ||
Version: 0, | ||
Type: workspaceV0V1Schema().CoreConfigSchema().ImpliedType(), | ||
Upgrade: workspaceUpgradeV0ToV1, | ||
} | ||
} | ||
|
||
func workspaceV0V1Schema() *schema.Resource { | ||
return &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"location": azure.SchemaLocation(), | ||
|
||
"resource_group_name": azure.SchemaResourceGroupNameDiffSuppress(), | ||
|
||
"internet_ingestion_enabled": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: true, | ||
}, | ||
|
||
"internet_query_enabled": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: true, | ||
}, | ||
|
||
"sku": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"retention_in_days": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
|
||
"daily_quota_gb": { | ||
Type: schema.TypeFloat, | ||
Optional: true, | ||
Default: -1.0, | ||
}, | ||
|
||
"workspace_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"portal_url": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"primary_shared_key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Sensitive: true, | ||
}, | ||
|
||
"secondary_shared_key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Sensitive: true, | ||
}, | ||
|
||
"tags": tags.Schema(), | ||
}, | ||
} | ||
} | ||
|
||
func workspaceUpgradeV0ToV1(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 := parse.NewLogAnalyticsWorkspaceID(subscriptionId, resourceGroup, name) | ||
|
||
rawState["id"] = id.ID() | ||
return rawState, nil | ||
} |
31 changes: 31 additions & 0 deletions
31
azurerm/internal/services/loganalytics/migration/workspace_v1_to_v2.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package migration | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/loganalytics/parse" | ||
) | ||
|
||
func WorkspaceV1ToV2() schema.StateUpgrader { | ||
// V1 to V2 is the same as v0 to v1 - to workaround a historical issue where `resource_group` was | ||
// used in place of `resource_group_name` - ergo using the same schema is fine. | ||
return schema.StateUpgrader{ | ||
Version: 1, | ||
Type: workspaceV0V1Schema().CoreConfigSchema().ImpliedType(), | ||
Upgrade: workspaceUpgradeV1ToV2, | ||
} | ||
} | ||
|
||
func workspaceUpgradeV1ToV2(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 := parse.NewLogAnalyticsWorkspaceID(subscriptionId, resourceGroup, name) | ||
|
||
rawState["id"] = id.ID() | ||
return rawState, nil | ||
} |