Skip to content

Commit

Permalink
Add internal fixed_position param to status page resources and sections
Browse files Browse the repository at this point in the history
  • Loading branch information
gyfis committed Oct 20, 2021
1 parent b7eca71 commit 372c16b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions internal/provider/ptr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
7 changes: 5 additions & 2 deletions internal/provider/resource_status_page_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 7 additions & 4 deletions internal/provider/resource_status_page_section.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 372c16b

Please sign in to comment.