diff --git a/internal/services/compute/client/client.go b/internal/services/compute/client/client.go index 3cc102f09ce5..9a074bcb14df 100644 --- a/internal/services/compute/client/client.go +++ b/internal/services/compute/client/client.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/proximityplacementgroups" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/sshpublickeys" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/disks" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots" "github.com/hashicorp/terraform-provider-azurerm/internal/common" ) @@ -30,7 +31,7 @@ type Client struct { MarketplaceAgreementsClient *marketplaceordering.MarketplaceAgreementsClient ProximityPlacementGroupsClient *proximityplacementgroups.ProximityPlacementGroupsClient SSHPublicKeysClient *sshpublickeys.SshPublicKeysClient - SnapshotsClient *compute.SnapshotsClient + SnapshotsClient *snapshots.SnapshotsClient UsageClient *compute.UsageClient VMExtensionImageClient *compute.VirtualMachineExtensionImagesClient VMExtensionClient *compute.VirtualMachineExtensionsClient @@ -91,7 +92,7 @@ func NewClient(o *common.ClientOptions) *Client { proximityPlacementGroupsClient := proximityplacementgroups.NewProximityPlacementGroupsClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&proximityPlacementGroupsClient.Client, o.ResourceManagerAuthorizer) - snapshotsClient := compute.NewSnapshotsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + snapshotsClient := snapshots.NewSnapshotsClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&snapshotsClient.Client, o.ResourceManagerAuthorizer) sshPublicKeysClient := sshpublickeys.NewSshPublicKeysClientWithBaseURI(o.ResourceManagerEndpoint) diff --git a/internal/services/compute/encryption_settings.go b/internal/services/compute/encryption_settings.go index 5679e029ebde..be4e497777c3 100644 --- a/internal/services/compute/encryption_settings.go +++ b/internal/services/compute/encryption_settings.go @@ -1,8 +1,8 @@ package compute import ( - "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/disks" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots" "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" @@ -114,50 +114,50 @@ func encryptionSettingsSchema() *pluginsdk.Schema { } } -func expandSnapshotDiskEncryptionSettings(settingsList []interface{}) *compute.EncryptionSettingsCollection { +func expandSnapshotDiskEncryptionSettings(settingsList []interface{}) *snapshots.EncryptionSettingsCollection { if len(settingsList) == 0 { - return &compute.EncryptionSettingsCollection{} + return &snapshots.EncryptionSettingsCollection{} } settings := settingsList[0].(map[string]interface{}) - config := &compute.EncryptionSettingsCollection{ - Enabled: utils.Bool(true), + config := &snapshots.EncryptionSettingsCollection{ + Enabled: true, } if !features.FourPointOhBeta() { - config.Enabled = utils.Bool(settings["enabled"].(bool)) + config.Enabled = settings["enabled"].(bool) } - var diskEncryptionKey *compute.KeyVaultAndSecretReference + var diskEncryptionKey *snapshots.KeyVaultAndSecretReference if v := settings["disk_encryption_key"].([]interface{}); len(v) > 0 { dek := v[0].(map[string]interface{}) secretURL := dek["secret_url"].(string) sourceVaultId := dek["source_vault_id"].(string) - diskEncryptionKey = &compute.KeyVaultAndSecretReference{ - SecretURL: utils.String(secretURL), - SourceVault: &compute.SourceVault{ - ID: utils.String(sourceVaultId), + diskEncryptionKey = &snapshots.KeyVaultAndSecretReference{ + SecretUrl: secretURL, + SourceVault: snapshots.SourceVault{ + Id: utils.String(sourceVaultId), }, } } - var keyEncryptionKey *compute.KeyVaultAndKeyReference + var keyEncryptionKey *snapshots.KeyVaultAndKeyReference if v := settings["key_encryption_key"].([]interface{}); len(v) > 0 { kek := v[0].(map[string]interface{}) secretURL := kek["key_url"].(string) sourceVaultId := kek["source_vault_id"].(string) - keyEncryptionKey = &compute.KeyVaultAndKeyReference{ - KeyURL: utils.String(secretURL), - SourceVault: &compute.SourceVault{ - ID: utils.String(sourceVaultId), + keyEncryptionKey = &snapshots.KeyVaultAndKeyReference{ + KeyUrl: secretURL, + SourceVault: snapshots.SourceVault{ + Id: utils.String(sourceVaultId), }, } } // at this time we only support a single element - config.EncryptionSettings = &[]compute.EncryptionSettingsElement{ + config.EncryptionSettings = &[]snapshots.EncryptionSettingsElement{ { DiskEncryptionKey: diskEncryptionKey, KeyEncryptionKey: keyEncryptionKey, @@ -166,7 +166,7 @@ func expandSnapshotDiskEncryptionSettings(settingsList []interface{}) *compute.E return config } -func flattenSnapshotDiskEncryptionSettings(encryptionSettings *compute.EncryptionSettingsCollection) []interface{} { +func flattenSnapshotDiskEncryptionSettings(encryptionSettings *snapshots.EncryptionSettingsCollection) []interface{} { if encryptionSettings == nil { return []interface{}{} } @@ -179,13 +179,13 @@ func flattenSnapshotDiskEncryptionSettings(encryptionSettings *compute.Encryptio if key := settings.DiskEncryptionKey; key != nil { secretUrl := "" - if key.SecretURL != nil { - secretUrl = *key.SecretURL + if key.SecretUrl != "" { + secretUrl = key.SecretUrl } sourceVaultId := "" - if key.SourceVault != nil && key.SourceVault.ID != nil { - sourceVaultId = *key.SourceVault.ID + if key.SourceVault.Id != nil { + sourceVaultId = *key.SourceVault.Id } diskEncryptionKeys = append(diskEncryptionKeys, map[string]interface{}{ @@ -196,13 +196,13 @@ func flattenSnapshotDiskEncryptionSettings(encryptionSettings *compute.Encryptio if key := settings.KeyEncryptionKey; key != nil { keyUrl := "" - if key.KeyURL != nil { - keyUrl = *key.KeyURL + if key.KeyUrl != "" { + keyUrl = key.KeyUrl } sourceVaultId := "" - if key.SourceVault != nil && key.SourceVault.ID != nil { - sourceVaultId = *key.SourceVault.ID + if key.SourceVault.Id != nil { + sourceVaultId = *key.SourceVault.Id } keyEncryptionKeys = append(keyEncryptionKeys, map[string]interface{}{ diff --git a/internal/services/compute/migration/snapshot_v0_to_v1.go b/internal/services/compute/migration/snapshot_v0_to_v1.go new file mode 100644 index 000000000000..2f9e60e1e7a9 --- /dev/null +++ b/internal/services/compute/migration/snapshot_v0_to_v1.go @@ -0,0 +1,134 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +var _ pluginsdk.StateUpgrade = SnapshotV0ToV1{} + +type SnapshotV0ToV1 struct{} + +func (SnapshotV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldIdRaw := rawState["id"].(string) + oldId, err := snapshots.ParseSnapshotIDInsensitively(oldIdRaw) + if err != nil { + return rawState, err + } + + newId := oldId.ID() + log.Printf("[DEBUG] Updating the ID from %q to %q", oldIdRaw, newId) + rawState["id"] = newId + return rawState, nil + } +} + +func (SnapshotV0ToV1) 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, + }, + + "create_option": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "source_uri": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "source_resource_id": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "storage_account_id": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "disk_size_gb": { + Type: pluginsdk.TypeInt, + Optional: true, + Computed: true, + }, + + "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, + }, + }, + }, + }, + }, + }, + }, + + "trusted_launch_enabled": { + Type: pluginsdk.TypeBool, + Computed: true, + }, + + "tags": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + } +} diff --git a/internal/services/compute/parse/snapshot.go b/internal/services/compute/parse/snapshot.go deleted file mode 100644 index 665c4cbbe532..000000000000 --- a/internal/services/compute/parse/snapshot.go +++ /dev/null @@ -1,69 +0,0 @@ -package parse - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import ( - "fmt" - "strings" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -type SnapshotId struct { - SubscriptionId string - ResourceGroup string - Name string -} - -func NewSnapshotID(subscriptionId, resourceGroup, name string) SnapshotId { - return SnapshotId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - Name: name, - } -} - -func (id SnapshotId) String() string { - segments := []string{ - fmt.Sprintf("Name %q", id.Name), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Snapshot", segmentsStr) -} - -func (id SnapshotId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/snapshots/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.Name) -} - -// SnapshotID parses a Snapshot ID into an SnapshotId struct -func SnapshotID(input string) (*SnapshotId, error) { - id, err := resourceids.ParseAzureResourceID(input) - if err != nil { - return nil, err - } - - resourceId := SnapshotId{ - SubscriptionId: id.SubscriptionID, - ResourceGroup: id.ResourceGroup, - } - - if resourceId.SubscriptionId == "" { - return nil, fmt.Errorf("ID was missing the 'subscriptions' element") - } - - if resourceId.ResourceGroup == "" { - return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") - } - - if resourceId.Name, err = id.PopSegment("snapshots"); err != nil { - return nil, err - } - - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err - } - - return &resourceId, nil -} diff --git a/internal/services/compute/parse/snapshot_test.go b/internal/services/compute/parse/snapshot_test.go deleted file mode 100644 index 8677b2294dc2..000000000000 --- a/internal/services/compute/parse/snapshot_test.go +++ /dev/null @@ -1,112 +0,0 @@ -package parse - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import ( - "testing" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -var _ resourceids.Id = SnapshotId{} - -func TestSnapshotIDFormatter(t *testing.T) { - actual := NewSnapshotID("12345678-1234-9876-4563-123456789012", "group1", "snapshot1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Compute/snapshots/snapshot1" - if actual != expected { - t.Fatalf("Expected %q but got %q", expected, actual) - } -} - -func TestSnapshotID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *SnapshotId - }{ - - { - // empty - Input: "", - Error: true, - }, - - { - // missing SubscriptionId - Input: "/", - Error: true, - }, - - { - // missing value for SubscriptionId - Input: "/subscriptions/", - Error: true, - }, - - { - // missing ResourceGroup - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", - Error: true, - }, - - { - // missing value for ResourceGroup - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", - Error: true, - }, - - { - // missing Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Compute/", - Error: true, - }, - - { - // missing value for Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Compute/snapshots/", - Error: true, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Compute/snapshots/snapshot1", - Expected: &SnapshotId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroup: "group1", - Name: "snapshot1", - }, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/GROUP1/PROVIDERS/MICROSOFT.COMPUTE/SNAPSHOTS/SNAPSHOT1", - Error: true, - }, - } - - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := SnapshotID(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %s", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.SubscriptionId != v.Expected.SubscriptionId { - t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) - } - if actual.ResourceGroup != v.Expected.ResourceGroup { - t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) - } - if actual.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) - } - } -} diff --git a/internal/services/compute/resourceids.go b/internal/services/compute/resourceids.go index 3f670c5ec042..03d28cd95b18 100644 --- a/internal/services/compute/resourceids.go +++ b/internal/services/compute/resourceids.go @@ -17,6 +17,5 @@ package compute //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=DiskAccess -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/diskAccesses/diskAccess1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=HybridMachine -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.HybridCompute/machines/machine1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=DataDisk -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Compute/virtualMachines/machine1/dataDisks/disk1 -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=Snapshot -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Compute/snapshots/snapshot1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=Plan -id=/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.MarketplaceOrdering/agreements/agreement1/offers/offer1/plans/hourly //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=HostGroup -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Compute/hostGroups/hostgroup1 diff --git a/internal/services/compute/shared_image_version_resource_test.go b/internal/services/compute/shared_image_version_resource_test.go index 3dab9c7286f1..024de9cb3232 100644 --- a/internal/services/compute/shared_image_version_resource_test.go +++ b/internal/services/compute/shared_image_version_resource_test.go @@ -7,6 +7,7 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" @@ -274,15 +275,13 @@ func (r SharedImageVersionResource) Exists(ctx context.Context, clients *clients } func (SharedImageVersionResource) revokeSnapshot(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) error { + subscriptionId := client.Account.SubscriptionId snapShotName := state.Attributes["name"] resourceGroup := state.Attributes["resource_group_name"] - future, err := client.Compute.SnapshotsClient.RevokeAccess(ctx, resourceGroup, snapShotName) - if err != nil { - return fmt.Errorf("bad: cannot revoke SAS on the snapshot: %+v", err) - } - if err := future.WaitForCompletionRef(ctx, client.Compute.SnapshotsClient.Client); err != nil { - return fmt.Errorf("bad: waiting the revoke of SAS on the snapshot: %+v", err) + snapshotId := snapshots.NewSnapshotID(subscriptionId, resourceGroup, snapShotName) + if err := client.Compute.SnapshotsClient.RevokeAccessThenPoll(ctx, snapshotId); err != nil { + return fmt.Errorf("revoking SAS on %s: %+v", snapshotId, err) } return nil diff --git a/internal/services/compute/snapshot_data_source.go b/internal/services/compute/snapshot_data_source.go index 72469bfc0416..546039ab6fc2 100644 --- a/internal/services/compute/snapshot_data_source.go +++ b/internal/services/compute/snapshot_data_source.go @@ -4,13 +4,12 @@ import ( "fmt" "time" - "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" + "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" - "github.com/hashicorp/terraform-provider-azurerm/utils" ) func dataSourceSnapshot() *pluginsdk.Resource { @@ -120,11 +119,11 @@ func dataSourceSnapshotRead(d *pluginsdk.ResourceData, meta interface{}) error { ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id := parse.NewSnapshotID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) + id := snapshots.NewSnapshotID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - resp, err := client.Get(ctx, id.ResourceGroup, id.Name) + resp, err := client.Get(ctx, id) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { + if response.WasNotFound(resp.HttpResponse) { return fmt.Errorf("%s was not found", id) } return fmt.Errorf("loading %s: %+v", id, err) @@ -132,32 +131,46 @@ func dataSourceSnapshotRead(d *pluginsdk.ResourceData, meta interface{}) error { d.SetId(id.ID()) - if props := resp.SnapshotProperties; props != nil { - d.Set("os_type", string(props.OsType)) - d.Set("time_created", props.TimeCreated.String()) + if model := resp.Model; model != nil { + if props := model.Properties; props != nil { + osType := "" + if props.OsType != nil { + osType = string(*props.OsType) + } + d.Set("os_type", osType) + + timeCreated := "" + if props.TimeCreated != nil { + t, err := time.Parse(time.RFC3339, *props.TimeCreated) + if err != nil { + return fmt.Errorf("converting `time_reated`: %+v", err) + } + timeCreated = t.Format(time.RFC3339) + } + d.Set("time_created", timeCreated) - if props.DiskSizeGB != nil { - d.Set("disk_size_gb", int(*props.DiskSizeGB)) - } + diskSizeGb := 0 + if props.DiskSizeGB != nil { + diskSizeGb = int(*props.DiskSizeGB) + } + d.Set("disk_size_gb", diskSizeGb) - if err := d.Set("encryption_settings", flattenSnapshotDiskEncryptionSettings(props.EncryptionSettingsCollection)); err != nil { - return fmt.Errorf("setting `encryption_settings`: %+v", err) - } + if err := d.Set("encryption_settings", flattenSnapshotDiskEncryptionSettings(props.EncryptionSettingsCollection)); err != nil { + return fmt.Errorf("setting `encryption_settings`: %+v", err) + } - trustedLaunchEnabled := false - if securityProfile := props.SecurityProfile; securityProfile != nil { - if securityProfile.SecurityType == compute.DiskSecurityTypesTrustedLaunch { - trustedLaunchEnabled = true + trustedLaunchEnabled := false + if securityProfile := props.SecurityProfile; securityProfile != nil && securityProfile.SecurityType != nil { + trustedLaunchEnabled = *securityProfile.SecurityType == snapshots.DiskSecurityTypesTrustedLaunch } - } - d.Set("trusted_launch_enabled", trustedLaunchEnabled) - } + d.Set("trusted_launch_enabled", trustedLaunchEnabled) - if data := resp.CreationData; data != nil { - d.Set("creation_option", string(data.CreateOption)) - d.Set("source_uri", data.SourceURI) - d.Set("source_resource_id", data.SourceResourceID) - d.Set("storage_account_id", data.StorageAccountID) + data := props.CreationData + d.Set("creation_option", string(data.CreateOption)) + d.Set("source_uri", data.SourceUri) + d.Set("source_resource_id", data.SourceResourceId) + d.Set("storage_account_id", data.StorageAccountId) + } } return nil diff --git a/internal/services/compute/snapshot_resource.go b/internal/services/compute/snapshot_resource.go index 7614ccadea17..a2a33aeccd0b 100644 --- a/internal/services/compute/snapshot_resource.go +++ b/internal/services/compute/snapshot_resource.go @@ -6,15 +6,16 @@ import ( "log" "time" - "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" + "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/features" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -29,7 +30,7 @@ func resourceSnapshot() *pluginsdk.Resource { Delete: resourceSnapshotDelete, Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { - _, err := parse.SnapshotID(id) + _, err := snapshots.ParseSnapshotID(id) return err }), @@ -40,6 +41,11 @@ func resourceSnapshot() *pluginsdk.Resource { Delete: pluginsdk.DefaultTimeout(30 * time.Minute), }, + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.SnapshotV0ToV1{}, + }), + Schema: map[string]*pluginsdk.Schema{ "name": { Type: pluginsdk.TypeString, @@ -56,8 +62,8 @@ func resourceSnapshot() *pluginsdk.Resource { Type: pluginsdk.TypeString, Required: true, ValidateFunc: validation.StringInSlice([]string{ - string(compute.DiskCreateOptionCopy), - string(compute.DiskCreateOptionImport), + string(snapshots.DiskCreateOptionCopy), + string(snapshots.DiskCreateOptionImport), }, false), }, @@ -92,7 +98,7 @@ func resourceSnapshot() *pluginsdk.Resource { Computed: true, }, - "tags": tags.Schema(), + "tags": commonschema.Tags(), }, // Encryption Settings cannot be disabled once enabled @@ -113,60 +119,55 @@ func resourceSnapshotCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) e ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id := parse.NewSnapshotID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) + id := snapshots.NewSnapshotID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) location := azure.NormalizeLocation(d.Get("location").(string)) createOption := d.Get("create_option").(string) t := d.Get("tags").(map[string]interface{}) if d.IsNewResource() { - existing, err := client.Get(ctx, id.ResourceGroup, id.Name) + existing, err := client.Get(ctx, id) if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { + if !response.WasNotFound(existing.HttpResponse) { return fmt.Errorf("checking for presence of existing %s: %+v", id, err) } } - if !utils.ResponseWasNotFound(existing.Response) { + if !response.WasNotFound(existing.HttpResponse) { return tf.ImportAsExistsError("azurerm_snapshot", id.ID()) } } - properties := compute.Snapshot{ - Location: utils.String(location), - SnapshotProperties: &compute.SnapshotProperties{ - CreationData: &compute.CreationData{ - CreateOption: compute.DiskCreateOption(createOption), + properties := snapshots.Snapshot{ + Location: location, + Properties: &snapshots.SnapshotProperties{ + CreationData: snapshots.CreationData{ + CreateOption: snapshots.DiskCreateOption(createOption), }, }, Tags: tags.Expand(t), } if v, ok := d.GetOk("source_uri"); ok { - properties.SnapshotProperties.CreationData.SourceURI = utils.String(v.(string)) + properties.Properties.CreationData.SourceUri = utils.String(v.(string)) } if v, ok := d.GetOk("source_resource_id"); ok { - properties.SnapshotProperties.CreationData.SourceResourceID = utils.String(v.(string)) + properties.Properties.CreationData.SourceResourceId = utils.String(v.(string)) } if v, ok := d.GetOk("storage_account_id"); ok { - properties.SnapshotProperties.CreationData.StorageAccountID = utils.String(v.(string)) + properties.Properties.CreationData.StorageAccountId = utils.String(v.(string)) } diskSizeGB := d.Get("disk_size_gb").(int) if diskSizeGB > 0 { - properties.SnapshotProperties.DiskSizeGB = utils.Int32(int32(diskSizeGB)) + properties.Properties.DiskSizeGB = utils.Int64(int64(diskSizeGB)) } - properties.EncryptionSettingsCollection = expandSnapshotDiskEncryptionSettings(d.Get("encryption_settings").([]interface{})) - - future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, properties) - if err != nil { - return fmt.Errorf("issuing create/update request for %s: %+v", id, err) - } + properties.Properties.EncryptionSettingsCollection = expandSnapshotDiskEncryptionSettings(d.Get("encryption_settings").([]interface{})) - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting on create/update future for %s: %+v", id, err) + if err := client.CreateOrUpdateThenPoll(ctx, id, properties); err != nil { + return fmt.Errorf("creating/updating %s: %+v", id, err) } d.SetId(id.ID()) @@ -179,55 +180,56 @@ func resourceSnapshotRead(d *pluginsdk.ResourceData, meta interface{}) error { ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.SnapshotID(d.Id()) + id, err := snapshots.ParseSnapshotID(d.Id()) if err != nil { return err } - resp, err := client.Get(ctx, id.ResourceGroup, id.Name) + resp, err := client.Get(ctx, *id) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { + if response.WasNotFound(resp.HttpResponse) { log.Printf("[INFO] Error reading Snapshot %q - removing from state", d.Id()) d.SetId("") return nil } - return fmt.Errorf("making Read request on Snapshot %q: %+v", id.Name, err) + return fmt.Errorf("retrieving %s: %+v", *id, err) } - d.Set("name", id.Name) - d.Set("resource_group_name", id.ResourceGroup) - if location := resp.Location; location != nil { - d.Set("location", azure.NormalizeLocation(*location)) - } + d.Set("name", id.SnapshotName) + d.Set("resource_group_name", id.ResourceGroupName) + + if model := resp.Model; model != nil { + d.Set("location", azure.NormalizeLocation(model.Location)) - if props := resp.SnapshotProperties; props != nil { - if data := props.CreationData; data != nil { + if props := model.Properties; props != nil { + data := props.CreationData d.Set("create_option", string(data.CreateOption)) + d.Set("storage_account_id", data.StorageAccountId) - if accountId := data.StorageAccountID; accountId != nil { - d.Set("storage_account_id", accountId) + diskSizeGb := 0 + if props.DiskSizeGB != nil { + diskSizeGb = int(*props.DiskSizeGB) } - } + d.Set("disk_size_gb", diskSizeGb) - if props.DiskSizeGB != nil { - d.Set("disk_size_gb", int(*props.DiskSizeGB)) - } + if err := d.Set("encryption_settings", flattenSnapshotDiskEncryptionSettings(props.EncryptionSettingsCollection)); err != nil { + return fmt.Errorf("setting `encryption_settings`: %+v", err) + } - if err := d.Set("encryption_settings", flattenSnapshotDiskEncryptionSettings(props.EncryptionSettingsCollection)); err != nil { - return fmt.Errorf("setting `encryption_settings`: %+v", err) + trustedLaunchEnabled := false + if securityProfile := props.SecurityProfile; securityProfile != nil && securityProfile.SecurityType != nil { + trustedLaunchEnabled = *securityProfile.SecurityType == snapshots.DiskSecurityTypesTrustedLaunch + } + d.Set("trusted_launch_enabled", trustedLaunchEnabled) } - trustedLaunchEnabled := false - if securityProfile := props.SecurityProfile; securityProfile != nil { - if securityProfile.SecurityType == compute.DiskSecurityTypesTrustedLaunch { - trustedLaunchEnabled = true - } + if err := tags.FlattenAndSet(d, model.Tags); err != nil { + return err } - d.Set("trusted_launch_enabled", trustedLaunchEnabled) } - return tags.FlattenAndSet(d, resp.Tags) + return nil } func resourceSnapshotDelete(d *pluginsdk.ResourceData, meta interface{}) error { @@ -235,18 +237,13 @@ func resourceSnapshotDelete(d *pluginsdk.ResourceData, meta interface{}) error { ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.SnapshotID(d.Id()) + id, err := snapshots.ParseSnapshotID(d.Id()) if err != nil { return err } - future, err := client.Delete(ctx, id.ResourceGroup, id.Name) - if err != nil { - return fmt.Errorf("deleting Snapshot: %+v", err) - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("deleting Snapshot: %+v", err) + if err := client.DeleteThenPoll(ctx, *id); err != nil { + return fmt.Errorf("deleting %s: %+v", *id, err) } return nil diff --git a/internal/services/compute/snapshot_resource_test.go b/internal/services/compute/snapshot_resource_test.go index 8e6201ca77d1..36bdb2701dcc 100644 --- a/internal/services/compute/snapshot_resource_test.go +++ b/internal/services/compute/snapshot_resource_test.go @@ -5,10 +5,10 @@ import ( "fmt" "testing" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" ) @@ -149,17 +149,17 @@ func TestAccSnapshot_trustedLaunch(t *testing.T) { } func (t SnapshotResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.SnapshotID(state.ID) + id, err := snapshots.ParseSnapshotID(state.ID) if err != nil { return nil, err } - resp, err := clients.Compute.SnapshotsClient.Get(ctx, id.ResourceGroup, id.Name) + resp, err := clients.Compute.SnapshotsClient.Get(ctx, *id) if err != nil { return nil, fmt.Errorf("retrieving Compute Shared Image Gallery %q", id) } - return utils.Bool(resp.ID != nil), nil + return utils.Bool(resp.Model != nil), nil } func (SnapshotResource) fromManagedDisk(data acceptance.TestData) string { diff --git a/internal/services/compute/validate/snapshot_id.go b/internal/services/compute/validate/snapshot_id.go deleted file mode 100644 index 2891b3b1b206..000000000000 --- a/internal/services/compute/validate/snapshot_id.go +++ /dev/null @@ -1,23 +0,0 @@ -package validate - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import ( - "fmt" - - "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" -) - -func SnapshotID(input interface{}, key string) (warnings []string, errors []error) { - v, ok := input.(string) - if !ok { - errors = append(errors, fmt.Errorf("expected %q to be a string", key)) - return - } - - if _, err := parse.SnapshotID(v); err != nil { - errors = append(errors, err) - } - - return -} diff --git a/internal/services/compute/validate/snapshot_id_test.go b/internal/services/compute/validate/snapshot_id_test.go deleted file mode 100644 index 2f737143e00b..000000000000 --- a/internal/services/compute/validate/snapshot_id_test.go +++ /dev/null @@ -1,76 +0,0 @@ -package validate - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import "testing" - -func TestSnapshotID(t *testing.T) { - cases := []struct { - Input string - Valid bool - }{ - - { - // empty - Input: "", - Valid: false, - }, - - { - // missing SubscriptionId - Input: "/", - Valid: false, - }, - - { - // missing value for SubscriptionId - Input: "/subscriptions/", - Valid: false, - }, - - { - // missing ResourceGroup - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", - Valid: false, - }, - - { - // missing value for ResourceGroup - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", - Valid: false, - }, - - { - // missing Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Compute/", - Valid: false, - }, - - { - // missing value for Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Compute/snapshots/", - Valid: false, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Compute/snapshots/snapshot1", - Valid: true, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/GROUP1/PROVIDERS/MICROSOFT.COMPUTE/SNAPSHOTS/SNAPSHOT1", - Valid: false, - }, - } - for _, tc := range cases { - t.Logf("[DEBUG] Testing Value %s", tc.Input) - _, errors := SnapshotID(tc.Input, "test") - valid := len(errors) == 0 - - if tc.Valid != valid { - t.Fatalf("Expected %t but got %t", tc.Valid, valid) - } - } -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/README.md new file mode 100644 index 000000000000..5dcfcd1c0de7 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/README.md @@ -0,0 +1,145 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots` Documentation + +The `snapshots` SDK allows for interaction with the Azure Resource Manager Service `compute` (API Version `2022-03-02`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots" +``` + + +### Client Initialization + +```go +client := snapshots.NewSnapshotsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SnapshotsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := snapshots.NewSnapshotID("12345678-1234-9876-4563-123456789012", "example-resource-group", "snapshotValue") + +payload := snapshots.Snapshot{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SnapshotsClient.Delete` + +```go +ctx := context.TODO() +id := snapshots.NewSnapshotID("12345678-1234-9876-4563-123456789012", "example-resource-group", "snapshotValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SnapshotsClient.Get` + +```go +ctx := context.TODO() +id := snapshots.NewSnapshotID("12345678-1234-9876-4563-123456789012", "example-resource-group", "snapshotValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SnapshotsClient.GrantAccess` + +```go +ctx := context.TODO() +id := snapshots.NewSnapshotID("12345678-1234-9876-4563-123456789012", "example-resource-group", "snapshotValue") + +payload := snapshots.GrantAccessData{ + // ... +} + + +if err := client.GrantAccessThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SnapshotsClient.List` + +```go +ctx := context.TODO() +id := snapshots.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SnapshotsClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := snapshots.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SnapshotsClient.RevokeAccess` + +```go +ctx := context.TODO() +id := snapshots.NewSnapshotID("12345678-1234-9876-4563-123456789012", "example-resource-group", "snapshotValue") + +if err := client.RevokeAccessThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SnapshotsClient.Update` + +```go +ctx := context.TODO() +id := snapshots.NewSnapshotID("12345678-1234-9876-4563-123456789012", "example-resource-group", "snapshotValue") + +payload := snapshots.SnapshotUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/client.go new file mode 100644 index 000000000000..62d2a1323835 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/client.go @@ -0,0 +1,18 @@ +package snapshots + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SnapshotsClient struct { + Client autorest.Client + baseUri string +} + +func NewSnapshotsClientWithBaseURI(endpoint string) SnapshotsClient { + return SnapshotsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/constants.go new file mode 100644 index 000000000000..ed79309a930c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/constants.go @@ -0,0 +1,427 @@ +package snapshots + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessLevel string + +const ( + AccessLevelNone AccessLevel = "None" + AccessLevelRead AccessLevel = "Read" + AccessLevelWrite AccessLevel = "Write" +) + +func PossibleValuesForAccessLevel() []string { + return []string{ + string(AccessLevelNone), + string(AccessLevelRead), + string(AccessLevelWrite), + } +} + +func parseAccessLevel(input string) (*AccessLevel, error) { + vals := map[string]AccessLevel{ + "none": AccessLevelNone, + "read": AccessLevelRead, + "write": AccessLevelWrite, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessLevel(input) + return &out, nil +} + +type Architecture string + +const ( + ArchitectureArmSixFour Architecture = "Arm64" + ArchitectureXSixFour Architecture = "x64" +) + +func PossibleValuesForArchitecture() []string { + return []string{ + string(ArchitectureArmSixFour), + string(ArchitectureXSixFour), + } +} + +func parseArchitecture(input string) (*Architecture, error) { + vals := map[string]Architecture{ + "arm64": ArchitectureArmSixFour, + "x64": ArchitectureXSixFour, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Architecture(input) + return &out, nil +} + +type CopyCompletionErrorReason string + +const ( + CopyCompletionErrorReasonCopySourceNotFound CopyCompletionErrorReason = "CopySourceNotFound" +) + +func PossibleValuesForCopyCompletionErrorReason() []string { + return []string{ + string(CopyCompletionErrorReasonCopySourceNotFound), + } +} + +func parseCopyCompletionErrorReason(input string) (*CopyCompletionErrorReason, error) { + vals := map[string]CopyCompletionErrorReason{ + "copysourcenotfound": CopyCompletionErrorReasonCopySourceNotFound, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CopyCompletionErrorReason(input) + return &out, nil +} + +type DataAccessAuthMode string + +const ( + DataAccessAuthModeAzureActiveDirectory DataAccessAuthMode = "AzureActiveDirectory" + DataAccessAuthModeNone DataAccessAuthMode = "None" +) + +func PossibleValuesForDataAccessAuthMode() []string { + return []string{ + string(DataAccessAuthModeAzureActiveDirectory), + string(DataAccessAuthModeNone), + } +} + +func parseDataAccessAuthMode(input string) (*DataAccessAuthMode, error) { + vals := map[string]DataAccessAuthMode{ + "azureactivedirectory": DataAccessAuthModeAzureActiveDirectory, + "none": DataAccessAuthModeNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataAccessAuthMode(input) + return &out, nil +} + +type DiskCreateOption string + +const ( + DiskCreateOptionAttach DiskCreateOption = "Attach" + DiskCreateOptionCopy DiskCreateOption = "Copy" + DiskCreateOptionCopyStart DiskCreateOption = "CopyStart" + DiskCreateOptionEmpty DiskCreateOption = "Empty" + DiskCreateOptionFromImage DiskCreateOption = "FromImage" + DiskCreateOptionImport DiskCreateOption = "Import" + DiskCreateOptionImportSecure DiskCreateOption = "ImportSecure" + DiskCreateOptionRestore DiskCreateOption = "Restore" + DiskCreateOptionUpload DiskCreateOption = "Upload" + DiskCreateOptionUploadPreparedSecure DiskCreateOption = "UploadPreparedSecure" +) + +func PossibleValuesForDiskCreateOption() []string { + return []string{ + string(DiskCreateOptionAttach), + string(DiskCreateOptionCopy), + string(DiskCreateOptionCopyStart), + string(DiskCreateOptionEmpty), + string(DiskCreateOptionFromImage), + string(DiskCreateOptionImport), + string(DiskCreateOptionImportSecure), + string(DiskCreateOptionRestore), + string(DiskCreateOptionUpload), + string(DiskCreateOptionUploadPreparedSecure), + } +} + +func parseDiskCreateOption(input string) (*DiskCreateOption, error) { + vals := map[string]DiskCreateOption{ + "attach": DiskCreateOptionAttach, + "copy": DiskCreateOptionCopy, + "copystart": DiskCreateOptionCopyStart, + "empty": DiskCreateOptionEmpty, + "fromimage": DiskCreateOptionFromImage, + "import": DiskCreateOptionImport, + "importsecure": DiskCreateOptionImportSecure, + "restore": DiskCreateOptionRestore, + "upload": DiskCreateOptionUpload, + "uploadpreparedsecure": DiskCreateOptionUploadPreparedSecure, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DiskCreateOption(input) + return &out, nil +} + +type DiskSecurityTypes string + +const ( + DiskSecurityTypesConfidentialVMDiskEncryptedWithCustomerKey DiskSecurityTypes = "ConfidentialVM_DiskEncryptedWithCustomerKey" + DiskSecurityTypesConfidentialVMDiskEncryptedWithPlatformKey DiskSecurityTypes = "ConfidentialVM_DiskEncryptedWithPlatformKey" + DiskSecurityTypesConfidentialVMVMGuestStateOnlyEncryptedWithPlatformKey DiskSecurityTypes = "ConfidentialVM_VMGuestStateOnlyEncryptedWithPlatformKey" + DiskSecurityTypesTrustedLaunch DiskSecurityTypes = "TrustedLaunch" +) + +func PossibleValuesForDiskSecurityTypes() []string { + return []string{ + string(DiskSecurityTypesConfidentialVMDiskEncryptedWithCustomerKey), + string(DiskSecurityTypesConfidentialVMDiskEncryptedWithPlatformKey), + string(DiskSecurityTypesConfidentialVMVMGuestStateOnlyEncryptedWithPlatformKey), + string(DiskSecurityTypesTrustedLaunch), + } +} + +func parseDiskSecurityTypes(input string) (*DiskSecurityTypes, error) { + vals := map[string]DiskSecurityTypes{ + "confidentialvm_diskencryptedwithcustomerkey": DiskSecurityTypesConfidentialVMDiskEncryptedWithCustomerKey, + "confidentialvm_diskencryptedwithplatformkey": DiskSecurityTypesConfidentialVMDiskEncryptedWithPlatformKey, + "confidentialvm_vmgueststateonlyencryptedwithplatformkey": DiskSecurityTypesConfidentialVMVMGuestStateOnlyEncryptedWithPlatformKey, + "trustedlaunch": DiskSecurityTypesTrustedLaunch, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DiskSecurityTypes(input) + return &out, nil +} + +type DiskState string + +const ( + DiskStateActiveSAS DiskState = "ActiveSAS" + DiskStateActiveSASFrozen DiskState = "ActiveSASFrozen" + DiskStateActiveUpload DiskState = "ActiveUpload" + DiskStateAttached DiskState = "Attached" + DiskStateFrozen DiskState = "Frozen" + DiskStateReadyToUpload DiskState = "ReadyToUpload" + DiskStateReserved DiskState = "Reserved" + DiskStateUnattached DiskState = "Unattached" +) + +func PossibleValuesForDiskState() []string { + return []string{ + string(DiskStateActiveSAS), + string(DiskStateActiveSASFrozen), + string(DiskStateActiveUpload), + string(DiskStateAttached), + string(DiskStateFrozen), + string(DiskStateReadyToUpload), + string(DiskStateReserved), + string(DiskStateUnattached), + } +} + +func parseDiskState(input string) (*DiskState, error) { + vals := map[string]DiskState{ + "activesas": DiskStateActiveSAS, + "activesasfrozen": DiskStateActiveSASFrozen, + "activeupload": DiskStateActiveUpload, + "attached": DiskStateAttached, + "frozen": DiskStateFrozen, + "readytoupload": DiskStateReadyToUpload, + "reserved": DiskStateReserved, + "unattached": DiskStateUnattached, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DiskState(input) + return &out, nil +} + +type EncryptionType string + +const ( + EncryptionTypeEncryptionAtRestWithCustomerKey EncryptionType = "EncryptionAtRestWithCustomerKey" + EncryptionTypeEncryptionAtRestWithPlatformAndCustomerKeys EncryptionType = "EncryptionAtRestWithPlatformAndCustomerKeys" + EncryptionTypeEncryptionAtRestWithPlatformKey EncryptionType = "EncryptionAtRestWithPlatformKey" +) + +func PossibleValuesForEncryptionType() []string { + return []string{ + string(EncryptionTypeEncryptionAtRestWithCustomerKey), + string(EncryptionTypeEncryptionAtRestWithPlatformAndCustomerKeys), + string(EncryptionTypeEncryptionAtRestWithPlatformKey), + } +} + +func parseEncryptionType(input string) (*EncryptionType, error) { + vals := map[string]EncryptionType{ + "encryptionatrestwithcustomerkey": EncryptionTypeEncryptionAtRestWithCustomerKey, + "encryptionatrestwithplatformandcustomerkeys": EncryptionTypeEncryptionAtRestWithPlatformAndCustomerKeys, + "encryptionatrestwithplatformkey": EncryptionTypeEncryptionAtRestWithPlatformKey, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EncryptionType(input) + return &out, nil +} + +type HyperVGeneration string + +const ( + HyperVGenerationVOne HyperVGeneration = "V1" + HyperVGenerationVTwo HyperVGeneration = "V2" +) + +func PossibleValuesForHyperVGeneration() []string { + return []string{ + string(HyperVGenerationVOne), + string(HyperVGenerationVTwo), + } +} + +func parseHyperVGeneration(input string) (*HyperVGeneration, error) { + vals := map[string]HyperVGeneration{ + "v1": HyperVGenerationVOne, + "v2": HyperVGenerationVTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HyperVGeneration(input) + return &out, nil +} + +type NetworkAccessPolicy string + +const ( + NetworkAccessPolicyAllowAll NetworkAccessPolicy = "AllowAll" + NetworkAccessPolicyAllowPrivate NetworkAccessPolicy = "AllowPrivate" + NetworkAccessPolicyDenyAll NetworkAccessPolicy = "DenyAll" +) + +func PossibleValuesForNetworkAccessPolicy() []string { + return []string{ + string(NetworkAccessPolicyAllowAll), + string(NetworkAccessPolicyAllowPrivate), + string(NetworkAccessPolicyDenyAll), + } +} + +func parseNetworkAccessPolicy(input string) (*NetworkAccessPolicy, error) { + vals := map[string]NetworkAccessPolicy{ + "allowall": NetworkAccessPolicyAllowAll, + "allowprivate": NetworkAccessPolicyAllowPrivate, + "denyall": NetworkAccessPolicyDenyAll, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NetworkAccessPolicy(input) + return &out, nil +} + +type OperatingSystemTypes string + +const ( + OperatingSystemTypesLinux OperatingSystemTypes = "Linux" + OperatingSystemTypesWindows OperatingSystemTypes = "Windows" +) + +func PossibleValuesForOperatingSystemTypes() []string { + return []string{ + string(OperatingSystemTypesLinux), + string(OperatingSystemTypesWindows), + } +} + +func parseOperatingSystemTypes(input string) (*OperatingSystemTypes, error) { + vals := map[string]OperatingSystemTypes{ + "linux": OperatingSystemTypesLinux, + "windows": OperatingSystemTypesWindows, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OperatingSystemTypes(input) + return &out, nil +} + +type PublicNetworkAccess string + +const ( + PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled" + PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" +) + +func PossibleValuesForPublicNetworkAccess() []string { + return []string{ + string(PublicNetworkAccessDisabled), + string(PublicNetworkAccessEnabled), + } +} + +func parsePublicNetworkAccess(input string) (*PublicNetworkAccess, error) { + vals := map[string]PublicNetworkAccess{ + "disabled": PublicNetworkAccessDisabled, + "enabled": PublicNetworkAccessEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PublicNetworkAccess(input) + return &out, nil +} + +type SnapshotStorageAccountTypes string + +const ( + SnapshotStorageAccountTypesPremiumLRS SnapshotStorageAccountTypes = "Premium_LRS" + SnapshotStorageAccountTypesStandardLRS SnapshotStorageAccountTypes = "Standard_LRS" + SnapshotStorageAccountTypesStandardZRS SnapshotStorageAccountTypes = "Standard_ZRS" +) + +func PossibleValuesForSnapshotStorageAccountTypes() []string { + return []string{ + string(SnapshotStorageAccountTypesPremiumLRS), + string(SnapshotStorageAccountTypesStandardLRS), + string(SnapshotStorageAccountTypesStandardZRS), + } +} + +func parseSnapshotStorageAccountTypes(input string) (*SnapshotStorageAccountTypes, error) { + vals := map[string]SnapshotStorageAccountTypes{ + "premium_lrs": SnapshotStorageAccountTypesPremiumLRS, + "standard_lrs": SnapshotStorageAccountTypesStandardLRS, + "standard_zrs": SnapshotStorageAccountTypesStandardZRS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SnapshotStorageAccountTypes(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/id_snapshot.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/id_snapshot.go new file mode 100644 index 000000000000..13e2c77c84d0 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/id_snapshot.go @@ -0,0 +1,124 @@ +package snapshots + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = SnapshotId{} + +// SnapshotId is a struct representing the Resource ID for a Snapshot +type SnapshotId struct { + SubscriptionId string + ResourceGroupName string + SnapshotName string +} + +// NewSnapshotID returns a new SnapshotId struct +func NewSnapshotID(subscriptionId string, resourceGroupName string, snapshotName string) SnapshotId { + return SnapshotId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SnapshotName: snapshotName, + } +} + +// ParseSnapshotID parses 'input' into a SnapshotId +func ParseSnapshotID(input string) (*SnapshotId, error) { + parser := resourceids.NewParserFromResourceIdType(SnapshotId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SnapshotId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.SnapshotName, ok = parsed.Parsed["snapshotName"]; !ok { + return nil, fmt.Errorf("the segment 'snapshotName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseSnapshotIDInsensitively parses 'input' case-insensitively into a SnapshotId +// note: this method should only be used for API response data and not user input +func ParseSnapshotIDInsensitively(input string) (*SnapshotId, error) { + parser := resourceids.NewParserFromResourceIdType(SnapshotId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SnapshotId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.SnapshotName, ok = parsed.Parsed["snapshotName"]; !ok { + return nil, fmt.Errorf("the segment 'snapshotName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateSnapshotID checks that 'input' can be parsed as a Snapshot ID +func ValidateSnapshotID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSnapshotID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Snapshot ID +func (id SnapshotId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/snapshots/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SnapshotName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Snapshot ID +func (id SnapshotId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCompute", "Microsoft.Compute", "Microsoft.Compute"), + resourceids.StaticSegment("staticSnapshots", "snapshots", "snapshots"), + resourceids.UserSpecifiedSegment("snapshotName", "snapshotValue"), + } +} + +// String returns a human-readable description of this Snapshot ID +func (id SnapshotId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Snapshot Name: %q", id.SnapshotName), + } + return fmt.Sprintf("Snapshot (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_createorupdate_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_createorupdate_autorest.go new file mode 100644 index 000000000000..2af00aeba847 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_createorupdate_autorest.go @@ -0,0 +1,79 @@ +package snapshots + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// CreateOrUpdate ... +func (c SnapshotsClient) CreateOrUpdate(ctx context.Context, id SnapshotId, input Snapshot) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreateOrUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c SnapshotsClient) CreateOrUpdateThenPoll(ctx context.Context, id SnapshotId, input Snapshot) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c SnapshotsClient) preparerForCreateOrUpdate(ctx context.Context, id SnapshotId, input Snapshot) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreateOrUpdate sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (c SnapshotsClient) senderForCreateOrUpdate(ctx context.Context, req *http.Request) (future CreateOrUpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_delete_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_delete_autorest.go new file mode 100644 index 000000000000..55f7d9d07967 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_delete_autorest.go @@ -0,0 +1,78 @@ +package snapshots + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c SnapshotsClient) Delete(ctx context.Context, id SnapshotId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c SnapshotsClient) DeleteThenPoll(ctx context.Context, id SnapshotId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c SnapshotsClient) preparerForDelete(ctx context.Context, id SnapshotId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c SnapshotsClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_get_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_get_autorest.go new file mode 100644 index 000000000000..b328ad1cf52e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_get_autorest.go @@ -0,0 +1,68 @@ +package snapshots + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *Snapshot +} + +// Get ... +func (c SnapshotsClient) Get(ctx context.Context, id SnapshotId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c SnapshotsClient) preparerForGet(ctx context.Context, id SnapshotId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c SnapshotsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_grantaccess_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_grantaccess_autorest.go new file mode 100644 index 000000000000..1d8e97978f33 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_grantaccess_autorest.go @@ -0,0 +1,79 @@ +package snapshots + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GrantAccessOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// GrantAccess ... +func (c SnapshotsClient) GrantAccess(ctx context.Context, id SnapshotId, input GrantAccessData) (result GrantAccessOperationResponse, err error) { + req, err := c.preparerForGrantAccess(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "GrantAccess", nil, "Failure preparing request") + return + } + + result, err = c.senderForGrantAccess(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "GrantAccess", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// GrantAccessThenPoll performs GrantAccess then polls until it's completed +func (c SnapshotsClient) GrantAccessThenPoll(ctx context.Context, id SnapshotId, input GrantAccessData) error { + result, err := c.GrantAccess(ctx, id, input) + if err != nil { + return fmt.Errorf("performing GrantAccess: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after GrantAccess: %+v", err) + } + + return nil +} + +// preparerForGrantAccess prepares the GrantAccess request. +func (c SnapshotsClient) preparerForGrantAccess(ctx context.Context, id SnapshotId, input GrantAccessData) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/beginGetAccess", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForGrantAccess sends the GrantAccess request. The method will close the +// http.Response Body if it receives an error. +func (c SnapshotsClient) senderForGrantAccess(ctx context.Context, req *http.Request) (future GrantAccessOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_list_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_list_autorest.go new file mode 100644 index 000000000000..0391c01f98fb --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_list_autorest.go @@ -0,0 +1,187 @@ +package snapshots + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]Snapshot + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []Snapshot +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c SnapshotsClient) List(ctx context.Context, id commonids.SubscriptionId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c SnapshotsClient) preparerForList(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Compute/snapshots", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c SnapshotsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c SnapshotsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []Snapshot `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c SnapshotsClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, SnapshotOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c SnapshotsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate SnapshotOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]Snapshot, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_listbyresourcegroup_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_listbyresourcegroup_autorest.go new file mode 100644 index 000000000000..e639936afead --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_listbyresourcegroup_autorest.go @@ -0,0 +1,187 @@ +package snapshots + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + Model *[]Snapshot + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) +} + +type ListByResourceGroupCompleteResult struct { + Items []Snapshot +} + +func (r ListByResourceGroupOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByResourceGroupOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByResourceGroup ... +func (c SnapshotsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroup(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByResourceGroup(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByResourceGroup prepares the ListByResourceGroup request. +func (c SnapshotsClient) preparerForListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Compute/snapshots", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. +func (c SnapshotsClient) preparerForListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (c SnapshotsClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { + type page struct { + Values []Snapshot `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroupWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByResourceGroup(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByResourceGroupComplete retrieves all of the results into a single object +func (c SnapshotsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, SnapshotOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c SnapshotsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate SnapshotOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { + items := make([]Snapshot, 0) + + page, err := c.ListByResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByResourceGroupCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_revokeaccess_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_revokeaccess_autorest.go new file mode 100644 index 000000000000..a6cad588ef76 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_revokeaccess_autorest.go @@ -0,0 +1,78 @@ +package snapshots + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RevokeAccessOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// RevokeAccess ... +func (c SnapshotsClient) RevokeAccess(ctx context.Context, id SnapshotId) (result RevokeAccessOperationResponse, err error) { + req, err := c.preparerForRevokeAccess(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "RevokeAccess", nil, "Failure preparing request") + return + } + + result, err = c.senderForRevokeAccess(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "RevokeAccess", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// RevokeAccessThenPoll performs RevokeAccess then polls until it's completed +func (c SnapshotsClient) RevokeAccessThenPoll(ctx context.Context, id SnapshotId) error { + result, err := c.RevokeAccess(ctx, id) + if err != nil { + return fmt.Errorf("performing RevokeAccess: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after RevokeAccess: %+v", err) + } + + return nil +} + +// preparerForRevokeAccess prepares the RevokeAccess request. +func (c SnapshotsClient) preparerForRevokeAccess(ctx context.Context, id SnapshotId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/endGetAccess", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForRevokeAccess sends the RevokeAccess request. The method will close the +// http.Response Body if it receives an error. +func (c SnapshotsClient) senderForRevokeAccess(ctx context.Context, req *http.Request) (future RevokeAccessOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_update_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_update_autorest.go new file mode 100644 index 000000000000..30b23a02d49d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/method_update_autorest.go @@ -0,0 +1,79 @@ +package snapshots + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Update ... +func (c SnapshotsClient) Update(ctx context.Context, id SnapshotId, input SnapshotUpdate) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "Update", nil, "Failure preparing request") + return + } + + result, err = c.senderForUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "snapshots.SnapshotsClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c SnapshotsClient) UpdateThenPoll(ctx context.Context, id SnapshotId, input SnapshotUpdate) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} + +// preparerForUpdate prepares the Update request. +func (c SnapshotsClient) preparerForUpdate(ctx context.Context, id SnapshotId, input SnapshotUpdate) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForUpdate sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (c SnapshotsClient) senderForUpdate(ctx context.Context, req *http.Request) (future UpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_accessuri.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_accessuri.go new file mode 100644 index 000000000000..3b05f32e3723 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_accessuri.go @@ -0,0 +1,9 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessUri struct { + AccessSAS *string `json:"accessSAS,omitempty"` + SecurityDataAccessSAS *string `json:"securityDataAccessSAS,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_copycompletionerror.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_copycompletionerror.go new file mode 100644 index 000000000000..b85619345f69 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_copycompletionerror.go @@ -0,0 +1,9 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CopyCompletionError struct { + ErrorCode CopyCompletionErrorReason `json:"errorCode"` + ErrorMessage string `json:"errorMessage"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_creationdata.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_creationdata.go new file mode 100644 index 000000000000..988598d91cc8 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_creationdata.go @@ -0,0 +1,17 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreationData struct { + CreateOption DiskCreateOption `json:"createOption"` + GalleryImageReference *ImageDiskReference `json:"galleryImageReference,omitempty"` + ImageReference *ImageDiskReference `json:"imageReference,omitempty"` + LogicalSectorSize *int64 `json:"logicalSectorSize,omitempty"` + SecurityDataUri *string `json:"securityDataUri,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + SourceUniqueId *string `json:"sourceUniqueId,omitempty"` + SourceUri *string `json:"sourceUri,omitempty"` + StorageAccountId *string `json:"storageAccountId,omitempty"` + UploadSizeBytes *int64 `json:"uploadSizeBytes,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_disksecurityprofile.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_disksecurityprofile.go new file mode 100644 index 000000000000..75fef09e0e13 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_disksecurityprofile.go @@ -0,0 +1,9 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskSecurityProfile struct { + SecureVMDiskEncryptionSetId *string `json:"secureVMDiskEncryptionSetId,omitempty"` + SecurityType *DiskSecurityTypes `json:"securityType,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_encryption.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_encryption.go new file mode 100644 index 000000000000..468ebc3c5056 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_encryption.go @@ -0,0 +1,9 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Encryption struct { + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + Type *EncryptionType `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_encryptionsettingscollection.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_encryptionsettingscollection.go new file mode 100644 index 000000000000..790d6adc9651 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_encryptionsettingscollection.go @@ -0,0 +1,10 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EncryptionSettingsCollection struct { + Enabled bool `json:"enabled"` + EncryptionSettings *[]EncryptionSettingsElement `json:"encryptionSettings,omitempty"` + EncryptionSettingsVersion *string `json:"encryptionSettingsVersion,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_encryptionsettingselement.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_encryptionsettingselement.go new file mode 100644 index 000000000000..e6f6768b71b4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_encryptionsettingselement.go @@ -0,0 +1,9 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EncryptionSettingsElement struct { + DiskEncryptionKey *KeyVaultAndSecretReference `json:"diskEncryptionKey,omitempty"` + KeyEncryptionKey *KeyVaultAndKeyReference `json:"keyEncryptionKey,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_grantaccessdata.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_grantaccessdata.go new file mode 100644 index 000000000000..4c8a9e6bf39b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_grantaccessdata.go @@ -0,0 +1,10 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GrantAccessData struct { + Access AccessLevel `json:"access"` + DurationInSeconds int64 `json:"durationInSeconds"` + GetSecureVMGuestStateSAS *bool `json:"getSecureVMGuestStateSAS,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_imagediskreference.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_imagediskreference.go new file mode 100644 index 000000000000..cd307a593968 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_imagediskreference.go @@ -0,0 +1,11 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImageDiskReference struct { + CommunityGalleryImageId *string `json:"communityGalleryImageId,omitempty"` + Id *string `json:"id,omitempty"` + Lun *int64 `json:"lun,omitempty"` + SharedGalleryImageId *string `json:"sharedGalleryImageId,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_keyvaultandkeyreference.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_keyvaultandkeyreference.go new file mode 100644 index 000000000000..f3f50f3491f0 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_keyvaultandkeyreference.go @@ -0,0 +1,9 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyVaultAndKeyReference struct { + KeyUrl string `json:"keyUrl"` + SourceVault SourceVault `json:"sourceVault"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_keyvaultandsecretreference.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_keyvaultandsecretreference.go new file mode 100644 index 000000000000..81a108c40ca4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_keyvaultandsecretreference.go @@ -0,0 +1,9 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyVaultAndSecretReference struct { + SecretUrl string `json:"secretUrl"` + SourceVault SourceVault `json:"sourceVault"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_purchaseplan.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_purchaseplan.go new file mode 100644 index 000000000000..17e16a5a6f39 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_purchaseplan.go @@ -0,0 +1,11 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PurchasePlan struct { + Name string `json:"name"` + Product string `json:"product"` + PromotionCode *string `json:"promotionCode,omitempty"` + Publisher string `json:"publisher"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_snapshot.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_snapshot.go new file mode 100644 index 000000000000..5af83c581d58 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_snapshot.go @@ -0,0 +1,20 @@ +package snapshots + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/edgezones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Snapshot struct { + ExtendedLocation *edgezones.Model `json:"extendedLocation,omitempty"` + Id *string `json:"id,omitempty"` + Location string `json:"location"` + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SnapshotProperties `json:"properties,omitempty"` + Sku *SnapshotSku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_snapshotproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_snapshotproperties.go new file mode 100644 index 000000000000..b38f90251240 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_snapshotproperties.go @@ -0,0 +1,47 @@ +package snapshots + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SnapshotProperties struct { + CompletionPercent *float64 `json:"completionPercent,omitempty"` + CopyCompletionError *CopyCompletionError `json:"copyCompletionError,omitempty"` + CreationData CreationData `json:"creationData"` + DataAccessAuthMode *DataAccessAuthMode `json:"dataAccessAuthMode,omitempty"` + DiskAccessId *string `json:"diskAccessId,omitempty"` + DiskSizeBytes *int64 `json:"diskSizeBytes,omitempty"` + DiskSizeGB *int64 `json:"diskSizeGB,omitempty"` + DiskState *DiskState `json:"diskState,omitempty"` + Encryption *Encryption `json:"encryption,omitempty"` + EncryptionSettingsCollection *EncryptionSettingsCollection `json:"encryptionSettingsCollection,omitempty"` + HyperVGeneration *HyperVGeneration `json:"hyperVGeneration,omitempty"` + Incremental *bool `json:"incremental,omitempty"` + NetworkAccessPolicy *NetworkAccessPolicy `json:"networkAccessPolicy,omitempty"` + OsType *OperatingSystemTypes `json:"osType,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + PurchasePlan *PurchasePlan `json:"purchasePlan,omitempty"` + SecurityProfile *DiskSecurityProfile `json:"securityProfile,omitempty"` + SupportedCapabilities *SupportedCapabilities `json:"supportedCapabilities,omitempty"` + SupportsHibernation *bool `json:"supportsHibernation,omitempty"` + TimeCreated *string `json:"timeCreated,omitempty"` + UniqueId *string `json:"uniqueId,omitempty"` +} + +func (o *SnapshotProperties) GetTimeCreatedAsTime() (*time.Time, error) { + if o.TimeCreated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TimeCreated, "2006-01-02T15:04:05Z07:00") +} + +func (o *SnapshotProperties) SetTimeCreatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TimeCreated = &formatted +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_snapshotsku.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_snapshotsku.go new file mode 100644 index 000000000000..141e20f3ae6e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_snapshotsku.go @@ -0,0 +1,9 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SnapshotSku struct { + Name *SnapshotStorageAccountTypes `json:"name,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_snapshotupdate.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_snapshotupdate.go new file mode 100644 index 000000000000..6b1321af8c92 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_snapshotupdate.go @@ -0,0 +1,10 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SnapshotUpdate struct { + Properties *SnapshotUpdateProperties `json:"properties,omitempty"` + Sku *SnapshotSku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_snapshotupdateproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_snapshotupdateproperties.go new file mode 100644 index 000000000000..66e5b21462dd --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_snapshotupdateproperties.go @@ -0,0 +1,17 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SnapshotUpdateProperties struct { + DataAccessAuthMode *DataAccessAuthMode `json:"dataAccessAuthMode,omitempty"` + DiskAccessId *string `json:"diskAccessId,omitempty"` + DiskSizeGB *int64 `json:"diskSizeGB,omitempty"` + Encryption *Encryption `json:"encryption,omitempty"` + EncryptionSettingsCollection *EncryptionSettingsCollection `json:"encryptionSettingsCollection,omitempty"` + NetworkAccessPolicy *NetworkAccessPolicy `json:"networkAccessPolicy,omitempty"` + OsType *OperatingSystemTypes `json:"osType,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + SupportedCapabilities *SupportedCapabilities `json:"supportedCapabilities,omitempty"` + SupportsHibernation *bool `json:"supportsHibernation,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_sourcevault.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_sourcevault.go new file mode 100644 index 000000000000..39d919a1f0bf --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_sourcevault.go @@ -0,0 +1,8 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SourceVault struct { + Id *string `json:"id,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_supportedcapabilities.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_supportedcapabilities.go new file mode 100644 index 000000000000..b1a91c7b0e7c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/model_supportedcapabilities.go @@ -0,0 +1,9 @@ +package snapshots + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SupportedCapabilities struct { + AcceleratedNetwork *bool `json:"acceleratedNetwork,omitempty"` + Architecture *Architecture `json:"architecture,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/predicates.go new file mode 100644 index 000000000000..856558a57850 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/predicates.go @@ -0,0 +1,34 @@ +package snapshots + +type SnapshotOperationPredicate struct { + Id *string + Location *string + ManagedBy *string + Name *string + Type *string +} + +func (p SnapshotOperationPredicate) Matches(input Snapshot) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.ManagedBy != nil && (input.ManagedBy == nil && *p.ManagedBy != *input.ManagedBy) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/version.go new file mode 100644 index 000000000000..21604564bc84 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots/version.go @@ -0,0 +1,12 @@ +package snapshots + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-03-02" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/snapshots/%s", defaultApiVersion) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 6df1daa65248..7715a32d18b3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -209,6 +209,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/dedicatedh github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/proximityplacementgroups github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/sshpublickeys github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/disks +github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots github.com/hashicorp/go-azure-sdk/resource-manager/confidentialledger/2022-05-13/confidentialledger github.com/hashicorp/go-azure-sdk/resource-manager/consumption/2019-10-01/budgets github.com/hashicorp/go-azure-sdk/resource-manager/containerinstance/2021-10-01/containerinstance