From f105b5a17184c3c147737eb940651a0f55a9a1ec Mon Sep 17 00:00:00 2001 From: Gabriela Limberea <115462667+glimberea@users.noreply.github.com> Date: Mon, 26 Aug 2024 13:23:13 +0300 Subject: [PATCH] fix: nfs nitpicks (#642) * doc nitpicks * remove additional minversion check * make fmt * add basic example * add basic setup for share example --- docs/resources/nfs_cluster.md | 49 +++++++++++++++++++++++++++--- docs/resources/nfs_share.md | 35 +++++++++++++++++++-- ionoscloud/resource_nfs_cluster.go | 6 ++-- 3 files changed, 82 insertions(+), 8 deletions(-) diff --git a/docs/resources/nfs_cluster.md b/docs/resources/nfs_cluster.md index 74732db55..62a64e923 100644 --- a/docs/resources/nfs_cluster.md +++ b/docs/resources/nfs_cluster.md @@ -14,6 +14,41 @@ Create clusters of Network File Storage (NFS) on IonosCloud. ## Example Usage ```hcl +# Basic example + +resource "ionoscloud_datacenter" "nfs_dc" { + name = "NFS Datacenter" + location = "de/txl" + description = "Datacenter Description" + sec_auth_protection = false +} + +resource "ionoscloud_lan" "nfs_lan" { + datacenter_id = ionoscloud_datacenter.nfs_dc.id + public = false + name = "Lan for NFS" +} + +resource "ionoscloud_nfs_cluster" "example" { + name = "test" + location = "de/txl" + size = 2 + + nfs { + min_version = "4.2" + } + + connections { + datacenter_id = ionoscloud_datacenter.nfs_dc.id + ip_address = "192.168.100.10/24" + lan = ionoscloud_lan.nfs_lan.id + } +} +``` + +```hcl +# Complete example + resource "ionoscloud_datacenter" "nfs_dc" { name = "NFS Datacenter" location = "de/txl" @@ -62,6 +97,12 @@ resource "ionoscloud_server" "nfs_server" { } } +locals { + nfs_server_cidr = format("%s/24", ionoscloud_server.nfs_server.nic[0].ips[0]) + nfs_cluster_ip = cidrhost(local.nfs_server_cidr, 10) + nfs_cluster_cidr = format("%s/24", local.nfs_cluster_ip) +} + resource "ionoscloud_nfs_cluster" "example" { name = "test" location = "de/txl" @@ -73,7 +114,7 @@ resource "ionoscloud_nfs_cluster" "example" { connections { datacenter_id = ionoscloud_datacenter.nfs_dc.id - ip_address = format("%s/24", ionoscloud_server.nfs_server.nic[0].ips[0]) + ip_address = local.nfs_cluster_cidr lan = ionoscloud_lan.nfs_lan.id } } @@ -89,8 +130,8 @@ The following arguments are supported: - `de/txl` - Berlin - `size` - (Required) The size of the Network File Storage cluster in TiB. Note that the cluster size cannot be reduced after provisioning. This value determines the billing fees. Default is `2`. The minimum value is `2` and the maximum value is `42`. - `nfs` - (Optional) The NFS configuration for the Network File Storage cluster. Each NFS configuration supports the following: - - `min_version` - (Optional) The minimum supported version of the NFS cluster. Default is `4.2` -- `connections` - (Required) A list of connections for the Network File Storage cluster. You can specify only one connection. Each connection supports the following: + - `min_version` - (Optional) The minimum supported version of the NFS cluster. Supported values: `4.2`. Default is `4.2`. +- `connections` - (Required) A list of connections for the Network File Storage cluster. You can specify only one connection. Connections are **immutable**. Each connection supports the following: - `datacenter_id` - (Required) The ID of the datacenter where the Network File Storage cluster is located. - `ip_address` - (Required) The IP address and prefix of the Network File Storage cluster. The IP address can be either IPv4 or IPv6. The IP address has to be given with CIDR notation. - `lan` - (Required) The Private LAN to which the Network File Storage cluster must be connected. @@ -101,4 +142,4 @@ A Network File Storage Cluster resource can be imported using its `location` and ```shell terraform import ionoscloud_nfs_cluster.name {location}:{uuid} -``` \ No newline at end of file +``` diff --git a/docs/resources/nfs_share.md b/docs/resources/nfs_share.md index 88dfd0abc..046564da4 100644 --- a/docs/resources/nfs_share.md +++ b/docs/resources/nfs_share.md @@ -14,8 +14,39 @@ Creates and manages Network File Storage (NFS) Share objects on IonosCloud. ## Example Usage ```hcl +# Basic example + +resource "ionoscloud_datacenter" "nfs_dc" { + name = "NFS Datacenter" + location = "de/txl" + description = "Datacenter Description" + sec_auth_protection = false +} + +resource "ionoscloud_lan" "nfs_lan" { + datacenter_id = ionoscloud_datacenter.nfs_dc.id + public = false + name = "Lan for NFS" +} + +resource "ionoscloud_nfs_cluster" "example" { + name = "test" + location = "de/txl" + size = 2 + + nfs { + min_version = "4.2" + } + + connections { + datacenter_id = ionoscloud_datacenter.nfs_dc.id + ip_address = "192.168.100.10/24" + lan = ionoscloud_lan.nfs_lan.id + } +} + resource "ionoscloud_nfs_share" "example" { - location = ionoscloud_nfs_cluster.example.location + location = "de/txl" cluster_id = ionoscloud_nfs_cluster.example.id name = "example-share" @@ -62,4 +93,4 @@ A Network File Storage Share resource can be imported using its `location`, `clu ```shell terraform import ionoscloud_nfs_share.name location:cluster_id:resource_id -``` \ No newline at end of file +``` diff --git a/ionoscloud/resource_nfs_cluster.go b/ionoscloud/resource_nfs_cluster.go index 0c9811b0f..666abca34 100644 --- a/ionoscloud/resource_nfs_cluster.go +++ b/ionoscloud/resource_nfs_cluster.go @@ -29,8 +29,10 @@ func resourceNFSCluster() *schema.Resource { Schema: map[string]*schema.Schema{ "location": { Type: schema.TypeString, - Description: fmt.Sprintf("The location of the Network File Storage Cluster. "+ - "Available locations: '%s'", strings.Join(nfs.ValidNFSLocations, ", '")), + Description: fmt.Sprintf( + "The location of the Network File Storage Cluster. "+ + "Available locations: '%s'", strings.Join(nfs.ValidNFSLocations, ", '"), + ), Required: true, ForceNew: true, ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice(nfs.ValidNFSLocations, false)),