Skip to content

Commit

Permalink
azurerm_sql_database: add validation to requested_service_objective_n…
Browse files Browse the repository at this point in the history
…ame preventing empty values & panics
  • Loading branch information
katbyte committed Oct 21, 2018
1 parent 2b3b8b1 commit 62f23f6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 112 deletions.
80 changes: 0 additions & 80 deletions azurerm/import_arm_sql_database_test.go

This file was deleted.

48 changes: 25 additions & 23 deletions azurerm/resource_arm_sql_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform/helper/validation"
"github.com/satori/go.uuid"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

Expand Down Expand Up @@ -43,9 +44,10 @@ func resourceArmSqlDatabase() *schema.Resource {
},

"create_mode": {
Type: schema.TypeString,
Optional: true,
Default: string(sql.Default),
Type: schema.TypeString,
Optional: true,
Default: string(sql.Default),
DiffSuppressFunc: suppress.CaseDifference,
ValidateFunc: validation.StringInSlice([]string{
string(sql.Copy),
string(sql.Default),
Expand All @@ -56,7 +58,6 @@ func resourceArmSqlDatabase() *schema.Resource {
string(sql.Restore),
string(sql.RestoreLongTermRetentionBackup),
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},

"import": {
Expand All @@ -75,13 +76,13 @@ func resourceArmSqlDatabase() *schema.Resource {
Sensitive: true,
},
"storage_key_type": {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: suppress.CaseDifference,
ValidateFunc: validation.StringInSlice([]string{
"StorageAccessKey",
"SharedAccessKey",
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},
"administrator_login": {
Type: schema.TypeString,
Expand All @@ -93,22 +94,22 @@ func resourceArmSqlDatabase() *schema.Resource {
Sensitive: true,
},
"authentication_type": {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: suppress.CaseDifference,
ValidateFunc: validation.StringInSlice([]string{
"ADPassword",
"SQL",
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},
"operation_mode": {
Type: schema.TypeString,
Optional: true,
Default: "Import",
Type: schema.TypeString,
Optional: true,
Default: "Import",
DiffSuppressFunc: suppress.CaseDifference,
ValidateFunc: validation.StringInSlice([]string{
"Import",
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},
},
},
Expand All @@ -124,20 +125,20 @@ func resourceArmSqlDatabase() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validateRFC3339Date,
ValidateFunc: validate.RFC3339Time,
},

"edition": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Type: schema.TypeString,
Optional: true,
Computed: true,
DiffSuppressFunc: suppress.CaseDifference,
ValidateFunc: validation.StringInSlice([]string{
string(sql.Basic),
string(sql.Standard),
string(sql.Premium),
string(sql.DataWarehouse),
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},

"collation": {
Expand All @@ -157,14 +158,15 @@ func resourceArmSqlDatabase() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validateUUID,
ValidateFunc: validate.UUID,
},

"requested_service_objective_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
DiffSuppressFunc: suppress.CaseDifference,
ValidateFunc: validation.NoZeroValues,
// TODO: add validation once the Enum's complete
// https://github.com/Azure/azure-rest-api-specs/issues/1609
},
Expand All @@ -173,7 +175,7 @@ func resourceArmSqlDatabase() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validateRFC3339Date,
ValidateFunc: validate.RFC3339Time,
},

"elastic_pool_name": {
Expand Down Expand Up @@ -207,6 +209,7 @@ func resourceArmSqlDatabase() *schema.Resource {
"disabled_alerts": {
Type: schema.TypeSet,
Optional: true,
Set: schema.HashString,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
Expand All @@ -215,7 +218,6 @@ func resourceArmSqlDatabase() *schema.Resource {
"Access_Anomaly",
}, true),
},
Set: schema.HashString,
},

"email_account_admins": {
Expand Down
34 changes: 25 additions & 9 deletions azurerm/resource_arm_sql_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,41 @@ import (
)

func TestAccAzureRMSqlDatabase_basic(t *testing.T) {
resourceName := "azurerm_sql_database.test"
ri := acctest.RandInt()
config := testAccAzureRMSqlDatabase_basic(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMSqlDatabaseDestroy,
Steps: []resource.TestStep{
{
Config: config,
Config: testAccAzureRMSqlDatabase_basic(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSqlDatabaseExists("azurerm_sql_database.test"),
testCheckAzureRMSqlDatabaseExists(resourceName),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"create_mode"},
},
},
})
}

func TestAccAzureRMSqlDatabase_disappears(t *testing.T) {
resourceName := "azurerm_sql_database.test"
ri := acctest.RandInt()
config := testAccAzureRMSqlDatabase_basic(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMSqlDatabaseDestroy,
Steps: []resource.TestStep{
{
Config: config,
Config: testAccAzureRMSqlDatabase_basic(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSqlDatabaseExists(resourceName),
testCheckAzureRMSqlDatabaseDisappears(resourceName),
Expand All @@ -55,20 +60,25 @@ func TestAccAzureRMSqlDatabase_disappears(t *testing.T) {
func TestAccAzureRMSqlDatabase_elasticPool(t *testing.T) {
resourceName := "azurerm_sql_database.test"
ri := acctest.RandInt()
config := testAccAzureRMSqlDatabase_elasticPool(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMSqlDatabaseDestroy,
Steps: []resource.TestStep{
{
Config: config,
Config: testAccAzureRMSqlDatabase_elasticPool(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSqlDatabaseExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "elastic_pool_name", fmt.Sprintf("acctestep%d", ri)),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"create_mode"},
},
},
})
}
Expand Down Expand Up @@ -104,20 +114,26 @@ func TestAccAzureRMSqlDatabase_withTags(t *testing.T) {
}

func TestAccAzureRMSqlDatabase_dataWarehouse(t *testing.T) {
resourceName := "azurerm_sql_database.test"
ri := acctest.RandInt()
config := testAccAzureRMSqlDatabase_dataWarehouse(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMSqlDatabaseDestroy,
Steps: []resource.TestStep{
{
Config: config,
Config: testAccAzureRMSqlDatabase_dataWarehouse(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSqlDatabaseExists("azurerm_sql_database.test"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"create_mode"},
},
},
})
}
Expand Down

0 comments on commit 62f23f6

Please sign in to comment.