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

azurerm_hpc_cache: update API version to 2020-03-01 and support mtu and root_squash_enabled properties #8078

Merged
merged 6 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion azurerm/internal/services/storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage"
"github.com/Azure/azure-sdk-for-go/services/storagecache/mgmt/2019-11-01/storagecache"
"github.com/Azure/azure-sdk-for-go/services/storagecache/mgmt/2020-03-01/storagecache"
"github.com/Azure/azure-sdk-for-go/services/storagesync/mgmt/2020-03-01/storagesync"
"github.com/Azure/go-autorest/autorest"
az "github.com/Azure/go-autorest/autorest/azure"
Expand Down
38 changes: 38 additions & 0 deletions azurerm/internal/services/storage/hpc_cache_target_import.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package storage

import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/storagecache/mgmt/2020-03-01/storagecache"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage/parsers"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
)

func importHpcCache(kind storagecache.TargetType) func(d *schema.ResourceData, meta interface{}) (data []*schema.ResourceData, err error) {
return func(d *schema.ResourceData, meta interface{}) (data []*schema.ResourceData, err error) {
id, err := parsers.HPCCacheTargetID(d.Id())
if err != nil {
return nil, err
}

client := meta.(*clients.Client).Storage.StorageTargetsClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

resp, err := client.Get(ctx, id.ResourceGroup, id.Cache, id.Name)
if err != nil {
return nil, fmt.Errorf("retrieving HPC Cache Target %q (Resource Group %q, Cahe %q): %+v", id.Name, id.ResourceGroup, id.Cache, err)
}

if resp.Type == nil {
return nil, fmt.Errorf(`HPC Cache Target %q (Resource Group %q, Cahe %q) nil "type"`, id.Name, id.ResourceGroup, id.Cache)
}

if *resp.Type != string(kind) {
return nil, fmt.Errorf(`HPC Cache Target %q (Resource Group %q, Cahe %q) "type" mismatch, expected "%s", got "%s"`, id.Name, id.ResourceGroup, id.Cache, kind, *resp.Type)
}
return []*schema.ResourceData{d}, nil
}
}
39 changes: 36 additions & 3 deletions azurerm/internal/services/storage/resource_arm_hpc_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/storagecache/mgmt/2019-11-01/storagecache"
"github.com/Azure/azure-sdk-for-go/services/storagecache/mgmt/2020-03-01/storagecache"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand All @@ -19,12 +19,14 @@ import (

func resourceArmHPCCache() *schema.Resource {
return &schema.Resource{
Create: resourceArmHPCCacheCreate,
Create: resourceArmHPCCacheCreateOrUpdate,
Update: resourceArmHPCCacheCreateOrUpdate,
Read: resourceArmHPCCacheRead,
Delete: resourceArmHPCCacheDelete,

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Update: schema.DefaultTimeout(30 * time.Minute),
Read: schema.DefaultTimeout(5 * time.Minute),
Delete: schema.DefaultTimeout(30 * time.Minute),
},
Expand Down Expand Up @@ -76,6 +78,23 @@ func resourceArmHPCCache() *schema.Resource {
}, false),
},

"mtu": {
Type: schema.TypeInt,
Optional: true,
Default: 1500,
ValidateFunc: validation.IntBetween(576, 1500),
},

"root_squash_enabled": {
Type: schema.TypeBool,
Optional: true,
// TODO 3.0: remove "Computed: true" and add "Default: true"
// The old resource has no consistent default for the rootSquash setting. In order not to
// break users, we intentionally mark this property as Computed.
// https://docs.microsoft.com/en-us/azure/hpc-cache/configuration#configure-root-squash.
Computed: true,
},

"mount_addresses": {
Type: schema.TypeList,
Computed: true,
Expand All @@ -85,7 +104,7 @@ func resourceArmHPCCache() *schema.Resource {
}
}

