Skip to content

Commit

Permalink
Update space managers
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacCalligeros95 committed Aug 16, 2024
1 parent ccf1d36 commit a5fd85a
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Set variables
$VERSION = "0.7.104"
$VERSION = "0.7.1298"
$BINARY = "terraform-provider-octopusdeploy.exe"
$HOSTNAME = "octopus.com"
$NAMESPACE = "com"
Expand Down
23 changes: 19 additions & 4 deletions octopusdeploy_framework/resource_space.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package octopusdeploy_framework
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/attr"
"strings"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/spaces"
Expand Down Expand Up @@ -109,7 +110,13 @@ func (s *spaceResource) Create(ctx context.Context, req resource.CreateRequest,
return
}

data.SpaceManagersTeams, diags = types.SetValueFrom(ctx, types.StringType, removeSpaceManagers(ctx, createdSpace.SpaceManagersTeams))
//data.SpaceManagersTeams, diags = types.SetValueFrom(ctx, types.StringType, removeSpaceManagers(ctx, createdSpace.SpaceManagersTeams))
if len(createdSpace.SpaceManagersTeams) == 0 {
data.SpaceManagersTeams = types.SetValueMust(types.StringType, []attr.Value{types.StringValue("")})
} else {
data.SpaceManagersTeams, _ = types.SetValueFrom(ctx, types.StringType, removeSpaceManagers(ctx, createdSpace.SpaceManagersTeams))
}

