Skip to content

Commit

Permalink
Added support for large volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
Malcolm Morgan committed Mar 15, 2024
1 parent 7fac71a commit 2341b06
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 3 deletions.
7 changes: 7 additions & 0 deletions internal/services/netapp/netapp_volume_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ func dataSourceNetAppVolume() *pluginsdk.Resource {
Type: pluginsdk.TypeBool,
Computed: true,
},

"is_large_volume": {
Type: pluginsdk.TypeBool,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -212,6 +217,8 @@ func dataSourceNetAppVolumeRead(d *pluginsdk.ResourceData, meta interface{}) err
if err := d.Set("data_protection_replication", flattenNetAppVolumeDataProtectionReplication(props.DataProtection)); err != nil {
return fmt.Errorf("setting `data_protection_replication`: %+v", err)
}

d.Set("is_large_volume", props.IsLargeVolume)
}

return nil
Expand Down
1 change: 1 addition & 0 deletions internal/services/netapp/netapp_volume_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestAccDataSourceNetAppVolume_basic(t *testing.T) {
check.That(data.ResourceName).Key("protocols.0").Exists(),
check.That(data.ResourceName).Key("mount_ip_addresses.#").HasValue("1"),
check.That(data.ResourceName).Key("encryption_key_source").HasValue("Microsoft.NetApp"),
check.That(data.ResourceName).Key("is_large_volume").HasValue("false"),
),
},
})
Expand Down
16 changes: 13 additions & 3 deletions internal/services/netapp/netapp_volume_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,8 @@ func resourceNetAppVolume() *pluginsdk.Resource {
},

"storage_quota_in_gb": {
Type: pluginsdk.TypeInt,
Required: true,
ValidateFunc: validation.IntBetween(100, 102400),
Type: pluginsdk.TypeInt,
Required: true,
},

"throughput_in_mibps": {
Expand Down Expand Up @@ -313,6 +312,12 @@ func resourceNetAppVolume() *pluginsdk.Resource {
Optional: true,
Default: false,
},

"is_large_volume": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},
},
}
}
Expand Down Expand Up @@ -474,6 +479,8 @@ func resourceNetAppVolumeCreate(d *pluginsdk.ResourceData, meta interface{}) err
avsDataStoreEnabled = volumes.AvsDataStoreEnabled
}

isLargeVolume := d.Get("is_large_volume").(bool)

parameters := volumes.Volume{
Location: location,
Properties: volumes.VolumeProperties{
Expand All @@ -495,6 +502,7 @@ func resourceNetAppVolumeCreate(d *pluginsdk.ResourceData, meta interface{}) err
},
AvsDataStore: &avsDataStoreEnabled,
SnapshotDirectoryVisible: utils.Bool(snapshotDirectoryVisible),
IsLargeVolume: &isLargeVolume,
},
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
Zones: zones,
Expand Down Expand Up @@ -707,6 +715,8 @@ func resourceNetAppVolumeRead(d *pluginsdk.ResourceData, meta interface{}) error
}
d.Set("smb_access_based_enumeration_enabled", smbAccessBasedEnumeration)

d.Set("is_large_volume", props.IsLargeVolume)

avsDataStore := false
if props.AvsDataStore != nil {
avsDataStore = strings.EqualFold(string(*props.AvsDataStore), string(volumes.AvsDataStoreEnabled))
Expand Down
122 changes: 122 additions & 0 deletions internal/services/netapp/netapp_volume_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ func TestAccNetAppVolume_complete(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("service_level").HasValue("Standard"),
check.That(data.ResourceName).Key("storage_quota_in_gb").HasValue("101"),
check.That(data.ResourceName).Key("is_large_volume").HasValue("false"),
check.That(data.ResourceName).Key("export_policy_rule.#").HasValue("3"),
check.That(data.ResourceName).Key("tags.%").HasValue("3"),
check.That(data.ResourceName).Key("tags.FoO").HasValue("BaR"),
Expand Down Expand Up @@ -326,6 +327,23 @@ func TestAccNetAppVolume_volEncryptionCmkSystemAssigned(t *testing.T) {
})
}

func TestAccNetAppVolume_largeVolume(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_netapp_volume", "test")
r := NetAppVolumeResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.largeVolume(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("storage_quota_in_gb").HasValue("103000"),
check.That(data.ResourceName).Key("is_large_volume").HasValue("true"),
),
},
data.ImportStep(),
})
}

