This document is provided as an AI translation. If the translation differs from the original, the Korean original takes precedence.

Storage > NAS > Terraform User Guide

This document details how to use NHN Cloud NAS services with Terraform.

Terraform

Terraform is an open-source tool designed for seamless infrastructure provisioning, secure updates, and efficient configuration management. For basics, refer to User Guide > NHN Cloud > Terraform User Guide.

Resource dependency

While resources are generally independent, some may have dependencies on others. When a resource references information from another through its label, Terraform automatically establishes these dependencies. For example, an interface named interface1 that connects to a volume named volume1 can be defined as follows.

# volume resource
resource "nhncloud_nas_storage_volume_v1" "volume1" {
  name = "volume1"
  size_gb = 300

  mount_protocol {
    protocol = "nfs"
  }
}

# interface resource
resource "nhncloud_nas_storage_volume_interface_v1" "interface1" {
  volume_id = nhncloud_nas_storage_volume_v1.volume1.id
  subnet_id = data.nhncloud_networking_vpcsubnet_v2.default_subnet.id
}

Note

For information on how to specify explicit resource dependencies, refer to Terraform's Resource dependencies document.

Resources

Create a Volume

Note: Using the CIFS protocol

To use the CIFS protocol, you must create CIFS credentials. Credentials are managed on a per-project basis, and you must register CIFS credentials to allow to access each CIFS volume. You can create CIFS credentials through the Storage > NAS > Manage CIFS Credentials of the console.

Note: Setting up encryption key storage

When you create an encrypted volume, the symmetric key used for encryption is stored in the key store of the NHN Cloud Secure Key Manager service. Therefore, to create an encrypted volume, you must first create a key store in the Secure Key Manager service. Check the key store ID and enter it in the encryption key store settings. You can enter the created key store ID in Storage > NAS > Encryption Key Store Settings in the console. When you create an encrypted volume, the symmetric key is stored in the configured key store. The symmetric key stored in the key store cannot be deleted while the encrypted volume is in use. When you delete the encrypted volume, the symmetric key is also deleted. When you change the key store ID, symmetric keys for encrypted volumes created afterward are stored in the new key store. Symmetric keys stored in the existing key store are retained.

# Create an empty NAS volume using the NFS protocol
resource "nhncloud_nas_storage_volume_v1" "volume_01" {
  name = "nas_volume_01"
  size_gb = 300
  mount_protocol {
    protocol = "nfs"
  }
}

# Create an empty NAS volume using the CIFS protocol
resource "nhncloud_nas_storage_volume_v1" "volume_02" {
  name = "nas_volume_02"
  size_gb = 300
  mount_protocol {
    protocol = "cifs"
    cifs_auth_ids = ["auth_id"]
  }
}

# Create a volume with settings including ACL, encryption settings
resource "nhncloud_nas_storage_volume_v1" "volume_03" {
  name = "nas_volume_03"
  description = "create nas volume by terraform"
  size_gb = 300

  acl = ["10.10.10.0/24"]


  encryption {
    enabled = true
  }


  mount_protocol {
    protocol = "cifs"
    cifs_auth_ids = ["auth_id"]
  }

  snapshot_policy {
    max_scheduled_count = 3
    reserve_percent = 10

    schedule {
      time = "00:00"
      time_offset = "+09:00"
      weekdays = [1, 3, 5]
    }
  }
}
Name Type Required Modifiable Description
region String N - Region of the volume to be created
Default is the region set in the provider configuration file
name String Y - Volume name
description String N O Volume description
size_gb Integer Y O Volume size (GB)
The volume can be set from a minimum of 300 GB to a maximum of 10,000 GB, in 100 GB increments.
acl List N O ACL list to set when creating a volume
Can be entered in IP or CIDR format.
encryption Object N - Encryption settings object when creating a volume
encryption.enabled Boolean N - Whether to enable encryption
After the encryption keystore is set up, setting its field to true enables encryption.
mount_protocol Object N - Protocol settings object when creating a volume
mount_protocol.cifs_auth_ids List(String) N O List of CIFS authentication IDs
No input required for NFS protocol selection
mount_protocol.protocol String Y - Protocol to use when mounting a volume
You can select either nfs or cifs.
snapshot_policy Object N - Volume snapshot settings object
snapshot_policy.max_scheduled_count Integer N O Maximum number of snapshots to store
You can set a maximum of 20, and the first automatically created snapshot will be deleted when the maximum number of saves is reached.
snapshot_policy.reserve_percent Integer N O Snapshot capacity ratio
snapshot_policy.schedule Object N - Snapshot auto-creation object
If null, snapshot auto-creation will not be configured.
snapshot_policy.schedule.time String N O Snapshot auto-creation time
snapshot_policy.schedule.time_offset String N O Time zone for snapshot auto-create
snapshot_policy.schedule.weekdays List N O Days of the week for snapshot auto-creation
An empty list means every day, and the days of the week are specified as a list of numbers from 0 (Sunday) to 6 (Saturday).

