diff --git a/integration_test.go b/integration_test.go index 06660fdcc..c6984bd08 100644 --- a/integration_test.go +++ b/integration_test.go @@ -38,6 +38,7 @@ import ( "fmt" "os" "path/filepath" + "sort" "strings" "testing" @@ -1337,6 +1338,97 @@ func TestProjectResource(t *testing.T) { }) } +func TestProjectInSpaceResource(t *testing.T) { + testFramework := test.OctopusContainerTest{} + testFramework.ArrangeTest(t, func(t *testing.T, container *test.OctopusContainer, spaceClient *client.Client) error { + // Act + newSpaceId, err := testFramework.Act(t, container, "./terraform", "19b-projectspace", []string{}) + + if err != nil { + return err + } + + err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "19b-projectspace"), newSpaceId, []string{}) + + if err != nil { + return err + } + + // Assert + client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) + + spaces, err := spaces.GetAll(client) + + if err != nil { + return err + } + idx := sort.Search(len(spaces), func(i int) bool { return spaces[i].Name == "Project Space Test" }) + space := spaces[idx] + + query := projects.ProjectsQuery{ + PartialName: "Test project in space", + Skip: 0, + Take: 1, + } + + resources, err := projects.Get(client, space.ID, query) + if err != nil { + return err + } + + if len(resources.Items) == 0 { + t.Fatalf("Space must have a project called \"Test project in space\"") + } + resource := resources.Items[0] + + if resource.Description != "Test project in space" { + t.Fatal("The project must be have a description of \"Test project in space\" (was \"" + resource.Description + "\")") + } + + if resource.AutoCreateRelease { + t.Fatal("The project must not have auto release create enabled") + } + + if resource.DefaultGuidedFailureMode != "EnvironmentDefault" { + t.Fatal("The project must be have a DefaultGuidedFailureMode of \"EnvironmentDefault\" (was \"" + resource.DefaultGuidedFailureMode + "\")") + } + + if resource.DefaultToSkipIfAlreadyInstalled { + t.Fatal("The project must not have DefaultToSkipIfAlreadyInstalled enabled") + } + + if resource.IsDisabled { + t.Fatal("The project must not have IsDisabled enabled") + } + + if resource.IsVersionControlled { + t.Fatal("The project must not have IsVersionControlled enabled") + } + + if resource.TenantedDeploymentMode != "Untenanted" { + t.Fatal("The project must be have a TenantedDeploymentMode of \"Untenanted\" (was \"" + resource.TenantedDeploymentMode + "\")") + } + + if len(resource.IncludedLibraryVariableSets) != 0 { + t.Fatal("The project must not have any library variable sets") + } + + if resource.ConnectivityPolicy.AllowDeploymentsToNoTargets { + t.Fatal("The project must not have ConnectivityPolicy.AllowDeploymentsToNoTargets enabled") + } + + if resource.ConnectivityPolicy.ExcludeUnhealthyTargets { + t.Fatal("The project must not have ConnectivityPolicy.AllowDeploymentsToNoTargets enabled") + } + + if resource.ConnectivityPolicy.SkipMachineBehavior != "SkipUnavailableMachines" { + t.Log("BUG: The project must be have a ConnectivityPolicy.SkipMachineBehavior of \"SkipUnavailableMachines\" (was \"" + resource.ConnectivityPolicy.SkipMachineBehavior + "\") - Known issue where the value returned by /api/Spaces-#/ProjectGroups/ProjectGroups-#/projects is different to /api/Spaces-/Projects") + } + + return nil + }) +} + // TestProjectChannelResource verifies that a project channel can be reimported with the correct settings func TestProjectChannelResource(t *testing.T) { testFramework := test.OctopusContainerTest{} diff --git a/terraform/19b-projectspace/config.tf b/terraform/19b-projectspace/config.tf new file mode 100644 index 000000000..8a9eaf8a9 --- /dev/null +++ b/terraform/19b-projectspace/config.tf @@ -0,0 +1,7 @@ +terraform { + required_providers { + octopusdeploy = { source = "OctopusDeployLabs/octopusdeploy", version = "0.11.3" } + // Use the option below when debugging + // octopusdeploy = { source = "octopus.com/com/octopusdeploy" } + } +} diff --git a/terraform/19b-projectspace/project.tf b/terraform/19b-projectspace/project.tf new file mode 100644 index 000000000..69746f309 --- /dev/null +++ b/terraform/19b-projectspace/project.tf @@ -0,0 +1,33 @@ +data "octopusdeploy_lifecycles" "lifecycle_default_lifecycle" { + ids = null + partial_name = "Default Lifecycle" + skip = 0 + take = 1 +} + + +resource "octopusdeploy_project" "deploy_frontend_project" { + auto_create_release = false + default_guided_failure_mode = "EnvironmentDefault" + default_to_skip_if_already_installed = false + description = "Test project" + discrete_channel_release = false + is_disabled = false + is_discrete_channel_release = false + is_version_controlled = false + lifecycle_id = data.octopusdeploy_lifecycles.lifecycle_default_lifecycle.lifecycles[0].id + name = "Test" + project_group_id = octopusdeploy_project_group.project_group_test.id + tenanted_deployment_participation = "Untenanted" + space_id = var.octopus_space_id + included_library_variable_sets = [] + versioning_strategy { + template = "#{Octopus.Version.LastMajor}.#{Octopus.Version.LastMinor}.#{Octopus.Version.LastPatch}.#{Octopus.Version.NextRevision}" + } + + connectivity_policy { + allow_deployments_to_no_targets = false + exclude_unhealthy_targets = false + skip_machine_behavior = "SkipUnavailableMachines" + } +} \ No newline at end of file diff --git a/terraform/19b-projectspace/project_group_test.tf b/terraform/19b-projectspace/project_group_test.tf new file mode 100644 index 000000000..dc8e4a69e --- /dev/null +++ b/terraform/19b-projectspace/project_group_test.tf @@ -0,0 +1,5 @@ +resource "octopusdeploy_project_group" "project_group_test" { + name = "Test" + description = "Test Description" + space_id = octopusdeploy_space.octopus_project_space_test.id +} diff --git a/terraform/19b-projectspace/provider.tf b/terraform/19b-projectspace/provider.tf new file mode 100644 index 000000000..a04197720 --- /dev/null +++ b/terraform/19b-projectspace/provider.tf @@ -0,0 +1,5 @@ +provider "octopusdeploy" { + address = "${var.octopus_server}" + api_key = "${var.octopus_apikey}" + space_id = "${var.octopus_space_id}" +} diff --git a/terraform/19b-projectspace/provider_vars.tf b/terraform/19b-projectspace/provider_vars.tf new file mode 100644 index 000000000..c7d93fe40 --- /dev/null +++ b/terraform/19b-projectspace/provider_vars.tf @@ -0,0 +1,18 @@ +variable "octopus_server" { + type = string + nullable = false + sensitive = false + description = "The URL of the Octopus server e.g. https://myinstance.octopus.app." +} +variable "octopus_apikey" { + type = string + nullable = false + sensitive = true + description = "The API key used to access the Octopus server. See https://octopus.com/docs/octopus-rest-api/how-to-create-an-api-key for details on creating an API key." +} +variable "octopus_space_id" { + type = string + nullable = false + sensitive = false + description = "The space ID to populate" +} diff --git a/terraform/19b-projectspace/space.tf b/terraform/19b-projectspace/space.tf new file mode 100644 index 000000000..34bc39e1e --- /dev/null +++ b/terraform/19b-projectspace/space.tf @@ -0,0 +1,4 @@ +resource "octopusdeploy_space" "project_space" { + name = "Project space" + description = "Test Description" +}