func resourceArmHPCCacheCreate(d *schema.ResourceData, meta interface{}) error {
func resourceArmHPCCacheCreateOrUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Storage.CachesClient
ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d)
defer cancel()
Expand All @@ -111,13 +130,21 @@ func resourceArmHPCCacheCreate(d *schema.ResourceData, meta interface{}) error {
cacheSize := d.Get("cache_size_in_gb").(int)
subnet := d.Get("subnet_id").(string)
skuName := d.Get("sku_name").(string)
rootSquash := d.Get("root_squash_enabled").(bool)
mtu := d.Get("mtu").(int)

cache := &storagecache.Cache{
Name: utils.String(name),
Location: utils.String(location),
CacheProperties: &storagecache.CacheProperties{
CacheSizeGB: utils.Int32(int32(cacheSize)),
Subnet: utils.String(subnet),
NetworkSettings: &storagecache.CacheNetworkSettings{
Mtu: utils.Int32(int32(mtu)),
},
SecuritySettings: &storagecache.CacheSecuritySettings{
RootSquash: &rootSquash,
},
},
Sku: &storagecache.CacheSku{
Name: utils.String(skuName),
Expand Down Expand Up @@ -174,6 +201,12 @@ func resourceArmHPCCacheRead(d *schema.ResourceData, meta interface{}) error {
d.Set("cache_size_in_gb", props.CacheSizeGB)
d.Set("subnet_id", props.Subnet)
d.Set("mount_addresses", utils.FlattenStringSlice(props.MountAddresses))
if props.NetworkSettings != nil {
d.Set("mtu", props.NetworkSettings.Mtu)
}
if props.SecuritySettings != nil {
d.Set("root_squash_enabled", props.SecuritySettings.RootSquash)
}
}

if sku := resp.Sku; sku != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/storagecache/mgmt/2019-11-01/storagecache"
"github.com/Azure/azure-sdk-for-go/services/storagecache/mgmt/2020-03-01/storagecache"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand All @@ -25,10 +25,10 @@ func resourceArmHPCCacheBlobTarget() *schema.Resource {
Read: resourceArmHPCCacheBlobTargetRead,
Delete: resourceArmHPCCacheBlobTargetDelete,

Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error {
Importer: azSchema.ValidateResourceIDPriorToImportThen(func(id string) error {
_, err := parsers.HPCCacheTargetID(id)
return err
}),
}, importHpcCache(storagecache.TargetTypeClfs)),

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Expand Down Expand Up @@ -104,9 +104,9 @@ func resourceArmHPCCacheBlobTargetCreateOrUpdate(d *schema.ResourceData, meta in
},
}
param := &storagecache.StorageTarget{
StorageTargetProperties: &storagecache.StorageTargetProperties{
BasicStorageTargetProperties: &storagecache.ClfsTargetProperties{
Junctions: &namespaceJunction,
TargetType: storagecache.StorageTargetTypeClfs,
TargetType: storagecache.TargetTypeClfs,
Clfs: &storagecache.ClfsTarget{
Target: utils.String(containerId),
},
Expand Down Expand Up @@ -161,7 +161,12 @@ func resourceArmHPCCacheBlobTargetRead(d *schema.ResourceData, meta interface{})
d.Set("resource_group_name", id.ResourceGroup)
d.Set("cache_name", id.Cache)

if props := resp.StorageTargetProperties; props != nil {
if props := resp.BasicStorageTargetProperties; props != nil {
props, ok := props.AsClfsTargetProperties()
if !ok {
return fmt.Errorf("The type of this HPC Cache Target %q (Resource Group %q, Cahe %q) is not a Blob Target", id.Name, id.ResourceGroup, id.Cache)
}

storageContainerId := ""
if props.Clfs != nil && props.Clfs.Target != nil {
storageContainerId = *props.Clfs.Target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema"

"github.com/Azure/azure-sdk-for-go/services/storagecache/mgmt/2019-11-01/storagecache"
"github.com/Azure/azure-sdk-for-go/services/storagecache/mgmt/2020-03-01/storagecache"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand All @@ -27,10 +27,10 @@ func resourceArmHPCCacheNFSTarget() *schema.Resource {
Read: resourceArmHPCCacheNFSTargetRead,
Delete: resourceArmHPCCacheNFSTargetDelete,

Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error {
Importer: azSchema.ValidateResourceIDPriorToImportThen(func(id string) error {
_, err := parsers.HPCCacheTargetID(id)
return err
}),
}, importHpcCache(storagecache.TargetTypeNfs3)),

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Expand Down Expand Up @@ -129,9 +129,9 @@ func resourceArmHPCCacheNFSTargetCreateOrUpdate(d *schema.ResourceData, meta int

// Construct parameters
param := &storagecache.StorageTarget{
StorageTargetProperties: &storagecache.StorageTargetProperties{
BasicStorageTargetProperties: &storagecache.Nfs3TargetProperties{
Junctions: expandNamespaceJunctions(d.Get("namespace_junction").(*schema.Set).List()),
TargetType: storagecache.StorageTargetTypeNfs3,
TargetType: storagecache.TargetTypeNfs3,
Nfs3: &storagecache.Nfs3Target{
Target: utils.String(d.Get("target_host_name").(string)),
UsageModel: utils.String(d.Get("usage_model").(string)),
Expand Down Expand Up @@ -186,7 +186,11 @@ func resourceArmHPCCacheNFSTargetRead(d *schema.ResourceData, meta interface{})
d.Set("resource_group_name", id.ResourceGroup)
d.Set("cache_name", id.Cache)

if props := resp.StorageTargetProperties; props != nil {
if props := resp.BasicStorageTargetProperties; props != nil {
props, ok := props.AsNfs3TargetProperties()
if !ok {
return fmt.Errorf("The type of this HPC Cache Target %q (Resource Group %q, Cahe %q) is not a NFS Target", id.Name, id.ResourceGroup, id.Cache)
}
if nfs3 := props.Nfs3; nfs3 != nil {
d.Set("target_host_name", nfs3.Target)
d.Set("usage_model", nfs3.UsageModel)
Expand Down
Loading