Attach an Interface to a Volume

data "nhncloud_networking_vpcsubnet_v2" "default_subnet" {
  ...
}

resource "nhncloud_nas_storage_volume_interface_v1" "nas_interface_01" {
  volume_id = nhncloud_nas_storage_volume_v1.volume_01.id
  subnet_id = data.nhncloud_networking_vpcsubnet_v2.default_subnet.id
}
Name Type Required Modifiable Description
region String N - Region of the volume to attach
Default is the region set in the provider configuration file
volume_id String Y - ID of the volume to attach
subnet_id String Y - ID of the subnet to attach

Set up Replication

When you create a Replication Settings resource, the target volume is automatically created.

You can update the target volume by changing the dst_volume value in the Replication Settings resource, but deleting the Replication Settings resource does not automatically delete the target volume.

Caution

Modifying certain values in the replication configuration resource may cause the existing resource to be destroyed and recreated; however, the original destination volume will persist. Please be aware that if the existing destination volume and the new one share the same name, the creation process may fail.

Note

Destination volumes that remain after a resource deletion or update must be managed manually via the console.

resource "nhncloud_nas_storage_volume_mirror_v1" "nas_mirror_01" {
  src_volume_id = nhncloud_nas_storage_volume_v1.volume_01.id
  dst_region    = "KR2"
  dst_tenant_id = "ba3be1254ab141bcaef674e74630a31f"

  dst_volume {
    name        = "nas_mirror"
    description = "create nas mirror by terraform"
    size_gb     = 400

    mount_protocol {
      protocol = "nfs"
    }
  }
}
Name Type Required Modifiable Description
src_region String N - Region of the source volume
Default is the region set in the provider configuration file
src_volume_id String Y - ID of the source volume
dst_region String Y - Region of the replication target volume
dst_tenant_id String Y - Tenant ID of the replication target volume
dst_volume Object Y - Replication target volume creation request object
dst_volume.acl List N O ACL list to set when creating a volume
Can be entered in IP or CIDR format.
dst_volume.description String N O Volume description
dst_volume.encryption Object N - Encryption settings object for volume creation
dst_volume.encryption.enabled Boolean N - Whether encryption settings are enabled
After the encryption keystore is set up, setting its field to true enables encryption.
dst_volume.mount_protocol Object N - Protocol settings object for volume creation
dst_volume.mount_protocol.cifs_auth_ids List(String) N O List of CIFS authentication IDs
No input required for NFS protocol selection
dst_volume.mount_protocol.protocol String Y - Protocol specified when mounting a volume
You can select either nfs or cifs.
dst_volume.name String Y - Volume name
dst_volume.size_gb Integer Y O Volume size (GB)
The volume can be set from a minimum of 300 GB to a maximum of 10,000 GB, in 100 GB increments.
dst_volume.snapshot_policy Object N - Volume snapshot settings object
dst_volume.snapshot_policy.max_scheduled_count Integer N O Maximum number of snapshots to store
You can set a maximum of 20, and the first automatically created snapshot will be deleted when the maximum number of saves is reached.
dst_volume.snapshot_policy.reserve_percent Integer N O Snapshot capacity ratio
dst_volume.snapshot_policy.schedule Object N O Snapshot auto-creation object
If null, snapshot auto-creation will not be configured.
dst_volume.snapshot_policy.schedule.time String N O Snapshot auto-creation time
dst_volume.snapshot_policy.schedule.time_offset String N O Time zone for snapshot auto-creation
dst_volume.snapshot_policy.schedule.weekdays List N O Days of the week for snapshot auto-creation
An empty list means every day, and the days of the week are specified as a list of numbers from 0 (Sunday) to 6 (Saturday).

References

TOP