From 74f5147d1e921192feab30dd9de2301e0167c558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Nie=C3=9F?= Date: Fri, 18 Nov 2022 15:47:20 +0100 Subject: [PATCH] fix: Status field missing from cluster resource fixes: #190 --- netbox/internal/util/nested.go | 8 ++++++++ .../resource_netbox_virtualization_cluster.go | 15 +++++++++++++++ ...resource_netbox_virtualization_cluster_test.go | 1 + 3 files changed, 24 insertions(+) diff --git a/netbox/internal/util/nested.go b/netbox/internal/util/nested.go index 7a7669859..da5ee62f7 100644 --- a/netbox/internal/util/nested.go +++ b/netbox/internal/util/nested.go @@ -4,6 +4,14 @@ import ( "github.com/smutel/go-netbox/v3/netbox/models" ) +func GetClusterStatusValue(nested *models.ClusterStatus) *string { + if nested == nil { + return nil + } + + return nested.Value +} + func GetNestedIPAddressAddress(nested *models.NestedIPAddress) *string { if nested == nil { return nil diff --git a/netbox/virtualization/resource_netbox_virtualization_cluster.go b/netbox/virtualization/resource_netbox_virtualization_cluster.go index 54f92b160..b8a830b10 100644 --- a/netbox/virtualization/resource_netbox_virtualization_cluster.go +++ b/netbox/virtualization/resource_netbox_virtualization_cluster.go @@ -72,6 +72,14 @@ func ResourceNetboxVirtualizationCluster() *schema.Resource { Optional: true, Description: "The site of this cluster.", }, + "status": { + Type: schema.TypeString, + Optional: true, + Default: "active", + ValidateFunc: validation.StringInSlice([]string{"offline", "active", + "planned", "staging", "decommissioning"}, false), + Description: "The status among offline, active, planned, staging or decommissioning (active by default).", + }, "tag": &tag.TagSchema, "tenant_id": { Type: schema.TypeInt, @@ -126,6 +134,7 @@ func resourceNetboxVirtualizationClusterCreate(ctx context.Context, d *schema.Re Name: &name, Tags: tag.ConvertTagsToNestedTags(tags), Type: &typeID, + Status: d.Get("status").(string), } if groupID != 0 { @@ -199,6 +208,9 @@ func resourceNetboxVirtualizationClusterRead(ctx context.Context, d *schema.Reso if err = d.Set("site_id", util.GetNestedSiteID(resource.Site)); err != nil { return diag.FromErr(err) } + if err = d.Set("status", util.GetClusterStatusValue(resource.Status)); err != nil { + return diag.FromErr(err) + } if err = d.Set("tag", tag.ConvertNestedTagsToTags(resource.Tags)); err != nil { return diag.FromErr(err) } @@ -247,6 +259,9 @@ func resourceNetboxVirtualizationClusterUpdate(ctx context.Context, d *schema.Re name := d.Get("name").(string) params.Name = &name } + if d.HasChange("status") { + params.Status = d.Get("status").(string) + } if d.HasChange("site_id") { siteID := int64(d.Get("site_id").(int)) params.Site = &siteID diff --git a/netbox/virtualization/resource_netbox_virtualization_cluster_test.go b/netbox/virtualization/resource_netbox_virtualization_cluster_test.go index 9171ca77f..ae6371238 100644 --- a/netbox/virtualization/resource_netbox_virtualization_cluster_test.go +++ b/netbox/virtualization/resource_netbox_virtualization_cluster_test.go @@ -126,6 +126,7 @@ func testAccCheckNetboxVirtualizationClusterConfig(nameSuffix string, resourceFu group_id = netbox_virtualization_cluster_group.test.id site_id = netbox_dcim_site.test.id tenant_id = netbox_tenancy_tenant.test.id + status = "decommissioning" comments = <<-EOT Test cluster