Skip to content

Commit

Permalink
Add intergration test for variables
Browse files Browse the repository at this point in the history
  • Loading branch information
tleed5 committed Jan 10, 2024
1 parent 5922f3b commit fb25578
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 0 deletions.
27 changes: 27 additions & 0 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3350,3 +3350,30 @@ func TestK8sPodAuthTargetResource(t *testing.T) {
return nil
})
}

func TestVariableResource(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", "49-variables", []string{})

if err != nil {
return err
}

// Assert
client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey)
project, err := client.Projects.GetByName("Test")
variableSet, err := client.Variables.GetAll(project.ID)

if err != nil {
return err
}

if len(variableSet.Variables) == 7 {
t.Fatalf("Expected 7 variables to be created")
}

return nil
})
}
7 changes: 7 additions & 0 deletions terraform/49-variables/config.tf
Original file line number Diff line number Diff line change
@@ -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" }
}
}
20 changes: 20 additions & 0 deletions terraform/49-variables/environments.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resource "octopusdeploy_environment" "development_environment" {
allow_dynamic_infrastructure = true
description = "A test 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 test environment"
name = "Production"
use_guided_failure = false
}
22 changes: 22 additions & 0 deletions terraform/49-variables/infrastructure.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
data "octopusdeploy_machine_policies" "default_machine_policy" {
ids = null
partial_name = "Default Machine Policy"
skip = 0
take = 1
}

resource "octopusdeploy_cloud_region_deployment_target" "test_target" {
environments = ["${octopusdeploy_environment.development_environment.id}"]
name = "Test"
roles = ["cloud"]
default_worker_pool_id = ""
health_status = "Healthy"
is_disabled = false
machine_policy_id = "${data.octopusdeploy_machine_policies.default_machine_policy.machine_policies[0].id}"
shell_name = "Unknown"
shell_version = "Unknown"
tenant_tags = []
tenanted_deployment_participation = "Untenanted"
tenants = []
thumbprint = ""
}
79 changes: 79 additions & 0 deletions terraform/49-variables/project.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
data "octopusdeploy_lifecycles" "lifecycle_default_lifecycle" {
ids = null
partial_name = "Default Lifecycle"
skip = 0
take = 1
}

resource "octopusdeploy_project_group" "project_group_test" {
name = "Test"
description = "Test Description"
}



resource "octopusdeploy_project" "test_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"
}
template {
name = "Project Template Variable"
label = "Test"
default_value = "Test"
display_settings = { "Octopus.ControlType" = "SingleLineText" }
}
}

resource "octopusdeploy_deployment_process" "test_deployment_process" {
project_id = octopusdeploy_project.test_project.id
step {
condition = "Success"
name = "Hello world (using PowerShell)"
package_requirement = "LetOctopusDecide"
start_trigger = "StartAfterPrevious"
run_script_action {
can_be_used_for_project_versioning = false
condition = "Success"
is_disabled = false
is_required = true
name = "Hello world (using PowerShell)"
script_body = <<-EOT
Write-Host 'Hello world, using PowerShell'
#TODO: Experiment with steps of your own :)
Write-Host '[Learn more about the types of steps available in Octopus](https://g.octopushq.com/OnboardingAddStepsLearnMore)'
EOT
run_on_server = true
}
}
}

resource "octopusdeploy_channel" "test_channel" {
depends_on = [octopusdeploy_deployment_process.test_deployment_process]
description = "Test Channel"
name = "Test Channel",
project_id = octopusdeploy_project.test_project.id

rule {
version_range = "1.0"
}
}
5 changes: 5 additions & 0 deletions terraform/49-variables/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
provider "octopusdeploy" {
address = "${var.octopus_server}"
api_key = "${var.octopus_apikey}"
space_id = "${var.octopus_space_id}"
}
18 changes: 18 additions & 0 deletions terraform/49-variables/provider_vars.tf
Original file line number Diff line number Diff line change
@@ -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"
}
3 changes: 3 additions & 0 deletions terraform/49-variables/space.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "octopus_space_id" {
value = var.octopus_space_id
}
66 changes: 66 additions & 0 deletions terraform/49-variables/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
resource "octopusdeploy_variable" "unscoped_project_variable" {
owner_id = octopusdeploy_project.test_project.id
type = "String"
name = "UnscopedVariable"
value = "UnscopedVariable"
}

resource "octopusdeploy_variable" "scoped_project_variable_action" {
owner_id = octopusdeploy_project.test_project.id
type = "String"
name = "ActionScopedVariable"
value = "unscoped variable"
scope {
actions = [octopusdeploy_deployment_process.test_deployment_process.step[0].run_script_action[0].id]
}
}

resource "octopusdeploy_variable" "scoped_project_variable_channel" {
owner_id = octopusdeploy_project.test_project.id
type = "String"
name = "ChannelScopedVariable"
value = "ChannelScopedVariable"
scope {
channels = [octopusdeploy_channel.test_channel.id]
}
}

resource "octopusdeploy_variable" "scoped_project_variable_environment" {
owner_id = octopusdeploy_project.test_project.id
type = "String"
name = "EnvironmentScopedVariable"
value = "EnvironmentScopedVariable"
scope {
channels = [octopusdeploy_environment.development_environment.id]
}
}

resource "octopusdeploy_variable" "scoped_project_variable_machine" {
owner_id = octopusdeploy_project.test_project.id
type = "String"
name = "MachineScopedVariable"
value = "MachineScopedVariable"
scope {
machines = [octopusdeploy_cloud_region_deployment_target.test_target.id]
}
}

resource "octopusdeploy_variable" "scoped_project_variable_process" {
owner_id = octopusdeploy_project.test_project.id
type = "String"
name = "ProcessScopedVariable"
value = "ProcessScopedVariable"
scope {
processes = [octopusdeploy_deployment_process.test_deployment_process.id]
}
}

resource "octopusdeploy_variable" "scoped_project_variable_role" {
owner_id = octopusdeploy_project.test_project.id
type = "String"
name = "RoleScopedVariable"
value = "RoleScopedVariable"
scope {
roles = ["role"]
}
}

0 comments on commit fb25578

Please sign in to comment.