Skip to content

Commit

Permalink
Add description to page resource
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzaadi committed May 12, 2024
1 parent 414b784 commit 82cd574
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 45 deletions.
18 changes: 10 additions & 8 deletions docs/resources/port_page.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ subcategory: ""
description: |-
Page resource
Docs about the different page types can be found here https://docs.getport.io/customize-pages-dashboards-and-plugins/page/catalog-page.
~> WARNINGThe page resource is currently in beta and is subject to change in future versions.Use it by setting the Environment Variable PORT_BETA_FEATURES_ENABLED=true.If this Environment Variable isn't specified, you won't be able to use the resource.
~> WARNING
The page resource is currently in beta and is subject to change in future versions.
Use it by setting the Environment Variable PORT_BETA_FEATURES_ENABLED=true.
If this Environment Variable isn't specified, you won't be able to use the resource.
Example Usage
Blueprint Entities Page
```hcl
Expand Down Expand Up @@ -213,10 +216,10 @@ description: |-

Docs about the different page types can be found [here](https://docs.getport.io/customize-pages-dashboards-and-plugins/page/catalog-page).

~> **WARNING**
The page resource is currently in beta and is subject to change in future versions.
Use it by setting the Environment Variable `PORT_BETA_FEATURES_ENABLED=true`.
If this Environment Variable isn't specified, you won't be able to use the resource.
~> **WARNING**
The page resource is currently in beta and is subject to change in future versions.
Use it by setting the Environment Variable `PORT_BETA_FEATURES_ENABLED=true`.
If this Environment Variable isn't specified, you won't be able to use the resource.

## Example Usage

Expand Down Expand Up @@ -440,7 +443,7 @@ resource "port_page" "home_page" {

The home page is a special page, which is created by default when you create a new organization.

- When deleting the home page resource using terraform, the home page will not be deleted from Port as it isn't deletable page, instead, the home page will be removed from the terraform state.
- When deleting the home page resource using terraform, the home page will not be deleted from Port as it isn't deletable page, instead, the home page will be removed from the terraform state.
- Due to only having one home page you'll have to import the state of the home page manually.

```
Expand All @@ -461,6 +464,7 @@ terraform import port_page.home_page "\$home"

- `after` (String) The identifier of the page/folder after which the page should be placed
- `blueprint` (String) The blueprint for which the page is created, relevant only for pages of type "blueprint-entities"
- `description` (String) The description of the page
- `icon` (String) The icon of the page
- `locked` (Boolean) Whether the page is locked, if true, viewers will not be able to edit the page widgets and filters
- `parent` (String) The identifier of the folder in which the page is in, default is the root of the sidebar
Expand All @@ -474,5 +478,3 @@ terraform import port_page.home_page "\$home"
- `id` (String) The ID of this resource.
- `updated_at` (String) The last update date of the page
- `updated_by` (String) The last updater of the page


