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_managed_disk - add log and remove feature flag in state migration #18993

Merged
merged 2 commits into from
Oct 26, 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
150 changes: 52 additions & 98 deletions internal/services/compute/migration/managed_disk_v0_to_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package migration

import (
"context"
"log"

"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/disks"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
)

Expand All @@ -15,12 +15,15 @@ type ManagedDiskV0ToV1 struct{}

func (ManagedDiskV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc {
return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
oldId, err := disks.ParseDiskIDInsensitively(rawState["id"].(string))
oldIdRaw := rawState["id"].(string)
oldId, err := disks.ParseDiskIDInsensitively(oldIdRaw)
if err != nil {
return rawState, err
}

rawState["id"] = oldId.ID()
newId := oldId.ID()
log.Printf("[DEBUG] Updating the ID from %q to %q", oldIdRaw, newId)
rawState["id"] = newId
return rawState, nil
}
}
Expand Down Expand Up @@ -129,7 +132,52 @@ func (ManagedDiskV0ToV1) Schema() map[string]*pluginsdk.Schema {
Optional: true,
},

"encryption_settings": encryptionSettingsSchema(),
"encryption_settings": {
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
},
"disk_encryption_key": {
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"secret_url": {
Type: pluginsdk.TypeString,
Required: true,
},

"source_vault_id": {
Type: pluginsdk.TypeString,
Required: true,
},
},
},
},
"key_encryption_key": {
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"key_url": {
Type: pluginsdk.TypeString,
Required: true,
},

"source_vault_id": {
Type: pluginsdk.TypeString,
Required: true,
},
},
},
},
},
},
},

"network_access_policy": {
Type: pluginsdk.TypeString,
Expand Down Expand Up @@ -196,97 +244,3 @@ func (ManagedDiskV0ToV1) Schema() map[string]*pluginsdk.Schema {
},
}
}

func encryptionSettingsSchema() *pluginsdk.Schema {
Copy link
Member

Choose a reason for hiding this comment

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

I missed this in the initial PR, but since this is a point in time reference we need to remove the schema feature flag and the Schema for 4.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make sense. I've removed the feature flag and kept only the 3.0 schema for this

if !features.FourPointOhBeta() {
return &pluginsdk.Schema{
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
},
"disk_encryption_key": {
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"secret_url": {
Type: pluginsdk.TypeString,
Required: true,
},

"source_vault_id": {
Type: pluginsdk.TypeString,
Required: true,
},
},
},
},
"key_encryption_key": {
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"key_url": {
Type: pluginsdk.TypeString,
Required: true,
},

"source_vault_id": {
Type: pluginsdk.TypeString,
Required: true,
},
},
},
},
},
},
}
}

return &pluginsdk.Schema{
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"disk_encryption_key": {
Type: pluginsdk.TypeList,
Required: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"secret_url": {
Type: pluginsdk.TypeString,
Required: true,
},

"source_vault_id": {
Type: pluginsdk.TypeString,
Required: true,
},
},
},
},
"key_encryption_key": {
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"key_url": {
Type: pluginsdk.TypeString,
Required: true,
},

"source_vault_id": {
Type: pluginsdk.TypeString,
Required: true,
},
},
},
},
},
},
}
}