From 372c16b71a2a2729873420d6aae42d9fc790f164 Mon Sep 17 00:00:00 2001 From: gyfis Date: Wed, 20 Oct 2021 13:23:23 +0200 Subject: [PATCH] Add internal fixed_position param to status page resources and sections --- internal/provider/ptr.go | 5 +++++ internal/provider/resource_status_page_resource.go | 7 +++++-- internal/provider/resource_status_page_section.go | 11 +++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/internal/provider/ptr.go b/internal/provider/ptr.go index 6e2233f..e35a602 100644 --- a/internal/provider/ptr.go +++ b/internal/provider/ptr.go @@ -44,3 +44,8 @@ func load(d *schema.ResourceData, key string, receiver interface{}) { panic(fmt.Errorf("unexpected type %T", receiver)) } } + +func truePtr() *bool { + b := true + return &b +} diff --git a/internal/provider/resource_status_page_resource.go b/internal/provider/resource_status_page_resource.go index b257a98..42c202c 100644 --- a/internal/provider/resource_status_page_resource.go +++ b/internal/provider/resource_status_page_resource.go @@ -98,6 +98,7 @@ type statusPageResource struct { Explanation *string `json:"explanation,omitempty"` History *bool `json:"history,omitempty"` Position *int `json:"position,omitempty"` + FixedPosition *bool `json:"fixed_position,omitempty"` } type statusPageResourceHTTPResponse struct { @@ -131,9 +132,10 @@ func statusPageResourceCreate(ctx context.Context, d *schema.ResourceData, meta for _, e := range statusPageResourceRef(&in) { load(d, e.k, e.v) } + in.FixedPosition = truePtr() statusPageID := d.Get("status_page_id").(string) var out statusPageResourceHTTPResponse - if err := resourceCreate(ctx, meta, fmt.Sprintf("/api/v2/status-pages/%s/resources?fixed_position=true", url.PathEscape(statusPageID)), &in, &out); err != nil { + if err := resourceCreate(ctx, meta, fmt.Sprintf("/api/v2/status-pages/%s/resources", url.PathEscape(statusPageID)), &in, &out); err != nil { return err } d.SetId(out.Data.ID) @@ -169,8 +171,9 @@ func statusPageResourceUpdate(ctx context.Context, d *schema.ResourceData, meta load(d, e.k, e.v) } } + in.FixedPosition = truePtr() statusPageID := d.Get("status_page_id").(string) - return resourceUpdate(ctx, meta, fmt.Sprintf("/api/v2/status-pages/%s/resources/%s?fixed_position=true", url.PathEscape(statusPageID), url.PathEscape(d.Id())), &in) + return resourceUpdate(ctx, meta, fmt.Sprintf("/api/v2/status-pages/%s/resources/%s", url.PathEscape(statusPageID), url.PathEscape(d.Id())), &in) } func statusPageResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { diff --git a/internal/provider/resource_status_page_section.go b/internal/provider/resource_status_page_section.go index afd95f5..df417e2 100644 --- a/internal/provider/resource_status_page_section.go +++ b/internal/provider/resource_status_page_section.go @@ -64,8 +64,9 @@ func newStatusPageSectionResource() *schema.Resource { } type statusPageSection struct { - Name *string `json:"name,omitempty"` - Position *int `json:"position,omitempty"` + Name *string `json:"name,omitempty"` + Position *int `json:"position,omitempty"` + FixedPosition *bool `json:"fixed_position,omitempty"` } type statusPageSectionHTTPResponse struct { @@ -94,9 +95,10 @@ func statusPageSectionCreate(ctx context.Context, d *schema.ResourceData, meta i for _, e := range statusPageSectionRef(&in) { load(d, e.k, e.v) } + in.FixedPosition = truePtr() statusPageID := d.Get("status_page_id").(string) var out statusPageSectionHTTPResponse - if err := resourceCreate(ctx, meta, fmt.Sprintf("/api/v2/status-pages/%s/sections?fixed_position=true", url.PathEscape(statusPageID)), &in, &out); err != nil { + if err := resourceCreate(ctx, meta, fmt.Sprintf("/api/v2/status-pages/%s/sections", url.PathEscape(statusPageID)), &in, &out); err != nil { return err } d.SetId(out.Data.ID) @@ -132,8 +134,9 @@ func statusPageSectionUpdate(ctx context.Context, d *schema.ResourceData, meta i load(d, e.k, e.v) } } + in.FixedPosition = truePtr() statusPageID := d.Get("status_page_id").(string) - return resourceUpdate(ctx, meta, fmt.Sprintf("/api/v2/status-pages/%s/sections/%s?fixed_position=true", url.PathEscape(statusPageID), url.PathEscape(d.Id())), &in) + return resourceUpdate(ctx, meta, fmt.Sprintf("/api/v2/status-pages/%s/sections/%s", url.PathEscape(statusPageID), url.PathEscape(d.Id())), &in) } func statusPageSectionDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {