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 for access_policy_name #11186

Merged
merged 1 commit into from
Apr 2, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ func resourceHPCCacheBlobTarget() *schema.Resource {
},

"access_policy_name": {
Type: schema.TypeString,
Optional: true,
// TODO 3.0: Remove `Computed` and add `Default: "default"`.
// O+C here is for backward compatibility to make the existing tf state no need to change to make the resource created prior to API 2021-03-01 work.
Computed: true,
Type: schema.TypeString,
Optional: true,
Default: "default",
ValidateFunc: validation.StringIsNotEmpty,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ func resourceHPCCacheNFSTarget() *schema.Resource {
Default: "",
ValidateFunc: validate.CacheNFSTargetPath,
},

"access_policy_name": {
Type: schema.TypeString,
Optional: true,
Default: "default",
ValidateFunc: validation.StringIsNotEmpty,
},
},
},
},
Expand Down Expand Up @@ -228,9 +235,10 @@ func expandNamespaceJunctions(input []interface{}) *[]storagecache.NamespaceJunc
for _, v := range input {
b := v.(map[string]interface{})
result = append(result, storagecache.NamespaceJunction{
NamespacePath: utils.String(b["namespace_path"].(string)),
NfsExport: utils.String(b["nfs_export"].(string)),
TargetPath: utils.String(b["target_path"].(string)),
NamespacePath: utils.String(b["namespace_path"].(string)),
NfsExport: utils.String(b["nfs_export"].(string)),
TargetPath: utils.String(b["target_path"].(string)),
NfsAccessPolicy: utils.String(b["access_policy_name"].(string)),
})
}

Expand Down Expand Up @@ -260,10 +268,16 @@ func flattenNamespaceJunctions(input *[]storagecache.NamespaceJunction) []interf
targetPath = *v
}

accessPolicy := ""
if v := e.NfsAccessPolicy; v != nil {
accessPolicy = *e.NfsAccessPolicy
}

output = append(output, map[string]interface{}{
"namespace_path": namespacePath,
"nfs_export": nfsExport,
"target_path": targetPath,
"namespace_path": namespacePath,
"nfs_export": nfsExport,
"target_path": targetPath,
"access_policy_name": accessPolicy,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,42 @@ func TestAccHPCCacheNFSTarget_requiresImport(t *testing.T) {
})
}

func TestAccHPCCacheNFSTarget_accessPolicy(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_hpc_cache_nfs_target", "test")
r := HPCCacheNFSTargetResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.basic(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.accessPolicy(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.accessPolicyUpdate(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.basic(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (HPCCacheNFSTargetResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) {
id, err := parse.StorageTargetID(state.ID)
if err != nil {
Expand Down Expand Up @@ -184,6 +220,76 @@ resource "azurerm_hpc_cache_nfs_target" "test" {
`, r.cacheTemplate(data), data.RandomString)
}

func (r HPCCacheNFSTargetResource) accessPolicy(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_hpc_cache_access_policy" "test" {
name = "p1"
hpc_cache_id = azurerm_hpc_cache.test.id
access_rule {
scope = "default"
access = "rw"
}

# This is not needed in Terraform v0.13, whilst needed in v0.14.
# Once https://github.com/hashicorp/terraform/issues/28193 is fixed, we can remove this lifecycle block.
lifecycle {
create_before_destroy = true
}
}

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_HEAVY_INFREQ"
namespace_junction {
namespace_path = "/nfs/a1"
nfs_export = "/export/a"
target_path = "1"
access_policy_name = azurerm_hpc_cache_access_policy.test.name
}
}
`, r.cacheTemplate(data), data.RandomString)
}

func (r HPCCacheNFSTargetResource) accessPolicyUpdate(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_hpc_cache_access_policy" "test" {
name = "p2"
hpc_cache_id = azurerm_hpc_cache.test.id
access_rule {
scope = "default"
access = "rw"
}

# This is not needed in Terraform v0.13, whilst needed in v0.14.
# Once https://github.com/hashicorp/terraform/issues/28193 is fixed, we can remove this lifecycle block.
lifecycle {
create_before_destroy = true
}
}

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_HEAVY_INFREQ"
namespace_junction {
namespace_path = "/nfs/a1"
nfs_export = "/export/a"
target_path = "1"
access_policy_name = azurerm_hpc_cache_access_policy.test.name
}
}
`, r.cacheTemplate(data), data.RandomString)
}

func (r HPCCacheNFSTargetResource) requiresImport(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/hpc_cache_blob_target.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ The following arguments are supported:

-> **Note:** This is the Resource Manager ID of the Storage Container, rather than the regular ID - and can be accessed on the `azurerm_storage_container` Data Source/Resource as `resource_manager_id`.

* `access_policy_name` - (Optional) The name of the access policy applied to this target.
* `access_policy_name` - (Optional) The name of the access policy applied to this target. Defaults to `default`.

## Attributes Reference

Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/hpc_cache_nfs_target.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ A `namespace_junction` block supports the following:

* `target_path` - (Optional) The relative subdirectory path from the `nfs_export` to map to the `namespace_path`. Defaults to `""`, in which case the whole `nfs_export` is exported.

* `access_policy_name` - (Optional) The name of the access policy applied to this target. Defaults to `default`.

## Attributes Reference

The following attributes are exported:
Expand Down