From 99fd18e0daa2f4a3094edd758c030c37cc8eb71b Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Wed, 13 Dec 2023 12:14:07 +0800 Subject: [PATCH 1/3] azurerm_hpc_cache_nfs_target - support verification_timer_in_seconds and write_back_timer_in_seconds properties --- .../hpc_cache_nfs_target_resource.go | 23 +++++++ .../hpc_cache_nfs_target_resource_test.go | 67 +++++++++++++++++-- .../docs/r/hpc_cache_nfs_target.html.markdown | 4 ++ 3 files changed, 88 insertions(+), 6 deletions(-) diff --git a/internal/services/storagecache/hpc_cache_nfs_target_resource.go b/internal/services/storagecache/hpc_cache_nfs_target_resource.go index e0f625237d53..eab6a6b7957d 100644 --- a/internal/services/storagecache/hpc_cache_nfs_target_resource.go +++ b/internal/services/storagecache/hpc_cache_nfs_target_resource.go @@ -5,6 +5,7 @@ package storagecache import ( "fmt" + "github.com/hashicorp/terraform-provider-azurerm/utils" "log" "time" @@ -115,6 +116,18 @@ func resourceHPCCacheNFSTarget() *pluginsdk.Resource { "WRITE_WORKLOAD_CLOUDWS", }, false), }, + + "verification_timer_in_seconds": { + Type: pluginsdk.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(1, 31536000), + }, + + "write_back_timer_in_seconds": { + Type: pluginsdk.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(1, 31536000), + }, }, } } @@ -153,6 +166,14 @@ func resourceHPCCacheNFSTargetCreateOrUpdate(d *pluginsdk.ResourceData, meta int }, } + if v, ok := d.GetOk("verification_timer_in_seconds"); ok { + param.Properties.BlobNfs.VerificationTimer = utils.Int64(int64(v.(int))) + } + + if v, ok := d.GetOk("write_back_timer_in_seconds"); ok { + param.Properties.BlobNfs.WriteBackTimer = utils.Int64(int64(v.(int))) + } + if err := client.CreateOrUpdateThenPoll(ctx, id, param); err != nil { return fmt.Errorf("creating %s: %+v", id, err) } @@ -194,6 +215,8 @@ func resourceHPCCacheNFSTargetRead(d *pluginsdk.ResourceData, meta interface{}) if nfs3 := props.Nfs3; nfs3 != nil { d.Set("target_host_name", nfs3.Target) d.Set("usage_model", nfs3.UsageModel) + d.Set("verification_timer_in_seconds", pointer.From(nfs3.VerificationTimer)) + d.Set("write_back_timer_in_seconds", pointer.From(nfs3.WriteBackTimer)) } if err := d.Set("namespace_junction", flattenNamespaceJunctions(props.Junctions)); err != nil { return fmt.Errorf(`error setting "namespace_junction"(%q): %+v`, id, err) diff --git a/internal/services/storagecache/hpc_cache_nfs_target_resource_test.go b/internal/services/storagecache/hpc_cache_nfs_target_resource_test.go index 29ddad46237b..effa5e0f61a8 100644 --- a/internal/services/storagecache/hpc_cache_nfs_target_resource_test.go +++ b/internal/services/storagecache/hpc_cache_nfs_target_resource_test.go @@ -46,21 +46,21 @@ func TestAccHPCCacheNFSTarget_usageModel(t *testing.T) { }, data.ImportStep(), { - Config: r.usageModel(data, "READ_HEAVY_CHECK_180"), + Config: r.usageModelReadHeavyCheck180(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { - Config: r.usageModel(data, "READ_WRITE"), + Config: r.usageModelReadWrite(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { - Config: r.usageModel(data, "READ_ONLY"), + Config: r.usageModelReadOnly(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -193,7 +193,7 @@ resource "azurerm_hpc_cache_nfs_target" "test" { `, r.cacheTemplate(data), data.RandomString) } -func (r HPCCacheNFSTargetResource) usageModel(data acceptance.TestData, modelName string) string { +func (r HPCCacheNFSTargetResource) usageModelReadHeavyCheck180(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -202,18 +202,73 @@ resource "azurerm_hpc_cache_nfs_target" "test" { resource_group_name = azurerm_resource_group.test.name cache_name = azurerm_hpc_cache.test.name target_host_name = azurerm_linux_virtual_machine.test.private_ip_address - usage_model = "%s" + usage_model = "READ_HEAVY_CHECK_180" + + namespace_junction { + namespace_path = "/nfs/a1" + nfs_export = "/export/a" + target_path = "1" + } + + namespace_junction { + namespace_path = "/nfs/b" + nfs_export = "/export/b" + } +} +`, r.cacheTemplate(data), data.RandomString) +} + +func (r HPCCacheNFSTargetResource) usageModelReadWrite(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_hpc_cache_nfs_target" "test" { + name = "acctest-HPCCTGT-%s" + resource_group_name = azurerm_resource_group.test.name + cache_name = azurerm_hpc_cache.test.name + target_host_name = azurerm_linux_virtual_machine.test.private_ip_address + usage_model = "READ_WRITE" + verification_timer_in_seconds = 29000 + write_back_timer_in_seconds = 3700 + namespace_junction { namespace_path = "/nfs/a1" nfs_export = "/export/a" target_path = "1" } + namespace_junction { namespace_path = "/nfs/b" nfs_export = "/export/b" } } -`, r.cacheTemplate(data), data.RandomString, modelName) +`, r.cacheTemplate(data), data.RandomString) +} + +func (r HPCCacheNFSTargetResource) usageModelReadOnly(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_hpc_cache_nfs_target" "test" { + name = "acctest-HPCCTGT-%s" + resource_group_name = azurerm_resource_group.test.name + cache_name = azurerm_hpc_cache.test.name + target_host_name = azurerm_linux_virtual_machine.test.private_ip_address + usage_model = "READ_ONLY" + verification_timer_in_seconds = 30000 + + namespace_junction { + namespace_path = "/nfs/a1" + nfs_export = "/export/a" + target_path = "1" + } + + namespace_junction { + namespace_path = "/nfs/b" + nfs_export = "/export/b" + } +} +`, r.cacheTemplate(data), data.RandomString) } func (r HPCCacheNFSTargetResource) namespaceJunction(data acceptance.TestData) string { diff --git a/website/docs/r/hpc_cache_nfs_target.html.markdown b/website/docs/r/hpc_cache_nfs_target.html.markdown index 17aa671389c3..807caababb0c 100644 --- a/website/docs/r/hpc_cache_nfs_target.html.markdown +++ b/website/docs/r/hpc_cache_nfs_target.html.markdown @@ -143,6 +143,10 @@ The following arguments are supported: * `namespace_junction` - (Required) Can be specified multiple times to define multiple `namespace_junction`. Each `namespace_junction` block supports fields documented below. +* `verification_timer_in_seconds` - (Optional) The amount of time the cache waits before it checks the back-end storage for file updates. Possible values are between `1` and `31536000`. + +* `write_back_timer_in_seconds` - (Optional) The amount of time the cache waits after the last file change before it copies the changed file to back-end storage. Possible values are between `1` and `31536000`. + --- A `namespace_junction` block supports the following: From b27377310258355a30373c100c26957c4ce78de9 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Wed, 13 Dec 2023 12:15:00 +0800 Subject: [PATCH 2/3] update code --- internal/services/storagecache/hpc_cache_nfs_target_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/storagecache/hpc_cache_nfs_target_resource.go b/internal/services/storagecache/hpc_cache_nfs_target_resource.go index eab6a6b7957d..04264f1a31eb 100644 --- a/internal/services/storagecache/hpc_cache_nfs_target_resource.go +++ b/internal/services/storagecache/hpc_cache_nfs_target_resource.go @@ -5,7 +5,6 @@ package storagecache import ( "fmt" - "github.com/hashicorp/terraform-provider-azurerm/utils" "log" "time" @@ -19,6 +18,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" + "github.com/hashicorp/terraform-provider-azurerm/utils" ) func resourceHPCCacheNFSTarget() *pluginsdk.Resource { From 499a4e6926504b79529190ede128d3c99b5c195c Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Wed, 13 Dec 2023 18:46:25 +0800 Subject: [PATCH 3/3] update code --- .../services/storagecache/hpc_cache_nfs_target_resource.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/services/storagecache/hpc_cache_nfs_target_resource.go b/internal/services/storagecache/hpc_cache_nfs_target_resource.go index 04264f1a31eb..1724dae48fe2 100644 --- a/internal/services/storagecache/hpc_cache_nfs_target_resource.go +++ b/internal/services/storagecache/hpc_cache_nfs_target_resource.go @@ -167,11 +167,11 @@ func resourceHPCCacheNFSTargetCreateOrUpdate(d *pluginsdk.ResourceData, meta int } if v, ok := d.GetOk("verification_timer_in_seconds"); ok { - param.Properties.BlobNfs.VerificationTimer = utils.Int64(int64(v.(int))) + param.Properties.Nfs3.VerificationTimer = utils.Int64(int64(v.(int))) } if v, ok := d.GetOk("write_back_timer_in_seconds"); ok { - param.Properties.BlobNfs.WriteBackTimer = utils.Int64(int64(v.(int))) + param.Properties.Nfs3.WriteBackTimer = utils.Int64(int64(v.(int))) } if err := client.CreateOrUpdateThenPoll(ctx, id, param); err != nil {