Skip to content

Commit

Permalink
r/shared_image_gallery: udpating to use a common id
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Nov 6, 2023
1 parent 12c3695 commit 359b2f0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
8 changes: 4 additions & 4 deletions internal/services/compute/gallery_application_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (

"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-sdk/resource-manager/compute/2022-03-03/galleries"
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryapplications"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate"
Expand Down Expand Up @@ -55,7 +55,7 @@ func (r GalleryApplicationResource) Arguments() map[string]*pluginsdk.Schema {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: galleries.ValidateGalleryID,
ValidateFunc: commonids.ValidateSharedImageGalleryID,
},

"location": commonschema.Location(),
Expand Down Expand Up @@ -128,7 +128,7 @@ func (r GalleryApplicationResource) Create() sdk.ResourceFunc {
client := metadata.Client.Compute.GalleryApplicationsClient
subscriptionId := metadata.Client.Account.SubscriptionId

galleryId, err := galleries.ParseGalleryID(state.GalleryId)
galleryId, err := commonids.ParseSharedImageGalleryID(state.GalleryId)
if err != nil {
return err
}
Expand Down Expand Up @@ -203,7 +203,7 @@ func (r GalleryApplicationResource) Read() sdk.ResourceFunc {

state := &GalleryApplicationModel{
Name: id.ApplicationName,
GalleryId: galleries.NewGalleryID(id.SubscriptionId, id.ResourceGroupName, id.GalleryName).ID(),
GalleryId: commonids.NewSharedImageGalleryID(id.SubscriptionId, id.ResourceGroupName, id.GalleryName).ID(),
}

if model := resp.Model; model != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"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"
Expand Down Expand Up @@ -58,7 +59,7 @@ func dataSourceSharedImageGalleryRead(d *pluginsdk.ResourceData, meta interface{
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id := galleries.NewGalleryID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))
id := commonids.NewSharedImageGalleryID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))
resp, err := client.Get(ctx, id, galleries.DefaultGetOperationOptions())
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
Expand Down
23 changes: 14 additions & 9 deletions internal/services/compute/shared_image_gallery_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"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"
Expand All @@ -30,7 +31,7 @@ func resourceSharedImageGallery() *pluginsdk.Resource {
Update: resourceSharedImageGalleryUpdate,
Delete: resourceSharedImageGalleryDelete,
Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error {
_, err := galleries.ParseGalleryID(id)
_, err := commonids.ParseSharedImageGalleryID(id)
return err
}),

Expand Down Expand Up @@ -135,7 +136,7 @@ func resourceSharedImageGalleryCreate(d *pluginsdk.ResourceData, meta interface{
ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d)
defer cancel()

id := galleries.NewGalleryID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))
id := commonids.NewSharedImageGalleryID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))
existing, err := client.Get(ctx, id, galleries.DefaultGetOperationOptions())
if err != nil {
if !response.WasNotFound(existing.HttpResponse) {
Expand Down Expand Up @@ -166,8 +167,10 @@ func resourceSharedImageGalleryCreate(d *pluginsdk.ResourceData, meta interface{
}

if permission == galleries.GallerySharingPermissionTypesCommunity {
gallerySharingUpdateId := gallerysharingupdate.NewGalleryID(id.SubscriptionId, id.ResourceGroupName, id.GalleryName)
if err = gallerySharingUpdateClient.GallerySharingProfileUpdateThenPoll(ctx, gallerySharingUpdateId, gallerysharingupdate.SharingUpdate{OperationType: gallerysharingupdate.SharingUpdateOperationTypesEnableCommunity}); err != nil {
updatePayload := gallerysharingupdate.SharingUpdate{
OperationType: gallerysharingupdate.SharingUpdateOperationTypesEnableCommunity,
}
if err = gallerySharingUpdateClient.GallerySharingProfileUpdateThenPoll(ctx, id, updatePayload); err != nil {
return fmt.Errorf("enabling community sharing of %s: %+v", id, err)
}
}
Expand All @@ -182,7 +185,7 @@ func resourceSharedImageGalleryRead(d *pluginsdk.ResourceData, meta interface{})
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := galleries.ParseGalleryID(d.Id())
id, err := commonids.ParseSharedImageGalleryID(d.Id())
if err != nil {
return err
}
Expand Down Expand Up @@ -229,7 +232,7 @@ func resourceSharedImageGalleryUpdate(d *pluginsdk.ResourceData, meta interface{
ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := galleries.ParseGalleryID(d.Id())
id, err := commonids.ParseSharedImageGalleryID(d.Id())
if err != nil {
return err
}
Expand Down Expand Up @@ -268,7 +271,7 @@ func resourceSharedImageGalleryDelete(d *pluginsdk.ResourceData, meta interface{
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := galleries.ParseGalleryID(d.Id())
id, err := commonids.ParseSharedImageGalleryID(d.Id())
if err != nil {
return err
}
Expand All @@ -281,8 +284,10 @@ func resourceSharedImageGalleryDelete(d *pluginsdk.ResourceData, meta interface{
if model := resp.Model; model != nil {
if prop := model.Properties; prop != nil && prop.SharingProfile != nil && prop.SharingProfile.Permissions != nil {
if pointer.From(prop.SharingProfile.Permissions) == galleries.GallerySharingPermissionTypesCommunity {
gallerySharingUpdateId := gallerysharingupdate.NewGalleryID(id.SubscriptionId, id.ResourceGroupName, id.GalleryName)
if err = gallerySharingUpdateClient.GallerySharingProfileUpdateThenPoll(ctx, gallerySharingUpdateId, gallerysharingupdate.SharingUpdate{OperationType: gallerysharingupdate.SharingUpdateOperationTypesReset}); err != nil {
updatePayload := gallerysharingupdate.SharingUpdate{
OperationType: gallerysharingupdate.SharingUpdateOperationTypesReset,
}
if err = gallerySharingUpdateClient.GallerySharingProfileUpdateThenPoll(ctx, *id, updatePayload); err != nil {
return fmt.Errorf("reseting community sharing of %s: %+v", id, err)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"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-sdk/resource-manager/compute/2022-03-03/galleries"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
Expand Down Expand Up @@ -142,7 +143,7 @@ func TestAccSharedImageGallery_privateGallery(t *testing.T) {
}

func (t SharedImageGalleryResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := galleries.ParseGalleryID(state.ID)
id, err := commonids.ParseSharedImageGalleryID(state.ID)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions internal/services/labservice/lab_service_plan_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"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-sdk/resource-manager/compute/2022-03-03/galleries"
"github.com/hashicorp/go-azure-sdk/resource-manager/labservices/2022-08-01/labplan"
azValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
Expand Down Expand Up @@ -188,7 +187,7 @@ func (r LabServicePlanResource) Arguments() map[string]*pluginsdk.Schema {
"shared_gallery_id": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: galleries.ValidateGalleryID,
ValidateFunc: commonids.ValidateSharedImageGalleryID,
},

"support": {
Expand Down

0 comments on commit 359b2f0

Please sign in to comment.