Skip to content

Commit

Permalink
Merge pull request #17289 from myc2h6o/image_forcenew
Browse files Browse the repository at this point in the history
`r\shared_image`: add `ForceNew` to `publisher` `offer` `sku` `privacy_statement_uri`
  • Loading branch information
tombuildsstuff authored Jun 22, 2022
2 parents 34511ef + 810d194 commit 83cf04a
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 4 deletions.
4 changes: 4 additions & 0 deletions internal/services/compute/shared_image_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,17 @@ func resourceSharedImage() *pluginsdk.Resource {
Schema: map[string]*pluginsdk.Schema{
"publisher": {
Type: pluginsdk.TypeString,
ForceNew: true,
Required: true,
},
"offer": {
Type: pluginsdk.TypeString,
ForceNew: true,
Required: true,
},
"sku": {
Type: pluginsdk.TypeString,
ForceNew: true,
Required: true,
},
},
Expand Down Expand Up @@ -142,6 +145,7 @@ func resourceSharedImage() *pluginsdk.Resource {

"privacy_statement_uri": {
Type: pluginsdk.TypeString,
ForceNew: true,
Optional: true,
},

Expand Down
178 changes: 178 additions & 0 deletions internal/services/compute/shared_image_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,48 @@ func TestAccSharedImage_withAcceleratedNetworkSupportEnabled(t *testing.T) {
})
}

func TestAccSharedImage_description(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_shared_image", "test")
r := SharedImageResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.description(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.descriptionUpdated(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccSharedImage_releaseNoteURI(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_shared_image", "test")
r := SharedImageResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.releaseNoteURI(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.releaseNoteURIUpdated(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (t SharedImageResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.SharedImageID(state.ID)
if err != nil {
Expand Down Expand Up @@ -348,3 +390,139 @@ resource "azurerm_shared_image" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (SharedImageResource) description(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%[2]d"
location = "%[1]s"
}
resource "azurerm_shared_image_gallery" "test" {
name = "acctestsig%[2]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
}
resource "azurerm_shared_image" "test" {
name = "acctestimg%[2]d"
gallery_name = azurerm_shared_image_gallery.test.name
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
os_type = "Linux"
description = "image description"
identifier {
publisher = "AccTesPublisher%[2]d"
offer = "AccTesOffer%[2]d"
sku = "AccTesSku%[2]d"
}
}
`, data.Locations.Primary, data.RandomInteger)
}

func (SharedImageResource) descriptionUpdated(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%[2]d"
location = "%[1]s"
}
resource "azurerm_shared_image_gallery" "test" {
name = "acctestsig%[2]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
}
resource "azurerm_shared_image" "test" {
name = "acctestimg%[2]d"
gallery_name = azurerm_shared_image_gallery.test.name
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
os_type = "Linux"
description = "image description updated"
identifier {
publisher = "AccTesPublisher%[2]d"
offer = "AccTesOffer%[2]d"
sku = "AccTesSku%[2]d"
}
}
`, data.Locations.Primary, data.RandomInteger)
}

func (SharedImageResource) releaseNoteURI(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%[2]d"
location = "%[1]s"
}
resource "azurerm_shared_image_gallery" "test" {
name = "acctestsig%[2]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
}
resource "azurerm_shared_image" "test" {
name = "acctestimg%[2]d"
gallery_name = azurerm_shared_image_gallery.test.name
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
os_type = "Linux"
release_note_uri = "https://test.com/changelog.md"
identifier {
publisher = "AccTesPublisher%[2]d"
offer = "AccTesOffer%[2]d"
sku = "AccTesSku%[2]d"
}
}
`, data.Locations.Primary, data.RandomInteger)
}

func (SharedImageResource) releaseNoteURIUpdated(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%[2]d"
location = "%[1]s"
}
resource "azurerm_shared_image_gallery" "test" {
name = "acctestsig%[2]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
}
resource "azurerm_shared_image" "test" {
name = "acctestimg%[2]d"
gallery_name = azurerm_shared_image_gallery.test.name
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
os_type = "Linux"
release_note_uri = "https://test.com/changelog2.md"
identifier {
publisher = "AccTesPublisher%[2]d"
offer = "AccTesOffer%[2]d"
sku = "AccTesSku%[2]d"
}
}
`, data.Locations.Primary, data.RandomInteger)
}
8 changes: 4 additions & 4 deletions website/docs/r/shared_image.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The following arguments are supported:

* `hyper_v_generation` - (Optional) The generation of HyperV that the Virtual Machine used to create the Shared Image is based on. Possible values are `V1` and `V2`. Defaults to `V1`. Changing this forces a new resource to be created.

* `privacy_statement_uri` - (Optional) The URI containing the Privacy Statement associated with this Shared Image.
* `privacy_statement_uri` - (Optional) The URI containing the Privacy Statement associated with this Shared Image. Changing this forces a new resource to be created.

* `release_note_uri` - (Optional) The URI containing the Release Notes associated with this Shared Image.

Expand All @@ -90,11 +90,11 @@ The following arguments are supported:

A `identifier` block supports the following:

* `offer` - (Required) The Offer Name for this Shared Image.
* `offer` - (Required) The Offer Name for this Shared Image. Changing this forces a new resource to be created.

* `publisher` - (Required) The Publisher Name for this Gallery Image.
* `publisher` - (Required) The Publisher Name for this Gallery Image. Changing this forces a new resource to be created.

* `sku` - (Required) The Name of the SKU for this Gallery Image.
* `sku` - (Required) The Name of the SKU for this Gallery Image. Changing this forces a new resource to be created.

---

Expand Down

0 comments on commit 83cf04a

Please sign in to comment.