1 change: 1 addition & 0 deletions examples/resources/port_page/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ resource "port_page" "microservice_blueprint_page" {
type = "blueprint-entities"
icon = "Microservice"
blueprint = port_blueprint.base_blueprint.identifier
description = "My microservice blueprint page"
widgets = [
jsonencode(
{
Expand Down
19 changes: 10 additions & 9 deletions internal/cli/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,16 @@ type (

Page struct {
Meta
Identifier string `json:"identifier,omitempty"`
Type string `json:"type,omitempty"`
Icon *string `json:"icon,omitempty"`
Parent *string `json:"parent,omitempty"`
After *string `json:"after,omitempty"`
Title *string `json:"title,omitempty"`
Locked *bool `json:"locked,omitempty"`
Blueprint *string `json:"blueprint,omitempty"`
Widgets *[]map[string]any `json:"widgets,omitempty"`
Identifier string `json:"identifier,omitempty"`
Type string `json:"type,omitempty"`
Icon *string `json:"icon,omitempty"`
Parent *string `json:"parent,omitempty"`
After *string `json:"after,omitempty"`
Title *string `json:"title,omitempty"`
Locked *bool `json:"locked,omitempty"`
Blueprint *string `json:"blueprint,omitempty"`
Widgets *[]map[string]any `json:"widgets,omitempty"`
Description *string `json:"description,omitempty"`
}

PageReadPermissions struct {
Expand Down
29 changes: 15 additions & 14 deletions port/page/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ package page
import "github.com/hashicorp/terraform-plugin-framework/types"

type PageModel struct {
ID types.String `tfsdk:"id"`
Identifier types.String `tfsdk:"identifier"`
Title types.String `tfsdk:"title"`
Type types.String `tfsdk:"type"`
Parent types.String `tfsdk:"parent"`
After types.String `tfsdk:"after"`
Icon types.String `tfsdk:"icon"`
Locked types.Bool `tfsdk:"locked"`
Blueprint types.String `tfsdk:"blueprint"`
Widgets []types.String `tfsdk:"widgets"`
CreatedAt types.String `tfsdk:"created_at"`
CreatedBy types.String `tfsdk:"created_by"`
UpdatedAt types.String `tfsdk:"updated_at"`
UpdatedBy types.String `tfsdk:"updated_by"`
ID types.String `tfsdk:"id"`
Identifier types.String `tfsdk:"identifier"`
Title types.String `tfsdk:"title"`
Type types.String `tfsdk:"type"`
Parent types.String `tfsdk:"parent"`
After types.String `tfsdk:"after"`
Icon types.String `tfsdk:"icon"`
Locked types.Bool `tfsdk:"locked"`
Blueprint types.String `tfsdk:"blueprint"`
Widgets []types.String `tfsdk:"widgets"`
CreatedAt types.String `tfsdk:"created_at"`
CreatedBy types.String `tfsdk:"created_by"`
UpdatedAt types.String `tfsdk:"updated_at"`
UpdatedBy types.String `tfsdk:"updated_by"`
Description types.String `tfsdk:"description"`
}
17 changes: 9 additions & 8 deletions port/page/pageToPortBody.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (

func PageToPortBody(pm *PageModel) (*cli.Page, error) {
pb := &cli.Page{
Identifier: pm.Identifier.ValueString(),
Type: pm.Type.ValueString(),
Icon: pm.Icon.ValueStringPointer(),
Title: pm.Title.ValueStringPointer(),
Locked: pm.Locked.ValueBoolPointer(),
Blueprint: pm.Blueprint.ValueStringPointer(),
Parent: pm.Parent.ValueStringPointer(),
After: pm.After.ValueStringPointer(),
Identifier: pm.Identifier.ValueString(),
Type: pm.Type.ValueString(),
Icon: pm.Icon.ValueStringPointer(),
Title: pm.Title.ValueStringPointer(),
Locked: pm.Locked.ValueBoolPointer(),
Blueprint: pm.Blueprint.ValueStringPointer(),
Parent: pm.Parent.ValueStringPointer(),
After: pm.After.ValueStringPointer(),
Description: pm.Description.ValueStringPointer(),
}

widgets, err := widgetsToPortBody(pm.Widgets)
Expand Down
1 change: 1 addition & 0 deletions port/page/refreshPageToState.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func refreshPageToState(pm *PageModel, b *cli.Page) error {
pm.Title = types.StringPointerValue(b.Title)
pm.Locked = types.BoolPointerValue(b.Locked)
pm.Blueprint = types.StringPointerValue(b.Blueprint)
pm.Description = types.StringPointerValue(b.Description)

pm.Widgets = make([]types.String, len(*b.Widgets))
if b.Widgets != nil {
Expand Down
2 changes: 2 additions & 0 deletions port/page/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func (r *PageResource) Create(ctx context.Context, req resource.CreateRequest, r
state.CreatedBy = types.StringValue(p.CreatedBy)
state.UpdatedAt = types.StringValue(p.UpdatedAt.String())
state.UpdatedBy = types.StringValue(p.UpdatedBy)
state.Description = types.StringPointerValue(p.Description)

resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
Expand Down Expand Up @@ -172,6 +173,7 @@ func (r *PageResource) Update(ctx context.Context, req resource.UpdateRequest, r
state.CreatedBy = types.StringValue(p.CreatedBy)
state.UpdatedAt = types.StringValue(p.UpdatedAt.String())
state.UpdatedBy = types.StringValue(p.UpdatedBy)
state.Description = types.StringPointerValue(p.Description)

resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)

Expand Down
1 change: 1 addition & 0 deletions port/page/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ resource "port_page" "microservice_dashboard_page" {
Config: acctest.ProviderConfig + testAccPortPageResourceBasic,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("port_page.microservice_dashboard_page", "identifier", pageIdentifier),
// resource.TestCheckResourceAttr("port_page.microservice_dashboard_page", "description", "My Dashboard Page Description"),
resource.TestCheckResourceAttr("port_page.microservice_dashboard_page", "title", "dashboards"),
resource.TestCheckResourceAttr("port_page.microservice_dashboard_page", "icon", "GitHub"),
resource.TestCheckResourceAttr("port_page.microservice_dashboard_page", "type", "dashboard"),
Expand Down
16 changes: 10 additions & 6 deletions port/page/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func PageSchema() map[string]schema.Attribute {
MarkdownDescription: "The last updater of the page",
Computed: true,
},
"description": schema.StringAttribute{
MarkdownDescription: "The description of the page",
Optional: true,
},
}
}

Expand Down Expand Up @@ -114,10 +118,10 @@ var PageResourceMarkdownDescription = `
Docs about the different page types can be found [here](https://docs.getport.io/customize-pages-dashboards-and-plugins/page/catalog-page).
~> **WARNING**
The page resource is currently in beta and is subject to change in future versions.
Use it by setting the Environment Variable ` + "`PORT_BETA_FEATURES_ENABLED=true`" + `.
If this Environment Variable isn't specified, you won't be able to use the resource.
~> **WARNING**
The page resource is currently in beta and is subject to change in future versions.
Use it by setting the Environment Variable ` + "`PORT_BETA_FEATURES_ENABLED=true`" + `.
If this Environment Variable isn't specified, you won't be able to use the resource.
## Example Usage
Expand Down Expand Up @@ -341,11 +345,11 @@ resource "port_page" "home_page" {
The home page is a special page, which is created by default when you create a new organization.
- When deleting the home page resource using terraform, the home page will not be deleted from Port as it isn't deletable page, instead, the home page will be removed from the terraform state.
- When deleting the home page resource using terraform, the home page will not be deleted from Port as it isn't deletable page, instead, the home page will be removed from the terraform state.
- Due to only having one home page you'll have to import the state of the home page manually.
` + "```" + `
terraform import port_page.home_page "\$home"
` + "```" + `
`

0 comments on commit 82cd574

Please sign in to comment.