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 NFSv4.1, vol sizing issue #5485

Merged
merged 24 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c13aa59
NFSv4.1 implementation+vol size bug fix+api bump
paulomarquesc Jan 22, 2020
31bd408
Module updates for ANF
paulomarquesc Jan 22, 2020
d014210
Default Nfsv3 test when missing protocol_types
paulomarquesc Jan 23, 2020
edc6ebf
Fixed format with terrafmt tool
paulomarquesc Jan 23, 2020
dfa8017
Attribute deprecation work starting
paulomarquesc Jan 23, 2020
ae59c78
Update azurerm/internal/services/netapp/data_source_netapp_volume.go
paulomarquesc Jan 24, 2020
d2899fa
Applying changes related to PR review
paulomarquesc Jan 26, 2020
6ddef14
Adding protocols and protocols_enabled to example
paulomarquesc Jan 26, 2020
4fa08cd
NFSv4.1 updates
paulomarquesc Jan 26, 2020
df8e8b8
Chaging wording
paulomarquesc Jan 26, 2020
b155983
Supporting only one item on protocols_enabled
paulomarquesc Jan 26, 2020
9ca983e
Reverting changes on go.mod and go.sum
paulomarquesc Jan 26, 2020
96e9a71
Fixing formatting
paulomarquesc Jan 26, 2020
2ddcac2
Removed unnecessary blank lines and comments
paulomarquesc Jan 26, 2020
92ed424
Adding extra line on go.mod
paulomarquesc Jan 26, 2020
db86619
Fixes to latest review round
paulomarquesc Feb 5, 2020
a5126b7
Removed not necessary log entry
paulomarquesc Feb 5, 2020
ab8c302
Fixfing tflint and lintrest CI issues
paulomarquesc Feb 5, 2020
0f40b36
More tflint fixes for CI
paulomarquesc Feb 5, 2020
3345b29
Update website/docs/r/netapp_volume.html.markdown
paulomarquesc Feb 6, 2020
940cd9b
Removing ForceNew and type fix on datasource
paulomarquesc Feb 6, 2020
da8ec80
ForceNew for volume and Type List on export policy
paulomarquesc Mar 4, 2020
af138cb
Changing comments related to v2
paulomarquesc Mar 4, 2020
389941e
git merge master
katbyte Mar 5, 2020
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
2 changes: 1 addition & 1 deletion azurerm/internal/services/netapp/client/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-06-01/netapp"
"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-10-01/netapp"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

Expand Down
21 changes: 21 additions & 0 deletions azurerm/internal/services/netapp/data_source_netapp_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
Expand Down Expand Up @@ -61,6 +62,18 @@ func dataSourceArmNetAppVolume() *schema.Resource {
Type: schema.TypeInt,
Computed: true,
},

"protocol_types": {
paulomarquesc marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
Elem: &schema.Schema{Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
paulomarquesc marked this conversation as resolved.
Show resolved Hide resolved
"NFSv3",
"NFSv4.1",
"CIFS",
}, false)},
},
},
}
}
Expand Down Expand Up @@ -101,6 +114,14 @@ func dataSourceArmNetAppVolumeRead(d *schema.ResourceData, meta interface{}) err
d.Set("service_level", props.ServiceLevel)
d.Set("subnet_id", props.SubnetID)

protocolTypes := make([]string, 0)
if prtclTypes := props.ProtocolTypes; prtclTypes != nil {
for _, protocol := range *prtclTypes {
protocolTypes = append(protocolTypes, protocol)
}
}
d.Set("protocol_types", protocolTypes)

if props.UsageThreshold != nil {
d.Set("storage_quota_in_gb", *props.UsageThreshold/1073741824)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-06-01/netapp"
"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-10-01/netapp"
"github.com/hashicorp/go-azure-helpers/response"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"
"time"

"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-06-01/netapp"
"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-10-01/netapp"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-06-01/netapp"
"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-10-01/netapp"
"github.com/hashicorp/go-azure-helpers/response"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down
32 changes: 23 additions & 9 deletions azurerm/internal/services/netapp/resource_arm_netapp_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-06-01/netapp"
"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-10-01/netapp"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down Expand Up @@ -89,6 +89,18 @@ func resourceArmNetAppVolume() *schema.Resource {
ValidateFunc: azure.ValidateResourceID,
},

"protocol_types": {
paulomarquesc marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeList,
paulomarquesc marked this conversation as resolved.
Show resolved Hide resolved
Required: true,
MaxItems: 1,
Elem: &schema.Schema{Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
"NFSv3",
"NFSv4.1",
"CIFS",
}, false)},
},

