-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Resource & Data Source:
azurerm_netapp_pool
(#4889)
- Loading branch information
Showing
14 changed files
with
775 additions
and
15 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
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,78 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"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/utils" | ||
) | ||
|
||
func dataSourceArmNetAppPool() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmNetAppPoolRead, | ||
|
||
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, | ||
}, | ||
|
||
"service_level": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"size_in_4_tb": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmNetAppPoolRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).Netapp.PoolClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
name := d.Get("name").(string) | ||
accountName := d.Get("account_name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
|
||
resp, err := client.Get(ctx, resourceGroup, accountName, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("Error: NetApp Pool %q (Resource Group %q) was not found", name, resourceGroup) | ||
} | ||
return fmt.Errorf("Error reading NetApp Pool %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
d.SetId(*resp.ID) | ||
|
||
d.Set("name", name) | ||
d.Set("account_name", accountName) | ||
d.Set("resource_group_name", resourceGroup) | ||
if location := resp.Location; location != nil { | ||
d.Set("location", azure.NormalizeLocation(*location)) | ||
} | ||
if poolProperties := resp.PoolProperties; poolProperties != nil { | ||
d.Set("service_level", poolProperties.ServiceLevel) | ||
if poolProperties.Size != nil { | ||
d.Set("size_in_4_tb", *poolProperties.Size/4398046511104) | ||
} | ||
} | ||
|
||
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 TestAccDataSourceAzureRMNetAppPool_basic(t *testing.T) { | ||
dataSourceName := "data.azurerm_netapp_pool.test" | ||
ri := tf.AccRandTimeInt() | ||
location := testLocation() | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceNetAppPool_basic(ri, location), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "name"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "account_name"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "service_level"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "size_in_4_tb"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceNetAppPool_basic(rInt int, location string) string { | ||
config := testAccAzureRMNetAppPool_basic(rInt, location) | ||
return fmt.Sprintf(` | ||
%s | ||
data "azurerm_netapp_pool" "test" { | ||
resource_group_name = "${azurerm_netapp_pool.test.resource_group_name}" | ||
account_name = "${azurerm_netapp_pool.test.account_name}" | ||
name = "${azurerm_netapp_pool.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package netapp | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
) | ||
|
||
func ValidateNetAppAccountName(v interface{}, k string) (warnings []string, errors []error) { | ||
value := v.(string) | ||
|
||
if !regexp.MustCompile(`^[-_\da-zA-Z]{3,64}$`).MatchString(value) { | ||
errors = append(errors, fmt.Errorf("%q must be between 3 and 64 characters in length and contains only letters, numbers, underscore or hyphens.", k)) | ||
} | ||
|
||
return warnings, errors | ||
} | ||
|
||
func ValidateNetAppPoolName(v interface{}, k string) (warnings []string, errors []error) { | ||
value := v.(string) | ||
|
||
if !regexp.MustCompile(`^[\da-zA-Z][-_\da-zA-Z]{2,63}$`).MatchString(value) { | ||
errors = append(errors, fmt.Errorf("%q must be between 3 and 64 characters in length and start with letters or numbers and contains only letters, numbers, underscore or hyphens.", k)) | ||
} | ||
|
||
return warnings, errors | ||
} |
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.