diff --git a/internal/services/netapp/netapp_volume_resource.go b/internal/services/netapp/netapp_volume_resource.go index f2d00209a3d9..432a9fe02d0f 100644 --- a/internal/services/netapp/netapp_volume_resource.go +++ b/internal/services/netapp/netapp_volume_resource.go @@ -254,6 +254,12 @@ func resourceNetAppVolume() *pluginsdk.Resource { }, }, }, + + "snapshot_directory_visible": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: true, + }, }, } } @@ -313,6 +319,8 @@ func resourceNetAppVolumeCreateUpdate(d *pluginsdk.ResourceData, meta interface{ volumeType = "DataProtection" } + snapshotDirectoryVisible := d.Get("snapshot_directory_visible").(bool) + // Handling volume creation from snapshot case snapshotResourceID := d.Get("create_from_snapshot_resource_id").(string) snapshotID := "" @@ -383,16 +391,17 @@ func resourceNetAppVolumeCreateUpdate(d *pluginsdk.ResourceData, meta interface{ parameters := netapp.Volume{ Location: utils.String(location), VolumeProperties: &netapp.VolumeProperties{ - CreationToken: utils.String(volumePath), - ServiceLevel: netapp.ServiceLevel(serviceLevel), - SubnetID: utils.String(subnetID), - ProtocolTypes: utils.ExpandStringSlice(protocols), - SecurityStyle: netapp.SecurityStyle(securityStyle), - UsageThreshold: utils.Int64(storageQuotaInGB), - ExportPolicy: exportPolicyRule, - VolumeType: utils.String(volumeType), - SnapshotID: utils.String(snapshotID), - DataProtection: dataProtectionReplication, + CreationToken: utils.String(volumePath), + ServiceLevel: netapp.ServiceLevel(serviceLevel), + SubnetID: utils.String(subnetID), + ProtocolTypes: utils.ExpandStringSlice(protocols), + SecurityStyle: netapp.SecurityStyle(securityStyle), + UsageThreshold: utils.Int64(storageQuotaInGB), + ExportPolicy: exportPolicyRule, + VolumeType: utils.String(volumeType), + SnapshotID: utils.String(snapshotID), + DataProtection: dataProtectionReplication, + SnapshotDirectoryVisible: utils.Bool(snapshotDirectoryVisible), }, Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } @@ -483,6 +492,7 @@ func resourceNetAppVolumeRead(d *pluginsdk.ResourceData, meta interface{}) error d.Set("subnet_id", props.SubnetID) d.Set("protocols", props.ProtocolTypes) d.Set("security_style", props.SecurityStyle) + d.Set("snapshot_directory_visible", props.SnapshotDirectoryVisible) if props.UsageThreshold != nil { d.Set("storage_quota_in_gb", *props.UsageThreshold/1073741824) } diff --git a/internal/services/netapp/netapp_volume_resource_test.go b/internal/services/netapp/netapp_volume_resource_test.go index 888cdadb688e..f5ba29497a41 100644 --- a/internal/services/netapp/netapp_volume_resource_test.go +++ b/internal/services/netapp/netapp_volume_resource_test.go @@ -78,6 +78,22 @@ func TestAccNetAppVolume_nfsv3FromSnapshot(t *testing.T) { }) } +func TestAccNetAppVolume_nfsv3SnapshotDirectoryVisibleFalse(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_netapp_volume", "test_snapshot_directory_visible_false") + r := NetAppVolumeResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.nfsv3SnapshotDirectoryVisibleFalse(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("snapshot_directory_visible").HasValue("false"), + ), + }, + data.ImportStep(), + }) +} + func TestAccNetAppVolume_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_netapp_volume", "test") r := NetAppVolumeResource{} @@ -303,16 +319,17 @@ resource "azurerm_netapp_volume" "test_primary" { } resource "azurerm_netapp_volume" "test_secondary" { - name = "acctest-NetAppVolume-secondary-%[2]d" - location = "%[3]s" - resource_group_name = azurerm_resource_group.test.name - account_name = azurerm_netapp_account.test_secondary.name - pool_name = azurerm_netapp_pool.test_secondary.name - volume_path = "my-unique-file-path-secondary-%[2]d" - service_level = "Standard" - subnet_id = azurerm_subnet.test_secondary.id - protocols = ["NFSv3"] - storage_quota_in_gb = 100 + name = "acctest-NetAppVolume-secondary-%[2]d" + location = "%[3]s" + resource_group_name = azurerm_resource_group.test.name + account_name = azurerm_netapp_account.test_secondary.name + pool_name = azurerm_netapp_pool.test_secondary.name + volume_path = "my-unique-file-path-secondary-%[2]d" + service_level = "Standard" + subnet_id = azurerm_subnet.test_secondary.id + protocols = ["NFSv3"] + storage_quota_in_gb = 100 + snapshot_directory_visible = false export_policy_rule { rule_index = 1 @@ -329,7 +346,7 @@ resource "azurerm_netapp_volume" "test_secondary" { replication_frequency = "10minutes" } } -`, template, data.RandomInteger, "northeurope") +`, template, data.RandomInteger, "germanywestcentral") } func (NetAppVolumeResource) nfsv3FromSnapshot(data acceptance.TestData) string { @@ -390,6 +407,35 @@ resource "azurerm_netapp_volume" "test_snapshot_vol" { `, template, data.RandomInteger) } +func (NetAppVolumeResource) nfsv3SnapshotDirectoryVisibleFalse(data acceptance.TestData) string { + template := NetAppVolumeResource{}.template(data) + return fmt.Sprintf(` +%[1]s + +resource "azurerm_netapp_volume" "test_snapshot_directory_visible_false" { + name = "acctest-NetAppVolume-%[2]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + account_name = azurerm_netapp_account.test.name + pool_name = azurerm_netapp_pool.test.name + volume_path = "my-unique-file-path-%[2]d" + service_level = "Standard" + subnet_id = azurerm_subnet.test.id + protocols = ["NFSv3"] + storage_quota_in_gb = 100 + snapshot_directory_visible = false + + export_policy_rule { + rule_index = 1 + allowed_clients = ["1.2.3.0/24"] + protocols_enabled = ["NFSv3"] + unix_read_only = false + unix_read_write = true + } +} +`, template, data.RandomInteger) +} + func (r NetAppVolumeResource) requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -572,7 +618,7 @@ resource "azurerm_netapp_pool" "test_secondary" { service_level = "Standard" size_in_tb = 4 } -`, r.template(data), data.RandomInteger, "northeurope") +`, r.template(data), data.RandomInteger, "germanywestcentral") } func (NetAppVolumeResource) template(data acceptance.TestData) string { @@ -623,5 +669,5 @@ resource "azurerm_netapp_pool" "test" { service_level = "Standard" size_in_tb = 4 } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, data.RandomInteger, data.Locations.Ternary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/website/docs/r/netapp_volume.html.markdown b/website/docs/r/netapp_volume.html.markdown index e9da626ffe42..21854adc0919 100644 --- a/website/docs/r/netapp_volume.html.markdown +++ b/website/docs/r/netapp_volume.html.markdown @@ -61,17 +61,18 @@ resource "azurerm_netapp_volume" "example" { prevent_destroy = true } - name = "example-netappvolume" - location = azurerm_resource_group.example.location - resource_group_name = azurerm_resource_group.example.name - account_name = azurerm_netapp_account.example.name - pool_name = azurerm_netapp_pool.example.name - volume_path = "my-unique-file-path" - service_level = "Premium" - subnet_id = azurerm_subnet.example.id - protocols = ["NFSv4.1"] - security_style = "Unix" - storage_quota_in_gb = 100 + name = "example-netappvolume" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + account_name = azurerm_netapp_account.example.name + pool_name = azurerm_netapp_pool.example.name + volume_path = "my-unique-file-path" + service_level = "Premium" + subnet_id = azurerm_subnet.example.id + protocols = ["NFSv4.1"] + security_style = "Unix" + storage_quota_in_gb = 100 + snapshot_directory_visible = false # When creating volume from a snapshot create_from_snapshot_resource_id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.NetApp/netAppAccounts/account1/capacityPools/pool1/volumes/volume1/snapshots/snapshot1" @@ -113,6 +114,8 @@ The following arguments are supported: * `storage_quota_in_gb` - (Required) The maximum Storage Quota allowed for a file system in Gigabytes. +* `snapshot_directory_visible` - (Optional) Specifies whether the .snapshot (NFS clients) or ~snapshot (SMB clients) path of a volume is visible, default value is true. + * `create_from_snapshot_resource_id` - (Optional) Creates volume from snapshot. Following properties must be the same as the original volume where the snapshot was taken from: `protocols`, `subnet_id`, `location`, `service_level`, `resource_group_name`, `account_name` and `pool_name`. * `data_protection_replication` - (Optional) A `data_protection_replication` block as defined below.