-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4457 from tcz001/upstream-issue-3319
[#3319] datalakestore gen2 filesystem resource
- Loading branch information
Showing
23 changed files
with
1,294 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.