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

[NEW RESOURCE] SQL ElasticPool using 2017-10-01-preview API #2071

Merged
merged 43 commits into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c94602c
[WIP] New schema for 2017-preview API
WodansSon Oct 3, 2018
be32e90
[wip] finished the expand functions
WodansSon Oct 4, 2018
e5043cb
[WIP] Updated code
WodansSon Oct 9, 2018
dcc4cfd
[WIP] Working now testing
WodansSon Oct 10, 2018
007a68d
For WIP PR
WodansSon Oct 13, 2018
4f09688
Merge branch 'master' into u-elasticPool-2017-10-01-preview
WodansSon Oct 16, 2018
e54cfaa
[WIP] Resolve Conflict With Master
WodansSon Oct 16, 2018
61944b5
Merge branch 'master' into u-elasticPool-2017-10-01-preview
WodansSon Oct 16, 2018
14d3869
[WIP] Resolve conflict.
WodansSon Oct 16, 2018
bd0fb44
Merge branch 'master' into u-elasticPool-2017-10-01-preview
WodansSon Oct 18, 2018
9a8a8a4
[WIP] Fix conflict
WodansSon Oct 19, 2018
e605c38
[WIP] CustomizeDiff validation
WodansSon Oct 20, 2018
d51d2a1
Merge branch 'master' into u-elasticPool-2017-10-01-preview
WodansSon Oct 29, 2018
6b9f631
[WIP] Vallidation Tests and fixed Conflict
WodansSon Oct 29, 2018
990dadc
[WIP] Fixing Linting Error
WodansSon Oct 29, 2018
f2a0ab8
[WIP] Fix Vendor issue
WodansSon Oct 30, 2018
938f231
added missed files for sql package.
metacpp Oct 30, 2018
3be7049
[New Resource] Updated Tests added Documentation
WodansSon Oct 30, 2018
e50d331
Fixed test issue
WodansSon Oct 30, 2018
ea99f40
Added validation to name and server_name
WodansSon Oct 31, 2018
bc5230c
Added azure.ValidateServiceName func and tests
WodansSon Nov 1, 2018
59dbd93
Fixed validation test issue
WodansSon Nov 1, 2018
13e8fd9
Updated BasicPool to StandardPool
WodansSon Nov 1, 2018
242830b
Updates per PR comments
WodansSon Nov 9, 2018
41e87dc
Corrected lint errors
WodansSon Nov 9, 2018
078e91b
Fixed validation function
WodansSon Nov 10, 2018
0212fac
Corrected fmt errors
WodansSon Nov 10, 2018
d3405b6
Updated CustomizeDiff
WodansSon Nov 10, 2018
8696148
Upgraded to 1.11.2 ran make fmt
WodansSon Nov 10, 2018
23642a6
Update azurerm/resource_arm_mssql_elasticpool.go
katbyte Nov 13, 2018
ee2783b
Update azurerm/resource_arm_mssql_elasticpool.go
katbyte Nov 13, 2018
d255c7b
Update azurerm/resource_arm_mssql_elasticpool.go
katbyte Nov 13, 2018
f27fbfe
update casing of client
WodansSon Nov 13, 2018
4a31920
Merge branch 'u-elasticPool-2017-10-01-preview' of https://github.com…
WodansSon Nov 13, 2018
95a741e
Addressing PR comments
WodansSon Nov 13, 2018
efdf223
Last of the PR comments
WodansSon Nov 13, 2018
a60c7d2
Final updates
WodansSon Nov 14, 2018
ddcd066
Update azurerm/resource_arm_mssql_elasticpool.go
katbyte Nov 14, 2018
a31537e
Update azurerm/resource_arm_mssql_elasticpool.go
katbyte Nov 14, 2018
40504e6
Update azurerm/resource_arm_mssql_elasticpool.go
katbyte Nov 14, 2018
359c273
Update azurerm/resource_arm_mssql_elasticpool.go
WodansSon Nov 14, 2018
900b6a2
moved FloatAtLeast to new file
katbyte Nov 14, 2018
c2a2792
Fix lint error
WodansSon Nov 14, 2018
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
15 changes: 11 additions & 4 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/preview/resources/mgmt/2018-03-01-preview/management"
"github.com/Azure/azure-sdk-for-go/services/preview/security/mgmt/2017-08-01-preview/security"
"github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/2015-05-01-preview/sql"
WodansSon marked this conversation as resolved.
Show resolved Hide resolved
MsSql "github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/2017-10-01-preview/sql"
"github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2016-06-01/backup"
"github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2016-06-01/recoveryservices"
"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2018-03-01/redis"
Expand Down Expand Up @@ -181,10 +182,12 @@ type ArmClient struct {
sqlDatabasesClient sql.DatabasesClient
sqlDatabaseThreatDetectionPoliciesClient sql.DatabaseThreatDetectionPoliciesClient
sqlElasticPoolsClient sql.ElasticPoolsClient
WodansSon marked this conversation as resolved.
Show resolved Hide resolved
sqlFirewallRulesClient sql.FirewallRulesClient
sqlServersClient sql.ServersClient
sqlServerAzureADAdministratorsClient sql.ServerAzureADAdministratorsClient
sqlVirtualNetworkRulesClient sql.VirtualNetworkRulesClient
// Client for the new 2017-10-01-preview SQL API which implements vCore, DTU, and Azure data standards
msSqlElasticPoolsClient MsSql.ElasticPoolsClient
sqlFirewallRulesClient sql.FirewallRulesClient
sqlServersClient sql.ServersClient
sqlServerAzureADAdministratorsClient sql.ServerAzureADAdministratorsClient
sqlVirtualNetworkRulesClient sql.VirtualNetworkRulesClient

// Data Lake Store
dataLakeStoreAccountClient storeAccount.AccountsClient
Expand Down Expand Up @@ -790,6 +793,10 @@ func (c *ArmClient) registerDatabases(endpoint, subscriptionId string, auth auto
c.configureClient(&sqlEPClient.Client, auth)
c.sqlElasticPoolsClient = sqlEPClient

MsSqlEPClient := MsSql.NewElasticPoolsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&MsSqlEPClient.Client, auth)
c.msSqlElasticPoolsClient = MsSqlEPClient

sqlSrvClient := sql.NewServersClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&sqlSrvClient.Client, auth)
c.sqlServersClient = sqlSrvClient
Expand Down
26 changes: 26 additions & 0 deletions azurerm/helpers/azure/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package azure

