github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/azure/resource_azure_storage_service_test.go (about)

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