Skip to content

Commit 9089b41

Browse files
committed
provider/azurerm: Support AzureRM Sql Database DataWarehouse
Fixes hashicorp#9194 Removes the validation for the types and adds an acceptance test to make sure we get a successful Sql Database created ``` % make testacc TEST=./builtin/providers/azurerm TESTARGS='-run=TestAccAzureRMSqlDatabase_datawarehouse' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/10/03 21:57:16 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/azurerm -v -run=TestAccAzureRMSqlDatabase_datawarehouse -timeout 120m === RUN TestAccAzureRMSqlDatabase_datawarehouse --- PASS: TestAccAzureRMSqlDatabase_datawarehouse (307.95s) PASS ok github.com/hashicorp/terraform/builtin/providers/azurerm307.963s ```
1 parent a879323 commit 9089b41

3 files changed

Lines changed: 78 additions & 31 deletions

File tree

builtin/providers/azurerm/resource_arm_sql_database.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,103 +17,103 @@ func resourceArmSqlDatabase() *schema.Resource {
1717
Delete: resourceArmSqlDatabaseDelete,
1818

1919
Schema: map[string]*schema.Schema{
20-
"name": &schema.Schema{
20+
"name": {
2121
Type: schema.TypeString,
2222
Required: true,
2323
ForceNew: true,
2424
},
2525

26-
"location": &schema.Schema{
26+
"location": {
2727
Type: schema.TypeString,
2828
Required: true,
2929
ForceNew: true,
3030
StateFunc: azureRMNormalizeLocation,
3131
},
3232

33-
"resource_group_name": &schema.Schema{
33+
"resource_group_name": {
3434
Type: schema.TypeString,
3535
Required: true,
3636
ForceNew: true,
3737
},
3838

39-
"server_name": &schema.Schema{
39+
"server_name": {
4040
Type: schema.TypeString,
4141
Required: true,
4242
ForceNew: true,
4343
},
4444

45-
"create_mode": &schema.Schema{
45+
"create_mode": {
4646
Type: schema.TypeString,
4747
Optional: true,
4848
Default: "Default",
4949
},
5050

51-
"source_database_id": &schema.Schema{
51+
"source_database_id": {
5252
Type: schema.TypeString,
5353
Optional: true,
5454
Computed: true,
5555
},
5656

57-
"restore_point_in_time": &schema.Schema{
57+
"restore_point_in_time": {
5858
Type: schema.TypeString,
5959
Optional: true,
6060
Computed: true,
6161
},
6262

63-
"edition": &schema.Schema{
63+
"edition": {
6464
Type: schema.TypeString,
6565
Optional: true,
6666
Computed: true,
6767
ValidateFunc: validateArmSqlDatabaseEdition,
6868
},
6969

70-
"collation": &schema.Schema{
70+
"collation": {
7171
Type: schema.TypeString,
7272
Optional: true,
7373
Computed: true,
7474
},
7575

76-
"max_size_bytes": &schema.Schema{
76+
"max_size_bytes": {
7777
Type: schema.TypeString,
7878
Optional: true,
7979
Computed: true,
8080
},
8181

82-
"requested_service_objective_id": &schema.Schema{
82+
"requested_service_objective_id": {
8383
Type: schema.TypeString,
8484
Optional: true,
8585
Computed: true,
8686
},
8787

88-
"requested_service_objective_name": &schema.Schema{
88+
"requested_service_objective_name": {
8989
Type: schema.TypeString,
9090
Optional: true,
9191
Computed: true,
9292
},
9393

94-
"source_database_deletion_date": &schema.Schema{
94+
"source_database_deletion_date": {
9595
Type: schema.TypeString,
9696
Optional: true,
9797
Computed: true,
9898
},
9999

100-
"elastic_pool_name": &schema.Schema{
100+
"elastic_pool_name": {
101101
Type: schema.TypeString,
102102
Optional: true,
103103
Computed: true,
104104
},
105105

106-
"encryption": &schema.Schema{
106+
"encryption": {
107107
Type: schema.TypeString,
108108
Computed: true,
109109
},
110110

111-
"creation_date": &schema.Schema{
111+
"creation_date": {
112112
Type: schema.TypeString,
113113
Computed: true,
114114
},
115115

116-
"default_secondary_location": &schema.Schema{
116+
"default_secondary_location": {
117117
Type: schema.TypeString,
118118
Computed: true,
119119
},
@@ -245,13 +245,13 @@ func resourceArmSqlDatabaseDelete(d *schema.ResourceData, meta interface{}) erro
245245

246246
func validateArmSqlDatabaseEdition(v interface{}, k string) (ws []string, errors []error) {
247247
editions := map[string]bool{
248-
"Basic": true,
249-
"Standard": true,
250-
"Premium": true,
248+
"Basic": true,
249+
"Standard": true,
250+
"Premium": true,
251+
"DataWarehouse": true,
251252
}
252-
253253
if !editions[v.(string)] {
254-
errors = append(errors, fmt.Errorf("SQL Database Edition can only be Basic, Standard or Premium"))
254+
errors = append(errors, fmt.Errorf("SQL Database Edition can only be Basic, Standard, Premium or DataWarehouse"))
255255
}
256256
return
257257
}

builtin/providers/azurerm/resource_arm_sql_database_test.go

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ func TestResourceAzureRMSqlDatabaseEdition_validation(t *testing.T) {
3131
Value: "Premium",
3232
ErrCount: 0,
3333
},
34+
{
35+
Value: "DataWarehouse",
36+
ErrCount: 0,
37+
},
3438
}
3539

3640
for _, tc := range cases {
@@ -51,7 +55,7 @@ func TestAccAzureRMSqlDatabase_basic(t *testing.T) {
5155
Providers: testAccProviders,
5256
CheckDestroy: testCheckAzureRMSqlDatabaseDestroy,
5357
Steps: []resource.TestStep{
54-
resource.TestStep{
58+
{
5559
Config: config,
5660
Check: resource.ComposeTestCheckFunc(
5761
testCheckAzureRMSqlDatabaseExists("azurerm_sql_database.test"),
@@ -71,16 +75,15 @@ func TestAccAzureRMSqlDatabase_withTags(t *testing.T) {
7175
Providers: testAccProviders,
7276
CheckDestroy: testCheckAzureRMSqlDatabaseDestroy,
7377
Steps: []resource.TestStep{
74-
resource.TestStep{
78+
{
7579
Config: preConfig,
7680
Check: resource.ComposeTestCheckFunc(
7781
testCheckAzureRMSqlDatabaseExists("azurerm_sql_database.test"),
7882
resource.TestCheckResourceAttr(
7983
"azurerm_sql_database.test", "tags.%", "2"),
8084
),
8185
},
82-
83-
resource.TestStep{
86+
{
8487
Config: postConfig,
8588
Check: resource.ComposeTestCheckFunc(
8689
testCheckAzureRMSqlDatabaseExists("azurerm_sql_database.test"),
@@ -92,6 +95,25 @@ func TestAccAzureRMSqlDatabase_withTags(t *testing.T) {
9295
})
9396
}
9497

98+
func TestAccAzureRMSqlDatabase_datawarehouse(t *testing.T) {
99+
ri := acctest.RandInt()
100+
config := fmt.Sprintf(testAccAzureRMSqlDatabase_datawarehouse, ri, ri, ri)
101+
102+
resource.Test(t, resource.TestCase{
103+
PreCheck: func() { testAccPreCheck(t) },
104+
Providers: testAccProviders,
105+
CheckDestroy: testCheckAzureRMSqlDatabaseDestroy,
106+
Steps: []resource.TestStep{
107+
{
108+
Config: config,
109+
Check: resource.ComposeTestCheckFunc(
110+
testCheckAzureRMSqlDatabaseExists("azurerm_sql_database.test"),
111+
),
112+
},
113+
},
114+
})
115+
}
116+
95117
func testCheckAzureRMSqlDatabaseExists(name string) resource.TestCheckFunc {
96118
return func(s *terraform.State) error {
97119

@@ -227,3 +249,28 @@ resource "azurerm_sql_database" "test" {
227249
}
228250
}
229251
`
252+
253+
var testAccAzureRMSqlDatabase_datawarehouse = `
254+
resource "azurerm_resource_group" "test" {
255+
name = "acctest_rg_%d"
256+
location = "West US"
257+
}
258+
resource "azurerm_sql_server" "test" {
259+
name = "acctestsqlserver%d"
260+
resource_group_name = "${azurerm_resource_group.test.name}"
261+
location = "West US"
262+
version = "12.0"
263+
administrator_login = "mradministrator"
264+
administrator_login_password = "thisIsDog11"
265+
}
266+
267+
resource "azurerm_sql_database" "test" {
268+
name = "acctestdb%d"
269+
resource_group_name = "${azurerm_resource_group.test.name}"
270+
server_name = "${azurerm_sql_server.test.name}"
271+
location = "West US"
272+
edition = "DataWarehouse"
273+
collation = "SQL_Latin1_General_CP1_CI_AS"
274+
requested_service_objective_name = "DW400"
275+
}
276+
`

website/source/docs/providers/azurerm/r/sql_database.html.markdown

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ resource "azurerm_sql_database" "test" {
2121
name = "MySQLDatabase"
2222
resource_group_name = "${azurerm_resource_group.test.name}"
2323
location = "West US"
24-
24+
2525
2626
tags {
2727
environment = "production"
@@ -34,7 +34,7 @@ The following arguments are supported:
3434

3535
* `name` - (Required) The name of the database.
3636

37-
* `resource_group_name` - (Required) The name of the resource group in which to create the database. This must be the same as Database Server resource group currently.
37+
* `resource_group_name` - (Required) The name of the resource group in which to create the database. This must be the same as Database Server resource group currently.
3838

3939
* `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created.
4040

@@ -46,22 +46,22 @@ The following arguments are supported:
4646

4747
* `restore_point_in_time` - (Optional) The point in time for the restore. Only applies if `create_mode` is `PointInTimeRestore` e.g. 2013-11-08T22:00:40Z
4848

49-
* `edition` - (Optional) The edition of the database to be created. Applies only if `create_mode` is `Default`. Valid values are: `Basic`, `Standard`, `Premium`. Please see [Azure SQL Database Service Tiers](https://azure.microsoft.com/en-gb/documentation/articles/sql-database-service-tiers/).
49+
* `edition` - (Optional) The edition of the database to be created. Applies only if `create_mode` is `Default`. Valid values are: `Basic`, `Standard`, `Premium`, or `DataWarehouse`. Please see [Azure SQL Database Service Tiers](https://azure.microsoft.com/en-gb/documentation/articles/sql-database-service-tiers/).
5050

5151
* `collation` - (Optional) The name of the collation. Applies only if `create_mode` is `Default`. Azure default is `SQL_LATIN1_GENERAL_CP1_CI_AS`
5252

5353
* `max_size_bytes` - (Optional) The maximum size that the database can grow to. Applies only if `create_mode` is `Default`. Please see [Azure SQL Database Service Tiers](https://azure.microsoft.com/en-gb/documentation/articles/sql-database-service-tiers/).
5454

5555
* `requested_service_objective_id` - (Optional) Use `requested_service_objective_id` or `requested_service_objective_name` to set the performance level for the database.
5656
Valid values are: `S0`, `S1`, `S2`, `S3`, `P1`, `P2`, `P4`, `P6`, `P11` and `ElasticPool`. Please see [Azure SQL Database Service Tiers](https://azure.microsoft.com/en-gb/documentation/articles/sql-database-service-tiers/).
57-
57+
5858
* `requested_service_objective_name` - (Optional) Use `requested_service_objective_name` or `requested_service_objective_id` to set the performance level for the database. Please see [Azure SQL Database Service Tiers](https://azure.microsoft.com/en-gb/documentation/articles/sql-database-service-tiers/).
5959

6060
* `source_database_deletion_date` - (Optional) The deletion date time of the source database. Only applies to deleted databases where `create_mode` is `PointInTimeRestore`.
6161

6262
* `elastic_pool_name` - (Optional) The name of the elastic database pool.
6363

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

6666
## Attributes Reference
6767

0 commit comments

Comments
 (0)