Skip to content

Commit

Permalink
Merge pull request #78 from iLert/feature/status-page-layout-fields
Browse files Browse the repository at this point in the history
Feature/status page layout fields
  • Loading branch information
STLVRTX authored Jan 3, 2024
2 parents 7c1a923 + 1a6214e commit 3ac37b0
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- fix/deprecate-uptime-monitors in [#74](https://github.com/iLert/terraform-provider-ilert/pull/74)
- feature/support-hours-resource in [#77](https://github.com/iLert/terraform-provider-ilert/pull/77)
- fixes issue [#76](https://github.com/iLert/terraform-provider-ilert/issues/76)
- feature/status-page-layout-fields in [#78](https://github.com/iLert/terraform-provider-ilert/pull/78)

## 15.12.2023, Version 2.3.1

Expand Down
2 changes: 2 additions & 0 deletions examples/status_page_group/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ resource "ilert_status_page" "example" {
# element {
# id = ilert_status_page_group.example.id
# type = "GROUP"
# options = ["expand"]
# child {
# id = ilert_service.example.id
# type = "SERVICE"
# options = ["no-graph"]
# }
# }
# element {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.19

require (
github.com/hashicorp/terraform-plugin-sdk/v2 v2.25.0
github.com/iLert/ilert-go/v3 v3.3.0
github.com/iLert/ilert-go/v3 v3.4.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/iLert/ilert-go/v3 v3.3.0 h1:vm99jXOwvVkY2FYyg34XeaRJqzDRl8Zxc7N3hzf3DqA=
github.com/iLert/ilert-go/v3 v3.3.0/go.mod h1:xHJ8qdmthK4HExcQOd3V5JARed/EBKTdX86MqrJ1yJ0=
github.com/iLert/ilert-go/v3 v3.4.0 h1:jcsJoaij1gsrgyyhN6xs0KoipEu/baWksskrokvJJRE=
github.com/iLert/ilert-go/v3 v3.4.0/go.mod h1:xHJ8qdmthK4HExcQOd3V5JARed/EBKTdX86MqrJ1yJ0=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
Expand Down
79 changes: 77 additions & 2 deletions ilert/resource_status_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ func resourceStatusPage() *schema.Resource {
Optional: true,
},
"custom_css": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
Description: "Don't use this field yet.",
},
"favicon_url": {
Type: schema.TypeString,
Expand Down Expand Up @@ -71,6 +72,12 @@ func resourceStatusPage() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"page_layout": {
Type: schema.TypeString,
Optional: true,
Default: ilert.StatusPageLayout.SingleColumn,
ValidateFunc: validation.StringInSlice(ilert.StatusPageLayoutAll, false),
},
"logo_redirect_url": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -149,6 +156,14 @@ func resourceStatusPage() *schema.Resource {
Required: true,
ValidateFunc: validation.StringInSlice(ilert.StatusPageElementTypeAll, false),
},
"options": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice(ilert.StatusPageElementOptionAll, false),
},
},
"child": {
Type: schema.TypeList,
Optional: true,
Expand All @@ -164,6 +179,14 @@ func resourceStatusPage() *schema.Resource {
Required: true,
ValidateFunc: validation.StringInSlice([]string{ilert.StatusPageElementTypeAll[0]}, false),
},
"options": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice(ilert.StatusPageElementOptionAll, false),
},
},
},
},
},
Expand All @@ -173,6 +196,12 @@ func resourceStatusPage() *schema.Resource {
},
},
},
"theme_mode": {
Type: schema.TypeString,
Optional: true,
Default: ilert.StatusPageThemeMode.Light,
ValidateFunc: validation.StringInSlice(ilert.StatusPageThemeModeAll, false),
},
},
CreateContext: resourceStatusPageCreate,
ReadContext: resourceStatusPageRead,
Expand Down Expand Up @@ -242,6 +271,10 @@ func buildStatusPage(d *schema.ResourceData) (*ilert.StatusPage, error) {
statusPage.PageDescription = val.(string)
}

if val, ok := d.GetOk("page_layout"); ok {
statusPage.PageLayout = val.(string)
}

if val, ok := d.GetOk("logo_redirect_url"); ok {
statusPage.LogoRedirectUrl = val.(string)
}
Expand Down Expand Up @@ -318,6 +351,15 @@ func buildStatusPage(d *schema.ResourceData) (*ilert.StatusPage, error) {
ID: eid,
Type: v["type"].(string),
}
if len(v["options"].([]interface{})) > 0 {
optionsList := v["options"].([]interface{})
options := make([]string, 0)
for _, value := range optionsList {
option := value.(string)
options = append(options, option)
}
el.Options = options
}
if v["child"] != nil {
cdr := make([]ilert.StatusPageElement, 0)
cL := v["child"].([]interface{})
Expand All @@ -332,6 +374,15 @@ func buildStatusPage(d *schema.ResourceData) (*ilert.StatusPage, error) {
ID: cid,
Type: v["type"].(string),
}
if len(v["options"].([]interface{})) > 0 {
optionsList := v["options"].([]interface{})
options := make([]string, 0)
for _, value := range optionsList {
option := value.(string)
options = append(options, option)
}
ch.Options = options
}
if v["child"] != nil && ch.Type == "SERVICE" {
log.Printf("[ERROR] Could not set child, as no children are allowed on type service %s", err.Error())
return nil, unconvertibleIDErr(v["id"].(string), err)
Expand All @@ -348,6 +399,10 @@ func buildStatusPage(d *schema.ResourceData) (*ilert.StatusPage, error) {
}
}

if val, ok := d.GetOk("theme_mode"); ok {
statusPage.ThemeMode = val.(string)
}

return statusPage, nil
}

