2015-06-05 16:12:21 +02:00
|
|
|
package azure
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccAzureStorageService(t *testing.T) {
|
|
|
|
name := "azure_storage_service.foo"
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccAzureStorageServiceDestroyed,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAzureStorageServiceConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccAzureStorageServiceExists(name),
|
|
|
|
resource.TestCheckResourceAttr(name, "name", "tftesting"),
|
|
|
|
resource.TestCheckResourceAttr(name, "location", "North Europe"),
|
|
|
|
resource.TestCheckResourceAttr(name, "description", "very descriptive"),
|
|
|
|
resource.TestCheckResourceAttr(name, "account_type", "Standard_LRS"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccAzureStorageServiceExists(name string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
resource, ok := s.RootModule().Resources[name]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Azure Storage Service Resource not found: %s", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if resource.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("Azure Storage Service ID not set.")
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:54:52 +02:00
|
|
|
storageServiceClient := testAccProvider.Meta().(*Client).storageServiceClient
|
|
|
|
_, err := storageServiceClient.GetStorageService(resource.Primary.ID)
|
2015-06-05 16:12:21 +02:00
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccAzureStorageServiceDestroyed(s *terraform.State) error {
|
2015-06-16 19:54:52 +02:00
|
|
|
storageServiceClient := testAccProvider.Meta().(*Client).storageServiceClient
|
2015-06-05 16:12:21 +02:00
|
|
|
|
|
|
|
for _, resource := range s.RootModule().Resources {
|
|
|
|
if resource.Type != "azure_storage_service" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if resource.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("Azure Storage Service ID not set.")
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:54:52 +02:00
|
|
|
_, err := storageServiceClient.GetStorageService(resource.Primary.ID)
|
2015-06-05 16:12:21 +02:00
|
|
|
return testAccResourceDestroyedErrorFilter("Storage Service", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var testAccAzureStorageServiceConfig = `
|
|
|
|
resource "azure_storage_service" "foo" {
|
|
|
|
# NOTE: storage service names constrained to lowercase letters only.
|
|
|
|
name = "tftesting"
|
|
|
|
location = "West US"
|
|
|
|
description = "very descriptive"
|
|
|
|
account_type = "Standard_LRS"
|
|
|
|
}
|
|
|
|
`
|