Skip to content

Commit

Permalink
fix: Status field missing from cluster resource
Browse files Browse the repository at this point in the history
fixes: #190
  • Loading branch information
amhn authored and smutel committed Mar 14, 2023
1 parent a93a3c9 commit 74f5147
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions netbox/internal/util/nested.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions netbox/virtualization/resource_netbox_virtualization_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 74f5147

Please sign in to comment.