Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#3319] datalakestore gen2 filesystem resource #4457

Merged
merged 6 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -413,6 +413,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