import (
"fmt"
"regexp"
)

func ValidateResourceID(i interface{}, k string) (_ []string, errors []error) {
Expand Down Expand Up @@ -32,3 +33,28 @@ func ValidateResourceIDOrEmpty(i interface{}, k string) (_ []string, errors []er

return ValidateResourceID(i, k)
}

//true for a resource ID or an empty string
func ValidateMsSqlServiceName(i interface{}, k string) (_ []string, errors []error) {
v, ok := i.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %q to be string", k))
return nil, errors
}

//First, second, and last characters must be a letter or number with a total length between 3 to 50 lowercase characters.
r := regexp.MustCompile("^[a-z0-9]{2}[-a-z0-9]{0,47}[a-z0-9]{1}$")
if !r.MatchString(v) {
errors = append(errors, fmt.Errorf("%q must be 3 - 50 characters in length", k))
errors = append(errors, fmt.Errorf("%q first, second, and last characters must be a lowercase letter or number", k))
errors = append(errors, fmt.Errorf("%q can only contain lowercase letters, numbers and hyphens", k))
}

//No consecutive dashes.
r = regexp.MustCompile("(--)")
if r.MatchString(v) {
errors = append(errors, fmt.Errorf("%q must not contain any consecutive hyphens", k))
}

return nil, errors
}
58 changes: 58 additions & 0 deletions azurerm/helpers/azure/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,61 @@ func TestAzureResourceIDOrEmpty(t *testing.T) {
})
}
}

