Skip to content

Commit

Permalink
Merge pull request #3828 from terraform-providers/f/storage-share
Browse files Browse the repository at this point in the history
r/storage_share: switching to use the new storage sdk
  • Loading branch information
tombuildsstuff authored Jul 11, 2019
2 parents e716538 + 0853912 commit bcaffac
Show file tree
Hide file tree
Showing 32 changed files with 1,640 additions and 260 deletions.
19 changes: 0 additions & 19 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1237,25 +1237,6 @@ func (c *ArmClient) getBlobStorageClientForStorageAccount(ctx context.Context, r
return &blobClient, true, nil
}

func (c *ArmClient) getFileServiceClientForStorageAccount(ctx context.Context, resourceGroupName, storageAccountName string) (*mainStorage.FileServiceClient, bool, error) {
key, accountExists, err := c.getKeyForStorageAccount(ctx, resourceGroupName, storageAccountName)
if err != nil {
return nil, accountExists, err
}
if !accountExists {
return nil, false, nil
}

storageClient, err := mainStorage.NewClient(storageAccountName, key, c.environment.StorageEndpointSuffix,
mainStorage.DefaultAPIVersion, true)
if err != nil {
return nil, true, fmt.Errorf("Error creating storage client for storage storeAccount %q: %s", storageAccountName, err)
}

fileClient := storageClient.GetFileService()
return &fileClient, true, nil
}

func (c *ArmClient) getTableServiceClientForStorageAccount(ctx context.Context, resourceGroupName, storageAccountName string) (*mainStorage.TableServiceClient, bool, error) {
key, accountExists, err := c.getKeyForStorageAccount(ctx, resourceGroupName, storageAccountName)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions azurerm/helpers/azure/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ func SchemaResourceGroupName() *schema.Schema {
}
}

func SchemaResourceGroupNameDeprecated() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
Deprecated: "This field has been deprecated and is no longer used - will be removed in 2.0 of the Azure Provider",
}
}

func SchemaResourceGroupNameDiffSuppress() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Expand Down
15 changes: 14 additions & 1 deletion azurerm/internal/services/storage/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/authorizers"
"github.com/tombuildsstuff/giovanni/storage/2018-11-09/file/directories"
"github.com/tombuildsstuff/giovanni/storage/2018-11-09/file/shares"
)

type Client struct {
Expand Down Expand Up @@ -56,7 +57,7 @@ func (client Client) FindResourceGroup(ctx context.Context, accountName string)
return resourceGroup, nil
}

func (client Client) FileShareClient(ctx context.Context, resourceGroup, accountName string) (*directories.Client, error) {
func (client Client) FileShareDirectoriesClient(ctx context.Context, resourceGroup, accountName string) (*directories.Client, error) {
accountKey, err := client.findAccountKey(ctx, resourceGroup, accountName)
if err != nil {
return nil, fmt.Errorf("Error retrieving Account Key: %s", err)
Expand All @@ -68,6 +69,18 @@ func (client Client) FileShareClient(ctx context.Context, resourceGroup, account
return &directoriesClient, nil
}

func (client Client) FileSharesClient(ctx context.Context, resourceGroup, accountName string) (*shares.Client, error) {
accountKey, err := client.findAccountKey(ctx, resourceGroup, accountName)
if err != nil {
return nil, fmt.Errorf("Error retrieving Account Key: %s", err)
}

storageAuth := authorizers.NewSharedKeyLiteAuthorizer(accountName, *accountKey)
directoriesClient := shares.New()
directoriesClient.Client.Authorizer = storageAuth
return &directoriesClient, nil
}

func (client Client) findAccountKey(ctx context.Context, resourceGroup, accountName string) (*string, error) {
props, err := client.accountsClient.ListKeys(ctx, resourceGroup, accountName)
if err != nil {
Expand Down
Loading

0 comments on commit bcaffac

Please sign in to comment.