From cfe976f68dd8d56ff9159c58ca9a4e7cb61e3b03 Mon Sep 17 00:00:00 2001 From: Travis Leeden Date: Tue, 7 May 2024 14:38:04 +1000 Subject: [PATCH] Add test for data source --- integration_test.go | 41 +++++++++++++++++++ .../config.tf | 5 +++ .../kubernetes_agent.tf | 9 ++++ .../provider.tf | 5 +++ .../provider_vars.tf | 18 ++++++++ .../space.tf | 3 ++ 6 files changed, 81 insertions(+) create mode 100644 terraform/55a-kubernetesagentdeploymenttargetds/config.tf create mode 100644 terraform/55a-kubernetesagentdeploymenttargetds/kubernetes_agent.tf create mode 100644 terraform/55a-kubernetesagentdeploymenttargetds/provider.tf create mode 100644 terraform/55a-kubernetesagentdeploymenttargetds/provider_vars.tf create mode 100644 terraform/55a-kubernetesagentdeploymenttargetds/space.tf diff --git a/integration_test.go b/integration_test.go index f97b9ebf6..37e546e57 100644 --- a/integration_test.go +++ b/integration_test.go @@ -3801,3 +3801,44 @@ func TestKubernetesDeploymentTargetResource(t *testing.T) { return nil }) } + +func TestKubernetesDeploymentTargetData(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", "55-kubernetesagentdeploymenttarget", []string{}) + + if err != nil { + return err + } + + err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "55a-kubernetesagentdeploymenttargetds"), newSpaceId, []string{}) + + // Assert + client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) + query := machines.MachinesQuery{ + DeploymentTargetTypes: []string{"KubernetesTentacle"}, + PartialName: "minimum-agent", + Skip: 0, + Take: 1, + } + + resources, err := machines.Get(client, newSpaceId, query) + if err != nil { + return err + } + + var foundAgent = resources.Items[0] + + lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "55a-kubernetesagentdeploymenttargetds"), "data_lookup") + if err != nil { + return err + } + + if lookup != foundAgent.ID { + t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + foundAgent.ID + "\".") + } + + return nil + }) +} diff --git a/terraform/55a-kubernetesagentdeploymenttargetds/config.tf b/terraform/55a-kubernetesagentdeploymenttargetds/config.tf new file mode 100644 index 000000000..2113da144 --- /dev/null +++ b/terraform/55a-kubernetesagentdeploymenttargetds/config.tf @@ -0,0 +1,5 @@ +terraform { + required_providers { + octopusdeploy = { source = "OctopusDeployLabs/octopusdeploy", version = "0.18.1" } + } +} diff --git a/terraform/55a-kubernetesagentdeploymenttargetds/kubernetes_agent.tf b/terraform/55a-kubernetesagentdeploymenttargetds/kubernetes_agent.tf new file mode 100644 index 000000000..97d09a1b9 --- /dev/null +++ b/terraform/55a-kubernetesagentdeploymenttargetds/kubernetes_agent.tf @@ -0,0 +1,9 @@ +data "octopusdeploy_kubernetes_agent_deployment_targets" "test" { + take = 1 + skip = 0 + partial_name = "minimum-agent" +} + +output "data_lookup" { + value = data.octopusdeploy_kubernetes_agent_deployment_targets.test.kubernetes_agent_deployment_targets[0].id +} \ No newline at end of file diff --git a/terraform/55a-kubernetesagentdeploymenttargetds/provider.tf b/terraform/55a-kubernetesagentdeploymenttargetds/provider.tf new file mode 100644 index 000000000..a04197720 --- /dev/null +++ b/terraform/55a-kubernetesagentdeploymenttargetds/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/55a-kubernetesagentdeploymenttargetds/provider_vars.tf b/terraform/55a-kubernetesagentdeploymenttargetds/provider_vars.tf new file mode 100644 index 000000000..c7d93fe40 --- /dev/null +++ b/terraform/55a-kubernetesagentdeploymenttargetds/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/55a-kubernetesagentdeploymenttargetds/space.tf b/terraform/55a-kubernetesagentdeploymenttargetds/space.tf new file mode 100644 index 000000000..ee59bdc80 --- /dev/null +++ b/terraform/55a-kubernetesagentdeploymenttargetds/space.tf @@ -0,0 +1,3 @@ +output "octopus_space_id" { + value = var.octopus_space_id +}