Skip to content

Commit

Permalink
new resource: azurerm_hpc_cache_blob_target
Browse files Browse the repository at this point in the history
  • Loading branch information
magodo committed Mar 9, 2020
1 parent e7b360e commit b006306
Show file tree
Hide file tree
Showing 9 changed files with 779 additions and 0 deletions.
5 changes: 5 additions & 0 deletions azurerm/internal/services/storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Client struct {
ManagementPoliciesClient storage.ManagementPoliciesClient
BlobServicesClient storage.BlobServicesClient
CachesClient *storagecache.CachesClient
StorageTargetsClient *storagecache.StorageTargetsClient
BlobAccountsClient *accounts.Client

environment az.Environment
Expand All @@ -49,6 +50,9 @@ func NewClient(options *common.ClientOptions) *Client {
cachesClient := storagecache.NewCachesClientWithBaseURI(options.ResourceManagerEndpoint, options.SubscriptionId)
options.ConfigureClient(&cachesClient.Client, options.ResourceManagerAuthorizer)

storageTargetsClient := storagecache.NewStorageTargetsClientWithBaseURI(options.ResourceManagerEndpoint, options.SubscriptionId)
options.ConfigureClient(&storageTargetsClient.Client, options.ResourceManagerAuthorizer)

blobAccountsClient := accounts.NewWithEnvironment(options.Environment)
options.ConfigureClient(&blobAccountsClient.Client, options.StorageAuthorizer)

Expand All @@ -60,6 +64,7 @@ func NewClient(options *common.ClientOptions) *Client {
ManagementPoliciesClient: managementPoliciesClient,
BlobServicesClient: blobServicesClient,
CachesClient: &cachesClient,
StorageTargetsClient: &storageTargetsClient,
BlobAccountsClient: &blobAccountsClient,
environment: options.Environment,
}
Expand Down
38 changes: 38 additions & 0 deletions azurerm/internal/services/storage/parsers/hpc_cache_target.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package parsers

import (
"fmt"

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

type HPCCacheTargetId struct {
ResourceGroup string
Cache string
Name string
}

func HPCCacheTargetID(input string) (*HPCCacheTargetId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, fmt.Errorf("[ERROR] Unable to parse HPC Cache Target ID %q: %+v", input, err)
}

target := HPCCacheTargetId{
ResourceGroup: id.ResourceGroup,
}

if target.Cache, err = id.PopSegment("caches"); err != nil {
return nil, err
}

if target.Name, err = id.PopSegment("storageTargets"); err != nil {
return nil, err
}

if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}

return &target, nil
}
89 changes: 89 additions & 0 deletions azurerm/internal/services/storage/parsers/hpc_cache_target_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package parsers

import (
"testing"
)

func TestHPCCacheTargetID(t *testing.T) {
testData := []struct {
Name string
Input string
Error bool
Expect *HPCCacheTargetId
}{
{
Name: "Empty",
Input: "",
Error: true,
},
{
Name: "No Resource Groups Segment",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000",
Error: true,
},
{
Name: "No Resource Groups Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/",
Error: true,
},
{
Name: "Resource Group ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/",
Error: true,
},
{
Name: "Missing Cache Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.StorageCache/caches/",
Error: true,
},
{
Name: "With Cache Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.StorageCache/caches/cache1",
Error: true,
},
{
Name: "Missing Storage Target Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.StorageCache/caches/cache1/storageTargets",
Error: true,
},
{
Name: "With Storage Target Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.StorageCache/caches/cache1/storageTargets/target1",
Expect: &HPCCacheTargetId{
ResourceGroup: "resGroup1",
Cache: "cache1",
Name: "target1",
},
},
{
Name: "Wrong Casing",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.StorageCache/caches/cache1/StorageTargets/target1",
Error: true,
},
}

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

actual, err := HPCCacheTargetID(v.Input)
if err != nil {
if v.Error {
continue
}

t.Fatalf("Expected a value but got an error: %s", err)
}

if actual.ResourceGroup != v.Expect.ResourceGroup {
t.Fatalf("Expected %q but got %q for Resource Group", v.Expect.ResourceGroup, actual.ResourceGroup)
}

if actual.Cache != v.Expect.Cache {
t.Fatalf("Expected %q but got %q for Cache", v.Expect.Cache, actual.Cache)
}

if actual.Name != v.Expect.Name {
t.Fatalf("Expected %q but got %q for Name", v.Expect.Name, actual.Name)
}
}
}
1 change: 1 addition & 0 deletions azurerm/internal/services/storage/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource {
func (r Registration) SupportedResources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"azurerm_hpc_cache": resourceArmHPCCache(),
"azurerm_hpc_cache_blob_target": resourceArmHPCCacheBlobTarget(),
"azurerm_storage_account": resourceArmStorageAccount(),
"azurerm_storage_account_customer_managed_key": resourceArmStorageAccountCustomerManagedKey(),
"azurerm_storage_account_network_rules": resourceArmStorageAccountNetworkRules(),
Expand Down
Loading

0 comments on commit b006306

Please sign in to comment.