diff --git a/builtin/providers/azurerm/config.go b/builtin/providers/azurerm/config.go index e740ea13e691..6390450cf03e 100644 --- a/builtin/providers/azurerm/config.go +++ b/builtin/providers/azurerm/config.go @@ -391,6 +391,25 @@ func (armClient *ArmClient) getBlobStorageClientForStorageAccount(resourceGroupN blobClient := storageClient.GetBlobService() return &blobClient, true, nil } + +func (armClient *ArmClient) getFileServiceClientForStorageAccount(resourceGroupName, storageAccountName string) (*mainStorage.FileServiceClient, bool, error) { + key, accountExists, err := armClient.getKeyForStorageAccount(resourceGroupName, storageAccountName) + if err != nil { + return nil, accountExists, err + } + if accountExists == false { + return nil, false, nil + } + + storageClient, err := mainStorage.NewBasicClient(storageAccountName, key) + if err != nil { + return nil, true, fmt.Errorf("Error creating storage client for storage account %q: %s", storageAccountName, err) + } + + fileClient := storageClient.GetFileService() + return &fileClient, true, nil +} + func (armClient *ArmClient) getTableServiceClientForStorageAccount(resourceGroupName, storageAccountName string) (*mainStorage.TableServiceClient, bool, error) { key, accountExists, err := armClient.getKeyForStorageAccount(resourceGroupName, storageAccountName) if err != nil { diff --git a/builtin/providers/azurerm/provider.go b/builtin/providers/azurerm/provider.go index b208c8e21414..4cd509cd80ee 100644 --- a/builtin/providers/azurerm/provider.go +++ b/builtin/providers/azurerm/provider.go @@ -60,6 +60,7 @@ func Provider() terraform.ResourceProvider { "azurerm_storage_account": resourceArmStorageAccount(), "azurerm_storage_blob": resourceArmStorageBlob(), "azurerm_storage_container": resourceArmStorageContainer(), + "azurerm_storage_share": resourceArmStorageShare(), "azurerm_storage_queue": resourceArmStorageQueue(), "azurerm_storage_table": resourceArmStorageTable(), "azurerm_subnet": resourceArmSubnet(), diff --git a/builtin/providers/azurerm/resource_arm_storage_share.go b/builtin/providers/azurerm/resource_arm_storage_share.go new file mode 100644 index 000000000000..62d572210535 --- /dev/null +++ b/builtin/providers/azurerm/resource_arm_storage_share.go @@ -0,0 +1,193 @@ +package azurerm + +import ( + "fmt" + "log" + // "strings" + "regexp" + "strconv" + + "github.com/Azure/azure-sdk-for-go/storage" + "github.com/hashicorp/terraform/helper/schema" +) + +func resourceArmStorageShare() *schema.Resource { + return &schema.Resource{ + Create: resourceArmStorageShareCreate, + Read: resourceArmStorageShareRead, + Exists: resourceArmStorageShareExists, + Delete: resourceArmStorageShareDelete, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateArmStorageShareName, + }, + "resource_group_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "storage_account_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "quota": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Default: 0, + }, + "url": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} +func resourceArmStorageShareCreate(d *schema.ResourceData, meta interface{}) error { + armClient := meta.(*ArmClient) + + resourceGroupName := d.Get("resource_group_name").(string) + storageAccountName := d.Get("storage_account_name").(string) + + fileClient, accountExists, err := armClient.getFileServiceClientForStorageAccount(resourceGroupName, storageAccountName) + if err != nil { + return err + } + if !accountExists { + return fmt.Errorf("Storage Account %q Not Found", storageAccountName) + } + + name := d.Get("name").(string) + + log.Printf("[INFO] Creating share %q in storage account %q", name, storageAccountName) + err = fileClient.CreateShare(name) + + log.Printf("[INFO] Setting share %q properties in storage account %q", name, storageAccountName) + fileClient.SetShareProperties(name, storage.ShareHeaders{Quota: strconv.Itoa(d.Get("quota").(int))}) + + d.SetId(name) + return resourceArmStorageShareRead(d, meta) +} + +func resourceArmStorageShareRead(d *schema.ResourceData, meta interface{}) error { + armClient := meta.(*ArmClient) + + resourceGroupName := d.Get("resource_group_name").(string) + storageAccountName := d.Get("storage_account_name").(string) + + fileClient, accountExists, err := armClient.getFileServiceClientForStorageAccount(resourceGroupName, storageAccountName) + if err != nil { + return err + } + if !accountExists { + log.Printf("[DEBUG] Storage account %q not found, removing file %q from state", storageAccountName, d.Id()) + d.SetId("") + return nil + } + + exists, err := resourceArmStorageShareExists(d, meta) + if err != nil { + return err + } + + if !exists { + // Exists already removed this from state + return nil + } + + name := d.Get("name").(string) + + url := fileClient.GetShareURL(name) + if url == "" { + log.Printf("[INFO] URL for %q is empty", name) + } + d.Set("url", url) + + return nil +} + +func resourceArmStorageShareExists(d *schema.ResourceData, meta interface{}) (bool, error) { + armClient := meta.(*ArmClient) + + resourceGroupName := d.Get("resource_group_name").(string) + storageAccountName := d.Get("storage_account_name").(string) + + fileClient, accountExists, err := armClient.getFileServiceClientForStorageAccount(resourceGroupName, storageAccountName) + if err != nil { + return false, err + } + if !accountExists { + log.Printf("[DEBUG] Storage account %q not found, removing share %q from state", storageAccountName, d.Id()) + d.SetId("") + return false, nil + } + + name := d.Get("name").(string) + + log.Printf("[INFO] Checking for existence of share %q.", name) + exists, err := fileClient.ShareExists(name) + if err != nil { + return false, fmt.Errorf("Error testing existence of share %q: %s", name, err) + } + + if !exists { + log.Printf("[INFO] Share %q no longer exists, removing from state...", name) + d.SetId("") + } + + return exists, nil +} + +func resourceArmStorageShareDelete(d *schema.ResourceData, meta interface{}) error { + armClient := meta.(*ArmClient) + + resourceGroupName := d.Get("resource_group_name").(string) + storageAccountName := d.Get("storage_account_name").(string) + + fileClient, accountExists, err := armClient.getFileServiceClientForStorageAccount(resourceGroupName, storageAccountName) + if err != nil { + return err + } + if !accountExists { + log.Printf("[INFO]Storage Account %q doesn't exist so the file won't exist", storageAccountName) + return nil + } + + name := d.Get("name").(string) + + log.Printf("[INFO] Deleting storage file %q", name) + if _, err = fileClient.DeleteShareIfExists(name); err != nil { + return fmt.Errorf("Error deleting storage file %q: %s", name, err) + } + + d.SetId("") + return nil +} + +//Following the naming convention as laid out in the docs https://msdn.microsoft.com/library/azure/dn167011.aspx +func validateArmStorageShareName(v interface{}, k string) (ws []string, errors []error) { + value := v.(string) + if !regexp.MustCompile(`^[0-9a-z-]+$`).MatchString(value) { + errors = append(errors, fmt.Errorf( + "only lowercase alphanumeric characters and hyphens allowed in %q: %q", + k, value)) + } + if len(value) < 3 || len(value) > 63 { + errors = append(errors, fmt.Errorf( + "%q must be between 3 and 63 characters: %q", k, value)) + } + if regexp.MustCompile(`^-`).MatchString(value) { + errors = append(errors, fmt.Errorf( + "%q cannot begin with a hyphen: %q", k, value)) + } + if regexp.MustCompile(`[-]{2,}`).MatchString(value) { + errors = append(errors, fmt.Errorf( + "%q does not allow consecutive hyphens: %q", k, value)) + } + return +} diff --git a/builtin/providers/azurerm/resource_arm_storage_share_test.go b/builtin/providers/azurerm/resource_arm_storage_share_test.go new file mode 100644 index 000000000000..b8880e556b3e --- /dev/null +++ b/builtin/providers/azurerm/resource_arm_storage_share_test.go @@ -0,0 +1,241 @@ +package azurerm + +import ( + "fmt" + "log" + "strings" + "testing" + + "github.com/Azure/azure-sdk-for-go/storage" + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccAzureRMStorageShare_basic(t *testing.T) { + var sS storage.Share + + ri := acctest.RandInt() + rs := strings.ToLower(acctest.RandString(11)) + config := fmt.Sprintf(testAccAzureRMStorageShare_basic, ri, rs) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMStorageShareDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMStorageShareExists("azurerm_storage_share.test", &sS), + ), + }, + }, + }) +} + +func TestAccAzureRMStorageShare_disappears(t *testing.T) { + var sS storage.Share + + ri := acctest.RandInt() + rs := strings.ToLower(acctest.RandString(11)) + config := fmt.Sprintf(testAccAzureRMStorageShare_basic, ri, rs) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMStorageShareDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMStorageShareExists("azurerm_storage_share.test", &sS), + testAccARMStorageShareDisappears("azurerm_storage_share.test", &sS), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func testCheckAzureRMStorageShareExists(name string, sS *storage.Share) resource.TestCheckFunc { + return func(s *terraform.State) error { + + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + name := rs.Primary.Attributes["name"] + storageAccountName := rs.Primary.Attributes["storage_account_name"] + resourceGroupName, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for share: %s", name) + } + + armClient := testAccProvider.Meta().(*ArmClient) + fileClient, accountExists, err := armClient.getFileServiceClientForStorageAccount(resourceGroupName, storageAccountName) + if err != nil { + return err + } + if !accountExists { + return fmt.Errorf("Bad: Storage Account %q does not exist", storageAccountName) + } + + shares, err := fileClient.ListShares(storage.ListSharesParameters{ + Prefix: name, + Timeout: 90, + }) + + if len(shares.Shares) == 0 { + return fmt.Errorf("Bad: Share %q (storage account: %q) does not exist", name, storageAccountName) + } + + var found bool + for _, share := range shares.Shares { + if share.Name == name { + found = true + *sS = share + } + } + + if !found { + return fmt.Errorf("Bad: Share %q (storage account: %q) does not exist", name, storageAccountName) + } + + return nil + } +} + +func testAccARMStorageShareDisappears(name string, sS *storage.Share) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + armClient := testAccProvider.Meta().(*ArmClient) + + storageAccountName := rs.Primary.Attributes["storage_account_name"] + resourceGroupName, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for storage share: %s", sS.Name) + } + + fileClient, accountExists, err := armClient.getFileServiceClientForStorageAccount(resourceGroupName, storageAccountName) + if err != nil { + return err + } + if !accountExists { + log.Printf("[INFO]Storage Account %q doesn't exist so the share won't exist", storageAccountName) + return nil + } + + _, err = fileClient.DeleteShareIfExists(sS.Name) + if err != nil { + return err + } + + return nil + } +} + +func testCheckAzureRMStorageShareDestroy(s *terraform.State) error { + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_storage_share" { + continue + } + + name := rs.Primary.Attributes["name"] + storageAccountName := rs.Primary.Attributes["storage_account_name"] + resourceGroupName, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for share: %s", name) + } + + armClient := testAccProvider.Meta().(*ArmClient) + fileClient, accountExists, err := armClient.getFileServiceClientForStorageAccount(resourceGroupName, storageAccountName) + if err != nil { + //If we can't get keys then the blob can't exist + return nil + } + if !accountExists { + return nil + } + + shares, err := fileClient.ListShares(storage.ListSharesParameters{ + Prefix: name, + Timeout: 90, + }) + + if err != nil { + return nil + } + + var found bool + for _, share := range shares.Shares { + if share.Name == name { + found = true + } + } + + if found { + return fmt.Errorf("Bad: Share %q (storage account: %q) still exists", name, storageAccountName) + } + } + + return nil +} + +func TestValidateArmStorageShareName(t *testing.T) { + validNames := []string{ + "valid-name", + "valid02-name", + } + for _, v := range validNames { + _, errors := validateArmStorageShareName(v, "name") + if len(errors) != 0 { + t.Fatalf("%q should be a valid Share Name: %q", v, errors) + } + } + + invalidNames := []string{ + "InvalidName1", + "-invalidname1", + "invalid_name", + "invalid!", + "double-hyphen--invalid", + "ww", + strings.Repeat("w", 65), + } + for _, v := range invalidNames { + _, errors := validateArmStorageShareName(v, "name") + if len(errors) == 0 { + t.Fatalf("%q should be an invalid Share Name", v) + } + } +} + +var testAccAzureRMStorageShare_basic = ` +resource "azurerm_resource_group" "test" { + name = "acctestrg-%d" + location = "westus" +} + +resource "azurerm_storage_account" "test" { + name = "acctestacc%s" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "westus" + account_type = "Standard_LRS" + + tags { + environment = "staging" + } +} + +resource "azurerm_storage_share" "test" { + name = "testshare" + resource_group_name = "${azurerm_resource_group.test.name}" + storage_account_name = "${azurerm_storage_account.test.name}" +} +` diff --git a/vendor/github.com/Azure/azure-sdk-for-go/storage/README.md b/vendor/github.com/Azure/azure-sdk-for-go/storage/README.md new file mode 100644 index 000000000000..0ab099848bba --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/storage/README.md @@ -0,0 +1,5 @@ +# Azure Storage SDK for Go + +The `github.com/Azure/azure-sdk-for-go/storage` package is used to perform operations in Azure Storage Service. To manage your storage accounts (Azure Resource Manager / ARM), use the [github.com/Azure/azure-sdk-for-go/arm/storage](../arm/storage) package. For your classic storage accounts (Azure Service Management / ASM), use [github.com/Azure/azure-sdk-for-go/management/storageservice](../management/storageservice) package. + +This package includes support for [Azure Storage Emulator](https://azure.microsoft.com/documentation/articles/storage-use-emulator/) \ No newline at end of file diff --git a/vendor/github.com/Azure/azure-sdk-for-go/storage/file.go b/vendor/github.com/Azure/azure-sdk-for-go/storage/file.go index 4710fbad36f8..2397587c886d 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/storage/file.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/storage/file.go @@ -1,9 +1,11 @@ package storage import ( + "encoding/xml" "fmt" "net/http" "net/url" + "strings" ) // FileServiceClient contains operations for Microsoft Azure File Service. @@ -11,11 +13,99 @@ type FileServiceClient struct { client Client } +// A Share is an entry in ShareListResponse. +type Share struct { + Name string `xml:"Name"` + Properties ShareProperties `xml:"Properties"` +} + +// ShareProperties contains various properties of a share returned from +// various endpoints like ListShares. +type ShareProperties struct { + LastModified string `xml:"Last-Modified"` + Etag string `xml:"Etag"` + Quota string `xml:"Quota"` +} + +// ShareListResponse contains the response fields from +// ListShares call. +// +// See https://msdn.microsoft.com/en-us/library/azure/dn167009.aspx +type ShareListResponse struct { + XMLName xml.Name `xml:"EnumerationResults"` + Xmlns string `xml:"xmlns,attr"` + Prefix string `xml:"Prefix"` + Marker string `xml:"Marker"` + NextMarker string `xml:"NextMarker"` + MaxResults int64 `xml:"MaxResults"` + Shares []Share `xml:"Shares>Share"` +} + +// ListSharesParameters defines the set of customizable parameters to make a +// List Shares call. +// +// See https://msdn.microsoft.com/en-us/library/azure/dn167009.aspx +type ListSharesParameters struct { + Prefix string + Marker string + Include string + MaxResults uint + Timeout uint +} + +// ShareHeaders contains various properties of a file and is an entry +// in SetShareProperties +type ShareHeaders struct { + Quota string `header:"x-ms-share-quota"` +} + +func (p ListSharesParameters) getParameters() url.Values { + out := url.Values{} + + if p.Prefix != "" { + out.Set("prefix", p.Prefix) + } + if p.Marker != "" { + out.Set("marker", p.Marker) + } + if p.Include != "" { + out.Set("include", p.Include) + } + if p.MaxResults != 0 { + out.Set("maxresults", fmt.Sprintf("%v", p.MaxResults)) + } + if p.Timeout != 0 { + out.Set("timeout", fmt.Sprintf("%v", p.Timeout)) + } + + return out +} + // pathForFileShare returns the URL path segment for a File Share resource func pathForFileShare(name string) string { return fmt.Sprintf("/%s", name) } +// ListShares returns the list of shares in a storage account along with +// pagination token and other response details. +// +// See https://msdn.microsoft.com/en-us/library/azure/dd179352.aspx +func (f FileServiceClient) ListShares(params ListSharesParameters) (ShareListResponse, error) { + q := mergeParams(params.getParameters(), url.Values{"comp": {"list"}}) + uri := f.client.getEndpoint(fileServiceName, "", q) + headers := f.client.getStandardHeaders() + + var out ShareListResponse + resp, err := f.client.exec("GET", uri, headers, nil) + if err != nil { + return out, err + } + defer resp.body.Close() + + err = xmlUnmarshal(resp.body, &out) + return out, err +} + // CreateShare operation creates a new share under the specified account. If the // share with the same name already exists, the operation fails. // @@ -29,6 +119,30 @@ func (f FileServiceClient) CreateShare(name string) error { return checkRespCode(resp.statusCode, []int{http.StatusCreated}) } +// ShareExists returns true if a share with given name exists +// on the storage account, otherwise returns false. +func (f FileServiceClient) ShareExists(name string) (bool, error) { + uri := f.client.getEndpoint(fileServiceName, pathForFileShare(name), url.Values{"restype": {"share"}}) + headers := f.client.getStandardHeaders() + + resp, err := f.client.exec("HEAD", uri, headers, nil) + if resp != nil { + defer resp.body.Close() + if resp.statusCode == http.StatusOK || resp.statusCode == http.StatusNotFound { + return resp.statusCode == http.StatusOK, nil + } + } + return false, err +} + +// GetShareURL gets the canonical URL to the share with the specified name in the +// specified container. This method does not create a publicly accessible URL if +// the file is private and this method does not check if the file +// exists. +func (f FileServiceClient) GetShareURL(name string) string { + return f.client.getEndpoint(fileServiceName, pathForFileShare(name), url.Values{}) +} + // CreateShareIfNotExists creates a new share under the specified account if // it does not exist. Returns true if container is newly created or false if // container already exists. @@ -55,6 +169,60 @@ func (f FileServiceClient) createShare(name string) (*storageResponse, error) { return f.client.exec("PUT", uri, headers, nil) } +// GetShareProperties provides various information about the specified +// file. See https://msdn.microsoft.com/en-us/library/azure/dn689099.aspx +func (f FileServiceClient) GetShareProperties(name string) (*ShareProperties, error) { + uri := f.client.getEndpoint(fileServiceName, pathForFileShare(name), url.Values{"restype": {"share"}}) + + headers := f.client.getStandardHeaders() + resp, err := f.client.exec("HEAD", uri, headers, nil) + if err != nil { + return nil, err + } + defer resp.body.Close() + + if err := checkRespCode(resp.statusCode, []int{http.StatusOK}); err != nil { + return nil, err + } + + return &ShareProperties{ + LastModified: resp.headers.Get("Last-Modified"), + Etag: resp.headers.Get("Etag"), + Quota: resp.headers.Get("x-ms-share-quota"), + }, nil +} + +// SetShareProperties replaces the ShareHeaders for the specified file. +// +// Some keys may be converted to Camel-Case before sending. All keys +// are returned in lower case by SetShareProperties. HTTP header names +// are case-insensitive so case munging should not matter to other +// applications either. +// +// See https://msdn.microsoft.com/en-us/library/azure/mt427368.aspx +func (f FileServiceClient) SetShareProperties(name string, shareHeaders ShareHeaders) error { + params := url.Values{} + params.Set("restype", "share") + params.Set("comp", "properties") + + uri := f.client.getEndpoint(fileServiceName, pathForFileShare(name), params) + headers := f.client.getStandardHeaders() + + extraHeaders := headersFromStruct(shareHeaders) + + for k, v := range extraHeaders { + headers[k] = v + } + + resp, err := f.client.exec("PUT", uri, headers, nil) + if err != nil { + return err + } + defer resp.body.Close() + + return checkRespCode(resp.statusCode, []int{http.StatusOK}) +} + // DeleteShare operation marks the specified share for deletion. The share // and any files contained within it are later deleted during garbage // collection. @@ -96,6 +264,84 @@ func (f FileServiceClient) deleteShare(name string) (*storageResponse, error) { return f.client.exec("DELETE", uri, f.client.getStandardHeaders(), nil) } +// SetShareMetadata replaces the metadata for the specified Share. +// +// Some keys may be converted to Camel-Case before sending. All keys +// are returned in lower case by GetShareMetadata. HTTP header names +// are case-insensitive so case munging should not matter to other +// applications either. +// +// See https://msdn.microsoft.com/en-us/library/azure/dd179414.aspx +func (f FileServiceClient) SetShareMetadata(name string, metadata map[string]string, extraHeaders map[string]string) error { + params := url.Values{} + params.Set("restype", "share") + params.Set("comp", "metadata") + + uri := f.client.getEndpoint(fileServiceName, pathForFileShare(name), params) + headers := f.client.getStandardHeaders() + for k, v := range metadata { + headers[userDefinedMetadataHeaderPrefix+k] = v + } + + for k, v := range extraHeaders { + headers[k] = v + } + + resp, err := f.client.exec("PUT", uri, headers, nil) + if err != nil { + return err + } + defer resp.body.Close() + + return checkRespCode(resp.statusCode, []int{http.StatusOK}) +} + +// GetShareMetadata returns all user-defined metadata for the specified share. +// +// All metadata keys will be returned in lower case. (HTTP header +// names are case-insensitive.) +// +// See https://msdn.microsoft.com/en-us/library/azure/dd179414.aspx +func (f FileServiceClient) GetShareMetadata(name string) (map[string]string, error) { + params := url.Values{} + params.Set("restype", "share") + params.Set("comp", "metadata") + + uri := f.client.getEndpoint(fileServiceName, pathForFileShare(name), params) + headers := f.client.getStandardHeaders() + + resp, err := f.client.exec("GET", uri, headers, nil) + if err != nil { + return nil, err + } + defer resp.body.Close() + + if err := checkRespCode(resp.statusCode, []int{http.StatusOK}); err != nil { + return nil, err + } + + metadata := make(map[string]string) + for k, v := range resp.headers { + // Can't trust CanonicalHeaderKey() to munge case + // reliably. "_" is allowed in identifiers: + // https://msdn.microsoft.com/en-us/library/azure/dd179414.aspx + // https://msdn.microsoft.com/library/aa664670(VS.71).aspx + // http://tools.ietf.org/html/rfc7230#section-3.2 + // ...but "_" is considered invalid by + // CanonicalMIMEHeaderKey in + // https://golang.org/src/net/textproto/reader.go?s=14615:14659#L542 + // so k can be "X-Ms-Meta-Foo" or "x-ms-meta-foo_bar". + k = strings.ToLower(k) + if len(v) == 0 || !strings.HasPrefix(k, strings.ToLower(userDefinedMetadataHeaderPrefix)) { + continue + } + // metadata["foo"] = content of the last X-Ms-Meta-Foo header + k = k[len(userDefinedMetadataHeaderPrefix):] + metadata[k] = v[len(v)-1] + } + return metadata, nil +} + //checkForStorageEmulator determines if the client is setup for use with //Azure Storage Emulator, and returns a relevant error func (f FileServiceClient) checkForStorageEmulator() error { diff --git a/vendor/github.com/Azure/azure-sdk-for-go/storage/table_entities.go b/vendor/github.com/Azure/azure-sdk-for-go/storage/table_entities.go index c81393e5f506..1b5919cd130f 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/storage/table_entities.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/storage/table_entities.go @@ -98,6 +98,10 @@ func (c *TableServiceClient) QueryTableEntities(tableName AzureTable, previousCo resp, err := c.client.execTable("GET", uri, headers, nil) + if err != nil { + return nil, nil, err + } + contToken := extractContinuationTokenFromHeaders(resp.headers) if err != nil { diff --git a/vendor/vendor.json b/vendor/vendor.json index 1f98178d730d..a3d710bd330b 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -208,13 +208,11 @@ "versionExact": "v3.2.0-beta" }, { - "checksumSHA1": "w1X4Sxcdx4WhCqVZdPWoUuMPn9U=", + "checksumSHA1": "T1DpzOaZGsKlUq16elkdwF6ddsU=", "comment": "v2.1.1-beta-8-gca4d906", "path": "github.com/Azure/azure-sdk-for-go/storage", - "revision": "bfc5b4af08f3d3745d908af36b7ed5b9060f0258", - "revisionTime": "2016-08-11T22:07:13Z", - "version": "v3.2.0-beta", - "versionExact": "v3.2.0-beta" + "revision": "a9e8b991cde41aeef7dde53fc1ee2c74af5ed30b", + "revisionTime": "2016-09-08T17:03:40Z" }, { "checksumSHA1": "eVSHe6GIHj9/ziFrQLZ1SC7Nn6k=", diff --git a/website/source/docs/providers/azurerm/r/storage_share.html.markdown b/website/source/docs/providers/azurerm/r/storage_share.html.markdown new file mode 100644 index 000000000000..6675330019ae --- /dev/null +++ b/website/source/docs/providers/azurerm/r/storage_share.html.markdown @@ -0,0 +1,58 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_storage_share" +sidebar_current: "docs-azurerm-resource-storage-share" +description: |- + Create an Azure Storage Share. +--- + +# azurerm\_storage\_share + +Create an Azure Storage File Share. + +## Example Usage + +``` +resource "azurerm_resource_group" "test" { + name = "acctestrg-%d" + location = "westus" +} + +resource "azurerm_storage_account" "test" { + name = "acctestacc%s" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "westus" + account_type = "Standard_LRS" +} + +resource "azurerm_storage_share" "testshare" { + name = "sharename" + + resource_group_name = "${azurerm_resource_group.test.name}" + storage_account_name = "${azurerm_storage_account.test.name}" + + quota = 50 +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the share. Must be unique within the storage account where the share is located. + +* `resource_group_name` - (Required) The name of the resource group in which to + create the share. Changing this forces a new resource to be created. + +* `storage_account_name` - (Required) Specifies the storage account in which to create the share. + Changing this forces a new resource to be created. + +* `quota` - (Optional) The maximum size of the share, in gigabytes. Must be greater than 0, and less than or equal to 5 TB (5120 GB). Default this is set to 0 which results in setting the quota to 5 TB. + + +## Attributes Reference + +The following attributes are exported in addition to the arguments listed above: + +* `id` - The storage share Resource ID. +* `url` - The URL of the share