"storage_quota_in_gb": {
Type: schema.TypeInt,
Required: true,
Expand Down Expand Up @@ -122,7 +134,7 @@ func resourceArmNetAppVolume() *schema.Resource {
Type: schema.TypeBool,
Required: true,
},
"nfsv4_enabled": {
"nfsv41_enabled": {
paulomarquesc marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeBool,
Required: true,
paulomarquesc marked this conversation as resolved.
Show resolved Hide resolved
},
Expand Down Expand Up @@ -167,6 +179,7 @@ func resourceArmNetAppVolumeCreateUpdate(d *schema.ResourceData, meta interface{
volumePath := d.Get("volume_path").(string)
serviceLevel := d.Get("service_level").(string)
subnetId := d.Get("subnet_id").(string)
protocolTypes := d.Get("protocol_types").([]interface{})
storageQuotaInGB := int64(d.Get("storage_quota_in_gb").(int) * 1073741824)
exportPolicyRule := d.Get("export_policy_rule").(*schema.Set).List()

Expand All @@ -176,6 +189,7 @@ func resourceArmNetAppVolumeCreateUpdate(d *schema.ResourceData, meta interface{
CreationToken: utils.String(volumePath),
ServiceLevel: netapp.ServiceLevel(serviceLevel),
SubnetID: utils.String(subnetId),
ProtocolTypes: utils.ExpandStringSlice(protocolTypes),
katbyte marked this conversation as resolved.
Show resolved Hide resolved
UsageThreshold: utils.Int64(storageQuotaInGB),
ExportPolicy: expandArmNetAppVolumeExportPolicyRule(exportPolicyRule),
},
Expand Down Expand Up @@ -236,7 +250,7 @@ func resourceArmNetAppVolumeRead(d *schema.ResourceData, meta interface{}) error
d.Set("volume_path", props.CreationToken)
d.Set("service_level", props.ServiceLevel)
d.Set("subnet_id", props.SubnetID)

d.Set("protocol_types", props.ProtocolTypes)
if props.UsageThreshold != nil {
d.Set("storage_quota_in_gb", *props.UsageThreshold/1073741824)
}
Expand Down Expand Up @@ -316,15 +330,15 @@ func expandArmNetAppVolumeExportPolicyRule(input []interface{}) *netapp.VolumePr
allowedClients := strings.Join(*utils.ExpandStringSlice(v["allowed_clients"].(*schema.Set).List()), ",")
cifsEnabled := v["cifs_enabled"].(bool)
nfsv3Enabled := v["nfsv3_enabled"].(bool)
nfsv4Enabled := v["nfsv4_enabled"].(bool)
nfsv41Enabled := v["nfsv41_enabled"].(bool)
unixReadOnly := v["unix_read_only"].(bool)
unixReadWrite := v["unix_read_write"].(bool)

result := netapp.ExportPolicyRule{
AllowedClients: utils.String(allowedClients),
Cifs: utils.Bool(cifsEnabled),
Nfsv3: utils.Bool(nfsv3Enabled),
Nfsv4: utils.Bool(nfsv4Enabled),
Nfsv41: utils.Bool(nfsv41Enabled),
RuleIndex: utils.Int32(ruleIndex),
UnixReadOnly: utils.Bool(unixReadOnly),
UnixReadWrite: utils.Bool(unixReadWrite),
Expand Down Expand Up @@ -362,9 +376,9 @@ func flattenArmNetAppVolumeExportPolicyRule(input *netapp.VolumePropertiesExport
if v := item.Nfsv3; v != nil {
nfsv3Enabled = *v
}
nfsv4Enabled := false
if v := item.Nfsv4; v != nil {
nfsv4Enabled = *v
nfsv41Enabled := false
if v := item.Nfsv41; v != nil {
nfsv41Enabled = *v
}
unixReadOnly := false
if v := item.UnixReadOnly; v != nil {
Expand All @@ -380,7 +394,7 @@ func flattenArmNetAppVolumeExportPolicyRule(input *netapp.VolumePropertiesExport
"allowed_clients": utils.FlattenStringSlice(&allowedClients),
"cifs_enabled": cifsEnabled,
"nfsv3_enabled": nfsv3Enabled,
"nfsv4_enabled": nfsv4Enabled,
"nfsv41_enabled": nfsv41Enabled,
"unix_read_only": unixReadOnly,
"unix_read_write": unixReadWrite,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func TestAccDataSourceAzureRMNetAppVolume_basic(t *testing.T) {
resource.TestCheckResourceAttrSet(data.ResourceName, "service_level"),
resource.TestCheckResourceAttrSet(data.ResourceName, "subnet_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "storage_quota_in_gb"),
resource.TestCheckResourceAttrSet(data.ResourceName, "protocol_types.0"),
),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestAccAzureRMNetAppPool_update(t *testing.T) {
Config: testAccAzureRMNetAppPool_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetAppPoolExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "service_level", "Premium"),
resource.TestCheckResourceAttr(data.ResourceName, "service_level", "Standard"),
resource.TestCheckResourceAttr(data.ResourceName, "size_in_tb", "4"),
),
},
Expand Down Expand Up @@ -177,7 +177,7 @@ resource "azurerm_netapp_pool" "test" {
account_name = "${azurerm_netapp_account.test.name}"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
service_level = "Premium"
service_level = "Standard"
size_in_tb = 4
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,47 @@ func TestAccAzureRMNetAppVolume_basic(t *testing.T) {
Config: testAccAzureRMNetAppVolume_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetAppVolumeExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "protocol_types.0", "NFSv3"),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMNetAppVolume_defaultProtocolType(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_netapp_volume", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMNetAppVolumeDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMNetAppVolume_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetAppVolumeExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "protocol_types.0", "NFSv3"),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMNetAppVolume_nfsv41(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_netapp_volume", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMNetAppVolumeDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMNetAppVolume_nfsv41(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetAppVolumeExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "protocol_types.0", "NFSv4.1"),
),
},
data.ImportStep(),
Expand Down Expand Up @@ -71,7 +112,7 @@ func TestAccAzureRMNetAppVolume_complete(t *testing.T) {
Config: testAccAzureRMNetAppVolume_complete(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetAppVolumeExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "service_level", "Premium"),
resource.TestCheckResourceAttr(data.ResourceName, "service_level", "Standard"),
resource.TestCheckResourceAttr(data.ResourceName, "storage_quota_in_gb", "101"),
resource.TestCheckResourceAttr(data.ResourceName, "export_policy_rule.#", "2"),
),
Expand Down Expand Up @@ -250,8 +291,48 @@ resource "azurerm_netapp_volume" "test" {
account_name = "${azurerm_netapp_account.test.name}"
pool_name = "${azurerm_netapp_pool.test.name}"
volume_path = "my-unique-file-path-%d"
service_level = "Premium"
service_level = "Standard"
subnet_id = "${azurerm_subnet.test.id}"
protocol_types = ["NFSv3"]
storage_quota_in_gb = 100
}
`, template, data.RandomInteger, data.RandomInteger)
}

func testAccAzureRMNetAppVolume_defaultProtocolType(data acceptance.TestData) string {
template := testAccAzureRMNetAppVolume_template(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 = 100
}
`, template, data.RandomInteger, data.RandomInteger)
}

func testAccAzureRMNetAppVolume_nfsv41(data acceptance.TestData) string {
template := testAccAzureRMNetAppVolume_template(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}"
protocol_types = ["NFSv4.1"]
storage_quota_in_gb = 100
}
`, template, data.RandomInteger, data.RandomInteger)
Expand Down Expand Up @@ -280,17 +361,18 @@ resource "azurerm_netapp_volume" "test" {
resource_group_name = "${azurerm_resource_group.test.name}"
account_name = "${azurerm_netapp_account.test.name}"
pool_name = "${azurerm_netapp_pool.test.name}"
service_level = "Premium"
service_level = "Standard"
volume_path = "my-unique-file-path-%d"
subnet_id = "${azurerm_subnet.test.id}"
protocol_types = ["NFSv3"]
storage_quota_in_gb = 101

export_policy_rule {
rule_index = 1
allowed_clients = ["1.2.3.0/24"]
cifs_enabled = false
nfsv3_enabled = true
nfsv4_enabled = false
nfsv41_enabled = false
unix_read_only = false
unix_read_write = true
}
Expand All @@ -300,7 +382,7 @@ resource "azurerm_netapp_volume" "test" {
allowed_clients = ["1.2.5.0"]
cifs_enabled = false
nfsv3_enabled = true
nfsv4_enabled = false
nfsv41_enabled = false
unix_read_only = true
unix_read_write = false
}
Expand Down Expand Up @@ -343,8 +425,9 @@ resource "azurerm_netapp_volume" "test" {
account_name = "${azurerm_netapp_account.test.name}"
pool_name = "${azurerm_netapp_pool.test.name}"
volume_path = "my-updated-unique-file-path-%d"
service_level = "Premium"
service_level = "Standard"
subnet_id = "${azurerm_subnet.updated.id}"
protocol_types = ["NFSv3"]
storage_quota_in_gb = 100
}
`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
Expand All @@ -361,17 +444,18 @@ resource "azurerm_netapp_volume" "test" {
resource_group_name = "${azurerm_resource_group.test.name}"
account_name = "${azurerm_netapp_account.test.name}"
pool_name = "${azurerm_netapp_pool.test.name}"
service_level = "Premium"
service_level = "Standard"
volume_path = "my-unique-file-path-%d"
subnet_id = "${azurerm_subnet.test.id}"
protocol_types = ["NFSv3"]
storage_quota_in_gb = 101

export_policy_rule {
rule_index = 1
allowed_clients = ["1.2.4.0/24", "1.3.4.0"]
cifs_enabled = false
nfsv3_enabled = true
nfsv4_enabled = false
nfsv41_enabled = false
unix_read_only = false
unix_read_write = true
}
Expand Down Expand Up @@ -420,7 +504,7 @@ resource "azurerm_netapp_pool" "test" {
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
account_name = "${azurerm_netapp_account.test.name}"
service_level = "Premium"
service_level = "Standard"
size_in_tb = 4
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
Expand Down
Loading