func (t NetAppVolumeResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := volumes.ParseVolumeID(state.ID)
if err != nil {
Expand Down Expand Up @@ -1238,6 +1256,84 @@ resource "azurerm_netapp_pool" "test" {
`, data.RandomInteger, "westus2", data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (NetAppVolumeResource) templateLargePool(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
alias = "all1"
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-netapp-%d"
location = "%s"
tags = {
"CreatedOnDate" = "2022-07-08T23:50:21Z",
"SkipASMAzSecPack" = "true",
"SkipNRMSNSG" = "true"
}
}
resource "azurerm_virtual_network" "test" {
name = "acctest-VirtualNetwork-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
address_space = ["10.6.0.0/16"]
tags = {
"CreatedOnDate" = "2022-07-08T23:50:21Z",
"SkipASMAzSecPack" = "true"
}
}
resource "azurerm_subnet" "test" {
name = "acctest-Subnet-%d"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefixes = ["10.6.2.0/24"]
delegation {
name = "testdelegation"
service_delegation {
name = "Microsoft.Netapp/volumes"
actions = ["Microsoft.Network/networkinterfaces/*", "Microsoft.Network/virtualNetworks/subnets/join/action"]
}
}
}
resource "azurerm_netapp_account" "test" {
name = "acctest-NetAppAccount-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
tags = {
"CreatedOnDate" = "2022-07-08T23:50:21Z",
"SkipASMAzSecPack" = "true"
}
}
resource "azurerm_netapp_pool" "test" {
name = "acctest-NetAppPool-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
account_name = azurerm_netapp_account.test.name
service_level = "Standard"
size_in_tb = "%d"
qos_type = "Manual"
tags = {
"CreatedOnDate" = "2022-07-08T23:50:21Z",
"SkipASMAzSecPack" = "true"
}
}
`, data.RandomInteger, "westus2", data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, 110)
}

func (NetAppVolumeResource) templatePoolQosManual(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down Expand Up @@ -1366,3 +1462,29 @@ resource "azurerm_subnet" "test-non-delegated" {
}
`, data.RandomInteger)
}

func (NetAppVolumeResource) largeVolume(data acceptance.TestData) string {
template := NetAppVolumeResource{}.templateLargePool(data)
return fmt.Sprintf(`
%s
resource "azurerm_netapp_volume" "test" {
name = "acctest-NetAppVolume-%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-%d"
service_level = "Standard"
subnet_id = azurerm_subnet.test.id
storage_quota_in_gb = 103000
is_large_volume = true
throughput_in_mibps = 1.0
tags = {
"CreatedOnDate" = "2022-07-08T23:50:21Z",
"SkipASMAzSecPack" = "true"
}
}
`, template, data.RandomInteger, data.RandomInteger)
}
2 changes: 2 additions & 0 deletions website/docs/d/netapp_volume.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ The following attributes are exported:
* `smb_non_browsable_enabled` - Limits clients from browsing for an SMB share.

* `smb_access_based_enumeration_enabled` - Limits enumeration of files and folders (that is, listing the contents) in SMB only to users with allowed access on the share.

* `is_large_volume` - A boolean specifying if the volume is a large volume.
---

A `data_protection_replication` block exports the following:
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/netapp_volume.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ The following arguments are supported:

* `smb_access_based_enumeration_enabled` - (Optional) Limits enumeration of files and folders (that is, listing the contents) in SMB only to users with allowed access on the share. For instance, if a user doesn't have access to read a file or folder in a share with access-based enumeration enabled, then the file or folder doesn't show up in directory listings. Defaults to `false`. For more information, please refer to [Understand NAS share permissions in Azure NetApp Files](https://learn.microsoft.com/en-us/azure/azure-netapp-files/network-attached-storage-permissions#:~:text=security%20for%20administrators.-,Access%2Dbased%20enumeration,in%20an%20Azure%20NetApp%20Files%20SMB%20volume.%20Only%20contosoadmin%20has%20access.,-In%20the%20below)

* `is_large_volume` - (Optional) A boolean specifying if the volume is a large volume, which is a volume greater than 100 TiB but less than 500 TiB. For more information, please refer to [Requirements and considerations for large volumes](https://learn.microsoft.com/en-us/azure/azure-netapp-files/large-volumes-requirements-considerations)

* `tags` - (Optional) A mapping of tags to assign to the resource.

-> **Note:** It is highly recommended to use the **lifecycle** property as noted in the example since it will prevent an accidental deletion of the volume if the `protocols` argument changes to a different protocol type.
Expand Down

0 comments on commit 2341b06

Please sign in to comment.