Skip to content

Commit

Permalink
Merge pull request #352 from terraform-providers/mysql
Browse files Browse the repository at this point in the history
New Resources: `azurerm_mysql_*`
  • Loading branch information
tombuildsstuff authored Sep 27, 2017
2 parents e14ce69 + 744295d commit 1a3dab3
Show file tree
Hide file tree
Showing 40 changed files with 4,372 additions and 86 deletions.
152 changes: 94 additions & 58 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/Azure/azure-sdk-for-go/arm/eventhub"
"github.com/Azure/azure-sdk-for-go/arm/graphrbac"
"github.com/Azure/azure-sdk-for-go/arm/keyvault"
"github.com/Azure/azure-sdk-for-go/arm/mysql"
"github.com/Azure/azure-sdk-for-go/arm/network"
"github.com/Azure/azure-sdk-for-go/arm/operationalinsights"
"github.com/Azure/azure-sdk-for-go/arm/postgresql"
Expand Down Expand Up @@ -101,11 +102,6 @@ type ArmClient struct {

workspacesClient operationalinsights.WorkspacesClient

postgresqlConfigurationsClient postgresql.ConfigurationsClient
postgresqlDatabasesClient postgresql.DatabasesClient
postgresqlFirewallRulesClient postgresql.FirewallRulesClient
postgresqlServersClient postgresql.ServersClient

providers resources.ProvidersClient
resourceGroupClient resources.GroupsClient
tagsClient resources.TagsClient
Expand Down Expand Up @@ -135,17 +131,26 @@ type ArmClient struct {
keyVaultClient keyvault.VaultsClient
keyVaultManagementClient keyVault.ManagementClient

sqlDatabasesClient sql.DatabasesClient
sqlElasticPoolsClient sql.ElasticPoolsClient
sqlFirewallRulesClient sql.FirewallRulesClient
sqlServersClient sql.ServersClient

appServicePlansClient web.AppServicePlansClient
appServicesClient web.AppsClient

appInsightsClient appinsights.ComponentsClient

servicePrincipalsClient graphrbac.ServicePrincipalsClient

// Databases
mysqlConfigurationsClient mysql.ConfigurationsClient
mysqlDatabasesClient mysql.DatabasesClient
mysqlFirewallRulesClient mysql.FirewallRulesClient
mysqlServersClient mysql.ServersClient
postgresqlConfigurationsClient postgresql.ConfigurationsClient
postgresqlDatabasesClient postgresql.DatabasesClient
postgresqlFirewallRulesClient postgresql.FirewallRulesClient
postgresqlServersClient postgresql.ServersClient
sqlDatabasesClient sql.DatabasesClient
sqlElasticPoolsClient sql.ElasticPoolsClient
sqlFirewallRulesClient sql.FirewallRulesClient
sqlServersClient sql.ServersClient
}

func withRequestLogging() autorest.SendDecorator {
Expand Down Expand Up @@ -457,30 +462,6 @@ func (c *Config) getArmClient() (*ArmClient, error) {
vnpc.Sender = sender
client.vnetPeeringsClient = vnpc

pcc := postgresql.NewConfigurationsClientWithBaseURI(endpoint, c.SubscriptionID)
setUserAgent(&pcc.Client)
pcc.Authorizer = auth
pcc.Sender = autorest.CreateSender(withRequestLogging())
client.postgresqlConfigurationsClient = pcc

pdbc := postgresql.NewDatabasesClientWithBaseURI(endpoint, c.SubscriptionID)
setUserAgent(&pdbc.Client)
pdbc.Authorizer = auth
pdbc.Sender = autorest.CreateSender(withRequestLogging())
client.postgresqlDatabasesClient = pdbc

pfwc := postgresql.NewFirewallRulesClientWithBaseURI(endpoint, c.SubscriptionID)
setUserAgent(&pfwc.Client)
pfwc.Authorizer = auth
pfwc.Sender = autorest.CreateSender(withRequestLogging())
client.postgresqlFirewallRulesClient = pfwc

psc := postgresql.NewServersClientWithBaseURI(endpoint, c.SubscriptionID)
setUserAgent(&psc.Client)
psc.Authorizer = auth
psc.Sender = autorest.CreateSender(withRequestLogging())
client.postgresqlServersClient = psc

rtc := network.NewRouteTablesClientWithBaseURI(endpoint, c.SubscriptionID)
setUserAgent(&rtc.Client)
rtc.Authorizer = auth
Expand Down Expand Up @@ -625,30 +606,6 @@ func (c *Config) getArmClient() (*ArmClient, error) {
sbsc.Sender = sender
client.serviceBusSubscriptionsClient = sbsc

sqldc := sql.NewDatabasesClientWithBaseURI(endpoint, c.SubscriptionID)
setUserAgent(&sqldc.Client)
sqldc.Authorizer = auth
sqldc.Sender = sender
client.sqlDatabasesClient = sqldc

sqlfrc := sql.NewFirewallRulesClientWithBaseURI(endpoint, c.SubscriptionID)
setUserAgent(&sqlfrc.Client)
sqlfrc.Authorizer = auth
sqlfrc.Sender = sender
client.sqlFirewallRulesClient = sqlfrc

sqlepc := sql.NewElasticPoolsClientWithBaseURI(endpoint, c.SubscriptionID)
setUserAgent(&sqlepc.Client)
sqlepc.Authorizer = auth
sqlepc.Sender = sender
client.sqlElasticPoolsClient = sqlepc

sqlsrv := sql.NewServersClientWithBaseURI(endpoint, c.SubscriptionID)
setUserAgent(&sqlsrv.Client)
sqlsrv.Authorizer = auth
sqlsrv.Sender = sender
client.sqlServersClient = sqlsrv

aspc := web.NewAppServicePlansClientWithBaseURI(endpoint, c.SubscriptionID)
setUserAgent(&aspc.Client)
aspc.Authorizer = auth
Expand Down Expand Up @@ -709,9 +666,88 @@ func (c *Config) getArmClient() (*ArmClient, error) {
kvmc.Sender = sender
client.keyVaultManagementClient = kvmc

client.registerDatabases(endpoint, c.SubscriptionID, auth, sender)

return &client, nil
}

func (c *ArmClient) registerDatabases(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) {
// MySQL
mysqlConfigClient := mysql.NewConfigurationsClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&mysqlConfigClient.Client)
mysqlConfigClient.Authorizer = auth
mysqlConfigClient.Sender = sender
c.mysqlConfigurationsClient = mysqlConfigClient

mysqlDBClient := mysql.NewDatabasesClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&mysqlDBClient.Client)
mysqlDBClient.Authorizer = auth
mysqlDBClient.Sender = sender
c.mysqlDatabasesClient = mysqlDBClient

mysqlFWClient := mysql.NewFirewallRulesClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&mysqlFWClient.Client)
mysqlFWClient.Authorizer = auth
mysqlFWClient.Sender = sender
c.mysqlFirewallRulesClient = mysqlFWClient

mysqlServersClient := mysql.NewServersClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&mysqlServersClient.Client)
mysqlServersClient.Authorizer = auth
mysqlServersClient.Sender = sender
c.mysqlServersClient = mysqlServersClient

// PostgreSQL
postgresqlConfigClient := postgresql.NewConfigurationsClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&postgresqlConfigClient.Client)
postgresqlConfigClient.Authorizer = auth
postgresqlConfigClient.Sender = autorest.CreateSender(withRequestLogging())
c.postgresqlConfigurationsClient = postgresqlConfigClient

