-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add New Resource & Data Source: azurerm_netapp_volume (#4933)
- Loading branch information
Showing
18 changed files
with
1,441 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
aznetapp "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/netapp" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceArmNetAppVolume() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmNetAppVolumeRead, | ||
|
||
Timeouts: &schema.ResourceTimeout{ | ||
Read: schema.DefaultTimeout(5 * time.Minute), | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: aznetapp.ValidateNetAppPoolName, | ||
}, | ||
|
||
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(), | ||
|
||
"location": azure.SchemaLocationForDataSource(), | ||
|
||
"account_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: aznetapp.ValidateNetAppAccountName, | ||
}, | ||
|
||
"pool_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: aznetapp.ValidateNetAppPoolName, | ||
}, | ||
|
||
"volume_path": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"service_level": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"subnet_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"storage_quota_in_gb": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmNetAppVolumeRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).NetApp.VolumeClient | ||
ctx, cancel := timeouts.ForRead(meta.(*ArmClient).StopContext, d) | ||
defer cancel() | ||
|
||
name := d.Get("name").(string) | ||
accountName := d.Get("account_name").(string) | ||
poolName := d.Get("pool_name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
|
||
resp, err := client.Get(ctx, resourceGroup, accountName, poolName, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("Error: NetApp Volume %q (Resource Group %q) was not found", name, resourceGroup) | ||
} | ||
return fmt.Errorf("Error reading NetApp Volume %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
if resp.ID == nil || *resp.ID == "" { | ||
return fmt.Errorf("Error retrieving NetApp Volume %q (Resource Group %q): ID was nil or empty", name, resourceGroup) | ||
} | ||
|
||
d.SetId(*resp.ID) | ||
|
||
d.Set("name", name) | ||
d.Set("resource_group_name", resourceGroup) | ||
d.Set("account_name", accountName) | ||
d.Set("pool_name", poolName) | ||
if location := resp.Location; location != nil { | ||
d.Set("location", azure.NormalizeLocation(*location)) | ||
} | ||
if props := resp.VolumeProperties; props != nil { | ||
d.Set("volume_path", props.CreationToken) | ||
d.Set("service_level", props.ServiceLevel) | ||
d.Set("subnet_id", props.SubnetID) | ||
|
||
if props.UsageThreshold != nil { | ||
d.Set("storage_quota_in_gb", *props.UsageThreshold/1073741824) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" | ||
) | ||
|
||
func TestAccDataSourceAzureRMNetAppVolume_basic(t *testing.T) { | ||
dataSourceName := "data.azurerm_netapp_volume.test" | ||
ri := tf.AccRandTimeInt() | ||
location := testLocation() | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceNetAppVolume_basic(ri, location), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceName, "volume_path"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "service_level"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "subnet_id"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "storage_quota_in_gb"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceNetAppVolume_basic(rInt int, location string) string { | ||
config := testAccAzureRMNetAppVolume_basic(rInt, location) | ||
return fmt.Sprintf(` | ||
%s | ||
data "azurerm_netapp_volume" "test" { | ||
resource_group_name = "${azurerm_netapp_volume.test.resource_group_name}" | ||
account_name = "${azurerm_netapp_volume.test.account_name}" | ||
pool_name = "${azurerm_netapp_volume.test.pool_name}" | ||
name = "${azurerm_netapp_volume.test.name}" | ||
} | ||
`, config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package netapp | ||
|
||
import "testing" | ||
|
||
func TestValidateNetAppVolumeName(t *testing.T) { | ||
testData := []struct { | ||
input string | ||
expected bool | ||
}{ | ||
{ | ||
// empty | ||
input: "", | ||
expected: false, | ||
}, | ||
{ | ||
// basic example | ||
input: "hello", | ||
expected: true, | ||
}, | ||
{ | ||
// can't start with an underscore | ||
input: "_hello", | ||
expected: false, | ||
}, | ||
{ | ||
// can't end with a dash | ||
input: "hello-", | ||
expected: true, | ||
}, | ||
{ | ||
// can't contain an exclamation mark | ||
input: "hello!", | ||
expected: false, | ||
}, | ||
{ | ||
// dash in the middle | ||
input: "malcolm-in-the-middle", | ||
expected: true, | ||
}, | ||
{ | ||
// can't end with a period | ||
input: "hello.", | ||
expected: false, | ||
}, | ||
{ | ||
// 63 chars | ||
input: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk", | ||
expected: true, | ||
}, | ||
{ | ||
// 64 chars | ||
input: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkj", | ||
expected: true, | ||
}, | ||
{ | ||
// 65 chars | ||
input: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkja", | ||
expected: false, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q..", v.input) | ||
|
||
_, errors := ValidateNetAppVolumeName(v.input, "name") | ||
actual := len(errors) == 0 | ||
if v.expected != actual { | ||
t.Fatalf("Expected %t but got %t", v.expected, actual) | ||
} | ||
} | ||
} | ||
|
||
func TestValidateNetAppVolumeVolumePath(t *testing.T) { | ||
testData := []struct { | ||
input string | ||
expected bool | ||
}{ | ||
{ | ||
// empty | ||
input: "", | ||
expected: false, | ||
}, | ||
{ | ||
// basic example | ||
input: "hello", | ||
expected: true, | ||
}, | ||
{ | ||
// can't start with an underscore | ||
input: "_hello", | ||
expected: false, | ||
}, | ||
{ | ||
// can't end with a dash | ||
input: "hello-", | ||
expected: true, | ||
}, | ||
{ | ||
// can't contain an exclamation mark | ||
input: "hello!", | ||
expected: false, | ||
}, | ||
{ | ||
// dash in the middle | ||
input: "malcolm-in-the-middle", | ||
expected: true, | ||
}, | ||
{ | ||
// can't end with a period | ||
input: "hello.", | ||
expected: false, | ||
}, | ||
{ | ||
// 79 chars | ||
input: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijabcdefgheysudciac", | ||
expected: true, | ||
}, | ||
{ | ||
// 80 chars | ||
input: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkasbdjdssardwyupac", | ||
expected: true, | ||
}, | ||
{ | ||
// 81 chars | ||
input: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkjspoiuytrewqasdfac", | ||
expected: false, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q..", v.input) | ||
|
||
_, errors := ValidateNetAppVolumeVolumePath(v.input, "volume_path") | ||
actual := len(errors) == 0 | ||
if v.expected != actual { | ||
t.Fatalf("Expected %t but got %t", v.expected, actual) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.