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_snapshot - support incremental_enabled #21263

Merged
merged 1 commit into from
Apr 3, 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
14 changes: 14 additions & 0 deletions internal/services/compute/snapshot_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
}
Expand Down Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions internal/services/compute/snapshot_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/snapshot.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---
Expand Down