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

With new datasource : ovh_dedicated_nasha_partition #817

Merged
merged 1 commit into from
Jan 31, 2025
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 ovh/data_dedicated_nasha.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ func dataSourceDedicatedNasha() *schema.Resource {
Computed: true,
Description: "the size of the HA-NAS",
},

"partitions_list": {
Type: schema.TypeList,
Computed: true,
Description: "List of partition names for this HA-NAS",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
}
}
Expand All @@ -90,12 +99,26 @@ func dataSourceDedicatedNashaRead(c context.Context, d *schema.ResourceData, met
)
}

var partitionsList []string
err = config.OVHClient.Get(
fmt.Sprintf("/dedicated/nasha/%s/partition", url.PathEscape(serviceName)),
&partitionsList,
)
if err != nil {
return diag.Errorf(
"Error calling /dedicated/nasha/%s/partition: %s",
serviceName,
err,
)
}

d.SetId(ds.ServiceName)
d.Set("urn", ds.URN)
d.Set("service_name", ds.ServiceName)
d.Set("monitored", ds.Monitored)
d.Set("zpool_size", ds.ZpoolSize)
d.Set("zpool_capacity", ds.ZpoolCapacity)
d.Set("partitions_list", partitionsList)
d.Set("datacenter", ds.Datacenter)
d.Set("disk_type", ds.DiskType)
d.Set("can_create_partition", ds.CanCreatePartition)
Expand Down
85 changes: 85 additions & 0 deletions ovh/data_dedicated_nasha_partition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package ovh

import (
"context"
"fmt"
"net/url"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceDedicatedNashaPartition() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceDedicatedNashaPartitionRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"service_name": {
Type: schema.TypeString,
Required: true,
},

// Computed
"description": {
Type: schema.TypeString,
Computed: true,
},
"protocol": {
Type: schema.TypeString,
Computed: true,
},
"size": {
Type: schema.TypeInt,
Computed: true,
},
"capacity": {
Type: schema.TypeInt,
Computed: true,
},
"used_by_snapshots": {
Type: schema.TypeInt,
Computed: true,
},
},
}
}

func dataSourceDedicatedNashaPartitionRead(c context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
config := meta.(*Config)
serviceName := d.Get("service_name").(string)
partitionName := d.Get("name").(string)

ds := &DedicatedNASHAPartition{}
err := config.OVHClient.Get(
fmt.Sprintf(
"/dedicated/nasha/%s/partition/%s",
url.PathEscape(serviceName),
url.PathEscape(partitionName),
),
&ds,
)

if err != nil {
return diag.Errorf(
"Error calling /dedicated/nasha/%s/partition/%s:\n\t %q",
serviceName,
partitionName,
err,
)
}

d.SetId(ds.Name)
d.Set("name", ds.Name)
d.Set("description", ds.Description)
d.Set("protocol", ds.Protocol)
d.Set("size", ds.Size)
d.Set("capacity", ds.Capacity)
d.Set("used_by_snapshots", ds.UsedBySnapshots)

return nil
}
1 change: 1 addition & 0 deletions ovh/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func Provider() *schema.Provider {
"ovh_dedicated_installation_templates": dataSourceDedicatedInstallationTemplates(),
"ovh_dedicated_installation_template": dataSourceDedicatedInstallationTemplate(),
"ovh_dedicated_nasha": dataSourceDedicatedNasha(),
"ovh_dedicated_nasha_partition": dataSourceDedicatedNashaPartition(),
"ovh_dedicated_server": dataSourceDedicatedServer(),
"ovh_dedicated_server_boots": dataSourceDedicatedServerBoots(),
"ovh_dedicated_servers": dataSourceDedicatedServers(),
Expand Down
4 changes: 4 additions & 0 deletions ovh/types_dedicated_nasha.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

type DedicatedNASHAPartitionsList struct {
PartitionName []string `json:"partitionName"`
}

type DedicatedNASHA struct {
ServiceName string `json:"serviceName,omitempty"`
Monitored bool `json:"monitored,omitempty"`
Expand Down
3 changes: 2 additions & 1 deletion website/docs/d/dedicated_nasha.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ In addition, the following attributes are exported:
* `ip` - Access IP of HA-NAS
* `monitored` - Send an email to customer if any issue is detected
* `zpool_capacity` - percentage of HA-NAS space used in %
* `zpool_size` - the size of the HA-NAS in GB
* `zpool_size` - the size of the HA-NAS in GB
* `partitions_list` - the list of the HA-NAS partitions name
33 changes: 33 additions & 0 deletions website/docs/d/dedicated_nasha_partition.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
subcategory : "NAS-HA"
---

# ovh_dedicated_nasha_partition (Data Source)

Use this data source to retrieve information about a dedicated HA-NAS partition.

## Example Usage

```hcl
data "ovh_dedicated_nasha_partition" "my_nas_ha_partition" {
service_name = "zpool-12345"
name = "my-zpool-partition"
}
```

## Argument Reference

* `service_name` - (Required) The service_name of your dedicated HA-NAS.
* `name` - (Required) The name of your dedicated HA-NAS partition.

## Attributes Reference

`id` is set with the name of the dedicated HA-NAS partition.
In addition, the following attributes are exported:

* `size` - size of the partition in GB
* `protocol` - one of "NFS", "CIFS" or "NFS_CIFS"
* `description` - A brief description of the partition
* `capacity` - Percentage of partition space used in %
* `used_by_snapshots` - Percentage of partition space used by snapshots in %