Skip to content

Commit

Permalink
Merge pull request #4457 from tcz001/upstream-issue-3319
Browse files Browse the repository at this point in the history
[#3319] datalakestore gen2 filesystem resource
  • Loading branch information
tombuildsstuff authored Oct 2, 2019
2 parents e34051e + f02a41f commit 7a8e3ed
Show file tree
Hide file tree
Showing 23 changed files with 1,294 additions and 7 deletions.
5 changes: 4 additions & 1 deletion azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ func getArmClient(authConfig *authentication.Config, skipProviderRegistration bo
}

// Storage Endpoints
storageAuth := authConfig.BearerAuthorizerCallback(sender, oauthConfig)
storageAuth, err := authConfig.GetAuthorizationToken(sender, oauthConfig, env.ResourceIdentifiers.Storage)
if err != nil {
return nil, err
}

// Key Vault Endpoints
keyVaultAuth := authConfig.BearerAuthorizerCallback(sender, oauthConfig)
Expand Down
13 changes: 10 additions & 3 deletions azurerm/internal/services/storage/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

"github.com/tombuildsstuff/giovanni/storage/2018-11-09/datalakestore/filesystems"

"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-04-01/storage"
az "github.com/Azure/go-autorest/autorest/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/authorizers"
Expand All @@ -18,7 +20,8 @@ import (
)

type Client struct {
AccountsClient storage.AccountsClient
AccountsClient *storage.AccountsClient
FileSystemsClient *filesystems.Client

environment az.Environment
}
Expand All @@ -27,11 +30,15 @@ func BuildClient(options *common.ClientOptions) *Client {
accountsClient := storage.NewAccountsClientWithBaseURI(options.ResourceManagerEndpoint, options.SubscriptionId)
options.ConfigureClient(&accountsClient.Client, options.ResourceManagerAuthorizer)

fileSystemsClient := filesystems.NewWithEnvironment(options.Environment)
fileSystemsClient.Authorizer = options.StorageAuthorizer

// TODO: switch Storage Containers to using the storage.BlobContainersClient
// (which should fix #2977) when the storage clients have been moved in here
return &Client{
AccountsClient: accountsClient,
environment: options.Environment,
AccountsClient: &accountsClient,
FileSystemsClient: &fileSystemsClient,
environment: options.Environment,
}
}

Expand Down
69 changes: 69 additions & 0 deletions azurerm/internal/services/storage/id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package storage

import (
"fmt"

"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
)

type AccountID struct {
Name string
ResourceGroup string

ID azure.ResourceID
}

func AccountIDSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: ValidateAccountID,
}
}

func ParseAccountID(id string) (*AccountID, error) {
storageID, err := azure.ParseAzureResourceID(id)
if err != nil {
return nil, err
}

resourceGroup := storageID.ResourceGroup
if resourceGroup == "" {
return nil, fmt.Errorf("%q is missing a Resource Group", id)
}

storageAccountName := storageID.Path["storageAccounts"]
if storageAccountName == "" {
return nil, fmt.Errorf("%q is missing the `storageAccounts` segment", id)
}

accountId := AccountID{
Name: storageAccountName,
ResourceGroup: resourceGroup,
ID: *storageID,
}
return &accountId, nil
}

func ValidateAccountID(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %q to be string", k))
return
}

id, err := azure.ParseAzureResourceID(v)
if err != nil {
errors = append(errors, fmt.Errorf("Can not parse %q as a Resource Id: %v", v, err))
}

if id != nil {
if id.Path["storageAccounts"] == "" {
errors = append(errors, fmt.Errorf("The 'storageAccounts' segment is missing from Resource ID %q", v))
}
}

return warnings, errors
}
74 changes: 74 additions & 0 deletions azurerm/internal/services/storage/id_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package storage

import (
"testing"
)

func TestParseAccountID(t *testing.T) {
testData := []struct {
input string
expected *AccountID
}{
{
input: "",
expected: nil,
},
{
input: "/subscriptions/00000000-0000-0000-0000-000000000000",
expected: nil,
},
{
input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups",
expected: nil,
},
{
input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/hello",
expected: nil,
},
{
// wrong case
input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/hello/storageaccounts/account1",
expected: nil,
},
{
input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/hello/storageAccounts/account1",
expected: &AccountID{
Name: "account1",
ResourceGroup: "hello",
},
},
}

for _, v := range testData {
t.Logf("[DEBUG] Testing %q..", v.input)
actual, err := ParseAccountID(v.input)

// if we get something there shouldn't be an error
if v.expected != nil && err == nil {
continue
}

// if nothing's expected we should get an error
if v.expected == nil && err != nil {
continue
}

if v.expected == nil && actual == nil {
continue
}

if v.expected == nil && actual != nil {
t.Fatalf("Expected nothing but got %+v", actual)
}
if v.expected != nil && actual == nil {
t.Fatalf("Expected %+v but got nil", actual)
}

if v.expected.ResourceGroup != actual.ResourceGroup {
t.Fatalf("Expected ResourceGroup to be %q but got %q", v.expected.ResourceGroup, actual.ResourceGroup)
}
if v.expected.Name != actual.Name {
t.Fatalf("Expected Name to be %q but got %q", v.expected.Name, actual.Name)
}
}
}
1 change: 1 addition & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_storage_account": resourceArmStorageAccount(),
"azurerm_storage_blob": resourceArmStorageBlob(),
"azurerm_storage_container": resourceArmStorageContainer(),
"azurerm_storage_data_lake_gen2_filesystem": resourceArmStorageDataLakeGen2FileSystem(),
"azurerm_storage_queue": resourceArmStorageQueue(),
"azurerm_storage_share": resourceArmStorageShare(),
"azurerm_storage_share_directory": resourceArmStorageShareDirectory(),
Expand Down
Loading

0 comments on commit 7a8e3ed

Please sign in to comment.