func TestAzureValidateMsSqlServiceName(t *testing.T) {
cases := []struct {
ServiceName string
Errors int
}{
{
ServiceName: "as",
Errors: 3,
},
{
ServiceName: "Asd",
Errors: 3,
},
{
ServiceName: "asd",
Errors: 0,
},
{
ServiceName: "-asd",
Errors: 3,
},
{
ServiceName: "asd-",
Errors: 3,
},
{
ServiceName: "asd-1",
Errors: 0,
},
{
ServiceName: "asd--1",
Errors: 1,
},
{
ServiceName: "asd--1-",
Errors: 4,
},
{
ServiceName: "asdfghjklzasdfghjklzasdfghjklzasdfghjklzasdfghjklz",
Errors: 0,
},
{
ServiceName: "asdfghjklzasdfghjklzasdfghjklzasdfghjklzasdfghjklz1",
Errors: 3,
},
}

for _, tc := range cases {
t.Run(tc.ServiceName, func(t *testing.T) {
_, errors := ValidateMsSqlServiceName(tc.ServiceName, "name")

if len(errors) < tc.Errors {
t.Fatalf("Expected TestAzureValidateMsSqlServiceName to have %d not %d errors for %q", tc.Errors, len(errors), tc.ServiceName)
}
})
}
}
26 changes: 26 additions & 0 deletions azurerm/helpers/validate/float.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package validate

import (
"fmt"

"github.com/hashicorp/terraform/helper/schema"
)

// FloatAtLeast returns a SchemaValidateFunc which tests if the provided value
// is of type float64 and is at least min (inclusive)
func FloatAtLeast(min float64) schema.SchemaValidateFunc {
return func(i interface{}, k string) (_ []string, errors []error) {
v, ok := i.(float64)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %s to be float64", k))
return nil, errors
}

if v < min {
errors = append(errors, fmt.Errorf("expected %s to be at least (%f), got %f", k, min, v))
return nil, errors
}

return nil, errors
}
}
83 changes: 83 additions & 0 deletions azurerm/helpers/validate/float_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package validate

import "testing"

func TestAzureFloatAtLeast(t *testing.T) {
cases := []struct {
Name string
MinValue float64
ActualValue float64
Errors int
}{
{
Name: "Min_Full_Stop_Zero_Greater",
MinValue: 0.0,
ActualValue: 1.0,
Errors: 0,
},
{
Name: "Min_One_Full_Stop_Zero_Lesser",
MinValue: 1.0,
ActualValue: 0.0,
Errors: 1,
},
{
Name: "Min_Full_Stop_Two_Five_Greater",
MinValue: 0.25,
ActualValue: 0.26,
Errors: 0,
},
{
Name: "Min_Full_Stop_Two_Five_Equal",
MinValue: 0.25,
ActualValue: 0.25,
Errors: 0,
},
{
Name: "Min_Full_Stop_Two_Five_Lesser",
MinValue: 0.25,
ActualValue: 0.24,
Errors: 1,
},
{
Name: "Min_Full_Stop_Long_Zero_Lesser",
MinValue: 0.0000000000000000000000000000000000000001,
ActualValue: 0,
Errors: 1,
},
{
Name: "Min_Full_Stop_Long_Greater",
MinValue: 0.0000000000000000000000000000000000000001,
ActualValue: -0,
Errors: 1,
},
{
Name: "Min_Negative_Full_Stop_Two_Five_Greater",
MinValue: -0.25,
ActualValue: 1,
Errors: 0,
},
{
Name: "Min_Zero_No_Full_Stop_Equal",
MinValue: 0,
ActualValue: -0,
Errors: 0,
},
{
Name: "Min_Negative_Full_Stop_Two_Five_Lesser",
MinValue: -0.25,
ActualValue: -0.26,
Errors: 1,
},
}

for _, tc := range cases {
t.Run(tc.Name, func(t *testing.T) {
_, errors := FloatAtLeast(tc.MinValue)(tc.ActualValue, "floatValue")

if len(errors) < tc.Errors {
t.Fatalf("Expected FloatAtLeast to have %d not %d errors for %q", tc.Errors, len(errors), tc.Name)
}
})
}
}
1 change: 1 addition & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_scheduler_job_collection": resourceArmSchedulerJobCollection(),
"azurerm_sql_database": resourceArmSqlDatabase(),
"azurerm_sql_elasticpool": resourceArmSqlElasticPool(),
"azurerm_mssql_elasticpool": resourceArmMsSqlElasticPool(),
"azurerm_sql_firewall_rule": resourceArmSqlFirewallRule(),
"azurerm_sql_active_directory_administrator": resourceArmSqlAdministrator(),
"azurerm_sql_server": resourceArmSqlServer(),
Expand Down
Loading