From 68cfbae186feefb5d0cc7674452d583efb916217 Mon Sep 17 00:00:00 2001 From: Steph Date: Wed, 3 Apr 2024 10:57:24 +0200 Subject: [PATCH 1/5] swap shared images to go-azure-sdk --- internal/services/compute/client/client.go | 12 +- .../compute/shared_image_data_source.go | 88 ++--- .../shared_image_gallery_data_source.go | 10 +- .../services/compute/shared_image_resource.go | 364 +++++++++--------- .../compute/shared_image_resource_test.go | 12 +- .../2022-03-03/galleryimages/README.md | 100 +++++ .../2022-03-03/galleryimages/client.go | 26 ++ .../2022-03-03/galleryimages/constants.go | 227 +++++++++++ .../galleryimages/id_galleryimage.go | 134 +++++++ .../galleryimages/method_createorupdate.go | 76 ++++ .../2022-03-03/galleryimages/method_delete.go | 71 ++++ .../2022-03-03/galleryimages/method_get.go | 54 +++ .../galleryimages/method_listbygallery.go | 92 +++++ .../2022-03-03/galleryimages/method_update.go | 74 ++++ .../galleryimages/model_disallowed.go | 8 + .../galleryimages/model_galleryimage.go | 13 + .../model_galleryimagefeature.go | 9 + .../model_galleryimageidentifier.go | 10 + .../model_galleryimageproperties.go | 40 ++ .../galleryimages/model_galleryimageupdate.go | 12 + .../galleryimages/model_imagepurchaseplan.go | 10 + .../model_recommendedmachineconfiguration.go | 9 + .../galleryimages/model_resourcerange.go | 9 + .../2022-03-03/galleryimages/predicates.go | 32 ++ .../2022-03-03/galleryimages/version.go | 12 + vendor/modules.txt | 1 + 26 files changed, 1252 insertions(+), 253 deletions(-) create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/README.md create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/client.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/constants.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/id_galleryimage.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/method_createorupdate.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/method_delete.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/method_get.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/method_listbygallery.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/method_update.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_disallowed.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_galleryimage.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_galleryimagefeature.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_galleryimageidentifier.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_galleryimageproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_galleryimageupdate.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_imagepurchaseplan.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_recommendedmachineconfiguration.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_resourcerange.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/predicates.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/version.go diff --git a/internal/services/compute/client/client.go b/internal/services/compute/client/client.go index 727e5a7952d1..c9845b87127b 100644 --- a/internal/services/compute/client/client.go +++ b/internal/services/compute/client/client.go @@ -21,6 +21,7 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleries" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryapplications" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryapplicationversions" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/gallerysharingupdate" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-03-01/virtualmachineruncommands" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-04-02/disks" @@ -49,7 +50,7 @@ type Client struct { GalleriesClient *galleries.GalleriesClient GalleryApplicationsClient *galleryapplications.GalleryApplicationsClient GalleryApplicationVersionsClient *galleryapplicationversions.GalleryApplicationVersionsClient - GalleryImagesClient *compute.GalleryImagesClient + GalleryImagesClient *galleryimages.GalleryImagesClient GalleryImageVersionsClient *compute.GalleryImageVersionsClient GallerySharingUpdateClient *gallerysharingupdate.GallerySharingUpdateClient ImagesClient *images.ImagesClient @@ -137,8 +138,11 @@ func NewClient(o *common.ClientOptions) (*Client, error) { } o.Configure(galleryApplicationVersionsClient.Client, o.Authorizers.ResourceManager) - galleryImagesClient := compute.NewGalleryImagesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) - o.ConfigureClient(&galleryImagesClient.Client, o.ResourceManagerAuthorizer) + galleryImagesClient, err := galleryimages.NewGalleryImagesClientWithBaseURI(o.Environment.ResourceManager) + if err != nil { + return nil, fmt.Errorf("building GalleryImages client: %+v", err) + } + o.Configure(galleryImagesClient.Client, o.Authorizers.ResourceManager) galleryImageVersionsClient := compute.NewGalleryImageVersionsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&galleryImageVersionsClient.Client, o.ResourceManagerAuthorizer) @@ -236,7 +240,7 @@ func NewClient(o *common.ClientOptions) (*Client, error) { GalleriesClient: galleriesClient, GalleryApplicationsClient: galleryApplicationsClient, GalleryApplicationVersionsClient: galleryApplicationVersionsClient, - GalleryImagesClient: &galleryImagesClient, + GalleryImagesClient: galleryImagesClient, GalleryImageVersionsClient: &galleryImageVersionsClient, GallerySharingUpdateClient: gallerySharingUpdateClient, ImagesClient: imagesClient, diff --git a/internal/services/compute/shared_image_data_source.go b/internal/services/compute/shared_image_data_source.go index 9e1a111fd566..9ec76db97168 100644 --- a/internal/services/compute/shared_image_data_source.go +++ b/internal/services/compute/shared_image_data_source.go @@ -5,18 +5,18 @@ package compute import ( "fmt" + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages" "time" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "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/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/timeouts" - "github.com/hashicorp/terraform-provider-azurerm/utils" - "github.com/tombuildsstuff/kermit/sdk/compute/2023-03-01/compute" ) func dataSourceSharedImage() *pluginsdk.Resource { @@ -126,7 +126,7 @@ func dataSourceSharedImage() *pluginsdk.Resource { Computed: true, }, - "tags": tags.SchemaDataSource(), + "tags": commonschema.TagsDataSource(), }, } } @@ -137,70 +137,66 @@ func dataSourceSharedImageRead(d *pluginsdk.ResourceData, meta interface{}) erro ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id := parse.NewSharedImageID(subscriptionId, d.Get("resource_group_name").(string), d.Get("gallery_name").(string), d.Get("name").(string)) + id := galleryimages.NewGalleryImageID(subscriptionId, d.Get("resource_group_name").(string), d.Get("gallery_name").(string), d.Get("name").(string)) - resp, err := client.Get(ctx, id.ResourceGroup, id.GalleryName, id.ImageName) + 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("making Read request on %s: %+v", id, err) + return fmt.Errorf("retrieving %s: %+v", id, err) } d.SetId(id.ID()) d.Set("name", id.ImageName) d.Set("gallery_name", id.GalleryName) - d.Set("resource_group_name", id.ResourceGroup) - - d.Set("location", location.NormalizeNilable(resp.Location)) - - if props := resp.GalleryImageProperties; props != nil { - d.Set("description", props.Description) - d.Set("eula", props.Eula) - d.Set("os_type", string(props.OsType)) - d.Set("architecture", string(props.Architecture)) - d.Set("specialized", props.OsState == compute.OperatingSystemStateTypesSpecialized) - d.Set("hyper_v_generation", string(props.HyperVGeneration)) - d.Set("privacy_statement_uri", props.PrivacyStatementURI) - d.Set("release_note_uri", props.ReleaseNoteURI) - - if err := d.Set("identifier", flattenGalleryImageDataSourceIdentifier(props.Identifier)); err != nil { - return fmt.Errorf("setting `identifier`: %+v", err) + d.Set("resource_group_name", id.ResourceGroupName) + + if model := resp.Model; model != nil { + d.Set("location", location.Normalize(model.Location)) + + if props := model.Properties; props != nil { + d.Set("description", props.Description) + d.Set("eula", props.Eula) + d.Set("os_type", string(props.OsType)) + d.Set("architecture", pointer.From(props.Architecture)) + d.Set("specialized", props.OsState == galleryimages.OperatingSystemStateTypesSpecialized) + d.Set("hyper_v_generation", pointer.From(props.HyperVGeneration)) + d.Set("privacy_statement_uri", props.PrivacyStatementUri) + d.Set("release_note_uri", props.ReleaseNoteUri) + + if err := d.Set("identifier", flattenGalleryImageDataSourceIdentifier(&props.Identifier)); err != nil { + return fmt.Errorf("setting `identifier`: %+v", err) + } + + if err := d.Set("purchase_plan", flattenGalleryImageDataSourcePurchasePlan(props.PurchasePlan)); err != nil { + return fmt.Errorf("setting `purchase_plan`: %+v", err) + } } - if err := d.Set("purchase_plan", flattenGalleryImageDataSourcePurchasePlan(props.PurchasePlan)); err != nil { - return fmt.Errorf("setting `purchase_plan`: %+v", err) - } - } + return tags.FlattenAndSet(d, model.Tags) - return tags.FlattenAndSet(d, resp.Tags) + } + return nil } -func flattenGalleryImageDataSourceIdentifier(input *compute.GalleryImageIdentifier) []interface{} { +func flattenGalleryImageDataSourceIdentifier(input *galleryimages.GalleryImageIdentifier) []interface{} { if input == nil { return []interface{}{} } - result := make(map[string]interface{}) - - if input.Offer != nil { - result["offer"] = *input.Offer - } - - if input.Publisher != nil { - result["publisher"] = *input.Publisher - } - - if input.Sku != nil { - result["sku"] = *input.Sku + return []interface{}{ + map[string]interface{}{ + "offer": input.Offer, + "publisher": input.Publisher, + "sku": input.Sku, + }, } - - return []interface{}{result} } -func flattenGalleryImageDataSourcePurchasePlan(input *compute.ImagePurchasePlan) []interface{} { +func flattenGalleryImageDataSourcePurchasePlan(input *galleryimages.ImagePurchasePlan) []interface{} { if input == nil { return []interface{}{} } diff --git a/internal/services/compute/shared_image_gallery_data_source.go b/internal/services/compute/shared_image_gallery_data_source.go index 4eddeb1dbab1..fe3887773a21 100644 --- a/internal/services/compute/shared_image_gallery_data_source.go +++ b/internal/services/compute/shared_image_gallery_data_source.go @@ -97,19 +97,15 @@ func dataSourceSharedImageGalleryRead(d *pluginsdk.ResourceData, meta interface{ } } - imagesResp, err := imagesClient.ListByGalleryComplete(ctx, id.ResourceGroupName, id.GalleryName) + imagesResp, err := imagesClient.ListByGalleryComplete(ctx, id) if err != nil { return fmt.Errorf("retrieving %s: %+v", id, err) } imageNames := make([]string, 0) - for imagesResp.NotDone() { - image := imagesResp.Value() + for _, image := range imagesResp.Items { if image.Name != nil { - imageNames = append(imageNames, *imagesResp.Value().Name) - } - if err := imagesResp.NextWithContext(ctx); err != nil { - return fmt.Errorf("listing next page of shared images for %s: %+v", id, err) + imageNames = append(imageNames, *image.Name) } } diff --git a/internal/services/compute/shared_image_resource.go b/internal/services/compute/shared_image_resource.go index ba2312785145..7e35884f7a57 100644 --- a/internal/services/compute/shared_image_resource.go +++ b/internal/services/compute/shared_image_resource.go @@ -6,23 +6,24 @@ package compute import ( "context" "fmt" + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages" "log" "strings" "time" "github.com/Azure/go-autorest/autorest/date" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" - "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "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/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/suppress" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" - "github.com/hashicorp/terraform-provider-azurerm/utils" "github.com/tombuildsstuff/kermit/sdk/compute/2023-03-01/compute" ) @@ -34,7 +35,7 @@ func resourceSharedImage() *pluginsdk.Resource { Delete: resourceSharedImageDelete, Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { - _, err := parse.SharedImageID(id) + _, err := galleryimages.ParseGalleryImageID(id) return err }), @@ -67,11 +68,11 @@ func resourceSharedImage() *pluginsdk.Resource { "architecture": { Type: pluginsdk.TypeString, Optional: true, - Default: string(compute.ArchitectureTypesX64), + Default: string(galleryimages.ArchitectureXSixFour), ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ - string(compute.ArchitectureTypesX64), - string(compute.ArchitectureTypesArm64), + string(galleryimages.ArchitectureXSixFour), + string(galleryimages.ArchitectureArmSixFour), }, false), }, @@ -80,8 +81,8 @@ func resourceSharedImage() *pluginsdk.Resource { Required: true, ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ - string(compute.OperatingSystemTypesLinux), - string(compute.OperatingSystemTypesWindows), + string(galleryimages.OperatingSystemTypesLinux), + string(galleryimages.OperatingSystemTypesWindows), }, false), }, @@ -107,11 +108,11 @@ func resourceSharedImage() *pluginsdk.Resource { "hyper_v_generation": { Type: pluginsdk.TypeString, Optional: true, - Default: string(compute.HyperVGenerationTypesV1), + Default: string(galleryimages.HyperVGenerationVOne), ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ - string(compute.HyperVGenerationV1), - string(compute.HyperVGenerationV2), + string(galleryimages.HyperVGenerationVOne), + string(galleryimages.HyperVGenerationVTwo), }, false), }, @@ -257,7 +258,7 @@ func resourceSharedImage() *pluginsdk.Resource { ForceNew: true, }, - "tags": tags.Schema(), + "tags": commonschema.Tags(), }, CustomizeDiff: pluginsdk.CustomDiffWithAll( @@ -275,17 +276,17 @@ func resourceSharedImageCreateUpdate(d *pluginsdk.ResourceData, meta interface{} defer cancel() log.Printf("[INFO] preparing arguments for Shared Image creation.") - id := parse.NewSharedImageID(subscriptionId, d.Get("resource_group_name").(string), d.Get("gallery_name").(string), d.Get("name").(string)) + id := galleryimages.NewGalleryImageID(subscriptionId, d.Get("resource_group_name").(string), d.Get("gallery_name").(string), d.Get("name").(string)) if d.IsNewResource() { - existing, err := client.Get(ctx, id.ResourceGroup, id.GalleryName, id.ImageName) + 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_shared_image", id.ID()) } } @@ -295,17 +296,17 @@ func resourceSharedImageCreateUpdate(d *pluginsdk.ResourceData, meta interface{} return err } - image := compute.GalleryImage{ - Location: utils.String(azure.NormalizeLocation(d.Get("location").(string))), - GalleryImageProperties: &compute.GalleryImageProperties{ - Description: utils.String(d.Get("description").(string)), + image := galleryimages.GalleryImage{ + Location: location.Normalize(d.Get("location").(string)), + Properties: &galleryimages.GalleryImageProperties{ + Description: pointer.To(d.Get("description").(string)), Disallowed: expandGalleryImageDisallowed(d), Identifier: expandGalleryImageIdentifier(d), - PrivacyStatementURI: utils.String(d.Get("privacy_statement_uri").(string)), - ReleaseNoteURI: utils.String(d.Get("release_note_uri").(string)), - Architecture: compute.Architecture(d.Get("architecture").(string)), - OsType: compute.OperatingSystemTypes(d.Get("os_type").(string)), - HyperVGeneration: compute.HyperVGeneration(d.Get("hyper_v_generation").(string)), + PrivacyStatementUri: pointer.To(d.Get("privacy_statement_uri").(string)), + ReleaseNoteUri: pointer.To(d.Get("release_note_uri").(string)), + Architecture: pointer.To(galleryimages.Architecture(d.Get("architecture").(string))), + OsType: galleryimages.OperatingSystemTypes(d.Get("os_type").(string)), + HyperVGeneration: pointer.To(galleryimages.HyperVGeneration(d.Get("hyper_v_generation").(string))), PurchasePlan: expandGalleryImagePurchasePlan(d.Get("purchase_plan").([]interface{})), Features: expandSharedImageFeatures(d), Recommended: recommended, @@ -315,30 +316,25 @@ func resourceSharedImageCreateUpdate(d *pluginsdk.ResourceData, meta interface{} if v, ok := d.GetOk("end_of_life_date"); ok { endOfLifeDate, _ := time.Parse(time.RFC3339, v.(string)) - image.GalleryImageProperties.EndOfLifeDate = &date.Time{ + image.Properties.EndOfLifeDate = pointer.To(date.Time{ Time: endOfLifeDate, - } + }.String()) } if v, ok := d.GetOk("eula"); ok { - image.GalleryImageProperties.Eula = utils.String(v.(string)) + image.Properties.Eula = pointer.To(v.(string)) } if d.Get("specialized").(bool) { - image.GalleryImageProperties.OsState = compute.OperatingSystemStateTypesSpecialized + image.Properties.OsState = galleryimages.OperatingSystemStateTypesSpecialized } else { - image.GalleryImageProperties.OsState = compute.OperatingSystemStateTypesGeneralized + image.Properties.OsState = galleryimages.OperatingSystemStateTypesGeneralized } - future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.GalleryName, id.ImageName, image) - if err != nil { + if err := client.CreateOrUpdateThenPoll(ctx, id, image); err != nil { return fmt.Errorf("creating/updating %s: %+v", id, err) } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for creation/update of %s: %+v", id, err) - } - d.SetId(id.ID()) return resourceSharedImageRead(d, meta) @@ -349,125 +345,132 @@ func resourceSharedImageRead(d *pluginsdk.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.SharedImageID(d.Id()) + id, err := galleryimages.ParseGalleryImageID(d.Id()) if err != nil { return err } - resp, err := client.Get(ctx, id.ResourceGroup, id.GalleryName, id.ImageName) + resp, err := client.Get(ctx, *id) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[DEBUG] Shared Image %q (Gallery %q / Resource Group %q) was not found - removing from state", id.ImageName, id.GalleryName, id.ResourceGroup) + if response.WasNotFound(resp.HttpResponse) { + log.Printf("[DEBUG] %s was not found - removing from state", id) d.SetId("") return nil } - return fmt.Errorf("making Read request on Shared Image %q (Gallery %q / Resource Group %q): %+v", id.ImageName, id.GalleryName, id.ResourceGroup, err) + return fmt.Errorf("retrieving %s: %+v", id, err) } d.Set("name", id.ImageName) d.Set("gallery_name", id.GalleryName) - d.Set("resource_group_name", id.ResourceGroup) - if location := resp.Location; location != nil { - d.Set("location", azure.NormalizeLocation(*location)) - } + d.Set("resource_group_name", id.ResourceGroupName) - if props := resp.GalleryImageProperties; props != nil { - d.Set("description", props.Description) - - diskTypesNotAllowed := make([]string, 0) - if disallowed := props.Disallowed; disallowed != nil { - if disallowed.DiskTypes != nil { - diskTypesNotAllowed = append(diskTypesNotAllowed, *disallowed.DiskTypes...) - } - } - d.Set("disk_types_not_allowed", diskTypesNotAllowed) - - if v := props.EndOfLifeDate; v != nil { - d.Set("end_of_life_date", props.EndOfLifeDate.Format(time.RFC3339)) - } + if model := resp.Model; model != nil { + d.Set("location", location.Normalize(model.Location)) - d.Set("eula", props.Eula) + if props := model.Properties; props != nil { + d.Set("description", props.Description) - maxRecommendedVcpuCount := 0 - minRecommendedVcpuCount := 0 - maxRecommendedMemoryInGB := 0 - minRecommendedMemoryInGB := 0 - if recommended := props.Recommended; recommended != nil { - if vcpus := recommended.VCPUs; vcpus != nil { - if vcpus.Max != nil { - maxRecommendedVcpuCount = int(*vcpus.Max) - } - if vcpus.Min != nil { - minRecommendedVcpuCount = int(*vcpus.Min) + diskTypesNotAllowed := make([]string, 0) + if disallowed := props.Disallowed; disallowed != nil { + if disallowed.DiskTypes != nil { + diskTypesNotAllowed = append(diskTypesNotAllowed, *disallowed.DiskTypes...) } } - if memory := recommended.Memory; memory != nil { - if memory.Max != nil { - maxRecommendedMemoryInGB = int(*memory.Max) + d.Set("disk_types_not_allowed", diskTypesNotAllowed) + + if v := props.EndOfLifeDate; v != nil { + d.Set("end_of_life_date", props.EndOfLifeDate) //.Format(time.RFC3339)) + } + + d.Set("eula", props.Eula) + + maxRecommendedVcpuCount := 0 + minRecommendedVcpuCount := 0 + maxRecommendedMemoryInGB := 0 + minRecommendedMemoryInGB := 0 + if recommended := props.Recommended; recommended != nil { + if vcpus := recommended.VCPUs; vcpus != nil { + if vcpus.Max != nil { + maxRecommendedVcpuCount = int(*vcpus.Max) + } + if vcpus.Min != nil { + minRecommendedVcpuCount = int(*vcpus.Min) + } } - if memory.Min != nil { - minRecommendedMemoryInGB = int(*memory.Min) + if memory := recommended.Memory; memory != nil { + if memory.Max != nil { + maxRecommendedMemoryInGB = int(*memory.Max) + } + if memory.Min != nil { + minRecommendedMemoryInGB = int(*memory.Min) + } } } - } - d.Set("max_recommended_vcpu_count", maxRecommendedVcpuCount) - d.Set("min_recommended_vcpu_count", minRecommendedVcpuCount) - d.Set("max_recommended_memory_in_gb", maxRecommendedMemoryInGB) - d.Set("min_recommended_memory_in_gb", minRecommendedMemoryInGB) + d.Set("max_recommended_vcpu_count", maxRecommendedVcpuCount) + d.Set("min_recommended_vcpu_count", minRecommendedVcpuCount) + d.Set("max_recommended_memory_in_gb", maxRecommendedMemoryInGB) + d.Set("min_recommended_memory_in_gb", minRecommendedMemoryInGB) - d.Set("os_type", string(props.OsType)) + d.Set("os_type", string(props.OsType)) - architecture := string((compute.ArchitectureTypesX64)) - if props.Architecture != "" { - architecture = string(props.Architecture) - } - d.Set("architecture", architecture) + architecture := string((galleryimages.ArchitectureXSixFour)) + if props.Architecture != nil { + architecture = string(*props.Architecture) + } + d.Set("architecture", architecture) - d.Set("specialized", props.OsState == compute.OperatingSystemStateTypesSpecialized) - d.Set("hyper_v_generation", string(props.HyperVGeneration)) - d.Set("privacy_statement_uri", props.PrivacyStatementURI) - d.Set("release_note_uri", props.ReleaseNoteURI) + d.Set("specialized", props.OsState == galleryimages.OperatingSystemStateTypesSpecialized) - if err := d.Set("identifier", flattenGalleryImageIdentifier(props.Identifier)); err != nil { - return fmt.Errorf("setting `identifier`: %+v", err) - } - - if err := d.Set("purchase_plan", flattenGalleryImagePurchasePlan(props.PurchasePlan)); err != nil { - return fmt.Errorf("setting `purchase_plan`: %+v", err) - } + hyperVGeneration := string(galleryimages.HyperVGenerationVOne) + if props.HyperVGeneration != nil { + hyperVGeneration = string(*props.HyperVGeneration) + } + d.Set("hyper_v_generation", hyperVGeneration) + d.Set("privacy_statement_uri", props.PrivacyStatementUri) + d.Set("release_note_uri", props.ReleaseNoteUri) - trustedLaunchSupported := false - trustedLaunchEnabled := false - cvmEnabled := false - cvmSupported := false - acceleratedNetworkSupportEnabled := false - if features := props.Features; features != nil { - for _, feature := range *features { - if feature.Name == nil || feature.Value == nil { - continue - } + if err := d.Set("identifier", flattenGalleryImageIdentifier(&props.Identifier)); err != nil { + return fmt.Errorf("setting `identifier`: %+v", err) + } - if strings.EqualFold(*feature.Name, "SecurityType") { - trustedLaunchSupported = strings.EqualFold(*feature.Value, "TrustedLaunchSupported") - trustedLaunchEnabled = strings.EqualFold(*feature.Value, "TrustedLaunch") - cvmSupported = strings.EqualFold(*feature.Value, "ConfidentialVmSupported") - cvmEnabled = strings.EqualFold(*feature.Value, "ConfidentialVm") - } + if err := d.Set("purchase_plan", flattenGalleryImagePurchasePlan(props.PurchasePlan)); err != nil { + return fmt.Errorf("setting `purchase_plan`: %+v", err) + } - if strings.EqualFold(*feature.Name, "IsAcceleratedNetworkSupported") { - acceleratedNetworkSupportEnabled = strings.EqualFold(*feature.Value, "true") + trustedLaunchSupported := false + trustedLaunchEnabled := false + cvmEnabled := false + cvmSupported := false + acceleratedNetworkSupportEnabled := false + if features := props.Features; features != nil { + for _, feature := range *features { + if feature.Name == nil || feature.Value == nil { + continue + } + + if strings.EqualFold(*feature.Name, "SecurityType") { + trustedLaunchSupported = strings.EqualFold(*feature.Value, "TrustedLaunchSupported") + trustedLaunchEnabled = strings.EqualFold(*feature.Value, "TrustedLaunch") + cvmSupported = strings.EqualFold(*feature.Value, "ConfidentialVmSupported") + cvmEnabled = strings.EqualFold(*feature.Value, "ConfidentialVm") + } + + if strings.EqualFold(*feature.Name, "IsAcceleratedNetworkSupported") { + acceleratedNetworkSupportEnabled = strings.EqualFold(*feature.Value, "true") + } } } + d.Set("confidential_vm_supported", cvmSupported) + d.Set("confidential_vm_enabled", cvmEnabled) + d.Set("trusted_launch_supported", trustedLaunchSupported) + d.Set("trusted_launch_enabled", trustedLaunchEnabled) + d.Set("accelerated_network_support_enabled", acceleratedNetworkSupportEnabled) } - d.Set("confidential_vm_supported", cvmSupported) - d.Set("confidential_vm_enabled", cvmEnabled) - d.Set("trusted_launch_supported", trustedLaunchSupported) - d.Set("trusted_launch_enabled", trustedLaunchEnabled) - d.Set("accelerated_network_support_enabled", acceleratedNetworkSupportEnabled) - } - return tags.FlattenAndSet(d, resp.Tags) + return tags.FlattenAndSet(d, model.Tags) + } + return nil } func resourceSharedImageDelete(d *pluginsdk.ResourceData, meta interface{}) error { @@ -475,24 +478,20 @@ func resourceSharedImageDelete(d *pluginsdk.ResourceData, meta interface{}) erro ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.SharedImageID(d.Id()) + id, err := galleryimages.ParseGalleryImageID(d.Id()) if err != nil { return err } - future, err := client.Delete(ctx, id.ResourceGroup, id.GalleryName, id.ImageName) - if err != nil { + if err := client.DeleteThenPoll(ctx, *id); err != nil { return fmt.Errorf("deleting %s: %+v", *id, err) } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for deletion of: %s: %+v", *id, err) - } log.Printf("[DEBUG] Waiting for %s to be eventually deleted", *id) stateConf := &pluginsdk.StateChangeConf{ Pending: []string{"Exists"}, Target: []string{"NotFound"}, - Refresh: sharedImageDeleteStateRefreshFunc(ctx, client, id.ResourceGroup, id.GalleryName, id.ImageName), + Refresh: sharedImageDeleteStateRefreshFunc(ctx, client, *id), MinTimeout: 10 * time.Second, ContinuousTargetOccurence: 10, Timeout: d.Timeout(pluginsdk.TimeoutDelete), @@ -505,16 +504,16 @@ func resourceSharedImageDelete(d *pluginsdk.ResourceData, meta interface{}) erro return nil } -func sharedImageDeleteStateRefreshFunc(ctx context.Context, client *compute.GalleryImagesClient, resourceGroupName string, galleryName string, imageName string) pluginsdk.StateRefreshFunc { +func sharedImageDeleteStateRefreshFunc(ctx context.Context, client *galleryimages.GalleryImagesClient, id galleryimages.GalleryImageId) pluginsdk.StateRefreshFunc { // The resource Shared Image depends on the resource Shared Image Gallery. // Although the delete API returns 404 which means the Shared Image resource has been deleted. // Then it tries to immediately delete Shared Image Gallery but it still throws error `Can not delete resource before nested resources are deleted.` // In this case we're going to try triggering the Deletion again, in-case it didn't work prior to this attempt. // For more details, see related Bug: https://github.com/Azure/azure-sdk-for-go/issues/8314 return func() (interface{}, string, error) { - res, err := client.Get(ctx, resourceGroupName, galleryName, imageName) + res, err := client.Get(ctx, id) if err != nil { - if utils.ResponseWasNotFound(res.Response) { + if response.WasNotFound(res.HttpResponse) { return "NotFound", "NotFound", nil } @@ -525,7 +524,7 @@ func sharedImageDeleteStateRefreshFunc(ctx context.Context, client *compute.Gall } } -func expandGalleryImageIdentifier(d *pluginsdk.ResourceData) *compute.GalleryImageIdentifier { +func expandGalleryImageIdentifier(d *pluginsdk.ResourceData) galleryimages.GalleryImageIdentifier { vs := d.Get("identifier").([]interface{}) v := vs[0].(map[string]interface{}) @@ -533,50 +532,35 @@ func expandGalleryImageIdentifier(d *pluginsdk.ResourceData) *compute.GalleryIma publisher := v["publisher"].(string) sku := v["sku"].(string) - return &compute.GalleryImageIdentifier{ - Sku: utils.String(sku), - Publisher: utils.String(publisher), - Offer: utils.String(offer), + return galleryimages.GalleryImageIdentifier{ + Sku: sku, + Publisher: publisher, + Offer: offer, } } -func flattenGalleryImageIdentifier(input *compute.GalleryImageIdentifier) []interface{} { +func flattenGalleryImageIdentifier(input *galleryimages.GalleryImageIdentifier) []interface{} { if input == nil { return []interface{}{} } - offer := "" - if input.Offer != nil { - offer = *input.Offer - } - - publisher := "" - if input.Publisher != nil { - publisher = *input.Publisher - } - - sku := "" - if input.Sku != nil { - sku = *input.Sku - } - return []interface{}{ map[string]interface{}{ - "offer": offer, - "publisher": publisher, - "sku": sku, + "offer": input.Offer, + "publisher": input.Publisher, + "sku": input.Sku, }, } } -func expandGalleryImagePurchasePlan(input []interface{}) *compute.ImagePurchasePlan { +func expandGalleryImagePurchasePlan(input []interface{}) *galleryimages.ImagePurchasePlan { if len(input) == 0 || input[0] == nil { return nil } v := input[0].(map[string]interface{}) - result := compute.ImagePurchasePlan{ - Name: utils.String(v["name"].(string)), + result := galleryimages.ImagePurchasePlan{ + Name: pointer.To(v["name"].(string)), } if publisher := v["publisher"].(string); publisher != "" { @@ -590,7 +574,7 @@ func expandGalleryImagePurchasePlan(input []interface{}) *compute.ImagePurchaseP return &result } -func flattenGalleryImagePurchasePlan(input *compute.ImagePurchasePlan) []interface{} { +func flattenGalleryImagePurchasePlan(input *galleryimages.ImagePurchasePlan) []interface{} { if input == nil { return []interface{}{} } @@ -619,7 +603,7 @@ func flattenGalleryImagePurchasePlan(input *compute.ImagePurchasePlan) []interfa } } -func expandGalleryImageDisallowed(d *pluginsdk.ResourceData) *compute.Disallowed { +func expandGalleryImageDisallowed(d *pluginsdk.ResourceData) *galleryimages.Disallowed { diskTypesNotAllowedRaw := d.Get("disk_types_not_allowed").(*pluginsdk.Set).List() diskTypesNotAllowed := make([]string, 0) @@ -627,15 +611,15 @@ func expandGalleryImageDisallowed(d *pluginsdk.ResourceData) *compute.Disallowed diskTypesNotAllowed = append(diskTypesNotAllowed, v.(string)) } - return &compute.Disallowed{ + return &galleryimages.Disallowed{ DiskTypes: &diskTypesNotAllowed, } } -func expandGalleryImageRecommended(d *pluginsdk.ResourceData) (*compute.RecommendedMachineConfiguration, error) { - result := &compute.RecommendedMachineConfiguration{ - VCPUs: &compute.ResourceRange{}, - Memory: &compute.ResourceRange{}, +func expandGalleryImageRecommended(d *pluginsdk.ResourceData) (*galleryimages.RecommendedMachineConfiguration, error) { + result := &galleryimages.RecommendedMachineConfiguration{ + VCPUs: &galleryimages.ResourceRange{}, + Memory: &galleryimages.ResourceRange{}, } maxVcpuCount := d.Get("max_recommended_vcpu_count").(int) @@ -644,10 +628,10 @@ func expandGalleryImageRecommended(d *pluginsdk.ResourceData) (*compute.Recommen return nil, fmt.Errorf("`max_recommended_vcpu_count` must be greater than or equal to `min_recommended_vcpu_count`") } if maxVcpuCount != 0 { - result.VCPUs.Max = utils.Int32(int32(maxVcpuCount)) + result.VCPUs.Max = pointer.To(int64(maxVcpuCount)) } if minVcpuCount != 0 { - result.VCPUs.Min = utils.Int32(int32(minVcpuCount)) + result.VCPUs.Min = pointer.To(int64(minVcpuCount)) } maxMemory := d.Get("max_recommended_memory_in_gb").(int) @@ -656,49 +640,49 @@ func expandGalleryImageRecommended(d *pluginsdk.ResourceData) (*compute.Recommen return nil, fmt.Errorf("`max_recommended_memory_in_gb` must be greater than or equal to `min_recommended_memory_in_gb`") } if maxMemory != 0 { - result.Memory.Max = utils.Int32(int32(maxMemory)) + result.Memory.Max = pointer.To(int64(maxMemory)) } if minMemory != 0 { - result.Memory.Min = utils.Int32(int32(minMemory)) + result.Memory.Min = pointer.To(int64(minMemory)) } return result, nil } -func expandSharedImageFeatures(d *pluginsdk.ResourceData) *[]compute.GalleryImageFeature { - var features []compute.GalleryImageFeature +func expandSharedImageFeatures(d *pluginsdk.ResourceData) *[]galleryimages.GalleryImageFeature { + var features []galleryimages.GalleryImageFeature if d.Get("accelerated_network_support_enabled").(bool) { - features = append(features, compute.GalleryImageFeature{ - Name: utils.String("IsAcceleratedNetworkSupported"), - Value: utils.String("true"), + features = append(features, galleryimages.GalleryImageFeature{ + Name: pointer.To("IsAcceleratedNetworkSupported"), + Value: pointer.To("true"), }) } if tvmSupported := d.Get("trusted_launch_supported").(bool); tvmSupported { - features = append(features, compute.GalleryImageFeature{ - Name: utils.String("SecurityType"), - Value: utils.String("TrustedLaunchSupported"), + features = append(features, galleryimages.GalleryImageFeature{ + Name: pointer.To("SecurityType"), + Value: pointer.To("TrustedLaunchSupported"), }) } if tvmEnabled := d.Get("trusted_launch_enabled").(bool); tvmEnabled { - features = append(features, compute.GalleryImageFeature{ - Name: utils.String("SecurityType"), - Value: utils.String("TrustedLaunch"), + features = append(features, galleryimages.GalleryImageFeature{ + Name: pointer.To("SecurityType"), + Value: pointer.To("TrustedLaunch"), }) } if cvmSupported := d.Get("confidential_vm_supported").(bool); cvmSupported { - features = append(features, compute.GalleryImageFeature{ - Name: utils.String("SecurityType"), - Value: utils.String("ConfidentialVmSupported"), + features = append(features, galleryimages.GalleryImageFeature{ + Name: pointer.To("SecurityType"), + Value: pointer.To("ConfidentialVmSupported"), }) } if cvmEnabled := d.Get("confidential_vm_enabled").(bool); cvmEnabled { - features = append(features, compute.GalleryImageFeature{ - Name: utils.String("SecurityType"), - Value: utils.String("ConfidentialVM"), + features = append(features, galleryimages.GalleryImageFeature{ + Name: pointer.To("SecurityType"), + Value: pointer.To("ConfidentialVM"), }) } diff --git a/internal/services/compute/shared_image_resource_test.go b/internal/services/compute/shared_image_resource_test.go index a15728bd66e1..eabce464dce5 100644 --- a/internal/services/compute/shared_image_resource_test.go +++ b/internal/services/compute/shared_image_resource_test.go @@ -9,12 +9,12 @@ import ( "testing" "time" + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages" "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" ) type SharedImageResource struct{} @@ -324,17 +324,17 @@ func TestAccSharedImage_recommended(t *testing.T) { } func (t SharedImageResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.SharedImageID(state.ID) + id, err := galleryimages.ParseGalleryImageID(state.ID) if err != nil { return nil, err } - resp, err := clients.Compute.GalleryImagesClient.Get(ctx, id.ResourceGroup, id.GalleryName, id.ImageName) + resp, err := clients.Compute.GalleryImagesClient.Get(ctx, *id) if err != nil { - return nil, fmt.Errorf("retrieving Compute Shared Image %q", id.String()) + return nil, fmt.Errorf("retrieving %s", id) } - return utils.Bool(resp.ID != nil), nil + return pointer.To(resp.Model != nil), nil } func (SharedImageResource) basic(data acceptance.TestData) string { diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/README.md new file mode 100644 index 000000000000..915c0167863b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/README.md @@ -0,0 +1,100 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages` Documentation + +The `galleryimages` SDK allows for interaction with the Azure Resource Manager Service `compute` (API Version `2022-03-03`). + +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-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages" +``` + + +### Client Initialization + +```go +client := galleryimages.NewGalleryImagesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GalleryImagesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := galleryimages.NewGalleryImageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "galleryValue", "imageValue") + +payload := galleryimages.GalleryImage{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `GalleryImagesClient.Delete` + +```go +ctx := context.TODO() +id := galleryimages.NewGalleryImageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "galleryValue", "imageValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `GalleryImagesClient.Get` + +```go +ctx := context.TODO() +id := galleryimages.NewGalleryImageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "galleryValue", "imageValue") + +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: `GalleryImagesClient.ListByGallery` + +```go +ctx := context.TODO() +id := commonids.NewSharedImageGalleryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "galleryValue") + +// alternatively `client.ListByGallery(ctx, id)` can be used to do batched pagination +items, err := client.ListByGalleryComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `GalleryImagesClient.Update` + +```go +ctx := context.TODO() +id := galleryimages.NewGalleryImageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "galleryValue", "imageValue") + +payload := galleryimages.GalleryImageUpdate{ + // ... +} + + +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-03/galleryimages/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/client.go new file mode 100644 index 000000000000..59b9c848dbd0 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/client.go @@ -0,0 +1,26 @@ +package galleryimages + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryImagesClient struct { + Client *resourcemanager.Client +} + +func NewGalleryImagesClientWithBaseURI(sdkApi sdkEnv.Api) (*GalleryImagesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "galleryimages", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GalleryImagesClient: %+v", err) + } + + return &GalleryImagesClient{ + Client: client, + }, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/constants.go new file mode 100644 index 000000000000..07479be5fc5c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/constants.go @@ -0,0 +1,227 @@ +package galleryimages + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Architecture string + +const ( + ArchitectureArmSixFour Architecture = "Arm64" + ArchitectureXSixFour Architecture = "x64" +) + +func PossibleValuesForArchitecture() []string { + return []string{ + string(ArchitectureArmSixFour), + string(ArchitectureXSixFour), + } +} + +func (s *Architecture) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseArchitecture(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +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 GalleryProvisioningState string + +const ( + GalleryProvisioningStateCreating GalleryProvisioningState = "Creating" + GalleryProvisioningStateDeleting GalleryProvisioningState = "Deleting" + GalleryProvisioningStateFailed GalleryProvisioningState = "Failed" + GalleryProvisioningStateMigrating GalleryProvisioningState = "Migrating" + GalleryProvisioningStateSucceeded GalleryProvisioningState = "Succeeded" + GalleryProvisioningStateUpdating GalleryProvisioningState = "Updating" +) + +func PossibleValuesForGalleryProvisioningState() []string { + return []string{ + string(GalleryProvisioningStateCreating), + string(GalleryProvisioningStateDeleting), + string(GalleryProvisioningStateFailed), + string(GalleryProvisioningStateMigrating), + string(GalleryProvisioningStateSucceeded), + string(GalleryProvisioningStateUpdating), + } +} + +func (s *GalleryProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGalleryProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGalleryProvisioningState(input string) (*GalleryProvisioningState, error) { + vals := map[string]GalleryProvisioningState{ + "creating": GalleryProvisioningStateCreating, + "deleting": GalleryProvisioningStateDeleting, + "failed": GalleryProvisioningStateFailed, + "migrating": GalleryProvisioningStateMigrating, + "succeeded": GalleryProvisioningStateSucceeded, + "updating": GalleryProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GalleryProvisioningState(input) + return &out, nil +} + +type HyperVGeneration string + +const ( + HyperVGenerationVOne HyperVGeneration = "V1" + HyperVGenerationVTwo HyperVGeneration = "V2" +) + +func PossibleValuesForHyperVGeneration() []string { + return []string{ + string(HyperVGenerationVOne), + string(HyperVGenerationVTwo), + } +} + +func (s *HyperVGeneration) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHyperVGeneration(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +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 OperatingSystemStateTypes string + +const ( + OperatingSystemStateTypesGeneralized OperatingSystemStateTypes = "Generalized" + OperatingSystemStateTypesSpecialized OperatingSystemStateTypes = "Specialized" +) + +func PossibleValuesForOperatingSystemStateTypes() []string { + return []string{ + string(OperatingSystemStateTypesGeneralized), + string(OperatingSystemStateTypesSpecialized), + } +} + +func (s *OperatingSystemStateTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperatingSystemStateTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOperatingSystemStateTypes(input string) (*OperatingSystemStateTypes, error) { + vals := map[string]OperatingSystemStateTypes{ + "generalized": OperatingSystemStateTypesGeneralized, + "specialized": OperatingSystemStateTypesSpecialized, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OperatingSystemStateTypes(input) + return &out, nil +} + +type OperatingSystemTypes string + +const ( + OperatingSystemTypesLinux OperatingSystemTypes = "Linux" + OperatingSystemTypesWindows OperatingSystemTypes = "Windows" +) + +func PossibleValuesForOperatingSystemTypes() []string { + return []string{ + string(OperatingSystemTypesLinux), + string(OperatingSystemTypesWindows), + } +} + +func (s *OperatingSystemTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperatingSystemTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +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 +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/id_galleryimage.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/id_galleryimage.go new file mode 100644 index 000000000000..c532745d841f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/id_galleryimage.go @@ -0,0 +1,134 @@ +package galleryimages + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GalleryImageId{} + +// GalleryImageId is a struct representing the Resource ID for a Gallery Image +type GalleryImageId struct { + SubscriptionId string + ResourceGroupName string + GalleryName string + ImageName string +} + +// NewGalleryImageID returns a new GalleryImageId struct +func NewGalleryImageID(subscriptionId string, resourceGroupName string, galleryName string, imageName string) GalleryImageId { + return GalleryImageId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + GalleryName: galleryName, + ImageName: imageName, + } +} + +// ParseGalleryImageID parses 'input' into a GalleryImageId +func ParseGalleryImageID(input string) (*GalleryImageId, error) { + parser := resourceids.NewParserFromResourceIdType(&GalleryImageId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GalleryImageId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGalleryImageIDInsensitively parses 'input' case-insensitively into a GalleryImageId +// note: this method should only be used for API response data and not user input +func ParseGalleryImageIDInsensitively(input string) (*GalleryImageId, error) { + parser := resourceids.NewParserFromResourceIdType(&GalleryImageId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GalleryImageId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GalleryImageId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.GalleryName, ok = input.Parsed["galleryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "galleryName", input) + } + + if id.ImageName, ok = input.Parsed["imageName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "imageName", input) + } + + return nil +} + +// ValidateGalleryImageID checks that 'input' can be parsed as a Gallery Image ID +func ValidateGalleryImageID(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 := ParseGalleryImageID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Gallery Image ID +func (id GalleryImageId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/galleries/%s/images/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.GalleryName, id.ImageName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Gallery Image ID +func (id GalleryImageId) 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("staticGalleries", "galleries", "galleries"), + resourceids.UserSpecifiedSegment("galleryName", "galleryValue"), + resourceids.StaticSegment("staticImages", "images", "images"), + resourceids.UserSpecifiedSegment("imageName", "imageValue"), + } +} + +// String returns a human-readable description of this Gallery Image ID +func (id GalleryImageId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Gallery Name: %q", id.GalleryName), + fmt.Sprintf("Image Name: %q", id.ImageName), + } + return fmt.Sprintf("Gallery Image (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/method_createorupdate.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/method_createorupdate.go new file mode 100644 index 000000000000..d9d3b57983d7 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/method_createorupdate.go @@ -0,0 +1,76 @@ +package galleryimages + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// 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 pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *GalleryImage +} + +// CreateOrUpdate ... +func (c GalleryImagesClient) CreateOrUpdate(ctx context.Context, id GalleryImageId, input GalleryImage) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c GalleryImagesClient) CreateOrUpdateThenPoll(ctx context.Context, id GalleryImageId, input GalleryImage) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/method_delete.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/method_delete.go new file mode 100644 index 000000000000..e746c7783771 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/method_delete.go @@ -0,0 +1,71 @@ +package galleryimages + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// 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 pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c GalleryImagesClient) Delete(ctx context.Context, id GalleryImageId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c GalleryImagesClient) DeleteThenPoll(ctx context.Context, id GalleryImageId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/method_get.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/method_get.go new file mode 100644 index 000000000000..5c642368aac6 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/method_get.go @@ -0,0 +1,54 @@ +package galleryimages + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// 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 + OData *odata.OData + Model *GalleryImage +} + +// Get ... +func (c GalleryImagesClient) Get(ctx context.Context, id GalleryImageId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model GalleryImage + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/method_listbygallery.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/method_listbygallery.go new file mode 100644 index 000000000000..481235590a2c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/method_listbygallery.go @@ -0,0 +1,92 @@ +package galleryimages + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByGalleryOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GalleryImage +} + +type ListByGalleryCompleteResult struct { + LatestHttpResponse *http.Response + Items []GalleryImage +} + +// ListByGallery ... +func (c GalleryImagesClient) ListByGallery(ctx context.Context, id commonids.SharedImageGalleryId) (result ListByGalleryOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/images", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]GalleryImage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByGalleryComplete retrieves all the results into a single object +func (c GalleryImagesClient) ListByGalleryComplete(ctx context.Context, id commonids.SharedImageGalleryId) (ListByGalleryCompleteResult, error) { + return c.ListByGalleryCompleteMatchingPredicate(ctx, id, GalleryImageOperationPredicate{}) +} + +// ListByGalleryCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GalleryImagesClient) ListByGalleryCompleteMatchingPredicate(ctx context.Context, id commonids.SharedImageGalleryId, predicate GalleryImageOperationPredicate) (result ListByGalleryCompleteResult, err error) { + items := make([]GalleryImage, 0) + + resp, err := c.ListByGallery(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByGalleryCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/method_update.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/method_update.go new file mode 100644 index 000000000000..a800e64b4de5 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/method_update.go @@ -0,0 +1,74 @@ +package galleryimages + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// 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 pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *GalleryImage +} + +// Update ... +func (c GalleryImagesClient) Update(ctx context.Context, id GalleryImageId, input GalleryImageUpdate) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c GalleryImagesClient) UpdateThenPoll(ctx context.Context, id GalleryImageId, input GalleryImageUpdate) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_disallowed.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_disallowed.go new file mode 100644 index 000000000000..8ef164ccb0ec --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_disallowed.go @@ -0,0 +1,8 @@ +package galleryimages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Disallowed struct { + DiskTypes *[]string `json:"diskTypes,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_galleryimage.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_galleryimage.go new file mode 100644 index 000000000000..4d2783b5612c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_galleryimage.go @@ -0,0 +1,13 @@ +package galleryimages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryImage struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *GalleryImageProperties `json:"properties,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-03/galleryimages/model_galleryimagefeature.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_galleryimagefeature.go new file mode 100644 index 000000000000..31ef74b406de --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_galleryimagefeature.go @@ -0,0 +1,9 @@ +package galleryimages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryImageFeature struct { + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_galleryimageidentifier.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_galleryimageidentifier.go new file mode 100644 index 000000000000..c4ba59a4105d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_galleryimageidentifier.go @@ -0,0 +1,10 @@ +package galleryimages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryImageIdentifier struct { + Offer string `json:"offer"` + Publisher string `json:"publisher"` + Sku string `json:"sku"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_galleryimageproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_galleryimageproperties.go new file mode 100644 index 000000000000..a1c163b7a45c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_galleryimageproperties.go @@ -0,0 +1,40 @@ +package galleryimages + +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 GalleryImageProperties struct { + Architecture *Architecture `json:"architecture,omitempty"` + Description *string `json:"description,omitempty"` + Disallowed *Disallowed `json:"disallowed,omitempty"` + EndOfLifeDate *string `json:"endOfLifeDate,omitempty"` + Eula *string `json:"eula,omitempty"` + Features *[]GalleryImageFeature `json:"features,omitempty"` + HyperVGeneration *HyperVGeneration `json:"hyperVGeneration,omitempty"` + Identifier GalleryImageIdentifier `json:"identifier"` + OsState OperatingSystemStateTypes `json:"osState"` + OsType OperatingSystemTypes `json:"osType"` + PrivacyStatementUri *string `json:"privacyStatementUri,omitempty"` + ProvisioningState *GalleryProvisioningState `json:"provisioningState,omitempty"` + PurchasePlan *ImagePurchasePlan `json:"purchasePlan,omitempty"` + Recommended *RecommendedMachineConfiguration `json:"recommended,omitempty"` + ReleaseNoteUri *string `json:"releaseNoteUri,omitempty"` +} + +func (o *GalleryImageProperties) GetEndOfLifeDateAsTime() (*time.Time, error) { + if o.EndOfLifeDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndOfLifeDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *GalleryImageProperties) SetEndOfLifeDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndOfLifeDate = &formatted +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_galleryimageupdate.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_galleryimageupdate.go new file mode 100644 index 000000000000..53b02d47d1aa --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_galleryimageupdate.go @@ -0,0 +1,12 @@ +package galleryimages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryImageUpdate struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GalleryImageProperties `json:"properties,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-03/galleryimages/model_imagepurchaseplan.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_imagepurchaseplan.go new file mode 100644 index 000000000000..7cb7961ccfa5 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_imagepurchaseplan.go @@ -0,0 +1,10 @@ +package galleryimages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImagePurchasePlan struct { + Name *string `json:"name,omitempty"` + Product *string `json:"product,omitempty"` + Publisher *string `json:"publisher,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_recommendedmachineconfiguration.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_recommendedmachineconfiguration.go new file mode 100644 index 000000000000..890f960704fb --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_recommendedmachineconfiguration.go @@ -0,0 +1,9 @@ +package galleryimages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedMachineConfiguration struct { + Memory *ResourceRange `json:"memory,omitempty"` + VCPUs *ResourceRange `json:"vCPUs,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_resourcerange.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_resourcerange.go new file mode 100644 index 000000000000..410e62e2f528 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/model_resourcerange.go @@ -0,0 +1,9 @@ +package galleryimages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceRange struct { + Max *int64 `json:"max,omitempty"` + Min *int64 `json:"min,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/predicates.go new file mode 100644 index 000000000000..90c6e156593f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/predicates.go @@ -0,0 +1,32 @@ +package galleryimages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryImageOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p GalleryImageOperationPredicate) Matches(input GalleryImage) 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.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-03/galleryimages/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/version.go new file mode 100644 index 000000000000..2eafb4c12715 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages/version.go @@ -0,0 +1,12 @@ +package galleryimages + +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-03" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/galleryimages/%s", defaultApiVersion) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 7494b6a73013..e1003d8a778d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -329,6 +329,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleries github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryapplications github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryapplicationversions +github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/gallerysharingupdate github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-03-01/restorepoints github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-03-01/virtualmachineruncommands From 3e3e956ebc326c38930de6fbdcc2ec41c0002afc Mon Sep 17 00:00:00 2001 From: Steph Date: Wed, 3 Apr 2024 13:43:58 +0200 Subject: [PATCH 2/5] swap shared image version data sources to go-azure-sdk --- internal/services/compute/client/client.go | 12 +- internal/services/compute/helpers.go | 3 +- internal/services/compute/helpers_test.go | 72 +-- .../compute/shared_image_data_source.go | 6 +- .../services/compute/shared_image_resource.go | 107 +++- .../shared_image_version_data_source.go | 116 ++-- .../compute/shared_image_version_resource.go | 201 ++++--- .../shared_image_version_resource_test.go | 13 +- .../shared_image_versions_data_source.go | 76 ++- .../2022-03-03/galleryimageversions/README.md | 99 ++++ .../2022-03-03/galleryimageversions/client.go | 26 + .../galleryimageversions/constants.go | 503 ++++++++++++++++++ .../galleryimageversions/id_galleryimage.go | 134 +++++ .../galleryimageversions/id_imageversion.go | 143 +++++ .../method_createorupdate.go | 76 +++ .../galleryimageversions/method_delete.go | 71 +++ .../galleryimageversions/method_get.go | 83 +++ .../method_listbygalleryimage.go | 91 ++++ .../galleryimageversions/method_update.go | 74 +++ .../model_datadiskimageencryption.go | 9 + .../model_encryptionimages.go | 9 + ...el_galleryartifactpublishingprofilebase.go | 45 ++ .../model_galleryartifactversionfullsource.go | 9 + .../model_gallerydatadiskimage.go | 11 + .../model_gallerydiskimage.go | 10 + .../model_gallerydiskimagesource.go | 10 + .../model_galleryextendedlocation.go | 9 + .../model_galleryimageversion.go | 13 + .../model_galleryimageversionproperties.go | 12 + .../model_galleryimageversionsafetyprofile.go | 10 + ...model_galleryimageversionstorageprofile.go | 10 + .../model_galleryimageversionupdate.go | 12 + .../model_gallerytargetextendedlocation.go | 12 + .../model_osdiskimageencryption.go | 9 + .../model_osdiskimagesecurityprofile.go | 9 + .../model_policyviolation.go | 9 + .../model_regionalreplicationstatus.go | 11 + .../model_replicationstatus.go | 9 + .../model_targetregion.go | 12 + .../galleryimageversions/predicates.go | 32 ++ .../galleryimageversions/version.go | 12 + vendor/modules.txt | 1 + 42 files changed, 1915 insertions(+), 276 deletions(-) create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/README.md create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/client.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/constants.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/id_galleryimage.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/id_imageversion.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_createorupdate.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_delete.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_get.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_listbygalleryimage.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_update.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_datadiskimageencryption.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_encryptionimages.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryartifactpublishingprofilebase.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryartifactversionfullsource.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_gallerydatadiskimage.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_gallerydiskimage.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_gallerydiskimagesource.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryextendedlocation.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryimageversion.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryimageversionproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryimageversionsafetyprofile.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryimageversionstorageprofile.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryimageversionupdate.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_gallerytargetextendedlocation.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_osdiskimageencryption.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_osdiskimagesecurityprofile.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_policyviolation.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_regionalreplicationstatus.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_replicationstatus.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_targetregion.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/predicates.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/version.go diff --git a/internal/services/compute/client/client.go b/internal/services/compute/client/client.go index c9845b87127b..86d31ce2cdaf 100644 --- a/internal/services/compute/client/client.go +++ b/internal/services/compute/client/client.go @@ -22,6 +22,7 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryapplications" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryapplicationversions" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/gallerysharingupdate" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-03-01/virtualmachineruncommands" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-04-02/disks" @@ -51,7 +52,7 @@ type Client struct { GalleryApplicationsClient *galleryapplications.GalleryApplicationsClient GalleryApplicationVersionsClient *galleryapplicationversions.GalleryApplicationVersionsClient GalleryImagesClient *galleryimages.GalleryImagesClient - GalleryImageVersionsClient *compute.GalleryImageVersionsClient + GalleryImageVersionsClient *galleryimageversions.GalleryImageVersionsClient GallerySharingUpdateClient *gallerysharingupdate.GallerySharingUpdateClient ImagesClient *images.ImagesClient MarketplaceAgreementsClient *agreements.AgreementsClient @@ -144,8 +145,11 @@ func NewClient(o *common.ClientOptions) (*Client, error) { } o.Configure(galleryImagesClient.Client, o.Authorizers.ResourceManager) - galleryImageVersionsClient := compute.NewGalleryImageVersionsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) - o.ConfigureClient(&galleryImageVersionsClient.Client, o.ResourceManagerAuthorizer) + galleryImageVersionsClient, err := galleryimageversions.NewGalleryImageVersionsClientWithBaseURI(o.Environment.ResourceManager) + if err != nil { + return nil, fmt.Errorf("building GalleryImageVersions client: %+v", err) + } + o.Configure(galleryImageVersionsClient.Client, o.Authorizers.ResourceManager) gallerySharingUpdateClient, err := gallerysharingupdate.NewGallerySharingUpdateClientWithBaseURI(o.Environment.ResourceManager) if err != nil { @@ -241,7 +245,7 @@ func NewClient(o *common.ClientOptions) (*Client, error) { GalleryApplicationsClient: galleryApplicationsClient, GalleryApplicationVersionsClient: galleryApplicationVersionsClient, GalleryImagesClient: galleryImagesClient, - GalleryImageVersionsClient: &galleryImageVersionsClient, + GalleryImageVersionsClient: galleryImageVersionsClient, GallerySharingUpdateClient: gallerySharingUpdateClient, ImagesClient: imagesClient, MarketplaceAgreementsClient: marketplaceAgreementsClient, diff --git a/internal/services/compute/helpers.go b/internal/services/compute/helpers.go index 79f7d9230a93..dad5d97459aa 100644 --- a/internal/services/compute/helpers.go +++ b/internal/services/compute/helpers.go @@ -6,6 +6,7 @@ package compute import ( "sort" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions" "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-provider-azurerm/utils" "github.com/tombuildsstuff/kermit/sdk/compute/2023-03-01/compute" @@ -57,7 +58,7 @@ func flattenSubResourcesToStringIDs(input *[]compute.SubResource) []string { return ids } -func sortSharedImageVersions(values []compute.GalleryImageVersion) ([]compute.GalleryImageVersion, []error) { +func sortSharedImageVersions(values []galleryimageversions.GalleryImageVersion) ([]galleryimageversions.GalleryImageVersion, []error) { errors := make([]error, 0) sort.Slice(values, func(i, j int) bool { if values[i].Name == nil || values[j].Name == nil { diff --git a/internal/services/compute/helpers_test.go b/internal/services/compute/helpers_test.go index cd3b5eacb241..a1936501b9c4 100644 --- a/internal/services/compute/helpers_test.go +++ b/internal/services/compute/helpers_test.go @@ -7,31 +7,31 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-provider-azurerm/utils" - "github.com/tombuildsstuff/kermit/sdk/compute/2023-03-01/compute" + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions" ) func TestSortVersions_valid(t *testing.T) { testData := []struct { - input []compute.GalleryImageVersion - expected []compute.GalleryImageVersion + input []galleryimageversions.GalleryImageVersion + expected []galleryimageversions.GalleryImageVersion }{ { - input: []compute.GalleryImageVersion{ - {Name: utils.String("1.0.1")}, - {Name: utils.String("1.2.15.0")}, - {Name: utils.String("1.0.8")}, - {Name: utils.String("1.0.9")}, - {Name: utils.String("1.0.1.1")}, - {Name: utils.String("1.0.10")}, + input: []galleryimageversions.GalleryImageVersion{ + {Name: pointer.To("1.0.1")}, + {Name: pointer.To("1.2.15.0")}, + {Name: pointer.To("1.0.8")}, + {Name: pointer.To("1.0.9")}, + {Name: pointer.To("1.0.1.1")}, + {Name: pointer.To("1.0.10")}, }, - expected: []compute.GalleryImageVersion{ - {Name: utils.String("1.0.1")}, - {Name: utils.String("1.0.1.1")}, - {Name: utils.String("1.0.8")}, - {Name: utils.String("1.0.9")}, - {Name: utils.String("1.0.10")}, - {Name: utils.String("1.2.15.0")}, + expected: []galleryimageversions.GalleryImageVersion{ + {Name: pointer.To("1.0.1")}, + {Name: pointer.To("1.0.1.1")}, + {Name: pointer.To("1.0.8")}, + {Name: pointer.To("1.0.9")}, + {Name: pointer.To("1.0.10")}, + {Name: pointer.To("1.2.15.0")}, }, }, } @@ -51,27 +51,27 @@ func TestSortVersions_valid(t *testing.T) { func TestSortVersions_invalid(t *testing.T) { testData := []struct { - input []compute.GalleryImageVersion - expected []compute.GalleryImageVersion + input []galleryimageversions.GalleryImageVersion + expected []galleryimageversions.GalleryImageVersion }{ { - input: []compute.GalleryImageVersion{ - {Name: utils.String("1.0.1")}, - {Name: utils.String("1.2.15.0")}, - {Name: utils.String("1.0.8")}, - {Name: utils.String("1.0.9")}, - {Name: utils.String("1.0.1.1")}, - {Name: utils.String("1.0.10")}, - {Name: utils.String("latest")}, + input: []galleryimageversions.GalleryImageVersion{ + {Name: pointer.To("1.0.1")}, + {Name: pointer.To("1.2.15.0")}, + {Name: pointer.To("1.0.8")}, + {Name: pointer.To("1.0.9")}, + {Name: pointer.To("1.0.1.1")}, + {Name: pointer.To("1.0.10")}, + {Name: pointer.To("latest")}, }, - expected: []compute.GalleryImageVersion{ - {Name: utils.String("1.0.1")}, - {Name: utils.String("1.2.15.0")}, - {Name: utils.String("1.0.8")}, - {Name: utils.String("1.0.9")}, - {Name: utils.String("1.0.1.1")}, - {Name: utils.String("1.0.10")}, - {Name: utils.String("latest")}, + expected: []galleryimageversions.GalleryImageVersion{ + {Name: pointer.To("1.0.1")}, + {Name: pointer.To("1.2.15.0")}, + {Name: pointer.To("1.0.8")}, + {Name: pointer.To("1.0.9")}, + {Name: pointer.To("1.0.1.1")}, + {Name: pointer.To("1.0.10")}, + {Name: pointer.To("latest")}, }, }, } diff --git a/internal/services/compute/shared_image_data_source.go b/internal/services/compute/shared_image_data_source.go index 9ec76db97168..6816ce7378e8 100644 --- a/internal/services/compute/shared_image_data_source.go +++ b/internal/services/compute/shared_image_data_source.go @@ -5,14 +5,14 @@ package compute import ( "fmt" - "github.com/hashicorp/go-azure-helpers/lang/pointer" - "github.com/hashicorp/go-azure-helpers/lang/response" - "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages" "time" + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" diff --git a/internal/services/compute/shared_image_resource.go b/internal/services/compute/shared_image_resource.go index 7e35884f7a57..0e090be4ab04 100644 --- a/internal/services/compute/shared_image_resource.go +++ b/internal/services/compute/shared_image_resource.go @@ -6,17 +6,17 @@ package compute import ( "context" "fmt" - "github.com/hashicorp/go-azure-helpers/lang/pointer" - "github.com/hashicorp/go-azure-helpers/lang/response" - "github.com/hashicorp/go-azure-helpers/resourcemanager/location" - "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages" "log" "strings" "time" "github.com/Azure/go-autorest/autorest/date" + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate" @@ -29,9 +29,9 @@ import ( func resourceSharedImage() *pluginsdk.Resource { return &pluginsdk.Resource{ - Create: resourceSharedImageCreateUpdate, + Create: resourceSharedImageCreate, Read: resourceSharedImageRead, - Update: resourceSharedImageCreateUpdate, + Update: resourceSharedImageUpdate, Delete: resourceSharedImageDelete, Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { @@ -269,28 +269,26 @@ func resourceSharedImage() *pluginsdk.Resource { } } -func resourceSharedImageCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { +func resourceSharedImageCreate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.GalleryImagesClient subscriptionId := meta.(*clients.Client).Account.SubscriptionId - ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() log.Printf("[INFO] preparing arguments for Shared Image creation.") id := galleryimages.NewGalleryImageID(subscriptionId, d.Get("resource_group_name").(string), d.Get("gallery_name").(string), d.Get("name").(string)) - if d.IsNewResource() { - existing, err := client.Get(ctx, id) - if err != nil { - if !response.WasNotFound(existing.HttpResponse) { - return fmt.Errorf("checking for presence of existing %s: %+v", id, err) - } - } - + existing, err := client.Get(ctx, id) + if err != nil { if !response.WasNotFound(existing.HttpResponse) { - return tf.ImportAsExistsError("azurerm_shared_image", id.ID()) + return fmt.Errorf("checking for presence of existing %s: %+v", id, err) } } + if !response.WasNotFound(existing.HttpResponse) { + return tf.ImportAsExistsError("azurerm_shared_image", id.ID()) + } + recommended, err := expandGalleryImageRecommended(d) if err != nil { return err @@ -332,7 +330,78 @@ func resourceSharedImageCreateUpdate(d *pluginsdk.ResourceData, meta interface{} } if err := client.CreateOrUpdateThenPoll(ctx, id, image); err != nil { - return fmt.Errorf("creating/updating %s: %+v", id, err) + return fmt.Errorf("creating %s: %+v", id, err) + } + + d.SetId(id.ID()) + + return resourceSharedImageRead(d, meta) +} + +func resourceSharedImageUpdate(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Compute.GalleryImagesClient + ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := galleryimages.ParseGalleryImageID(d.Id()) + if err != nil { + return err + } + + existing, err := client.Get(ctx, *id) + if err != nil { + if !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for presence of existing %s: %+v", id, err) + } + } + + payload := existing.Model + + if payload == nil { + return fmt.Errorf("model is nil for %s", id) + } + + if d.HasChange("disk_types_not_allowed") { + payload.Properties.Disallowed = expandGalleryImageDisallowed(d) + } + + if d.HasChange("end_of_life_date") { + endOfLifeDate, _ := time.Parse(time.RFC3339, d.Get("end_of_life_date").(string)) + payload.Properties.EndOfLifeDate = pointer.To(date.Time{ + Time: endOfLifeDate, + }.String()) + } + + if d.HasChange("description") { + payload.Properties.Description = pointer.To(d.Get("description").(string)) + } + + if d.HasChange("eula") { + payload.Properties.Description = pointer.To(d.Get("eula").(string)) + } + + if d.HasChange("specialized") { + if d.Get("specialized").(bool) { + payload.Properties.OsState = galleryimages.OperatingSystemStateTypesSpecialized + } else { + payload.Properties.OsState = galleryimages.OperatingSystemStateTypesGeneralized + } + } + + if d.HasChanges("max_recommended_vcpu_count", "min_recommended_vcpu_count", "max_recommended_memory_in_gb", "min_recommended_memory_in_gb") { + recommended, err := expandGalleryImageRecommended(d) + if err != nil { + return err + } + payload.Properties.Recommended = recommended + } + + if d.HasChange("tags") { + payload.Tags = tags.Expand(d.Get("tags").(map[string]interface{})) + } + + if err := client.CreateOrUpdateThenPoll(ctx, *id, *payload); err != nil { + return fmt.Errorf("updating %s: %+v", id, err) } d.SetId(id.ID()) @@ -380,7 +449,7 @@ func resourceSharedImageRead(d *pluginsdk.ResourceData, meta interface{}) error d.Set("disk_types_not_allowed", diskTypesNotAllowed) if v := props.EndOfLifeDate; v != nil { - d.Set("end_of_life_date", props.EndOfLifeDate) //.Format(time.RFC3339)) + d.Set("end_of_life_date", props.EndOfLifeDate) } d.Set("eula", props.Eula) diff --git a/internal/services/compute/shared_image_version_data_source.go b/internal/services/compute/shared_image_version_data_source.go index c794b1242426..2ba7a7d8ba6b 100644 --- a/internal/services/compute/shared_image_version_data_source.go +++ b/internal/services/compute/shared_image_version_data_source.go @@ -8,18 +8,16 @@ import ( "fmt" "time" + "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" - "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions" "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/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/timeouts" - "github.com/hashicorp/terraform-provider-azurerm/utils" - "github.com/tombuildsstuff/kermit/sdk/compute/2023-03-01/compute" ) func dataSourceSharedImageVersion() *pluginsdk.Resource { @@ -102,7 +100,7 @@ func dataSourceSharedImageVersion() *pluginsdk.Resource { Computed: true, }, - "tags": tags.SchemaDataSource(), + "tags": commonschema.Tags(), }, } } @@ -113,10 +111,10 @@ func dataSourceSharedImageVersionRead(d *pluginsdk.ResourceData, meta interface{ ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id := parse.NewSharedImageVersionID(subscriptionId, d.Get("resource_group_name").(string), d.Get("gallery_name").(string), d.Get("image_name").(string), d.Get("name").(string)) + id := galleryimageversions.NewImageVersionID(subscriptionId, d.Get("resource_group_name").(string), d.Get("gallery_name").(string), d.Get("image_name").(string), d.Get("name").(string)) sortBySemVer := d.Get("sort_versions_by_semver").(bool) - image, err := obtainImage(client, ctx, id.ResourceGroup, id.GalleryName, id.ImageName, id.VersionName, sortBySemVer) + image, err := obtainImage(client, ctx, id, sortBySemVer) if err != nil { return err } @@ -126,17 +124,17 @@ func dataSourceSharedImageVersionRead(d *pluginsdk.ResourceData, meta interface{ name = *image.Name } - exactId := parse.NewSharedImageVersionID(subscriptionId, id.ResourceGroup, id.GalleryName, id.ImageName, name) + exactId := galleryimageversions.NewImageVersionID(subscriptionId, id.ResourceGroupName, id.GalleryName, id.ImageName, name) d.SetId(exactId.ID()) d.Set("name", name) d.Set("image_name", id.ImageName) d.Set("gallery_name", id.GalleryName) - d.Set("resource_group_name", id.ResourceGroup) + d.Set("resource_group_name", id.ResourceGroupName) d.Set("sort_versions_by_semver", sortBySemVer) - d.Set("location", location.NormalizeNilable(image.Location)) + d.Set("location", location.Normalize(image.Location)) - if props := image.GalleryImageVersionProperties; props != nil { + if props := image.Properties; props != nil { if profile := props.PublishingProfile; profile != nil { d.Set("exclude_from_latest", profile.ExcludeFromLatest) @@ -145,48 +143,41 @@ func dataSourceSharedImageVersionRead(d *pluginsdk.ResourceData, meta interface{ } } - if profile := props.StorageProfile; profile != nil { - if source := profile.Source; source != nil { - d.Set("managed_image_id", source.ID) - } - + if source := props.StorageProfile.Source; source != nil { + d.Set("managed_image_id", source.Id) osDiskSnapShotID := "" - if profile.OsDiskImage != nil && profile.OsDiskImage.Source != nil && profile.OsDiskImage.Source.ID != nil { - osDiskSnapShotID = *profile.OsDiskImage.Source.ID + if props.StorageProfile.OsDiskImage != nil && props.StorageProfile.OsDiskImage.Source != nil && props.StorageProfile.OsDiskImage.Source.Id != nil { + osDiskSnapShotID = *props.StorageProfile.OsDiskImage.Source.Id } d.Set("os_disk_snapshot_id", osDiskSnapShotID) osDiskImageSize := 0 - if profile.OsDiskImage != nil && profile.OsDiskImage.SizeInGB != nil { - osDiskImageSize = int(*profile.OsDiskImage.SizeInGB) + if props.StorageProfile.OsDiskImage != nil && props.StorageProfile.OsDiskImage.SizeInGB != nil { + osDiskImageSize = int(*props.StorageProfile.OsDiskImage.SizeInGB) } d.Set("os_disk_image_size_gb", osDiskImageSize) } + return tags.FlattenAndSet(d, image.Tags) } - - return tags.FlattenAndSet(d, image.Tags) + return nil } -func obtainImage(client *compute.GalleryImageVersionsClient, ctx context.Context, resourceGroup string, galleryName string, galleryImageName string, galleryImageVersionName string, sortBySemVer bool) (*compute.GalleryImageVersion, error) { - notFoundError := fmt.Errorf("A Version was not found for Shared Image %q / Gallery %q / Resource Group %q", galleryImageName, galleryName, resourceGroup) +func obtainImage(client *galleryimageversions.GalleryImageVersionsClient, ctx context.Context, id galleryimageversions.ImageVersionId, sortBySemVer bool) (*galleryimageversions.GalleryImageVersion, error) { + galleryImageId := galleryimageversions.NewGalleryImageID(id.SubscriptionId, id.ResourceGroupName, id.GalleryName, id.ImageName) - switch galleryImageVersionName { + notFoundError := fmt.Errorf("a version was not found for %s", galleryImageId) + + switch id.VersionName { case "latest": - imagesIterator, err := client.ListByGalleryImageComplete(ctx, resourceGroup, galleryName, galleryImageName) + resp, err := client.ListByGalleryImageComplete(ctx, galleryImageId) if err != nil { - if utils.ResponseWasNotFound(imagesIterator.Response().Response) { + if response.WasNotFound(resp.LatestHttpResponse) { return nil, notFoundError } - return nil, fmt.Errorf("retrieving Shared Image Versions (Image %q / Gallery %q / Resource Group %q): %+v", galleryImageName, galleryName, resourceGroup, err) + return nil, fmt.Errorf("retrieving `latest` versions for %s: %+v", galleryImageId, err) } - images := make([]compute.GalleryImageVersion, 0) - for imagesIterator.NotDone() { - images = append(images, imagesIterator.Value()) - if err := imagesIterator.NextWithContext(ctx); err != nil { - return nil, fmt.Errorf("listing Shared Image Versions (Image %q / Gallery %q / Resource Group %q): %+v", galleryImageName, galleryName, resourceGroup, err) - } - } + images := resp.Items // the last image in the list is the latest version if len(images) > 0 { @@ -204,7 +195,7 @@ func obtainImage(client *compute.GalleryImageVersionsClient, ctx context.Context } for i := len(images) - 1; i >= 0; i-- { - if prop := images[i].GalleryImageVersionProperties; prop == nil || prop.PublishingProfile == nil || prop.PublishingProfile.ExcludeFromLatest == nil || !*prop.PublishingProfile.ExcludeFromLatest { + if prop := images[i].Properties; prop == nil || prop.PublishingProfile == nil || prop.PublishingProfile.ExcludeFromLatest == nil || !*prop.PublishingProfile.ExcludeFromLatest { return &(images[i]), nil } } @@ -212,28 +203,29 @@ func obtainImage(client *compute.GalleryImageVersionsClient, ctx context.Context return nil, notFoundError case "recent": - imagesIterator, err := client.ListByGalleryImageComplete(ctx, resourceGroup, galleryName, galleryImageName) + resp, err := client.ListByGalleryImageComplete(ctx, galleryImageId) if err != nil { - if utils.ResponseWasNotFound(imagesIterator.Response().Response) { + if response.WasNotFound(resp.LatestHttpResponse) { return nil, notFoundError } - return nil, fmt.Errorf("retrieving Shared Image Versions (Image %q / Gallery %q / Resource Group %q): %+v", galleryImageName, galleryName, resourceGroup, err) + return nil, fmt.Errorf("retrieving `recent` versions for %s: %+v", galleryImageId, err) } - var image *compute.GalleryImageVersion + var image *galleryimageversions.GalleryImageVersion var recentDate *time.Time // compare dates until we find the image that was updated most recently - for imagesIterator.NotDone() { - currImage := imagesIterator.Value() - if profile := currImage.PublishingProfile; profile != nil { - if profile.PublishedDate != nil && (recentDate == nil || profile.PublishedDate.Time.After(*recentDate)) { - recentDate = &profile.PublishedDate.Time - image = &currImage + for _, currentImage := range resp.Items { + if profile := currentImage.Properties.PublishingProfile; profile != nil { + if profile.PublishedDate != nil { + publishedDate, err := time.Parse(time.RFC3339, *profile.PublishedDate) + if err != nil { + return nil, fmt.Errorf("parsing published date for %s: %+v", galleryImageId, err) + } + if recentDate == nil || publishedDate.After(*recentDate) { + recentDate = &publishedDate + image = ¤tImage + } } } - - if err := imagesIterator.NextWithContext(ctx); err != nil { - return nil, fmt.Errorf("listing Shared Image Versions (Image %q / Gallery %q / Resource Group %q): %+v", galleryImageName, galleryName, resourceGroup, err) - } } if image != nil { @@ -243,34 +235,38 @@ func obtainImage(client *compute.GalleryImageVersionsClient, ctx context.Context return nil, notFoundError default: - image, err := client.Get(ctx, resourceGroup, galleryName, galleryImageName, galleryImageVersionName, compute.ReplicationStatusTypesReplicationStatus) + image, err := client.Get(ctx, id, galleryimageversions.DefaultGetOperationOptions()) if err != nil { - if utils.ResponseWasNotFound(image.Response) { + if response.WasNotFound(image.HttpResponse) { return nil, notFoundError } - return nil, fmt.Errorf("retrieving Shared Image Version %q (Image %q / Gallery %q / Resource Group %q): %+v", galleryImageVersionName, galleryImageName, galleryName, resourceGroup, err) + return nil, fmt.Errorf("retrieving %s: %+v", id, err) + } + + if image.Model == nil { + return nil, fmt.Errorf("model is nil for %s", id) } - return &image, nil + return image.Model, nil } } -func flattenSharedImageVersionDataSourceTargetRegions(input *[]compute.TargetRegion) []interface{} { +func flattenSharedImageVersionDataSourceTargetRegions(input *[]galleryimageversions.TargetRegion) []interface{} { results := make([]interface{}, 0) if input != nil { for _, v := range *input { output := make(map[string]interface{}) - if v.Name != nil { - output["name"] = azure.NormalizeLocation(*v.Name) - } + output["name"] = location.Normalize(v.Name) if v.RegionalReplicaCount != nil { output["regional_replica_count"] = int(*v.RegionalReplicaCount) } - output["storage_account_type"] = string(v.StorageAccountType) + if v.StorageAccountType != nil { + output["storage_account_type"] = string(*v.StorageAccountType) + } results = append(results, output) } diff --git a/internal/services/compute/shared_image_version_resource.go b/internal/services/compute/shared_image_version_resource.go index 74a050f1dabd..65e09f89f6fb 100644 --- a/internal/services/compute/shared_image_version_resource.go +++ b/internal/services/compute/shared_image_version_resource.go @@ -11,22 +11,21 @@ import ( "github.com/Azure/go-autorest/autorest/date" "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-01/images" - "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "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/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/suppress" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" "github.com/hashicorp/terraform-provider-azurerm/utils" - "github.com/tombuildsstuff/kermit/sdk/compute/2023-03-01/compute" ) func resourceSharedImageVersion() *pluginsdk.Resource { @@ -37,7 +36,7 @@ func resourceSharedImageVersion() *pluginsdk.Resource { Delete: resourceSharedImageVersionDelete, Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { - _, err := parse.SharedImageVersionID(id) + _, err := galleryimageversions.ParseImageVersionID(id) return err }), @@ -114,11 +113,11 @@ func resourceSharedImageVersion() *pluginsdk.Resource { Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringInSlice([]string{ - string(compute.StorageAccountTypePremiumLRS), - string(compute.StorageAccountTypeStandardLRS), - string(compute.StorageAccountTypeStandardZRS), + string(galleryimageversions.StorageAccountTypePremiumLRS), + string(galleryimageversions.StorageAccountTypeStandardLRS), + string(galleryimageversions.StorageAccountTypeStandardZRS), }, false), - Default: string(compute.StorageAccountTypeStandardLRS), + Default: string(galleryimageversions.StorageAccountTypeStandardLRS), }, }, }, @@ -172,10 +171,10 @@ func resourceSharedImageVersion() *pluginsdk.Resource { Optional: true, ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ - string(compute.ReplicationModeFull), - string(compute.ReplicationModeShallow), + string(galleryimageversions.ReplicationModeFull), + string(galleryimageversions.ReplicationModeShallow), }, false), - Default: compute.ReplicationModeFull, + Default: galleryimageversions.ReplicationModeFull, }, "exclude_from_latest": { @@ -191,7 +190,7 @@ func resourceSharedImageVersion() *pluginsdk.Resource { Default: false, }, - "tags": tags.Schema(), + "tags": commonschema.Tags(), }, CustomizeDiff: pluginsdk.CustomDiffWithAll( @@ -208,17 +207,17 @@ func resourceSharedImageVersionCreateUpdate(d *pluginsdk.ResourceData, meta inte ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id := parse.NewSharedImageVersionID(subscriptionId, d.Get("resource_group_name").(string), d.Get("gallery_name").(string), d.Get("image_name").(string), d.Get("name").(string)) + id := galleryimageversions.NewImageVersionID(subscriptionId, d.Get("resource_group_name").(string), d.Get("gallery_name").(string), d.Get("image_name").(string), d.Get("name").(string)) if d.IsNewResource() { - existing, err := client.Get(ctx, id.ResourceGroup, id.GalleryName, id.ImageName, id.VersionName, "") + existing, err := client.Get(ctx, id, galleryimageversions.DefaultGetOperationOptions()) 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_shared_image_version", id.ID()) } } @@ -228,61 +227,56 @@ func resourceSharedImageVersionCreateUpdate(d *pluginsdk.ResourceData, meta inte return err } - version := compute.GalleryImageVersion{ - Location: utils.String(azure.NormalizeLocation(d.Get("location").(string))), - GalleryImageVersionProperties: &compute.GalleryImageVersionProperties{ - PublishingProfile: &compute.GalleryImageVersionPublishingProfile{ - ExcludeFromLatest: utils.Bool(d.Get("exclude_from_latest").(bool)), - ReplicationMode: compute.ReplicationMode(d.Get("replication_mode").(string)), + version := galleryimageversions.GalleryImageVersion{ + Location: location.Normalize(d.Get("location").(string)), + Properties: &galleryimageversions.GalleryImageVersionProperties{ + PublishingProfile: &galleryimageversions.GalleryArtifactPublishingProfileBase{ + ExcludeFromLatest: pointer.To(d.Get("exclude_from_latest").(bool)), + ReplicationMode: pointer.To(galleryimageversions.ReplicationMode(d.Get("replication_mode").(string))), TargetRegions: targetRegions, }, - SafetyProfile: &compute.GalleryImageVersionSafetyProfile{ + SafetyProfile: &galleryimageversions.GalleryImageVersionSafetyProfile{ AllowDeletionOfReplicatedLocations: utils.Bool(d.Get("deletion_of_replicated_locations_enabled").(bool)), }, - StorageProfile: &compute.GalleryImageVersionStorageProfile{}, + StorageProfile: galleryimageversions.GalleryImageVersionStorageProfile{}, }, Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } if v, ok := d.GetOk("end_of_life_date"); ok { endOfLifeDate, _ := time.Parse(time.RFC3339, v.(string)) - version.GalleryImageVersionProperties.PublishingProfile.EndOfLifeDate = &date.Time{ + version.Properties.PublishingProfile.EndOfLifeDate = pointer.To(date.Time{ Time: endOfLifeDate, - } + }.String()) } if v, ok := d.GetOk("managed_image_id"); ok { - version.GalleryImageVersionProperties.StorageProfile.Source = &compute.GalleryArtifactVersionFullSource{ - ID: utils.String(v.(string)), + version.Properties.StorageProfile.Source = &galleryimageversions.GalleryArtifactVersionFullSource{ + Id: utils.String(v.(string)), } } if v, ok := d.GetOk("os_disk_snapshot_id"); ok { - version.GalleryImageVersionProperties.StorageProfile.OsDiskImage = &compute.GalleryOSDiskImage{ - Source: &compute.GalleryDiskImageSource{ - ID: utils.String(v.(string)), + version.Properties.StorageProfile.OsDiskImage = &galleryimageversions.GalleryDiskImage{ + Source: &galleryimageversions.GalleryDiskImageSource{ + Id: pointer.To(v.(string)), }, } } if v, ok := d.GetOk("blob_uri"); ok { - version.GalleryImageVersionProperties.StorageProfile.OsDiskImage = &compute.GalleryOSDiskImage{ - Source: &compute.GalleryDiskImageSource{ - ID: utils.String(d.Get("storage_account_id").(string)), - URI: utils.String(v.(string)), + version.Properties.StorageProfile.OsDiskImage = &galleryimageversions.GalleryDiskImage{ + Source: &galleryimageversions.GalleryDiskImageSource{ + Id: pointer.To(d.Get("storage_account_id").(string)), + Uri: pointer.To(v.(string)), }, } } - future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.GalleryName, id.ImageName, id.VersionName, version) - if err != nil { + if err := client.CreateOrUpdateThenPoll(ctx, id, version); err != nil { return fmt.Errorf("creating %s: %+v", id, err) } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for the creation of %s: %+v", id, err) - } - d.SetId(id.ID()) return resourceSharedImageVersionRead(d, meta) @@ -293,64 +287,62 @@ func resourceSharedImageVersionRead(d *pluginsdk.ResourceData, meta interface{}) ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.SharedImageVersionID(d.Id()) + id, err := galleryimageversions.ParseImageVersionID(d.Id()) if err != nil { return err } - resp, err := client.Get(ctx, id.ResourceGroup, id.GalleryName, id.ImageName, id.VersionName, compute.ReplicationStatusTypesReplicationStatus) + resp, err := client.Get(ctx, *id, galleryimageversions.DefaultGetOperationOptions()) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[DEBUG] Shared Image Version %q (Image %q / Gallery %q / Resource Group %q) was not found - removing from state", id.VersionName, id.ImageName, id.GalleryName, id.ResourceGroup) + if response.WasNotFound(resp.HttpResponse) { + log.Printf("[DEBUG] %s was not found - removing from state", id) d.SetId("") return nil } - return fmt.Errorf("retrieving Shared Image Version %q (Image %q / Gallery %q / Resource Group %q): %+v", id.VersionName, id.ImageName, id.GalleryName, id.ResourceGroup, err) + return fmt.Errorf("retrieving %s: %+v", id, err) } - d.Set("name", resp.Name) + d.Set("name", id.VersionName) d.Set("image_name", id.ImageName) d.Set("gallery_name", id.GalleryName) - d.Set("resource_group_name", id.ResourceGroup) + d.Set("resource_group_name", id.ResourceGroupName) - if location := resp.Location; location != nil { - d.Set("location", azure.NormalizeLocation(*location)) - } + if model := resp.Model; model != nil { + d.Set("location", location.Normalize(model.Location)) - if props := resp.GalleryImageVersionProperties; props != nil { - if profile := props.PublishingProfile; profile != nil { - if v := profile.EndOfLifeDate; v != nil { - d.Set("end_of_life_date", profile.EndOfLifeDate.Format(time.RFC3339)) - } + if props := model.Properties; props != nil { + if profile := props.PublishingProfile; profile != nil { + if v := profile.EndOfLifeDate; v != nil { + d.Set("end_of_life_date", profile.EndOfLifeDate) + } - d.Set("exclude_from_latest", profile.ExcludeFromLatest) + d.Set("exclude_from_latest", profile.ExcludeFromLatest) - replicationMode := string(compute.ReplicationModeFull) - if profile.ReplicationMode != "" { - replicationMode = string(profile.ReplicationMode) - } - d.Set("replication_mode", replicationMode) + replicationMode := string(galleryimageversions.ReplicationModeFull) + if profile.ReplicationMode != nil { + replicationMode = string(*profile.ReplicationMode) + } + d.Set("replication_mode", replicationMode) - if err := d.Set("target_region", flattenSharedImageVersionTargetRegions(profile.TargetRegions)); err != nil { - return fmt.Errorf("setting `target_region`: %+v", err) + if err := d.Set("target_region", flattenSharedImageVersionTargetRegions(profile.TargetRegions)); err != nil { + return fmt.Errorf("setting `target_region`: %+v", err) + } } - } - if profile := props.StorageProfile; profile != nil { - if source := profile.Source; source != nil { - d.Set("managed_image_id", source.ID) + if source := props.StorageProfile.Source; source != nil { + d.Set("managed_image_id", source.Id) } blobURI := "" - if profile.OsDiskImage != nil && profile.OsDiskImage.Source != nil && profile.OsDiskImage.Source.URI != nil { - blobURI = *profile.OsDiskImage.Source.URI + if props.StorageProfile.OsDiskImage != nil && props.StorageProfile.OsDiskImage.Source != nil && props.StorageProfile.OsDiskImage.Source.Uri != nil { + blobURI = *props.StorageProfile.OsDiskImage.Source.Uri } d.Set("blob_uri", blobURI) osDiskSnapShotID := "" storageAccountID := "" - if profile.OsDiskImage != nil && profile.OsDiskImage.Source != nil && profile.OsDiskImage.Source.ID != nil { - sourceID := *profile.OsDiskImage.Source.ID + if props.StorageProfile.OsDiskImage != nil && props.StorageProfile.OsDiskImage.Source != nil && props.StorageProfile.OsDiskImage.Source.Id != nil { + sourceID := *props.StorageProfile.OsDiskImage.Source.Id if blobURI == "" { osDiskSnapShotID = sourceID } else { @@ -359,14 +351,16 @@ func resourceSharedImageVersionRead(d *pluginsdk.ResourceData, meta interface{}) } d.Set("os_disk_snapshot_id", osDiskSnapShotID) d.Set("storage_account_id", storageAccountID) - } - if safetyProfile := props.SafetyProfile; safetyProfile != nil { - d.Set("deletion_of_replicated_locations_enabled", pointer.From(safetyProfile.AllowDeletionOfReplicatedLocations)) + if safetyProfile := props.SafetyProfile; safetyProfile != nil { + d.Set("deletion_of_replicated_locations_enabled", pointer.From(safetyProfile.AllowDeletionOfReplicatedLocations)) + } + } - } + return tags.FlattenAndSet(d, model.Tags) - return tags.FlattenAndSet(d, resp.Tags) + } + return nil } func resourceSharedImageVersionDelete(d *pluginsdk.ResourceData, meta interface{}) error { @@ -374,20 +368,15 @@ func resourceSharedImageVersionDelete(d *pluginsdk.ResourceData, meta interface{ ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.SharedImageVersionID(d.Id()) + id, err := galleryimageversions.ParseImageVersionID(d.Id()) if err != nil { return err } - future, err := client.Delete(ctx, id.ResourceGroup, id.GalleryName, id.ImageName, id.VersionName) - if err != nil { + if err := client.DeleteThenPoll(ctx, *id); err != nil { return fmt.Errorf("deleting %s: %+v", *id, err) } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for deletion of %s: %+v", *id, err) - } - // @tombuildsstuff: there appears to be an eventual consistency issue here timeout, _ := ctx.Deadline() log.Printf("[DEBUG] Waiting for %s to be eventually deleted", *id) @@ -407,14 +396,14 @@ func resourceSharedImageVersionDelete(d *pluginsdk.ResourceData, meta interface{ return nil } -func sharedImageVersionDeleteStateRefreshFunc(ctx context.Context, client *compute.GalleryImageVersionsClient, id parse.SharedImageVersionId) pluginsdk.StateRefreshFunc { +func sharedImageVersionDeleteStateRefreshFunc(ctx context.Context, client *galleryimageversions.GalleryImageVersionsClient, id galleryimageversions.ImageVersionId) pluginsdk.StateRefreshFunc { // Whilst the Shared Image Version is deleted quickly, it appears it's not actually finished replicating at this time // so the deletion of the parent Shared Image fails with "can not delete until nested resources are deleted" // ergo we need to poll on this for a bit return func() (interface{}, string, error) { - res, err := client.Get(ctx, id.ResourceGroup, id.GalleryName, id.ImageName, id.VersionName, "") + res, err := client.Get(ctx, id, galleryimageversions.DefaultGetOperationOptions()) if err != nil { - if utils.ResponseWasNotFound(res.Response) { + if response.WasNotFound(res.HttpResponse) { return "NotFound", "NotFound", nil } @@ -425,9 +414,9 @@ func sharedImageVersionDeleteStateRefreshFunc(ctx context.Context, client *compu } } -func expandSharedImageVersionTargetRegions(d *pluginsdk.ResourceData) (*[]compute.TargetRegion, error) { +func expandSharedImageVersionTargetRegions(d *pluginsdk.ResourceData) (*[]galleryimageversions.TargetRegion, error) { vs := d.Get("target_region").([]interface{}) - results := make([]compute.TargetRegion, 0) + results := make([]galleryimageversions.TargetRegion, 0) for _, v := range vs { input := v.(map[string]interface{}) @@ -438,21 +427,21 @@ func expandSharedImageVersionTargetRegions(d *pluginsdk.ResourceData) (*[]comput diskEncryptionSetId := input["disk_encryption_set_id"].(string) excludeFromLatest := input["exclude_from_latest_enabled"].(bool) - output := compute.TargetRegion{ - Name: utils.String(name), - ExcludeFromLatest: utils.Bool(excludeFromLatest), - RegionalReplicaCount: utils.Int32(int32(regionalReplicaCount)), - StorageAccountType: compute.StorageAccountType(storageAccountType), + output := galleryimageversions.TargetRegion{ + Name: name, + ExcludeFromLatest: pointer.To(excludeFromLatest), + RegionalReplicaCount: pointer.To(int64(regionalReplicaCount)), + StorageAccountType: pointer.To(galleryimageversions.StorageAccountType(storageAccountType)), } if diskEncryptionSetId != "" { - if d.Get("replication_mode").(string) == string(compute.ReplicationModeShallow) { + if d.Get("replication_mode").(string) == string(galleryimageversions.ReplicationModeShallow) { return nil, fmt.Errorf("`disk_encryption_set_id` cannot be used when `replication_mode` is `Shallow`") } - output.Encryption = &compute.EncryptionImages{ - OsDiskImage: &compute.OSDiskImageEncryption{ - DiskEncryptionSetID: utils.String(diskEncryptionSetId), + output.Encryption = &galleryimageversions.EncryptionImages{ + OsDiskImage: &galleryimageversions.OSDiskImageEncryption{ + DiskEncryptionSetId: pointer.To(diskEncryptionSetId), }, } } @@ -463,26 +452,26 @@ func expandSharedImageVersionTargetRegions(d *pluginsdk.ResourceData) (*[]comput return &results, nil } -func flattenSharedImageVersionTargetRegions(input *[]compute.TargetRegion) []interface{} { +func flattenSharedImageVersionTargetRegions(input *[]galleryimageversions.TargetRegion) []interface{} { results := make([]interface{}, 0) if input != nil { for _, v := range *input { output := make(map[string]interface{}) - if v.Name != nil { - output["name"] = azure.NormalizeLocation(*v.Name) - } + output["name"] = location.Normalize(v.Name) if v.RegionalReplicaCount != nil { output["regional_replica_count"] = int(*v.RegionalReplicaCount) } - output["storage_account_type"] = string(v.StorageAccountType) + if v.StorageAccountType != nil { + output["storage_account_type"] = string(*v.StorageAccountType) + } diskEncryptionSetId := "" - if v.Encryption != nil && v.Encryption.OsDiskImage != nil && v.Encryption.OsDiskImage.DiskEncryptionSetID != nil { - diskEncryptionSetId = *v.Encryption.OsDiskImage.DiskEncryptionSetID + if v.Encryption != nil && v.Encryption.OsDiskImage != nil && v.Encryption.OsDiskImage.DiskEncryptionSetId != nil { + diskEncryptionSetId = *v.Encryption.OsDiskImage.DiskEncryptionSetId } output["disk_encryption_set_id"] = diskEncryptionSetId diff --git a/internal/services/compute/shared_image_version_resource_test.go b/internal/services/compute/shared_image_version_resource_test.go index fee03ee1c86d..2d0b41393ba5 100644 --- a/internal/services/compute/shared_image_version_resource_test.go +++ b/internal/services/compute/shared_image_version_resource_test.go @@ -9,14 +9,13 @@ import ( "testing" "time" + "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions" "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" - "github.com/tombuildsstuff/kermit/sdk/compute/2023-03-01/compute" ) type SharedImageVersionResource struct{} @@ -287,17 +286,17 @@ func TestAccSharedImageVersion_requiresImport(t *testing.T) { } func (r SharedImageVersionResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.SharedImageVersionID(state.ID) + id, err := galleryimageversions.ParseImageVersionID(state.ID) if err != nil { return nil, err } - resp, err := clients.Compute.GalleryImageVersionsClient.Get(ctx, id.ResourceGroup, id.GalleryName, id.ImageName, id.VersionName, compute.ReplicationStatusTypesReplicationStatus) + resp, err := clients.Compute.GalleryImageVersionsClient.Get(ctx, *id, galleryimageversions.DefaultGetOperationOptions()) if err != nil { - return nil, fmt.Errorf("retrieving Compute Shared Image Gallery %q", id.String()) + return nil, fmt.Errorf("retrieving %s: %+v", id, err) } - return utils.Bool(resp.ID != nil), nil + return pointer.To(resp.Model != nil), nil } func (SharedImageVersionResource) revokeSnapshot(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) error { diff --git a/internal/services/compute/shared_image_versions_data_source.go b/internal/services/compute/shared_image_versions_data_source.go index 603eec561ecb..b07180fc9ae5 100644 --- a/internal/services/compute/shared_image_versions_data_source.go +++ b/internal/services/compute/shared_image_versions_data_source.go @@ -7,15 +7,15 @@ import ( "fmt" "time" + "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "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/timeouts" - "github.com/hashicorp/terraform-provider-azurerm/utils" - "github.com/tombuildsstuff/kermit/sdk/compute/2023-03-01/compute" ) func dataSourceSharedImageVersions() *pluginsdk.Resource { @@ -41,7 +41,7 @@ func dataSourceSharedImageVersions() *pluginsdk.Resource { "resource_group_name": commonschema.ResourceGroupNameForDataSource(), - "tags_filter": tags.Schema(), + "tags_filter": commonschema.Tags(), "images": { Type: pluginsdk.TypeList, @@ -93,7 +93,7 @@ func dataSourceSharedImageVersions() *pluginsdk.Resource { Computed: true, }, - "tags": tags.SchemaDataSource(), + "tags": commonschema.TagsDataSource(), }, }, }, @@ -103,40 +103,31 @@ func dataSourceSharedImageVersions() *pluginsdk.Resource { func dataSourceSharedImageVersionsRead(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.GalleryImageVersionsClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - imageName := d.Get("image_name").(string) - galleryName := d.Get("gallery_name").(string) - resourceGroup := d.Get("resource_group_name").(string) + id := galleryimageversions.NewGalleryImageID(subscriptionId, d.Get("resource_group_name").(string), d.Get("gallery_name").(string), d.Get("image_name").(string)) filterTags := tags.Expand(d.Get("tags_filter").(map[string]interface{})) - resp, err := client.ListByGalleryImageComplete(ctx, resourceGroup, galleryName, imageName) + resp, err := client.ListByGalleryImageComplete(ctx, id) if err != nil { - if utils.ResponseWasNotFound(resp.Response().Response) { - return fmt.Errorf("No Versions were found for Shared Image %q / Gallery %q / Resource Group %q", imageName, galleryName, resourceGroup) + if response.WasNotFound(resp.LatestHttpResponse) { + return fmt.Errorf("no versions were found for %s", id) } - return fmt.Errorf("retrieving Shared Image Versions (Image %q / Gallery %q / Resource Group %q): %+v", imageName, galleryName, resourceGroup, err) + return fmt.Errorf("retrieving %s: %+v", id, err) } - images := make([]compute.GalleryImageVersion, 0) - for resp.NotDone() { - images = append(images, resp.Value()) - if err := resp.NextWithContext(ctx); err != nil { - return fmt.Errorf("listing next page of images for Shared Image %q / Gallery %q / Resource Group %q: %+v", imageName, galleryName, resourceGroup, err) - } - } - - flattenedImages := flattenSharedImageVersions(images, filterTags) + flattenedImages := flattenSharedImageVersions(resp.Items, filterTags) if len(flattenedImages) == 0 { return fmt.Errorf("unable to find any images") } - d.SetId(fmt.Sprintf("%s-%s-%s", imageName, galleryName, resourceGroup)) + d.SetId(fmt.Sprintf("%s-%s-%s", id.ImageName, id.GalleryName, id.ResourceGroupName)) - d.Set("image_name", imageName) - d.Set("gallery_name", galleryName) - d.Set("resource_group_name", resourceGroup) + d.Set("image_name", id.ImageName) + d.Set("gallery_name", id.GalleryName) + d.Set("resource_group_name", id.ResourceGroupName) if err := d.Set("images", flattenedImages); err != nil { return fmt.Errorf("setting `images`: %+v", err) @@ -145,21 +136,28 @@ func dataSourceSharedImageVersionsRead(d *pluginsdk.ResourceData, meta interface return nil } -func flattenSharedImageVersions(input []compute.GalleryImageVersion, filterTags map[string]*string) []interface{} { +func flattenSharedImageVersions(input []galleryimageversions.GalleryImageVersion, filterTags *map[string]string) []interface{} { results := make([]interface{}, 0) + if len(input) == 0 { + return results + } + for _, imageVersion := range input { flattenedImageVersion := flattenSharedImageVersion(imageVersion) found := true // Loop through our filter tags and see if they match - for k, v := range filterTags { - if v != nil { - // If the tags don't match, return false - if imageVersion.Tags[k] == nil || *v != *imageVersion.Tags[k] { - found = false - break + if filterTags != nil { + for k, v := range *filterTags { + if imageVersion.Tags != nil { + // If the tags don't match, return false + if v != (*imageVersion.Tags)[k] { + found = false + break + } } } + } if found { @@ -170,23 +168,21 @@ func flattenSharedImageVersions(input []compute.GalleryImageVersion, filterTags return results } -func flattenSharedImageVersion(input compute.GalleryImageVersion) map[string]interface{} { +func flattenSharedImageVersion(input galleryimageversions.GalleryImageVersion) map[string]interface{} { output := make(map[string]interface{}) - output["id"] = input.ID + output["id"] = input.Id output["name"] = input.Name - output["location"] = location.NormalizeNilable(input.Location) + output["location"] = location.Normalize(input.Location) - if props := input.GalleryImageVersionProperties; props != nil { + if props := input.Properties; props != nil { if profile := props.PublishingProfile; profile != nil { output["exclude_from_latest"] = profile.ExcludeFromLatest output["target_region"] = flattenSharedImageVersionDataSourceTargetRegions(profile.TargetRegions) } - if profile := props.StorageProfile; profile != nil { - if source := profile.Source; source != nil { - output["managed_image_id"] = source.ID - } + if source := props.StorageProfile.Source; source != nil { + output["managed_image_id"] = source.Id } } diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/README.md new file mode 100644 index 000000000000..3c2142389ced --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions` Documentation + +The `galleryimageversions` SDK allows for interaction with the Azure Resource Manager Service `compute` (API Version `2022-03-03`). + +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-03/galleryimageversions" +``` + + +### Client Initialization + +```go +client := galleryimageversions.NewGalleryImageVersionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GalleryImageVersionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := galleryimageversions.NewImageVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "galleryValue", "imageValue", "versionValue") + +payload := galleryimageversions.GalleryImageVersion{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `GalleryImageVersionsClient.Delete` + +```go +ctx := context.TODO() +id := galleryimageversions.NewImageVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "galleryValue", "imageValue", "versionValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `GalleryImageVersionsClient.Get` + +```go +ctx := context.TODO() +id := galleryimageversions.NewImageVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "galleryValue", "imageValue", "versionValue") + +read, err := client.Get(ctx, id, galleryimageversions.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GalleryImageVersionsClient.ListByGalleryImage` + +```go +ctx := context.TODO() +id := galleryimageversions.NewGalleryImageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "galleryValue", "imageValue") + +// alternatively `client.ListByGalleryImage(ctx, id)` can be used to do batched pagination +items, err := client.ListByGalleryImageComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `GalleryImageVersionsClient.Update` + +```go +ctx := context.TODO() +id := galleryimageversions.NewImageVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "galleryValue", "imageValue", "versionValue") + +payload := galleryimageversions.GalleryImageVersionUpdate{ + // ... +} + + +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-03/galleryimageversions/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/client.go new file mode 100644 index 000000000000..c8bf5a50ca79 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/client.go @@ -0,0 +1,26 @@ +package galleryimageversions + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryImageVersionsClient struct { + Client *resourcemanager.Client +} + +func NewGalleryImageVersionsClientWithBaseURI(sdkApi sdkEnv.Api) (*GalleryImageVersionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "galleryimageversions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GalleryImageVersionsClient: %+v", err) + } + + return &GalleryImageVersionsClient{ + Client: client, + }, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/constants.go new file mode 100644 index 000000000000..820acc558783 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/constants.go @@ -0,0 +1,503 @@ +package galleryimageversions + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AggregatedReplicationState string + +const ( + AggregatedReplicationStateCompleted AggregatedReplicationState = "Completed" + AggregatedReplicationStateFailed AggregatedReplicationState = "Failed" + AggregatedReplicationStateInProgress AggregatedReplicationState = "InProgress" + AggregatedReplicationStateUnknown AggregatedReplicationState = "Unknown" +) + +func PossibleValuesForAggregatedReplicationState() []string { + return []string{ + string(AggregatedReplicationStateCompleted), + string(AggregatedReplicationStateFailed), + string(AggregatedReplicationStateInProgress), + string(AggregatedReplicationStateUnknown), + } +} + +func (s *AggregatedReplicationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAggregatedReplicationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAggregatedReplicationState(input string) (*AggregatedReplicationState, error) { + vals := map[string]AggregatedReplicationState{ + "completed": AggregatedReplicationStateCompleted, + "failed": AggregatedReplicationStateFailed, + "inprogress": AggregatedReplicationStateInProgress, + "unknown": AggregatedReplicationStateUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AggregatedReplicationState(input) + return &out, nil +} + +type ConfidentialVMEncryptionType string + +const ( + ConfidentialVMEncryptionTypeEncryptedVMGuestStateOnlyWithPmk ConfidentialVMEncryptionType = "EncryptedVMGuestStateOnlyWithPmk" + ConfidentialVMEncryptionTypeEncryptedWithCmk ConfidentialVMEncryptionType = "EncryptedWithCmk" + ConfidentialVMEncryptionTypeEncryptedWithPmk ConfidentialVMEncryptionType = "EncryptedWithPmk" +) + +func PossibleValuesForConfidentialVMEncryptionType() []string { + return []string{ + string(ConfidentialVMEncryptionTypeEncryptedVMGuestStateOnlyWithPmk), + string(ConfidentialVMEncryptionTypeEncryptedWithCmk), + string(ConfidentialVMEncryptionTypeEncryptedWithPmk), + } +} + +func (s *ConfidentialVMEncryptionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidentialVMEncryptionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConfidentialVMEncryptionType(input string) (*ConfidentialVMEncryptionType, error) { + vals := map[string]ConfidentialVMEncryptionType{ + "encryptedvmgueststateonlywithpmk": ConfidentialVMEncryptionTypeEncryptedVMGuestStateOnlyWithPmk, + "encryptedwithcmk": ConfidentialVMEncryptionTypeEncryptedWithCmk, + "encryptedwithpmk": ConfidentialVMEncryptionTypeEncryptedWithPmk, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConfidentialVMEncryptionType(input) + return &out, nil +} + +type EdgeZoneStorageAccountType string + +const ( + EdgeZoneStorageAccountTypePremiumLRS EdgeZoneStorageAccountType = "Premium_LRS" + EdgeZoneStorageAccountTypeStandardLRS EdgeZoneStorageAccountType = "Standard_LRS" + EdgeZoneStorageAccountTypeStandardSSDLRS EdgeZoneStorageAccountType = "StandardSSD_LRS" + EdgeZoneStorageAccountTypeStandardZRS EdgeZoneStorageAccountType = "Standard_ZRS" +) + +func PossibleValuesForEdgeZoneStorageAccountType() []string { + return []string{ + string(EdgeZoneStorageAccountTypePremiumLRS), + string(EdgeZoneStorageAccountTypeStandardLRS), + string(EdgeZoneStorageAccountTypeStandardSSDLRS), + string(EdgeZoneStorageAccountTypeStandardZRS), + } +} + +func (s *EdgeZoneStorageAccountType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEdgeZoneStorageAccountType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEdgeZoneStorageAccountType(input string) (*EdgeZoneStorageAccountType, error) { + vals := map[string]EdgeZoneStorageAccountType{ + "premium_lrs": EdgeZoneStorageAccountTypePremiumLRS, + "standard_lrs": EdgeZoneStorageAccountTypeStandardLRS, + "standardssd_lrs": EdgeZoneStorageAccountTypeStandardSSDLRS, + "standard_zrs": EdgeZoneStorageAccountTypeStandardZRS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EdgeZoneStorageAccountType(input) + return &out, nil +} + +type GalleryExtendedLocationType string + +const ( + GalleryExtendedLocationTypeEdgeZone GalleryExtendedLocationType = "EdgeZone" + GalleryExtendedLocationTypeUnknown GalleryExtendedLocationType = "Unknown" +) + +func PossibleValuesForGalleryExtendedLocationType() []string { + return []string{ + string(GalleryExtendedLocationTypeEdgeZone), + string(GalleryExtendedLocationTypeUnknown), + } +} + +func (s *GalleryExtendedLocationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGalleryExtendedLocationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGalleryExtendedLocationType(input string) (*GalleryExtendedLocationType, error) { + vals := map[string]GalleryExtendedLocationType{ + "edgezone": GalleryExtendedLocationTypeEdgeZone, + "unknown": GalleryExtendedLocationTypeUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GalleryExtendedLocationType(input) + return &out, nil +} + +type GalleryProvisioningState string + +const ( + GalleryProvisioningStateCreating GalleryProvisioningState = "Creating" + GalleryProvisioningStateDeleting GalleryProvisioningState = "Deleting" + GalleryProvisioningStateFailed GalleryProvisioningState = "Failed" + GalleryProvisioningStateMigrating GalleryProvisioningState = "Migrating" + GalleryProvisioningStateSucceeded GalleryProvisioningState = "Succeeded" + GalleryProvisioningStateUpdating GalleryProvisioningState = "Updating" +) + +func PossibleValuesForGalleryProvisioningState() []string { + return []string{ + string(GalleryProvisioningStateCreating), + string(GalleryProvisioningStateDeleting), + string(GalleryProvisioningStateFailed), + string(GalleryProvisioningStateMigrating), + string(GalleryProvisioningStateSucceeded), + string(GalleryProvisioningStateUpdating), + } +} + +func (s *GalleryProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGalleryProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGalleryProvisioningState(input string) (*GalleryProvisioningState, error) { + vals := map[string]GalleryProvisioningState{ + "creating": GalleryProvisioningStateCreating, + "deleting": GalleryProvisioningStateDeleting, + "failed": GalleryProvisioningStateFailed, + "migrating": GalleryProvisioningStateMigrating, + "succeeded": GalleryProvisioningStateSucceeded, + "updating": GalleryProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GalleryProvisioningState(input) + return &out, nil +} + +type HostCaching string + +const ( + HostCachingNone HostCaching = "None" + HostCachingReadOnly HostCaching = "ReadOnly" + HostCachingReadWrite HostCaching = "ReadWrite" +) + +func PossibleValuesForHostCaching() []string { + return []string{ + string(HostCachingNone), + string(HostCachingReadOnly), + string(HostCachingReadWrite), + } +} + +func (s *HostCaching) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHostCaching(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHostCaching(input string) (*HostCaching, error) { + vals := map[string]HostCaching{ + "none": HostCachingNone, + "readonly": HostCachingReadOnly, + "readwrite": HostCachingReadWrite, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HostCaching(input) + return &out, nil +} + +type PolicyViolationCategory string + +const ( + PolicyViolationCategoryCopyrightValidation PolicyViolationCategory = "CopyrightValidation" + PolicyViolationCategoryIPTheft PolicyViolationCategory = "IpTheft" + PolicyViolationCategoryImageFlaggedUnsafe PolicyViolationCategory = "ImageFlaggedUnsafe" + PolicyViolationCategoryOther PolicyViolationCategory = "Other" +) + +func PossibleValuesForPolicyViolationCategory() []string { + return []string{ + string(PolicyViolationCategoryCopyrightValidation), + string(PolicyViolationCategoryIPTheft), + string(PolicyViolationCategoryImageFlaggedUnsafe), + string(PolicyViolationCategoryOther), + } +} + +func (s *PolicyViolationCategory) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyViolationCategory(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyViolationCategory(input string) (*PolicyViolationCategory, error) { + vals := map[string]PolicyViolationCategory{ + "copyrightvalidation": PolicyViolationCategoryCopyrightValidation, + "iptheft": PolicyViolationCategoryIPTheft, + "imageflaggedunsafe": PolicyViolationCategoryImageFlaggedUnsafe, + "other": PolicyViolationCategoryOther, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyViolationCategory(input) + return &out, nil +} + +type ReplicationMode string + +const ( + ReplicationModeFull ReplicationMode = "Full" + ReplicationModeShallow ReplicationMode = "Shallow" +) + +func PossibleValuesForReplicationMode() []string { + return []string{ + string(ReplicationModeFull), + string(ReplicationModeShallow), + } +} + +func (s *ReplicationMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReplicationMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReplicationMode(input string) (*ReplicationMode, error) { + vals := map[string]ReplicationMode{ + "full": ReplicationModeFull, + "shallow": ReplicationModeShallow, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReplicationMode(input) + return &out, nil +} + +type ReplicationState string + +const ( + ReplicationStateCompleted ReplicationState = "Completed" + ReplicationStateFailed ReplicationState = "Failed" + ReplicationStateReplicating ReplicationState = "Replicating" + ReplicationStateUnknown ReplicationState = "Unknown" +) + +func PossibleValuesForReplicationState() []string { + return []string{ + string(ReplicationStateCompleted), + string(ReplicationStateFailed), + string(ReplicationStateReplicating), + string(ReplicationStateUnknown), + } +} + +func (s *ReplicationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReplicationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReplicationState(input string) (*ReplicationState, error) { + vals := map[string]ReplicationState{ + "completed": ReplicationStateCompleted, + "failed": ReplicationStateFailed, + "replicating": ReplicationStateReplicating, + "unknown": ReplicationStateUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReplicationState(input) + return &out, nil +} + +type ReplicationStatusTypes string + +const ( + ReplicationStatusTypesReplicationStatus ReplicationStatusTypes = "ReplicationStatus" +) + +func PossibleValuesForReplicationStatusTypes() []string { + return []string{ + string(ReplicationStatusTypesReplicationStatus), + } +} + +func (s *ReplicationStatusTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReplicationStatusTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReplicationStatusTypes(input string) (*ReplicationStatusTypes, error) { + vals := map[string]ReplicationStatusTypes{ + "replicationstatus": ReplicationStatusTypesReplicationStatus, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReplicationStatusTypes(input) + return &out, nil +} + +type StorageAccountType string + +const ( + StorageAccountTypePremiumLRS StorageAccountType = "Premium_LRS" + StorageAccountTypeStandardLRS StorageAccountType = "Standard_LRS" + StorageAccountTypeStandardZRS StorageAccountType = "Standard_ZRS" +) + +func PossibleValuesForStorageAccountType() []string { + return []string{ + string(StorageAccountTypePremiumLRS), + string(StorageAccountTypeStandardLRS), + string(StorageAccountTypeStandardZRS), + } +} + +func (s *StorageAccountType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStorageAccountType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStorageAccountType(input string) (*StorageAccountType, error) { + vals := map[string]StorageAccountType{ + "premium_lrs": StorageAccountTypePremiumLRS, + "standard_lrs": StorageAccountTypeStandardLRS, + "standard_zrs": StorageAccountTypeStandardZRS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StorageAccountType(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/id_galleryimage.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/id_galleryimage.go new file mode 100644 index 000000000000..0eb7b8a22c62 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/id_galleryimage.go @@ -0,0 +1,134 @@ +package galleryimageversions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GalleryImageId{} + +// GalleryImageId is a struct representing the Resource ID for a Gallery Image +type GalleryImageId struct { + SubscriptionId string + ResourceGroupName string + GalleryName string + ImageName string +} + +// NewGalleryImageID returns a new GalleryImageId struct +func NewGalleryImageID(subscriptionId string, resourceGroupName string, galleryName string, imageName string) GalleryImageId { + return GalleryImageId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + GalleryName: galleryName, + ImageName: imageName, + } +} + +// ParseGalleryImageID parses 'input' into a GalleryImageId +func ParseGalleryImageID(input string) (*GalleryImageId, error) { + parser := resourceids.NewParserFromResourceIdType(&GalleryImageId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GalleryImageId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGalleryImageIDInsensitively parses 'input' case-insensitively into a GalleryImageId +// note: this method should only be used for API response data and not user input +func ParseGalleryImageIDInsensitively(input string) (*GalleryImageId, error) { + parser := resourceids.NewParserFromResourceIdType(&GalleryImageId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GalleryImageId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GalleryImageId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.GalleryName, ok = input.Parsed["galleryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "galleryName", input) + } + + if id.ImageName, ok = input.Parsed["imageName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "imageName", input) + } + + return nil +} + +// ValidateGalleryImageID checks that 'input' can be parsed as a Gallery Image ID +func ValidateGalleryImageID(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 := ParseGalleryImageID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Gallery Image ID +func (id GalleryImageId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/galleries/%s/images/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.GalleryName, id.ImageName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Gallery Image ID +func (id GalleryImageId) 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("staticGalleries", "galleries", "galleries"), + resourceids.UserSpecifiedSegment("galleryName", "galleryValue"), + resourceids.StaticSegment("staticImages", "images", "images"), + resourceids.UserSpecifiedSegment("imageName", "imageValue"), + } +} + +// String returns a human-readable description of this Gallery Image ID +func (id GalleryImageId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Gallery Name: %q", id.GalleryName), + fmt.Sprintf("Image Name: %q", id.ImageName), + } + return fmt.Sprintf("Gallery Image (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/id_imageversion.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/id_imageversion.go new file mode 100644 index 000000000000..5501bc7e83b8 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/id_imageversion.go @@ -0,0 +1,143 @@ +package galleryimageversions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ImageVersionId{} + +// ImageVersionId is a struct representing the Resource ID for a Image Version +type ImageVersionId struct { + SubscriptionId string + ResourceGroupName string + GalleryName string + ImageName string + VersionName string +} + +// NewImageVersionID returns a new ImageVersionId struct +func NewImageVersionID(subscriptionId string, resourceGroupName string, galleryName string, imageName string, versionName string) ImageVersionId { + return ImageVersionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + GalleryName: galleryName, + ImageName: imageName, + VersionName: versionName, + } +} + +// ParseImageVersionID parses 'input' into a ImageVersionId +func ParseImageVersionID(input string) (*ImageVersionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ImageVersionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ImageVersionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseImageVersionIDInsensitively parses 'input' case-insensitively into a ImageVersionId +// note: this method should only be used for API response data and not user input +func ParseImageVersionIDInsensitively(input string) (*ImageVersionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ImageVersionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ImageVersionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ImageVersionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.GalleryName, ok = input.Parsed["galleryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "galleryName", input) + } + + if id.ImageName, ok = input.Parsed["imageName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "imageName", input) + } + + if id.VersionName, ok = input.Parsed["versionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "versionName", input) + } + + return nil +} + +// ValidateImageVersionID checks that 'input' can be parsed as a Image Version ID +func ValidateImageVersionID(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 := ParseImageVersionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Image Version ID +func (id ImageVersionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/galleries/%s/images/%s/versions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.GalleryName, id.ImageName, id.VersionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Image Version ID +func (id ImageVersionId) 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("staticGalleries", "galleries", "galleries"), + resourceids.UserSpecifiedSegment("galleryName", "galleryValue"), + resourceids.StaticSegment("staticImages", "images", "images"), + resourceids.UserSpecifiedSegment("imageName", "imageValue"), + resourceids.StaticSegment("staticVersions", "versions", "versions"), + resourceids.UserSpecifiedSegment("versionName", "versionValue"), + } +} + +// String returns a human-readable description of this Image Version ID +func (id ImageVersionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Gallery Name: %q", id.GalleryName), + fmt.Sprintf("Image Name: %q", id.ImageName), + fmt.Sprintf("Version Name: %q", id.VersionName), + } + return fmt.Sprintf("Image Version (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_createorupdate.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_createorupdate.go new file mode 100644 index 000000000000..ad69a8d98012 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_createorupdate.go @@ -0,0 +1,76 @@ +package galleryimageversions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// 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 pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *GalleryImageVersion +} + +// CreateOrUpdate ... +func (c GalleryImageVersionsClient) CreateOrUpdate(ctx context.Context, id ImageVersionId, input GalleryImageVersion) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c GalleryImageVersionsClient) CreateOrUpdateThenPoll(ctx context.Context, id ImageVersionId, input GalleryImageVersion) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_delete.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_delete.go new file mode 100644 index 000000000000..57eff6eb56f4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_delete.go @@ -0,0 +1,71 @@ +package galleryimageversions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// 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 pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c GalleryImageVersionsClient) Delete(ctx context.Context, id ImageVersionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c GalleryImageVersionsClient) DeleteThenPoll(ctx context.Context, id ImageVersionId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_get.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_get.go new file mode 100644 index 000000000000..3c1effc049e3 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_get.go @@ -0,0 +1,83 @@ +package galleryimageversions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// 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 + OData *odata.OData + Model *GalleryImageVersion +} + +type GetOperationOptions struct { + Expand *ReplicationStatusTypes +} + +func DefaultGetOperationOptions() GetOperationOptions { + return GetOperationOptions{} +} + +func (o GetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +// Get ... +func (c GalleryImageVersionsClient) Get(ctx context.Context, id ImageVersionId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model GalleryImageVersion + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_listbygalleryimage.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_listbygalleryimage.go new file mode 100644 index 000000000000..8db8c2cda60c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_listbygalleryimage.go @@ -0,0 +1,91 @@ +package galleryimageversions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByGalleryImageOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GalleryImageVersion +} + +type ListByGalleryImageCompleteResult struct { + LatestHttpResponse *http.Response + Items []GalleryImageVersion +} + +// ListByGalleryImage ... +func (c GalleryImageVersionsClient) ListByGalleryImage(ctx context.Context, id GalleryImageId) (result ListByGalleryImageOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/versions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]GalleryImageVersion `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByGalleryImageComplete retrieves all the results into a single object +func (c GalleryImageVersionsClient) ListByGalleryImageComplete(ctx context.Context, id GalleryImageId) (ListByGalleryImageCompleteResult, error) { + return c.ListByGalleryImageCompleteMatchingPredicate(ctx, id, GalleryImageVersionOperationPredicate{}) +} + +// ListByGalleryImageCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GalleryImageVersionsClient) ListByGalleryImageCompleteMatchingPredicate(ctx context.Context, id GalleryImageId, predicate GalleryImageVersionOperationPredicate) (result ListByGalleryImageCompleteResult, err error) { + items := make([]GalleryImageVersion, 0) + + resp, err := c.ListByGalleryImage(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByGalleryImageCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_update.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_update.go new file mode 100644 index 000000000000..da2897707aed --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_update.go @@ -0,0 +1,74 @@ +package galleryimageversions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// 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 pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *GalleryImageVersion +} + +// Update ... +func (c GalleryImageVersionsClient) Update(ctx context.Context, id ImageVersionId, input GalleryImageVersionUpdate) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c GalleryImageVersionsClient) UpdateThenPoll(ctx context.Context, id ImageVersionId, input GalleryImageVersionUpdate) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_datadiskimageencryption.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_datadiskimageencryption.go new file mode 100644 index 000000000000..73202b2acbbf --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_datadiskimageencryption.go @@ -0,0 +1,9 @@ +package galleryimageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataDiskImageEncryption struct { + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + Lun int64 `json:"lun"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_encryptionimages.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_encryptionimages.go new file mode 100644 index 000000000000..58b77b5ffe72 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_encryptionimages.go @@ -0,0 +1,9 @@ +package galleryimageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EncryptionImages struct { + DataDiskImages *[]DataDiskImageEncryption `json:"dataDiskImages,omitempty"` + OsDiskImage *OSDiskImageEncryption `json:"osDiskImage,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryartifactpublishingprofilebase.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryartifactpublishingprofilebase.go new file mode 100644 index 000000000000..0e29e1bee54d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryartifactpublishingprofilebase.go @@ -0,0 +1,45 @@ +package galleryimageversions + +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 GalleryArtifactPublishingProfileBase struct { + EndOfLifeDate *string `json:"endOfLifeDate,omitempty"` + ExcludeFromLatest *bool `json:"excludeFromLatest,omitempty"` + PublishedDate *string `json:"publishedDate,omitempty"` + ReplicaCount *int64 `json:"replicaCount,omitempty"` + ReplicationMode *ReplicationMode `json:"replicationMode,omitempty"` + StorageAccountType *StorageAccountType `json:"storageAccountType,omitempty"` + TargetExtendedLocations *[]GalleryTargetExtendedLocation `json:"targetExtendedLocations,omitempty"` + TargetRegions *[]TargetRegion `json:"targetRegions,omitempty"` +} + +func (o *GalleryArtifactPublishingProfileBase) GetEndOfLifeDateAsTime() (*time.Time, error) { + if o.EndOfLifeDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndOfLifeDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *GalleryArtifactPublishingProfileBase) SetEndOfLifeDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndOfLifeDate = &formatted +} + +func (o *GalleryArtifactPublishingProfileBase) GetPublishedDateAsTime() (*time.Time, error) { + if o.PublishedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.PublishedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *GalleryArtifactPublishingProfileBase) SetPublishedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.PublishedDate = &formatted +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryartifactversionfullsource.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryartifactversionfullsource.go new file mode 100644 index 000000000000..2101511e20e5 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryartifactversionfullsource.go @@ -0,0 +1,9 @@ +package galleryimageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryArtifactVersionFullSource struct { + CommunityGalleryImageId *string `json:"communityGalleryImageId,omitempty"` + Id *string `json:"id,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_gallerydatadiskimage.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_gallerydatadiskimage.go new file mode 100644 index 000000000000..3184ea8e53de --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_gallerydatadiskimage.go @@ -0,0 +1,11 @@ +package galleryimageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryDataDiskImage struct { + HostCaching *HostCaching `json:"hostCaching,omitempty"` + Lun int64 `json:"lun"` + SizeInGB *int64 `json:"sizeInGB,omitempty"` + Source *GalleryDiskImageSource `json:"source,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_gallerydiskimage.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_gallerydiskimage.go new file mode 100644 index 000000000000..d1075b583fd4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_gallerydiskimage.go @@ -0,0 +1,10 @@ +package galleryimageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryDiskImage struct { + HostCaching *HostCaching `json:"hostCaching,omitempty"` + SizeInGB *int64 `json:"sizeInGB,omitempty"` + Source *GalleryDiskImageSource `json:"source,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_gallerydiskimagesource.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_gallerydiskimagesource.go new file mode 100644 index 000000000000..d6f1022a8e6a --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_gallerydiskimagesource.go @@ -0,0 +1,10 @@ +package galleryimageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryDiskImageSource struct { + Id *string `json:"id,omitempty"` + StorageAccountId *string `json:"storageAccountId,omitempty"` + Uri *string `json:"uri,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryextendedlocation.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryextendedlocation.go new file mode 100644 index 000000000000..a4ac5e30511c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryextendedlocation.go @@ -0,0 +1,9 @@ +package galleryimageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryExtendedLocation struct { + Name *string `json:"name,omitempty"` + Type *GalleryExtendedLocationType `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryimageversion.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryimageversion.go new file mode 100644 index 000000000000..d038f0448b6c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryimageversion.go @@ -0,0 +1,13 @@ +package galleryimageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryImageVersion struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *GalleryImageVersionProperties `json:"properties,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-03/galleryimageversions/model_galleryimageversionproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryimageversionproperties.go new file mode 100644 index 000000000000..0da2fcc7bcf6 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryimageversionproperties.go @@ -0,0 +1,12 @@ +package galleryimageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryImageVersionProperties struct { + ProvisioningState *GalleryProvisioningState `json:"provisioningState,omitempty"` + PublishingProfile *GalleryArtifactPublishingProfileBase `json:"publishingProfile,omitempty"` + ReplicationStatus *ReplicationStatus `json:"replicationStatus,omitempty"` + SafetyProfile *GalleryImageVersionSafetyProfile `json:"safetyProfile,omitempty"` + StorageProfile GalleryImageVersionStorageProfile `json:"storageProfile"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryimageversionsafetyprofile.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryimageversionsafetyprofile.go new file mode 100644 index 000000000000..7b8e16d09954 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryimageversionsafetyprofile.go @@ -0,0 +1,10 @@ +package galleryimageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryImageVersionSafetyProfile struct { + AllowDeletionOfReplicatedLocations *bool `json:"allowDeletionOfReplicatedLocations,omitempty"` + PolicyViolations *[]PolicyViolation `json:"policyViolations,omitempty"` + ReportedForPolicyViolation *bool `json:"reportedForPolicyViolation,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryimageversionstorageprofile.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryimageversionstorageprofile.go new file mode 100644 index 000000000000..91803334ad0f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryimageversionstorageprofile.go @@ -0,0 +1,10 @@ +package galleryimageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryImageVersionStorageProfile struct { + DataDiskImages *[]GalleryDataDiskImage `json:"dataDiskImages,omitempty"` + OsDiskImage *GalleryDiskImage `json:"osDiskImage,omitempty"` + Source *GalleryArtifactVersionFullSource `json:"source,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryimageversionupdate.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryimageversionupdate.go new file mode 100644 index 000000000000..ebddb919c60c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_galleryimageversionupdate.go @@ -0,0 +1,12 @@ +package galleryimageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryImageVersionUpdate struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GalleryImageVersionProperties `json:"properties,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-03/galleryimageversions/model_gallerytargetextendedlocation.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_gallerytargetextendedlocation.go new file mode 100644 index 000000000000..f9b4b77c96cf --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_gallerytargetextendedlocation.go @@ -0,0 +1,12 @@ +package galleryimageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryTargetExtendedLocation struct { + Encryption *EncryptionImages `json:"encryption,omitempty"` + ExtendedLocation *GalleryExtendedLocation `json:"extendedLocation,omitempty"` + ExtendedLocationReplicaCount *int64 `json:"extendedLocationReplicaCount,omitempty"` + Name *string `json:"name,omitempty"` + StorageAccountType *EdgeZoneStorageAccountType `json:"storageAccountType,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_osdiskimageencryption.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_osdiskimageencryption.go new file mode 100644 index 000000000000..791a2890c131 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_osdiskimageencryption.go @@ -0,0 +1,9 @@ +package galleryimageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OSDiskImageEncryption struct { + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + SecurityProfile *OSDiskImageSecurityProfile `json:"securityProfile,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_osdiskimagesecurityprofile.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_osdiskimagesecurityprofile.go new file mode 100644 index 000000000000..f74ac2781cf8 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_osdiskimagesecurityprofile.go @@ -0,0 +1,9 @@ +package galleryimageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OSDiskImageSecurityProfile struct { + ConfidentialVMEncryptionType *ConfidentialVMEncryptionType `json:"confidentialVMEncryptionType,omitempty"` + SecureVMDiskEncryptionSetId *string `json:"secureVMDiskEncryptionSetId,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_policyviolation.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_policyviolation.go new file mode 100644 index 000000000000..9717573fc8c8 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_policyviolation.go @@ -0,0 +1,9 @@ +package galleryimageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyViolation struct { + Category *PolicyViolationCategory `json:"category,omitempty"` + Details *string `json:"details,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_regionalreplicationstatus.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_regionalreplicationstatus.go new file mode 100644 index 000000000000..bc867dae92d5 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_regionalreplicationstatus.go @@ -0,0 +1,11 @@ +package galleryimageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegionalReplicationStatus struct { + Details *string `json:"details,omitempty"` + Progress *int64 `json:"progress,omitempty"` + Region *string `json:"region,omitempty"` + State *ReplicationState `json:"state,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_replicationstatus.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_replicationstatus.go new file mode 100644 index 000000000000..52f236a42d99 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_replicationstatus.go @@ -0,0 +1,9 @@ +package galleryimageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationStatus struct { + AggregatedState *AggregatedReplicationState `json:"aggregatedState,omitempty"` + Summary *[]RegionalReplicationStatus `json:"summary,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_targetregion.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_targetregion.go new file mode 100644 index 000000000000..137ef422ba5f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/model_targetregion.go @@ -0,0 +1,12 @@ +package galleryimageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetRegion struct { + Encryption *EncryptionImages `json:"encryption,omitempty"` + ExcludeFromLatest *bool `json:"excludeFromLatest,omitempty"` + Name string `json:"name"` + RegionalReplicaCount *int64 `json:"regionalReplicaCount,omitempty"` + StorageAccountType *StorageAccountType `json:"storageAccountType,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/predicates.go new file mode 100644 index 000000000000..bd9aebcaedfc --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/predicates.go @@ -0,0 +1,32 @@ +package galleryimageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryImageVersionOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p GalleryImageVersionOperationPredicate) Matches(input GalleryImageVersion) 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.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-03/galleryimageversions/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/version.go new file mode 100644 index 000000000000..1a7f8e9a4139 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/version.go @@ -0,0 +1,12 @@ +package galleryimageversions + +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-03" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/galleryimageversions/%s", defaultApiVersion) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index e1003d8a778d..ed965022d399 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -330,6 +330,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleries github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryapplications github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryapplicationversions github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages +github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/gallerysharingupdate github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-03-01/restorepoints github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-03-01/virtualmachineruncommands From a7096434d350c4f3359cd9b78cfcb73e92f8ed51 Mon Sep 17 00:00:00 2001 From: Steph Date: Wed, 3 Apr 2024 14:17:41 +0200 Subject: [PATCH 3/5] rename several tests and split createupdate for shared image version resource --- .../compute/shared_image_data_source_test.go | 6 +- .../services/compute/shared_image_resource.go | 4 + .../compute/shared_image_resource_test.go | 4 +- .../compute/shared_image_version_resource.go | 87 ++++++++++++++++--- 4 files changed, 83 insertions(+), 18 deletions(-) diff --git a/internal/services/compute/shared_image_data_source_test.go b/internal/services/compute/shared_image_data_source_test.go index 853eae24004d..58e3018977de 100644 --- a/internal/services/compute/shared_image_data_source_test.go +++ b/internal/services/compute/shared_image_data_source_test.go @@ -13,7 +13,7 @@ import ( type SharedImageDataSource struct{} -func TestAccDataSourceAzureRMSharedImage_basic(t *testing.T) { +func TestAccDataSourceSharedImage_basic(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_shared_image", "test") r := SharedImageDataSource{} data.DataSourceTest(t, []acceptance.TestStep{ @@ -26,7 +26,7 @@ func TestAccDataSourceAzureRMSharedImage_basic(t *testing.T) { }) } -func TestAccDataSourceAzureRMSharedImage_basic_hyperVGeneration_V2(t *testing.T) { +func TestAccDataSourceSharedImage_basicHyperVGenerationV2(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_shared_image", "test") r := SharedImageDataSource{} data.DataSourceTest(t, []acceptance.TestStep{ @@ -40,7 +40,7 @@ func TestAccDataSourceAzureRMSharedImage_basic_hyperVGeneration_V2(t *testing.T) }) } -func TestAccDataSourceAzureRMSharedImage_complete(t *testing.T) { +func TestAccDataSourceSharedImage_complete(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_shared_image", "test") r := SharedImageDataSource{} data.DataSourceTest(t, []acceptance.TestStep{ diff --git a/internal/services/compute/shared_image_resource.go b/internal/services/compute/shared_image_resource.go index 0e090be4ab04..3149a6946496 100644 --- a/internal/services/compute/shared_image_resource.go +++ b/internal/services/compute/shared_image_resource.go @@ -388,6 +388,10 @@ func resourceSharedImageUpdate(d *pluginsdk.ResourceData, meta interface{}) erro } } + if d.HasChange("release_note_uri") { + payload.Properties.ReleaseNoteUri = pointer.To(d.Get("release_note_uri").(string)) + } + if d.HasChanges("max_recommended_vcpu_count", "min_recommended_vcpu_count", "max_recommended_memory_in_gb", "min_recommended_memory_in_gb") { recommended, err := expandGalleryImageRecommended(d) if err != nil { diff --git a/internal/services/compute/shared_image_resource_test.go b/internal/services/compute/shared_image_resource_test.go index eabce464dce5..5ab2b8eb1693 100644 --- a/internal/services/compute/shared_image_resource_test.go +++ b/internal/services/compute/shared_image_resource_test.go @@ -34,7 +34,7 @@ func TestAccSharedImage_basic(t *testing.T) { }) } -func TestAccSharedImage_basic_hyperVGeneration_V2(t *testing.T) { +func TestAccSharedImage_basicHyperVGenerationV2(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_shared_image", "test") r := SharedImageResource{} data.ResourceTest(t, r, []acceptance.TestStep{ @@ -50,7 +50,7 @@ func TestAccSharedImage_basic_hyperVGeneration_V2(t *testing.T) { }) } -func TestAccSharedImage_basic_Arm(t *testing.T) { +func TestAccSharedImage_basicArmArchitecture(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_shared_image", "test") r := SharedImageResource{} data.ResourceTest(t, r, []acceptance.TestStep{ diff --git a/internal/services/compute/shared_image_version_resource.go b/internal/services/compute/shared_image_version_resource.go index 65e09f89f6fb..20dba27c41b1 100644 --- a/internal/services/compute/shared_image_version_resource.go +++ b/internal/services/compute/shared_image_version_resource.go @@ -30,9 +30,9 @@ import ( func resourceSharedImageVersion() *pluginsdk.Resource { return &pluginsdk.Resource{ - Create: resourceSharedImageVersionCreateUpdate, + Create: resourceSharedImageVersionCreate, Read: resourceSharedImageVersionRead, - Update: resourceSharedImageVersionCreateUpdate, + Update: resourceSharedImageVersionUpdate, Delete: resourceSharedImageVersionDelete, Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { @@ -201,27 +201,25 @@ func resourceSharedImageVersion() *pluginsdk.Resource { } } -func resourceSharedImageVersionCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { +func resourceSharedImageVersionCreate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.GalleryImageVersionsClient subscriptionId := meta.(*clients.Client).Account.SubscriptionId - ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() id := galleryimageversions.NewImageVersionID(subscriptionId, d.Get("resource_group_name").(string), d.Get("gallery_name").(string), d.Get("image_name").(string), d.Get("name").(string)) - if d.IsNewResource() { - existing, err := client.Get(ctx, id, galleryimageversions.DefaultGetOperationOptions()) - if err != nil { - if !response.WasNotFound(existing.HttpResponse) { - return fmt.Errorf("checking for presence of existing %s: %+v", id, err) - } - } - + existing, err := client.Get(ctx, id, galleryimageversions.DefaultGetOperationOptions()) + if err != nil { if !response.WasNotFound(existing.HttpResponse) { - return tf.ImportAsExistsError("azurerm_shared_image_version", id.ID()) + return fmt.Errorf("checking for presence of existing %s: %+v", id, err) } } + if !response.WasNotFound(existing.HttpResponse) { + return tf.ImportAsExistsError("azurerm_shared_image_version", id.ID()) + } + targetRegions, err := expandSharedImageVersionTargetRegions(d) if err != nil { return err @@ -282,6 +280,69 @@ func resourceSharedImageVersionCreateUpdate(d *pluginsdk.ResourceData, meta inte return resourceSharedImageVersionRead(d, meta) } +func resourceSharedImageVersionUpdate(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Compute.GalleryImageVersionsClient + ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := galleryimageversions.ParseImageVersionID(d.Id()) + if err != nil { + return err + } + + existing, err := client.Get(ctx, *id, galleryimageversions.DefaultGetOperationOptions()) + if err != nil { + if !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for presence of existing %s: %+v", id, err) + } + } + + payload := existing.Model + if payload == nil { + return fmt.Errorf("model is nil for %s", id) + } + + if payload.Properties == nil { + return fmt.Errorf("properties is nil for %s", id) + } + + if payload.Properties.PublishingProfile == nil { + payload.Properties.PublishingProfile = &galleryimageversions.GalleryArtifactPublishingProfileBase{} + } + + if d.HasChange("target_region") { + targetRegions, err := expandSharedImageVersionTargetRegions(d) + if err != nil { + return err + } + + payload.Properties.PublishingProfile.TargetRegions = targetRegions + } + + if d.HasChange("end_of_life_date") { + endOfLifeDate, _ := time.Parse(time.RFC3339, d.Get("end_of_life_date").(string)) + payload.Properties.PublishingProfile.EndOfLifeDate = pointer.To(date.Time{ + Time: endOfLifeDate, + }.String()) + } + + if d.HasChange("exclude_from_latest") { + payload.Properties.PublishingProfile.ExcludeFromLatest = pointer.To(d.Get("exclude_from_latest").(bool)) + } + + if d.HasChange("tags") { + payload.Tags = tags.Expand(d.Get("tags").(map[string]interface{})) + } + + if err := client.CreateOrUpdateThenPoll(ctx, *id, *payload); err != nil { + return fmt.Errorf("updating %s: %+v", id, err) + } + + d.SetId(id.ID()) + + return resourceSharedImageVersionRead(d, meta) +} + func resourceSharedImageVersionRead(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.GalleryImageVersionsClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) From b89c372342bbf4859953ce59f083367463d93a8f Mon Sep 17 00:00:00 2001 From: Steph Date: Wed, 3 Apr 2024 16:08:00 +0200 Subject: [PATCH 4/5] fix issue where latest updated image version isn't returned when obtaining all versions --- .../services/compute/shared_image_version_data_source.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/services/compute/shared_image_version_data_source.go b/internal/services/compute/shared_image_version_data_source.go index 2ba7a7d8ba6b..3b862046e619 100644 --- a/internal/services/compute/shared_image_version_data_source.go +++ b/internal/services/compute/shared_image_version_data_source.go @@ -6,6 +6,7 @@ package compute import ( "context" "fmt" + "github.com/hashicorp/go-azure-helpers/lang/pointer" "time" "github.com/hashicorp/go-azure-helpers/lang/response" @@ -221,8 +222,8 @@ func obtainImage(client *galleryimageversions.GalleryImageVersionsClient, ctx co return nil, fmt.Errorf("parsing published date for %s: %+v", galleryImageId, err) } if recentDate == nil || publishedDate.After(*recentDate) { - recentDate = &publishedDate - image = ¤tImage + recentDate = pointer.To(publishedDate) + image = pointer.To(currentImage) } } } From 1b1de586255ad44525464ce406e3351cfbdeb55a Mon Sep 17 00:00:00 2001 From: Steph Date: Wed, 3 Apr 2024 16:22:11 +0200 Subject: [PATCH 5/5] goimports --- internal/services/compute/shared_image_version_data_source.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/compute/shared_image_version_data_source.go b/internal/services/compute/shared_image_version_data_source.go index 3b862046e619..551619d7e281 100644 --- a/internal/services/compute/shared_image_version_data_source.go +++ b/internal/services/compute/shared_image_version_data_source.go @@ -6,9 +6,9 @@ package compute import ( "context" "fmt" - "github.com/hashicorp/go-azure-helpers/lang/pointer" "time" + "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location"