Expand Down Expand Up @@ -450,6 +505,7 @@ func resourceStatusPageRead(ctx context.Context, d *schema.ResourceData, m inter
d.Set("show_incident_history_option", result.StatusPage.ShowIncidentHistoryOption)
d.Set("page_title", result.StatusPage.PageTitle)
d.Set("page_description", result.StatusPage.PageDescription)
d.Set("page_layout", result.StatusPage.PageLayout)
d.Set("logo_redirect_url", result.StatusPage.LogoRedirectUrl)
d.Set("activated", result.StatusPage.Activated)

Expand Down Expand Up @@ -483,6 +539,8 @@ func resourceStatusPageRead(ctx context.Context, d *schema.ResourceData, m inter
return diag.Errorf("error setting structure: %s", err)
}

d.Set("theme_mode", result.StatusPage.ThemeMode)

return nil
}

Expand Down Expand Up @@ -622,12 +680,29 @@ func flattenStatusPageStructure(structure *ilert.StatusPageStructure) ([]interfa
el["id"] = strconv.FormatInt(e.ID, 10)
el["type"] = e.Type

if e.Options != nil && len(e.Options) > 0 {
options := make([]interface{}, 0)
for _, option := range e.Options {
options = append(options, option)
}
el["options"] = options
}

if e.Children != nil && len(e.Children) > 0 {
chd := make([]interface{}, 0)
for _, c := range e.Children {
ch := make(map[string]interface{})
ch["id"] = strconv.FormatInt(c.ID, 10)
ch["type"] = c.Type

if c.Options != nil && len(c.Options) > 0 {
options := make([]interface{}, 0)
for _, option := range c.Options {
options = append(options, option)
}
ch["options"] = options
}

chd = append(chd, ch)
}
el["child"] = chd
Expand Down
8 changes: 6 additions & 2 deletions website/docs/r/status_page.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,21 @@ The following arguments are supported:
- `service` - (Required) One or more [service](#service-arguments) blocks.
- `domain` - (Optional) The custom domain of the status page.
- `timezone` - (Optional) The timezone of the status page. In timezone format, e.g. `Europe/Berlin`, `America/New_York`, `America/Los_Angeles`, `Asia/Istanbul`.
- `custom_css` - (Optional) Custom CSS Styles for the status page.
- `custom_css` - (Optional) Custom CSS Styles for the status page. NOTE: Don't use this field yet.
- `favicon_url` - (Optional) The favicon of the status page.
- `logo_url` - (Optional) The logo of the status page.
- `hidden_from_search` - (Optional) Indicates whether or not the status page is hidden from search.
- `show_subscribe_action` - (Optional) Indicates whether or not the status page subscribe action should be shown.
- `show_incident_history_option` - (Optional) Indicates whether or not the incident history option should be shown.
- `page_title` - (Optional) The title of the status page.
- `page_description` - (Optional) The description of the status page.
- `page_layout` - (Optional) The layout of the status page. Allowed values are `SINGLE_COLUMN` and `RESPONSIVE`.
- `logo_redirect_url` - (Optional) The redirect url for the status page logo.
- `team` - (Optional) One or more [team](#team-arguments) blocks.
- `ip_whitelist` - (Optional) One or more IP's to whitelist.
- `account_wide_view` - (Optional) Indicates whether or not the status page should be shown account wide.
- `structure` - (Optional) A [structure](#structure-arguments) block.
- `theme_mode` - (Optional) The theme mode of the status page. Allowed values are `LIGHT` and `DARK`.

#### Service Arguments

Expand All @@ -83,12 +85,14 @@ The following arguments are supported:

- `id` - (Required) The ID of the element. Can be either an id of a service or a status page group.
- `type` - (Required) The type of the element. Allowed values are `SERVICE` and `GROUP`.
- `options` - (Optional) One or more options to provide for the element. Allowed values for type `GROUP` are `expand`. Allowed values for type `SERVICE` are `no-graph`.
- `child` - (Optional) One or more [child](#child-arguments) blocks.

#### Child Arguments

- `id` - (Required) The ID of the child. Must be a status page group id.
- `type` - (Required) The type of the child. Allowed values are `SERVICE`.
- `options` - (Optional) One or more options to provide for the child. Allowed values are `no-graph`.

## Attributes Reference

Expand All @@ -101,7 +105,7 @@ The following attributes are exported:

## Import

Services can be imported using the `id`, e.g.
Status pages can be imported using the `id`, e.g.

```sh
$ terraform import ilert_status_page.main 123456789
Expand Down

0 comments on commit 3ac37b0

Please sign in to comment.