Skip to content

Commit

Permalink
azurerm_shared_image_gallery: support directly sharing (#23570)
Browse files Browse the repository at this point in the history
* azurerm_shared_image_gallery: support directly sharing

* add test case
  • Loading branch information
ziyeqf authored Oct 16, 2023
1 parent 02d7ca2 commit 9a038f2
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
2 changes: 2 additions & 0 deletions internal/services/compute/shared_image_gallery_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func resourceSharedImageGallery() *pluginsdk.Resource {
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(galleries.GallerySharingPermissionTypesCommunity),
string(galleries.GallerySharingPermissionTypesGroups),
string(galleries.GallerySharingPermissionTypesPrivate),
}, false),
},

Expand Down
76 changes: 76 additions & 0 deletions internal/services/compute/shared_image_gallery_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,36 @@ 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 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 {
Expand Down Expand Up @@ -213,3 +243,49 @@ 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)
}

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)
}
2 changes: 1 addition & 1 deletion website/docs/r/shared_image_gallery.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 9a038f2

Please sign in to comment.