-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
azurerm_managed_disk
- add state upgrader from V0 to V1 to fix ID i…
…ssue (#18885) * `azurerm_managed_disk` - add state upgrader from V0 to V1 to fix ID issue * Remove uncessary meta-argument
- Loading branch information
Showing
2 changed files
with
298 additions
and
0 deletions.
There are no files selected for viewing
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
292 changes: 292 additions & 0 deletions
292
internal/services/compute/migration/managed_disk_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,292 @@ | ||
package migration | ||
|
||
import ( | ||
"context" | ||
|
||
"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" | ||
) | ||
|
||
var _ pluginsdk.StateUpgrade = ManagedDiskV0ToV1{} | ||
|
||
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)) | ||
if err != nil { | ||
return rawState, err | ||
} | ||
|
||
rawState["id"] = oldId.ID() | ||
return rawState, nil | ||
} | ||
} | ||
|
||
func (ManagedDiskV0ToV1) Schema() map[string]*pluginsdk.Schema { | ||
return map[string]*pluginsdk.Schema{ | ||
"name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"location": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"resource_group_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"storage_account_type": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"create_option": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"edge_zone": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
|
||
"logical_sector_size": { | ||
Type: pluginsdk.TypeInt, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
|
||
"source_uri": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
|
||
"source_resource_id": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
}, | ||
|
||
"storage_account_id": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
}, | ||
|
||
"image_reference_id": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
}, | ||
|
||
"gallery_image_reference_id": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
}, | ||
|
||
"os_type": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
}, | ||
|
||
"disk_size_gb": { | ||
Type: pluginsdk.TypeInt, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
|
||
"disk_iops_read_write": { | ||
Type: pluginsdk.TypeInt, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
|
||
"disk_mbps_read_write": { | ||
Type: pluginsdk.TypeInt, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
|
||
"disk_iops_read_only": { | ||
Type: pluginsdk.TypeInt, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
|
||
"disk_mbps_read_only": { | ||
Type: pluginsdk.TypeInt, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
|
||
"disk_encryption_set_id": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
}, | ||
|
||
"encryption_settings": encryptionSettingsSchema(), | ||
|
||
"network_access_policy": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
}, | ||
"disk_access_id": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
}, | ||
|
||
"public_network_access_enabled": { | ||
Type: pluginsdk.TypeBool, | ||
Optional: true, | ||
}, | ||
|
||
"tier": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
|
||
"max_shares": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
|
||
"trusted_launch_enabled": { | ||
Type: pluginsdk.TypeBool, | ||
Optional: true, | ||
}, | ||
|
||
"secure_vm_disk_encryption_set_id": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
}, | ||
|
||
"security_type": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
}, | ||
|
||
"hyper_v_generation": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
}, | ||
|
||
"on_demand_bursting_enabled": { | ||
Type: pluginsdk.TypeBool, | ||
Optional: true, | ||
}, | ||
|
||
"zone": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
|
||
"tags": { | ||
Type: schema.TypeMap, | ||
Optional: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func encryptionSettingsSchema() *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, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} |