Skip to content

Commit

Permalink
Merge branch 'terraform-providers-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhijeet Gaiha committed Sep 6, 2017
2 parents a1365c7 + 215a9f2 commit 3274477
Show file tree
Hide file tree
Showing 37 changed files with 4,354 additions and 50 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## 0.1.7 (Unreleased)

FEATURES:

* **New Resource:** `azurerm_postgresql_configuration` [GH-210]
* **New Resource:** `azurerm_postgresql_database` [GH-210]
* **New Resource:** `azurerm_postgresql_firewall_rule` [GH-210]
* **New Resource:** `azurerm_postgresql_server` [GH-210]

IMPROVEMENTS:

* `azurerm_cdn_endpoint` - defaulting the `http_port` and `https_port` [GH-301]
Expand Down
30 changes: 30 additions & 0 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/graphrbac"
"github.com/Azure/azure-sdk-for-go/arm/keyvault"
"github.com/Azure/azure-sdk-for-go/arm/network"
"github.com/Azure/azure-sdk-for-go/arm/postgresql"
"github.com/Azure/azure-sdk-for-go/arm/redis"
"github.com/Azure/azure-sdk-for-go/arm/resources/resources"
"github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions"
Expand Down Expand Up @@ -92,6 +93,11 @@ type ArmClient struct {
eventHubConsumerGroupClient eventhub.ConsumerGroupsClient
eventHubNamespacesClient eventhub.NamespacesClient

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 @@ -409,6 +415,30 @@ func (c *Config) getArmClient() (*ArmClient, error) {
vnpc.Sender = autorest.CreateSender(withRequestLogging())
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
77 changes: 77 additions & 0 deletions azurerm/import_arm_postgresql_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 TestAccAzureRMPostgreSQLConfiguration_importBackslashQuote(t *testing.T) {
resourceName := "azurerm_postgresql_configuration.test"

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

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

func TestAccAzureRMPostgreSQLConfiguration_importClientMinMessages(t *testing.T) {
resourceName := "azurerm_postgresql_configuration.test"

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

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

func TestAccAzureRMPostgreSQLConfiguration_importDeadlockTimeout(t *testing.T) {
resourceName := "azurerm_postgresql_configuration.test"

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

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMPostgreSQLConfigurationDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
31 changes: 31 additions & 0 deletions azurerm/import_arm_postgresql_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 TestAccAzureRMPostgreSQLDatabase_importBasic(t *testing.T) {
resourceName := "azurerm_postgresql_database.test"

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

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMPostgreSQLDatabaseDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
31 changes: 31 additions & 0 deletions azurerm/import_arm_postgresql_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 TestAccAzureRMPostgreSQLFirewallRule_importBasic(t *testing.T) {
resourceName := "azurerm_postgresql_firewall_rule.test"

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

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

import (
"testing"

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

func TestAccAzureRMPostgreSQLServer_importBasicNinePointFive(t *testing.T) {
resourceName := "azurerm_postgresql_server.test"

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

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMPostgreSQLServerDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"administrator_login_password", // not returned as sensitive
},
},
},
})
}

func TestAccAzureRMPostgreSQLServer_importBasicNinePointSix(t *testing.T) {
resourceName := "azurerm_postgresql_server.test"

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

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMPostgreSQLServerDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"administrator_login_password", // not returned as sensitive
},
},
},
})
}
39 changes: 22 additions & 17 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ func Provider() terraform.ResourceProvider {
"azurerm_network_interface": resourceArmNetworkInterface(),
"azurerm_network_security_group": resourceArmNetworkSecurityGroup(),
"azurerm_network_security_rule": resourceArmNetworkSecurityRule(),
"azurerm_postgresql_configuration": resourceArmPostgreSQLConfiguration(),
"azurerm_postgresql_database": resourceArmPostgreSQLDatabase(),
"azurerm_postgresql_firewall_rule": resourceArmPostgreSQLFirewallRule(),
"azurerm_postgresql_server": resourceArmPostgreSQLServer(),
"azurerm_public_ip": resourceArmPublicIp(),
"azurerm_redis_cache": resourceArmRedisCache(),
"azurerm_resource_group": resourceArmResourceGroup(),
Expand Down Expand Up @@ -240,23 +244,24 @@ var providerRegistrationOnce sync.Once

func determineAzureResourceProvidersToRegister(providerList []resources.Provider) map[string]struct{} {
providers := map[string]struct{}{
"Microsoft.Cache": struct{}{},
"Microsoft.Cdn": struct{}{},
"Microsoft.Compute": struct{}{},
"Microsoft.ContainerRegistry": struct{}{},
"Microsoft.ContainerService": struct{}{},
"Microsoft.ContainerInstance": struct{}{},
"Microsoft.DocumentDB": struct{}{},
"Microsoft.EventGrid": struct{}{},
"Microsoft.EventHub": struct{}{},
"Microsoft.KeyVault": struct{}{},
"microsoft.insights": struct{}{},
"Microsoft.Network": struct{}{},
"Microsoft.Resources": struct{}{},
"Microsoft.Search": struct{}{},
"Microsoft.ServiceBus": struct{}{},
"Microsoft.Sql": struct{}{},
"Microsoft.Storage": struct{}{},
"Microsoft.Cache": {},
"Microsoft.Cdn": {},
"Microsoft.Compute": {},
"Microsoft.ContainerInstance": {},
"Microsoft.ContainerRegistry": {},
"Microsoft.ContainerService": {},
"Microsoft.DBforPostgreSQL": {},
"Microsoft.DocumentDB": {},
"Microsoft.EventGrid": {},
"Microsoft.EventHub": {},
"Microsoft.KeyVault": {},
"microsoft.insights": {},
"Microsoft.Network": {},
"Microsoft.Resources": {},
"Microsoft.Search": {},
"Microsoft.ServiceBus": {},
"Microsoft.Sql": {},
"Microsoft.Storage": {},
}

// filter out any providers already registered
Expand Down
52 changes: 51 additions & 1 deletion azurerm/resource_arm_cosmos_db_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,64 @@ package azurerm

import (
"fmt"
"log"
"net/http"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func init() {
resource.AddTestSweepers("azurerm_cosmosdb_account", &resource.Sweeper{
Name: "azurerm_cosmosdb_account",
F: testSweepCosmosDBAccount,
})
}

func testSweepCosmosDBAccount(region string) error {
armClient, err := buildConfigForSweepers()
if err != nil {
return err
}

client := (*armClient).cosmosDBClient

log.Printf("Retrieving the CosmosDB Accounts..")
results, err := client.List()
if err != nil {
return fmt.Errorf("Error Listing on CosmosDB Accounts: %+v", err)
}

for _, account := range *results.Value {
if !shouldSweepAcceptanceTestResource(*account.Name, *account.Location, region) {
continue
}

resourceId, err := parseAzureResourceID(*account.ID)
if err != nil {
return err
}

resourceGroup := resourceId.ResourceGroup
name := resourceId.Path["databaseAccounts"]

log.Printf("Deleting CosmosDB Account '%s' in Resource Group '%s'", name, resourceGroup)
deleteResp, deleteErr := client.Delete(resourceGroup, name, make(chan struct{}))
resp := <-deleteResp
err = <-deleteErr
if err != nil {
if !utils.ResponseWasNotFound(resp) {
return err
}
}
}

return nil
}

func TestAccAzureRMCosmosDBAccountName_validation(t *testing.T) {
str := acctest.RandString(50)
cases := []struct {
Expand Down Expand Up @@ -194,7 +244,7 @@ func testCheckAzureRMCosmosDBAccountDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*ArmClient).cosmosDBClient

for _, rs := range s.RootModule().Resources {
if rs.Type != "azurerm_cosmos_db" {
if rs.Type != "azurerm_cosmosdb_account" {
continue
}

Expand Down
Loading

0 comments on commit 3274477

Please sign in to comment.