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_nfs_target - support verification_timer_in_seconds and write_back_timer_in_seconds properties #24208

Merged
merged 3 commits into from
Dec 14, 2023
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
23 changes: 23 additions & 0 deletions internal/services/storagecache/hpc_cache_nfs_target_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,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 {
Expand Down Expand Up @@ -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),
},
},
}
}
Expand Down Expand Up @@ -153,6 +166,14 @@ func resourceHPCCacheNFSTargetCreateOrUpdate(d *pluginsdk.ResourceData, meta int
},
}

if v, ok := d.GetOk("verification_timer_in_seconds"); ok {
param.Properties.Nfs3.VerificationTimer = utils.Int64(int64(v.(int)))
}

if v, ok := d.GetOk("write_back_timer_in_seconds"); ok {
param.Properties.Nfs3.WriteBackTimer = utils.Int64(int64(v.(int)))
}

if err := client.CreateOrUpdateThenPoll(ctx, id, param); err != nil {
return fmt.Errorf("creating %s: %+v", id, err)
}
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/hpc_cache_nfs_target.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading