From 5874d0ca0145109ad4fac02384dc4f808c3dcfee Mon Sep 17 00:00:00 2001 From: Yichun Ma Date: Mon, 3 Apr 2023 19:08:16 +0800 Subject: [PATCH] `azurerm_snapshot` - support `incremental_enabled` --- .../services/compute/snapshot_resource.go | 14 ++++++ .../compute/snapshot_resource_test.go | 46 +++++++++++++++++++ website/docs/r/snapshot.html.markdown | 2 + 3 files changed, 62 insertions(+) diff --git a/internal/services/compute/snapshot_resource.go b/internal/services/compute/snapshot_resource.go index a2a33aeccd0b..58356943cb6c 100644 --- a/internal/services/compute/snapshot_resource.go +++ b/internal/services/compute/snapshot_resource.go @@ -67,6 +67,13 @@ func resourceSnapshot() *pluginsdk.Resource { }, false), }, + "incremental_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + ForceNew: true, + }, + "source_uri": { Type: pluginsdk.TypeString, Optional: true, @@ -143,6 +150,7 @@ func resourceSnapshotCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) e CreationData: snapshots.CreationData{ CreateOption: snapshots.DiskCreateOption(createOption), }, + Incremental: utils.Bool(d.Get("incremental_enabled").(bool)), }, Tags: tags.Expand(t), } @@ -217,6 +225,12 @@ func resourceSnapshotRead(d *pluginsdk.ResourceData, meta interface{}) error { return fmt.Errorf("setting `encryption_settings`: %+v", err) } + incrementalEnabled := false + if props.Incremental != nil { + incrementalEnabled = *props.Incremental + } + d.Set("incremental_enabled", incrementalEnabled) + trustedLaunchEnabled := false if securityProfile := props.SecurityProfile; securityProfile != nil && securityProfile.SecurityType != nil { trustedLaunchEnabled = *securityProfile.SecurityType == snapshots.DiskSecurityTypesTrustedLaunch diff --git a/internal/services/compute/snapshot_resource_test.go b/internal/services/compute/snapshot_resource_test.go index b246b813d25a..a280190d7787 100644 --- a/internal/services/compute/snapshot_resource_test.go +++ b/internal/services/compute/snapshot_resource_test.go @@ -132,6 +132,21 @@ func TestAccSnapshot_fromUnmanagedDisk(t *testing.T) { }) } +func TestAccSnapshot_incrementalEnabled(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_snapshot", "test") + r := SnapshotResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.incrementalEnabled(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("source_uri"), + }) +} + func TestAccSnapshot_trustedLaunch(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_snapshot", "test") r := SnapshotResource{} @@ -606,6 +621,37 @@ resource "azurerm_snapshot" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger, data.RandomInteger) } +func (SnapshotResource) incrementalEnabled(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%[2]d" + location = "%[1]s" +} + +resource "azurerm_managed_disk" "test" { + name = "acctestmd-%[2]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + storage_account_type = "Standard_LRS" + create_option = "Empty" + disk_size_gb = "10" +} + +resource "azurerm_snapshot" "test" { + name = "acctestss_%[2]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + create_option = "Copy" + source_uri = azurerm_managed_disk.test.id + incremental_enabled = true +} +`, data.Locations.Primary, data.RandomInteger) +} + func (SnapshotResource) trustedLaunch(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { diff --git a/website/docs/r/snapshot.html.markdown b/website/docs/r/snapshot.html.markdown index c2f643ad4e3d..7562dd519fde 100644 --- a/website/docs/r/snapshot.html.markdown +++ b/website/docs/r/snapshot.html.markdown @@ -63,6 +63,8 @@ The following arguments are supported: ~> **NOTE:** Removing `encryption_settings` forces a new resource to be created. +* `incremental_enabled` - (Optional) Specifies if the Snapshot is incremental. + * `tags` - (Optional) A mapping of tags to assign to the resource. ---