diff --git a/build.ps1 b/build.ps1 index 6ca0774f9..f59b54798 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,5 +1,5 @@ # Set variables -$VERSION = "0.7.104" +$VERSION = "0.7.1298" $BINARY = "terraform-provider-octopusdeploy.exe" $HOSTNAME = "octopus.com" $NAMESPACE = "com" diff --git a/octopusdeploy_framework/resource_space.go b/octopusdeploy_framework/resource_space.go index 42470551a..1b9309a02 100644 --- a/octopusdeploy_framework/resource_space.go +++ b/octopusdeploy_framework/resource_space.go @@ -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" @@ -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 @@ -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)) @@ -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)...) } diff --git a/octopusdeploy/resource_space_integration_test.go b/octopusdeploy_framework/resource_space_integration_test.go similarity index 97% rename from octopusdeploy/resource_space_integration_test.go rename to octopusdeploy_framework/resource_space_integration_test.go index 1bef05735..da12739b3 100644 --- a/octopusdeploy/resource_space_integration_test.go +++ b/octopusdeploy_framework/resource_space_integration_test.go @@ -1,4 +1,4 @@ -package octopusdeploy +package octopusdeploy_framework import ( "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/spaces" diff --git a/octopusdeploy/resource_space_test.go b/octopusdeploy_framework/resource_space_test.go similarity index 62% rename from octopusdeploy/resource_space_test.go rename to octopusdeploy_framework/resource_space_test.go index 3cca37024..beaf40840 100644 --- a/octopusdeploy/resource_space_test.go +++ b/octopusdeploy_framework/resource_space_test.go @@ -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) { @@ -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{ { @@ -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{ { @@ -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"), @@ -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 @@ -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) +} diff --git a/octopusdeploy_framework/schemas/space.go b/octopusdeploy_framework/schemas/space.go index 0c1159553..a38a38edc 100644 --- a/octopusdeploy_framework/schemas/space.go +++ b/octopusdeploy_framework/schemas/space.go @@ -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" ) @@ -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, diff --git a/octopusdeploy_framework/testing_container_test.go b/octopusdeploy_framework/testing_container_test.go index 49319d02e..d3c759383 100644 --- a/octopusdeploy_framework/testing_container_test.go +++ b/octopusdeploy_framework/testing_container_test.go @@ -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