diff --git a/.github/workflows/pr_checks.yml b/.github/workflows/pr_checks.yml index ce32fde..e618550 100644 --- a/.github/workflows/pr_checks.yml +++ b/.github/workflows/pr_checks.yml @@ -18,4 +18,6 @@ jobs: run: go build -v ./... - name: Test run: go test ./... + env: + LICENSE: ${{ secrets.LICENSE }} diff --git a/terraform/1-singlespace/space.tf b/terraform/1-singlespace/space.tf index 456c997..52dbd84 100644 --- a/terraform/1-singlespace/space.tf +++ b/terraform/1-singlespace/space.tf @@ -1,8 +1,8 @@ resource "octopusdeploy_space" "octopus_space_test" { - name = "${var.octopus_space_name}" + name = var.octopus_space_name is_default = false is_task_queue_stopped = false - description = "My test space" + description = var.octopus_space_description space_managers_teams = ["teams-administrators"] } @@ -17,3 +17,11 @@ variable "octopus_space_name" { description = "The name of the new space" default = "Test" } + +variable "octopus_space_description" { + type = string + nullable = false + sensitive = false + description = "The description of the new space" + default = "My test space" +} diff --git a/terraform/2-simpleexample/config.tf b/terraform/2-simpleexample/config.tf new file mode 100644 index 0000000..6abbbda --- /dev/null +++ b/terraform/2-simpleexample/config.tf @@ -0,0 +1,5 @@ +terraform { + required_providers { + octopusdeploy = { source = "OctopusDeployLabs/octopusdeploy", version = "0.21.4" } + } +} diff --git a/terraform/2-simpleexample/environments.tf b/terraform/2-simpleexample/environments.tf new file mode 100644 index 0000000..720d18f --- /dev/null +++ b/terraform/2-simpleexample/environments.tf @@ -0,0 +1,20 @@ +resource "octopusdeploy_environment" "development_environment" { + allow_dynamic_infrastructure = true + description = "A development environment" + name = "Development" + use_guided_failure = false +} + +resource "octopusdeploy_environment" "test_environment" { + allow_dynamic_infrastructure = true + description = "A test environment" + name = "Test" + use_guided_failure = false +} + +resource "octopusdeploy_environment" "production_environment" { + allow_dynamic_infrastructure = true + description = "A production environment" + name = "Production" + use_guided_failure = false +} \ No newline at end of file diff --git a/terraform/2-simpleexample/provider.tf b/terraform/2-simpleexample/provider.tf new file mode 100644 index 0000000..a041977 --- /dev/null +++ b/terraform/2-simpleexample/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/2-simpleexample/provider_vars.tf b/terraform/2-simpleexample/provider_vars.tf new file mode 100644 index 0000000..c7d93fe --- /dev/null +++ b/terraform/2-simpleexample/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/2-simpleexample/space.tf b/terraform/2-simpleexample/space.tf new file mode 100644 index 0000000..ee59bdc --- /dev/null +++ b/terraform/2-simpleexample/space.tf @@ -0,0 +1,3 @@ +output "octopus_space_id" { + value = var.octopus_space_id +} diff --git a/test/octopus_container_test_framework_test.go b/test/octopus_container_test_framework_test.go index 2eed7f9..ab77562 100644 --- a/test/octopus_container_test_framework_test.go +++ b/test/octopus_container_test_framework_test.go @@ -1,6 +1,10 @@ package test import ( + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/environments" + "github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework/octoclient" + "path/filepath" "testing" ) @@ -60,3 +64,37 @@ func TestContainerWithNoSpecifiedVersionWillUseLatest(t *testing.T) { t.Errorf("The OctopusServer version is %v", version) } } + +// TestCreateEnvironments is an example of the kind of tests that can be written using the OctopusContainerTest framework. +func TestCreateEnvironments(t *testing.T) { + testFramework := OctopusContainerTest{} + testFramework.ArrangeTest(t, func(t *testing.T, container *OctopusContainer, client *client.Client) error { + // Act + newSpaceId, err := testFramework.Act( + t, + container, + filepath.Join("..", "terraform"), "2-simpleexample", []string{}) + + if err != nil { + return err + } + + newSpaceClient, err := octoclient.CreateClient(container.URI, newSpaceId, ApiKey) + + if err != nil { + return err + } + + testEnvironments, err := environments.GetAll(newSpaceClient, newSpaceId) + + if err != nil { + return err + } + + if len(testEnvironments) != 3 { + t.Fatalf("Expected 3 environments, got %d", len(testEnvironments)) + } + + return nil + }) +}