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_netapp_volume - support for the snapshot_directory_visible property - Fixes #9143 #12961

Merged
merged 8 commits into from
Aug 17, 2021
30 changes: 20 additions & 10 deletions internal/services/netapp/netapp_volume_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ func resourceNetAppVolume() *pluginsdk.Resource {
},
},
},

"snapshot_directory_visible": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: true,
},
},
}
}
Expand Down Expand Up @@ -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 := ""
Expand Down Expand Up @@ -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{})),
}
Expand Down Expand Up @@ -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)
}
Expand Down
72 changes: 59 additions & 13 deletions internal/services/netapp/netapp_volume_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
25 changes: 14 additions & 11 deletions website/docs/r/netapp_volume.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down