Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic runtime error in terraform provider for page resources #190

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ env:
GO_VERSION: "1.18"
PORT_CLIENT_ID: ${{ secrets.PORT_CLIENT_ID }}
PORT_CLIENT_SECRET: ${{ secrets.PORT_CLIENT_SECRET }}
CI_USER_NAME: ${{ secrets.CI_USER_NAME }}

jobs:
lint:
Expand Down Expand Up @@ -47,4 +48,4 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
- name: Run dialect tests
run: make acctest PORT_CLIENT_ID=${{ secrets.PORT_CLIENT_ID }} PORT_CLIENT_SECRET=${{ secrets.PORT_CLIENT_SECRET }} PORT_BASE_URL=${{ secrets.PORT_BASE_URL }}
run: make acctest CI_USER_NAME=${{ secrets.CI_USER_NAME }} PORT_CLIENT_ID=${{ secrets.PORT_CLIENT_ID }} PORT_CLIENT_SECRET=${{ secrets.PORT_CLIENT_SECRET }} PORT_BASE_URL=${{ secrets.PORT_BASE_URL }}
9 changes: 7 additions & 2 deletions internal/cli/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ func (c *PortClient) CreatePage(ctx context.Context, page *Page) (*Page, error)
return nil, err
}
if !pb.OK {

if resp.IsSuccess() {
return nil, nil
}
return nil, fmt.Errorf("failed to create page, got: %s", resp.Body())
}
return &pb.Page, nil
// For forward compatibility, handle cases where the response body is empty when a page is created.
// The current API response body is { "ok": true, "identifier": "page_identifier" },
// but it is expected to be the page object in the future to align with other API endpoints.
if pb.Page.Identifier != "" {
return &pb.Page, nil
matan84 marked this conversation as resolved.
Show resolved Hide resolved
}
return nil, nil
matan84 marked this conversation as resolved.
Show resolved Hide resolved
}

func (c *PortClient) UpdatePage(ctx context.Context, pageId string, page *Page) (*Page, error) {
Expand Down
15 changes: 9 additions & 6 deletions port/team/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package team_test
import (
"fmt"
"github.com/port-labs/terraform-provider-port-labs/v2/internal/utils"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand Down Expand Up @@ -36,6 +37,7 @@ func TestAccPortTeam(t *testing.T) {

func TestAccPortTeamUpdate(t *testing.T) {
teamName := utils.GenID()
userName := os.Getenv("CI_USER_NAME")
var testAccTeamConfigCreate = fmt.Sprintf(`
resource "port_team" "team" {
name = "%s"
Expand All @@ -47,8 +49,8 @@ func TestAccPortTeamUpdate(t *testing.T) {
resource "port_team" "team" {
name = "%s"
description = "Test description2"
users = ["[email protected]"]
}`, teamName)
users = ["%s"]
}`, teamName, userName)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
Expand All @@ -68,7 +70,7 @@ func TestAccPortTeamUpdate(t *testing.T) {
resource.TestCheckResourceAttr("port_team.team", "name", teamName),
resource.TestCheckResourceAttr("port_team.team", "description", "Test description2"),
resource.TestCheckResourceAttr("port_team.team", "users.#", "1"),
resource.TestCheckResourceAttr("port_team.team", "users.0", "[email protected]"),
resource.TestCheckResourceAttr("port_team.team", "users.0", userName),
),
},
},
Expand Down Expand Up @@ -115,12 +117,13 @@ func TestAccPortTeamEmptyDescription(t *testing.T) {

func TestAccPortTeamImport(t *testing.T) {
teamName := utils.GenID()
userName := os.Getenv("CI_USER_NAME")
var testAccTeamConfigCreate = fmt.Sprintf(`
resource "port_team" "team" {
name = "%s"
description = "Test description"
users = ["[email protected]"]
}`, teamName)
users = ["%s"]
}`, teamName, userName)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
Expand All @@ -132,7 +135,7 @@ func TestAccPortTeamImport(t *testing.T) {
resource.TestCheckResourceAttr("port_team.team", "name", teamName),
resource.TestCheckResourceAttr("port_team.team", "description", "Test description"),
resource.TestCheckResourceAttr("port_team.team", "users.#", "1"),
resource.TestCheckResourceAttr("port_team.team", "users.0", "[email protected]"),
resource.TestCheckResourceAttr("port_team.team", "users.0", userName),
),
},
{
Expand Down
Loading