Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_shared_image_gallery: support directly sharing #23570

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading