github.com/bendemaree/terraform@v0.5.4-0.20150613200311-f50d97d6eee6/builtin/providers/azure/resource_azure_storage_service_test.go (about)

     1  package azure
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/Azure/azure-sdk-for-go/management/storageservice"
     8  	"github.com/hashicorp/terraform/helper/resource"
     9  	"github.com/hashicorp/terraform/terraform"
    10  )
    11  
    12  func TestAccAzureStorageService(t *testing.T) {
    13  	name := "azure_storage_service.foo"
    14  
    15  	resource.Test(t, resource.TestCase{
    16  		PreCheck:     func() { testAccPreCheck(t) },
    17  		Providers:    testAccProviders,
    18  		CheckDestroy: testAccAzureStorageServiceDestroyed,
    19  		Steps: []resource.TestStep{
    20  			resource.TestStep{
    21  				Config: testAccAzureStorageServiceConfig,
    22  				Check: resource.ComposeTestCheckFunc(
    23  					testAccAzureStorageServiceExists(name),
    24  					resource.TestCheckResourceAttr(name, "name", "tftesting"),
    25  					resource.TestCheckResourceAttr(name, "location", "North Europe"),
    26  					resource.TestCheckResourceAttr(name, "description", "very descriptive"),
    27  					resource.TestCheckResourceAttr(name, "account_type", "Standard_LRS"),
    28  				),
    29  			},
    30  		},
    31  	})
    32  }
    33  
    34  func testAccAzureStorageServiceExists(name string) resource.TestCheckFunc {
    35  	return func(s *terraform.State) error {
    36  		resource, ok := s.RootModule().Resources[name]
    37  		if !ok {
    38  			return fmt.Errorf("Azure Storage Service Resource not found: %s", name)
    39  		}
    40  
    41  		if resource.Primary.ID == "" {
    42  			return fmt.Errorf("Azure Storage Service ID not set.")
    43  		}
    44  
    45  		mgmtClient := testAccProvider.Meta().(*Client).mgmtClient
    46  		_, err := storageservice.NewClient(mgmtClient).GetStorageService(resource.Primary.ID)
    47  
    48  		return err
    49  	}
    50  }
    51  
    52  func testAccAzureStorageServiceDestroyed(s *terraform.State) error {
    53  	mgmgClient := testAccProvider.Meta().(*Client).mgmtClient
    54  
    55  	for _, resource := range s.RootModule().Resources {
    56  		if resource.Type != "azure_storage_service" {
    57  			continue
    58  		}
    59  
    60  		if resource.Primary.ID == "" {
    61  			return fmt.Errorf("Azure Storage Service ID not set.")
    62  		}
    63  
    64  		_, err := storageservice.NewClient(mgmgClient).GetStorageService(resource.Primary.ID)
    65  		return testAccResourceDestroyedErrorFilter("Storage Service", err)
    66  	}
    67  
    68  	return nil
    69  }
    70  
    71  var testAccAzureStorageServiceConfig = `
    72  resource "azure_storage_service" "foo" {
    73      # NOTE: storage service names constrained to lowercase letters only.
    74  	name = "tftesting"
    75  	location = "West US"
    76      description = "very descriptive"
    77  	account_type = "Standard_LRS"
    78  }
    79  `