From fda3a456d689be5039b31a2041a5b7bb4812648c Mon Sep 17 00:00:00 2001 From: Yichun Ma Date: Wed, 26 Oct 2022 14:58:15 +0800 Subject: [PATCH 1/2] `azurerm_managed_disk` - add log to state migration and update schema function name --- .../compute/migration/managed_disk_v0_to_v1.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/services/compute/migration/managed_disk_v0_to_v1.go b/internal/services/compute/migration/managed_disk_v0_to_v1.go index 922eaa7c0b55..57e7160be091 100644 --- a/internal/services/compute/migration/managed_disk_v0_to_v1.go +++ b/internal/services/compute/migration/managed_disk_v0_to_v1.go @@ -2,6 +2,7 @@ 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" @@ -15,12 +16,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 } } @@ -129,7 +133,7 @@ func (ManagedDiskV0ToV1) Schema() map[string]*pluginsdk.Schema { Optional: true, }, - "encryption_settings": encryptionSettingsSchema(), + "encryption_settings": managedDiskEncryptionSettingsSchemaV0(), "network_access_policy": { Type: pluginsdk.TypeString, @@ -197,7 +201,7 @@ func (ManagedDiskV0ToV1) Schema() map[string]*pluginsdk.Schema { } } -func encryptionSettingsSchema() *pluginsdk.Schema { +func managedDiskEncryptionSettingsSchemaV0() *pluginsdk.Schema { if !features.FourPointOhBeta() { return &pluginsdk.Schema{ Type: pluginsdk.TypeList, From d707ece445b857512ff6776b54c06b5e52e0061c Mon Sep 17 00:00:00 2001 From: Yichun Ma Date: Wed, 26 Oct 2022 21:48:25 +0800 Subject: [PATCH 2/2] remove feature flag --- .../migration/managed_disk_v0_to_v1.go | 142 ++++++------------ 1 file changed, 46 insertions(+), 96 deletions(-) diff --git a/internal/services/compute/migration/managed_disk_v0_to_v1.go b/internal/services/compute/migration/managed_disk_v0_to_v1.go index 57e7160be091..66f216ae14a2 100644 --- a/internal/services/compute/migration/managed_disk_v0_to_v1.go +++ b/internal/services/compute/migration/managed_disk_v0_to_v1.go @@ -6,7 +6,6 @@ import ( "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" ) @@ -133,7 +132,52 @@ func (ManagedDiskV0ToV1) Schema() map[string]*pluginsdk.Schema { Optional: true, }, - "encryption_settings": managedDiskEncryptionSettingsSchemaV0(), + "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, @@ -200,97 +244,3 @@ func (ManagedDiskV0ToV1) Schema() map[string]*pluginsdk.Schema { }, } } - -func managedDiskEncryptionSettingsSchemaV0() *pluginsdk.Schema { - 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, - }, - }, - }, - }, - }, - }, - } -}