postgresqlDBClient := postgresql.NewDatabasesClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&postgresqlDBClient.Client)
postgresqlDBClient.Authorizer = auth
postgresqlDBClient.Sender = autorest.CreateSender(withRequestLogging())
c.postgresqlDatabasesClient = postgresqlDBClient

postgresqlFWClient := postgresql.NewFirewallRulesClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&postgresqlFWClient.Client)
postgresqlFWClient.Authorizer = auth
postgresqlFWClient.Sender = autorest.CreateSender(withRequestLogging())
c.postgresqlFirewallRulesClient = postgresqlFWClient

postgresqlSrvClient := postgresql.NewServersClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&postgresqlSrvClient.Client)
postgresqlSrvClient.Authorizer = auth
postgresqlSrvClient.Sender = autorest.CreateSender(withRequestLogging())
c.postgresqlServersClient = postgresqlSrvClient

// SQL Azure
sqlDBClient := sql.NewDatabasesClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&sqlDBClient.Client)
sqlDBClient.Authorizer = auth
sqlDBClient.Sender = sender
c.sqlDatabasesClient = sqlDBClient

sqlFWClient := sql.NewFirewallRulesClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&sqlFWClient.Client)
sqlFWClient.Authorizer = auth
sqlFWClient.Sender = sender
c.sqlFirewallRulesClient = sqlFWClient

sqlEPClient := sql.NewElasticPoolsClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&sqlEPClient.Client)
sqlEPClient.Authorizer = auth
sqlEPClient.Sender = sender
c.sqlElasticPoolsClient = sqlEPClient

sqlSrvClient := sql.NewServersClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&sqlSrvClient.Client)
sqlSrvClient.Authorizer = auth
sqlSrvClient.Sender = sender
c.sqlServersClient = sqlSrvClient
}

func (armClient *ArmClient) getKeyForStorageAccount(resourceGroupName, storageAccountName string) (string, bool, error) {
accountKeys, err := armClient.storageServiceClient.ListKeys(resourceGroupName, storageAccountName)
if accountKeys.StatusCode == http.StatusNotFound {
Expand Down
77 changes: 77 additions & 0 deletions azurerm/import_arm_mysql_configuration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package azurerm

import (
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccAzureRMMySQLConfiguration_importCharacterSetServer(t *testing.T) {
resourceName := "azurerm_mysql_configuration.test"

ri := acctest.RandInt()
config := testAccAzureRMMySQLConfiguration_characterSetServer(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMMySQLConfigurationDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMPostgreSQLConfiguration_importInteractiveTimeout(t *testing.T) {
resourceName := "azurerm_mysql_configuration.test"

ri := acctest.RandInt()
config := testAccAzureRMMySQLConfiguration_interactiveTimeout(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMMySQLConfigurationDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMPostgreSQLConfiguration_importLogSlowAdminStatements(t *testing.T) {
resourceName := "azurerm_mysql_configuration.test"

ri := acctest.RandInt()
config := testAccAzureRMMySQLConfiguration_logSlowAdminStatements(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMMySQLConfigurationDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
31 changes: 31 additions & 0 deletions azurerm/import_arm_mysql_database_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package azurerm

import (
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccAzureRMMySQLDatabase_importBasic(t *testing.T) {
resourceName := "azurerm_mysql_database.test"

ri := acctest.RandInt()
config := testAccAzureRMMySQLDatabase_basic(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMMySQLDatabaseDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
31 changes: 31 additions & 0 deletions azurerm/import_arm_mysql_firewall_rule_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package azurerm

import (
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccAzureRMMySQLFirewallRule_importBasic(t *testing.T) {
resourceName := "azurerm_mysql_firewall_rule.test"

ri := acctest.RandInt()
config := testAccAzureRMMySQLFirewallRule_basic(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMMySQLFirewallRuleDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Loading

0 comments on commit 1a3dab3

Please sign in to comment.