Skip to content

Commit b9732b4

Browse files
Port 14112 bug port team terraform module does not support updating team name after creation (#295)
* add dynamic unknown fields to the blueprint property types * fix team updates by using the old team name in the url * fix team updates by using the old team name in the url * fix team updates by using the old team name in the url
1 parent b1f48f6 commit b9732b4

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

port/team/resource.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package team
22

33
import (
44
"context"
5+
56
"github.com/hashicorp/terraform-plugin-framework/path"
67
"github.com/hashicorp/terraform-plugin-framework/resource"
78
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -104,13 +105,21 @@ func (r *TeamResource) Update(ctx context.Context, req resource.UpdateRequest, r
104105
return
105106
}
106107

108+
var currentState *TeamModel
109+
resp.Diagnostics.Append(req.State.Get(ctx, &currentState)...)
110+
111+
if resp.Diagnostics.HasError() {
112+
return
113+
}
114+
107115
t, err := TeamResourceToPortBody(ctx, state)
108116
if err != nil {
109117
resp.Diagnostics.AddError("failed to convert team resource to body", err.Error())
110118
return
111119
}
112120

113-
tp, err := r.portClient.UpdateTeam(ctx, t.Name, &t.PortTeam)
121+
oldTeamName := currentState.Name.ValueString()
122+
tp, err := r.portClient.UpdateTeam(ctx, oldTeamName, &t.PortTeam)
114123
if err != nil {
115124
resp.Diagnostics.AddError("failed to update the team", err.Error())
116125
return

port/team/resource_test.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package team_test
22

33
import (
44
"fmt"
5-
"github.com/port-labs/terraform-provider-port-labs/v2/internal/utils"
65
"os"
76
"testing"
87

8+
"github.com/port-labs/terraform-provider-port-labs/v2/internal/utils"
9+
910
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1011
"github.com/port-labs/terraform-provider-port-labs/v2/internal/acctest"
1112
)
@@ -115,6 +116,47 @@ func TestAccPortTeamEmptyDescription(t *testing.T) {
115116
})
116117
}
117118

119+
func TestAccPortTeamNameUpdate(t *testing.T) {
120+
initialTeamName := utils.GenID()
121+
updatedTeamName := utils.GenID()
122+
var testAccTeamConfigCreate = fmt.Sprintf(`
123+
resource "port_team" "team" {
124+
name = "%s"
125+
description = "Test description"
126+
users = []
127+
}`, initialTeamName)
128+
129+
var testAccTeamConfigUpdate = fmt.Sprintf(`
130+
resource "port_team" "team" {
131+
name = "%s"
132+
description = "Test description"
133+
users = []
134+
}`, updatedTeamName)
135+
136+
resource.Test(t, resource.TestCase{
137+
PreCheck: func() { acctest.TestAccPreCheck(t) },
138+
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
139+
Steps: []resource.TestStep{
140+
{
141+
Config: acctest.ProviderConfig + testAccTeamConfigCreate,
142+
Check: resource.ComposeTestCheckFunc(
143+
resource.TestCheckResourceAttr("port_team.team", "name", initialTeamName),
144+
resource.TestCheckResourceAttr("port_team.team", "description", "Test description"),
145+
resource.TestCheckResourceAttr("port_team.team", "users.#", "0"),
146+
),
147+
},
148+
{
149+
Config: acctest.ProviderConfig + testAccTeamConfigUpdate,
150+
Check: resource.ComposeTestCheckFunc(
151+
resource.TestCheckResourceAttr("port_team.team", "name", updatedTeamName),
152+
resource.TestCheckResourceAttr("port_team.team", "description", "Test description"),
153+
resource.TestCheckResourceAttr("port_team.team", "users.#", "0"),
154+
),
155+
},
156+
},
157+
})
158+
}
159+
118160
func TestAccPortTeamImport(t *testing.T) {
119161
teamName := utils.GenID()
120162
userName := os.Getenv("CI_USER_NAME")

0 commit comments

Comments
 (0)