if diags.HasError() {
resp.Diagnostics.Append(diags...)
return
Expand Down Expand Up @@ -143,7 +150,12 @@ func (s *spaceResource) Read(ctx context.Context, req resource.ReadRequest, resp
data.IsTaskQueueStopped = types.BoolValue(spaceResult.TaskQueueStopped)
data.IsDefault = types.BoolValue(spaceResult.IsDefault)
data.SpaceManagersTeamMembers, _ = types.SetValueFrom(ctx, types.StringType, spaceResult.SpaceManagersTeamMembers)
data.SpaceManagersTeams, _ = types.SetValueFrom(ctx, types.StringType, removeSpaceManagers(ctx, spaceResult.SpaceManagersTeams))
//data.SpaceManagersTeams, _ = types.SetValueFrom(ctx, types.StringType, removeSpaceManagers(ctx, spaceResult.SpaceManagersTeams))
if len(spaceResult.SpaceManagersTeams) == 0 {
data.SpaceManagersTeams = types.SetValueMust(types.StringType, []attr.Value{types.StringValue("")})
} else {
data.SpaceManagersTeams, _ = types.SetValueFrom(ctx, types.StringType, removeSpaceManagers(ctx, spaceResult.SpaceManagersTeams))
}

resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
tflog.Info(ctx, fmt.Sprintf("space read (%s)", data.ID))
Expand Down Expand Up @@ -209,8 +221,11 @@ func (s *spaceResource) Update(ctx context.Context, req resource.UpdateRequest,
plan.IsTaskQueueStopped = types.BoolValue(spaceResult.TaskQueueStopped)
plan.IsDefault = types.BoolValue(spaceResult.IsDefault)
plan.SpaceManagersTeamMembers, _ = types.SetValueFrom(ctx, types.StringType, spaceResult.SpaceManagersTeamMembers)
plan.SpaceManagersTeams, _ = types.SetValueFrom(ctx, types.StringType, removeSpaceManagers(ctx, updatedSpace.SpaceManagersTeams))

if len(updatedSpace.SpaceManagersTeams) == 0 {
plan.SpaceManagersTeams = types.SetValueMust(types.StringType, []attr.Value{types.StringValue("")})
} else {
plan.SpaceManagersTeams, _ = types.SetValueFrom(ctx, types.StringType, removeSpaceManagers(ctx, updatedSpace.SpaceManagersTeams))
}
// save plan to state
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package octopusdeploy
package octopusdeploy_framework

import (
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/spaces"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package octopusdeploy
package octopusdeploy_framework

import (
"fmt"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"testing"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/spaces"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccSpaceImportBasic(t *testing.T) {
Expand All @@ -19,7 +19,7 @@ func TestAccSpaceImportBasic(t *testing.T) {

resource.Test(t, resource.TestCase{
CheckDestroy: testAccSpaceCheckDestroy,
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { TestAccPreCheck(t) },
ProtoV6ProviderFactories: ProtoV6ProviderFactories(),
Steps: []resource.TestStep{
{
Expand All @@ -43,7 +43,7 @@ func TestAccSpaceBasic(t *testing.T) {

resource.Test(t, resource.TestCase{
CheckDestroy: testAccSpaceCheckDestroy,
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { TestAccPreCheck(t) },
ProtoV6ProviderFactories: ProtoV6ProviderFactories(),
Steps: []resource.TestStep{
{
Expand All @@ -57,6 +57,17 @@ func TestAccSpaceBasic(t *testing.T) {
),
Config: testSpaceBasic(localName, name, slug),
},
{
Check: resource.ComposeTestCheckFunc(
testSpaceExists(prefix),
resource.TestCheckResourceAttrSet(prefix, "id"),
resource.TestCheckResourceAttr(prefix, "name", name),
resource.TestCheckResourceAttr(prefix, "slug", slug),
resource.TestCheckResourceAttr(prefix, "space_managers_teams.#", "1"),
resource.TestCheckResourceAttrSet(prefix, "space_managers_teams.0"),
),
Config: testSpaceBasicUpdated(localName, name, slug),
},
{
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(prefix, "id"),
Expand Down Expand Up @@ -96,6 +107,24 @@ func testSpaceBasic(localName string, name string, slug string) string {
}`, localName, name, slug)
}

func testSpaceBasicUpdated(localName string, name string, slug string) string {
userLocalName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
userDisplayName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
userEmailAddress := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha) + "." + acctest.RandStringFromCharSet(20, acctest.CharSetAlpha) + "@example.com"
userPassword := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
userUsername := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)

return fmt.Sprintf(testAccUserBasic(userLocalName, userDisplayName, true, false, userPassword, userUsername, userEmailAddress)+"\n"+
`resource "octopusdeploy_space" "%s" {
name = "%s"
slug = "%s"
space_managers_teams = []
lifecycle {
ignore_changes = []
}
}`, localName, name, slug)
}

func testSpaceExists(prefix string) resource.TestCheckFunc {
return func(s *terraform.State) error {
spaceID := s.RootModule().Resources[prefix].Primary.ID
Expand All @@ -120,3 +149,28 @@ func testAccSpaceCheckDestroy(s *terraform.State) error {

return nil
}

func testAccUserBasic(localName string, displayName string, isActive bool, isService bool, password string, username string, emailAddress string) string {
return fmt.Sprintf(`resource "octopusdeploy_user" "%s" {
display_name = "%s"
email_address = "%s"
is_active = %v
is_service = %v
password = "%s"
username = "%s"
identity {
provider = "Octopus ID"
claim {
name = "email"
is_identifying_claim = true
value = "%s"
}
claim {
name = "dn"
is_identifying_claim = false
value = "%s"
}
}
}`, localName, displayName, emailAddress, isActive, isService, password, username, emailAddress, displayName)
}
9 changes: 9 additions & 0 deletions octopusdeploy_framework/schemas/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setdefault"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
)
Expand Down Expand Up @@ -36,6 +37,14 @@ func GetSpaceResourceSchema() map[string]resourceSchema.Attribute {
Description: "A list of team IDs designated to be managers of this space.",
Optional: true,
Computed: true,
Default: setdefault.StaticValue(
types.SetValueMust(
types.StringType,
[]attr.Value{
types.StringValue(""),
},
),
),
},
"space_managers_team_members": resourceSchema.SetAttribute{
ElementType: types.StringType,
Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy_framework/testing_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/testcontainers/testcontainers-go"
)

var createSharedContainer = flag.Bool("createSharedContainer", false, "Set to true to run integration tests in containers")
var createSharedContainer = flag.Bool("createSharedContainer", true, "Set to true to run integration tests in containers")

var octoContainer *test.OctopusContainer
var octoClient *client.Client
Expand Down

0 comments on commit a5fd85a

Please sign in to comment.