From 622e5bf37163b79a996ff263327d56d45083fa0a Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Mon, 16 Oct 2023 14:13:59 +0800 Subject: [PATCH 1/2] azurerm_shared_image_gallery: support directly sharing --- .../compute/shared_image_gallery_resource.go | 2 + .../shared_image_gallery_resource_test.go | 38 +++++++++++++++++++ .../docs/r/shared_image_gallery.html.markdown | 2 +- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/internal/services/compute/shared_image_gallery_resource.go b/internal/services/compute/shared_image_gallery_resource.go index e3f0289327bd..b2b5308d2f3e 100644 --- a/internal/services/compute/shared_image_gallery_resource.go +++ b/internal/services/compute/shared_image_gallery_resource.go @@ -71,6 +71,8 @@ func resourceSharedImageGallery() *pluginsdk.Resource { ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ string(galleries.GallerySharingPermissionTypesCommunity), + string(galleries.GallerySharingPermissionTypesGroups), + string(galleries.GallerySharingPermissionTypesPrivate), }, false), }, diff --git a/internal/services/compute/shared_image_gallery_resource_test.go b/internal/services/compute/shared_image_gallery_resource_test.go index a3af428402d3..cffe34afd529 100644 --- a/internal/services/compute/shared_image_gallery_resource_test.go +++ b/internal/services/compute/shared_image_gallery_resource_test.go @@ -111,6 +111,21 @@ func TestAccSharedImageGallery_communityGallery(t *testing.T) { }) } +func TestAccSharedImageGallery_groupsGallery(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_shared_image_gallery", "test") + r := SharedImageGalleryResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.groupsGallery(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func (t SharedImageGalleryResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { id, err := galleries.ParseGalleryID(state.ID) if err != nil { @@ -213,3 +228,26 @@ resource "azurerm_shared_image_gallery" "test" { } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } + +func (SharedImageGalleryResource) groupsGallery(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_shared_image_gallery" "test" { + name = "acctestsig%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + + sharing { + permission = "Groups" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} diff --git a/website/docs/r/shared_image_gallery.html.markdown b/website/docs/r/shared_image_gallery.html.markdown index a11d93deb059..eeb037b9ee80 100644 --- a/website/docs/r/shared_image_gallery.html.markdown +++ b/website/docs/r/shared_image_gallery.html.markdown @@ -52,7 +52,7 @@ The following arguments are supported: A `sharing` block supports the following: -* `permission` - (Required) The permission of the Shared Image Gallery when sharing. The only possible value now is `Community`. Changing this forces a new resource to be created. +* `permission` - (Required) The permission of the Shared Image Gallery when sharing. Possible values are `Community`, `Groups` and `Private`. Changing this forces a new resource to be created. -> **Note:** This requires that the Preview Feature `Microsoft.Compute/CommunityGalleries` is enabled, see [the documentation](https://learn.microsoft.com/azure/virtual-machines/share-gallery-community?tabs=cli) for more information. From a5df0bd464e5cfb807142a1ddcb4d1712618925f Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Mon, 16 Oct 2023 16:17:39 +0800 Subject: [PATCH 2/2] add test case --- .../shared_image_gallery_resource_test.go | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/internal/services/compute/shared_image_gallery_resource_test.go b/internal/services/compute/shared_image_gallery_resource_test.go index cffe34afd529..9dc421493781 100644 --- a/internal/services/compute/shared_image_gallery_resource_test.go +++ b/internal/services/compute/shared_image_gallery_resource_test.go @@ -126,6 +126,21 @@ func TestAccSharedImageGallery_groupsGallery(t *testing.T) { }) } +func TestAccSharedImageGallery_privateGallery(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_shared_image_gallery", "test") + r := SharedImageGalleryResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.privateGallery(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func (t SharedImageGalleryResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { id, err := galleries.ParseGalleryID(state.ID) if err != nil { @@ -251,3 +266,26 @@ resource "azurerm_shared_image_gallery" "test" { } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } + +func (SharedImageGalleryResource) privateGallery(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_shared_image_gallery" "test" { + name = "acctestsig%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + + sharing { + permission = "Private" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +}