From e44242fdc44eb950727dc59fba84bdd95e2f341e Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Mon, 17 Jun 2024 16:33:53 +1000 Subject: [PATCH 01/34] add k8s worker to terraform --- docs/resources/kubernetes_agent_worker.md | 71 +++++++ .../resource_kubernetes_agent_worker.go | 78 ++++++++ .../schema_kubernetes_agent_worker.go | 175 ++++++++++++++++++ 3 files changed, 324 insertions(+) create mode 100644 docs/resources/kubernetes_agent_worker.md create mode 100644 octopusdeploy/resource_kubernetes_agent_worker.go create mode 100644 octopusdeploy/schema_kubernetes_agent_worker.go diff --git a/docs/resources/kubernetes_agent_worker.md b/docs/resources/kubernetes_agent_worker.md new file mode 100644 index 000000000..26b14474a --- /dev/null +++ b/docs/resources/kubernetes_agent_worker.md @@ -0,0 +1,71 @@ +--- +page_title: "octopusdeploy_kubernetes_agent_deployment_target Resource - terraform-provider-octopusdeploy" +subcategory: "Deployment Targets" +description: |- + This resource manages Kubernetes agent deployment targets in Octopus Deploy. +--- + +# octopusdeploy_kubernetes_agent_deployment_target (Resource) + +This resource manages Kubernetes agent deployment targets in Octopus Deploy. + +## Example Usage + +```terraform +resource "octopusdeploy_kubernetes_agent_worker" "minimal" { + name = "agent-minimal" + worker_pools = ["worker-pools-1"] + thumbprint = "96203ED84246201C26A2F4360D7CBC36AC1D232D" + uri = "poll://kcxzcv2fpsxkn6tk9u6d/" +} + +resource "octopusdeploy_kubernetes_agent_worker" "optionals" { + name = "agent-optionals" + worker_pools = ["worker-pools-1"] + thumbprint = "96203ED84246201C26A2F4360D7CBC36AC1D232D" + uri = "poll://kcxzcv2fpsxkn6tk9u6d/" + machine_policy_id = "machinepolicies-1" + default_namespace = "kubernetes-namespace" + upgrade_locked = true + is_disabled = true +} +``` + +## Schema + +### Required + +- `environments` (List of String) A list of environment IDs this Kubernetes agent can deploy to. +- `name` (String) The name of this resource. +- `roles` (List of String) A list of target roles that are associated to this Kubernetes agent. +- `thumbprint` (String) The thumbprint of the Kubernetes agent's certificate used by server to verify the identity of the agent. This is the same thumbprint that was used when installing the agent. +- `uri` (String) The URI of the Kubernetes agent's used by the server to queue messages. This is the same subscription uri that was used when installing the agent. + +### Optional + +- `communication_mode` (String) The communication mode used by the Kubernetes agent to communicate with Octopus Server. Currently, the only supported value is 'Polling'. +- `default_namespace` (String) Optional default namespace that will be used when using Kubernetes deployment steps, can be overrides within step configurations. +- `id` (String) The unique ID for this resource. +- `is_disabled` (Boolean) Whether the Kubernetes agent is disabled. If the agent is disabled, it will not be included in any deployments. +- `machine_policy_id` (String) Optional ID of the machine policy that the Kubernetes agent will use. If not provided the default machine policy will be used. +- `space_id` (String) The space ID associated with this resource. +- `tenant_tags` (List of String) A list of tenant tags associated with this resource. +- `tenanted_deployment_participation` (String) The tenanted deployment mode of the resource. Valid account types are `Untenanted`, `TenantedOrUntenanted`, or `Tenanted`. +- `tenants` (List of String) A list of tenant IDs associated with this resource. +- `upgrade_locked` (Boolean) If enabled the Kubernetes agent will not automatically upgrade and will stay on the currently installed version, even if the associated machine policy is configured to automatically upgrade. + +### Read-Only + +- `agent_helm_release_name` (String) Name of the Helm release that the agent belongs to. +- `agent_kubernetes_namespace` (String) Name of the Kubernetes namespace where the agent is installed. +- `agent_tentacle_version` (String) Current Tentacle version of the agent +- `agent_upgrade_status` (String) Current upgrade availability status of the agent. One of 'NoUpgrades', 'UpgradeAvailable', 'UpgradeSuggested', 'UpgradeRequired' +- `agent_version` (String) Current Helm chart version of the agent. + +## Import + +Import is supported using the following syntax: + +```shell +terraform import [options] octopusdeploy_kubernetes_agent_deployment_target. +``` diff --git a/octopusdeploy/resource_kubernetes_agent_worker.go b/octopusdeploy/resource_kubernetes_agent_worker.go new file mode 100644 index 000000000..b12648266 --- /dev/null +++ b/octopusdeploy/resource_kubernetes_agent_worker.go @@ -0,0 +1,78 @@ +package octopusdeploy + +import ( + "context" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client" + "github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func resourceKubernetesAgentWorker() *schema.Resource { + return &schema.Resource{ + CreateContext: resourceKubernetesAgentWorkerCreate, + DeleteContext: resourceKubernetesAgentWorkerDelete, + Description: "This resource manages Kubernetes agent deployment targets in Octopus Deploy.", + Importer: getImporter(), + ReadContext: resourceKubernetesAgentWorkerRead, + Schema: getKubernetesAgentWorkerSchema(), + UpdateContext: resourceKubernetesAgentWorkerUpdate, + } +} + +func resourceKubernetesAgentWorkerCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + worker := expandKubernetesAgentWorker(d) + client := m.(*client.Client) + createdWorker, err := client.Workers.Add(worker) + if err != nil { + return diag.FromErr(err) + } + + d.SetId(createdWorker.GetID()) + return nil +} + +func resourceKubernetesAgentWorkerRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + client := m.(*client.Client) + Worker, err := client.Workers.GetByID(d.Id()) + if err != nil { + return errors.ProcessApiError(ctx, d, err, "kubernetes tentacle deployment target") + } + + flattenedKubernetesAgentWorker := flattenKubernetesAgentWorker(Worker) + for key, value := range flattenedKubernetesAgentWorker { + if key != "id" { + err := d.Set(key, value) + if err != nil { + return diag.FromErr(err) + } + } + } + + return nil +} + +func resourceKubernetesAgentWorkerDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + client := m.(*client.Client) + if err := client.Workers.DeleteByID(d.Id()); err != nil { + return diag.FromErr(err) + } + d.SetId("") + return nil +} + +func resourceKubernetesAgentWorkerUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + Worker := expandKubernetesAgentWorker(d) + client := m.(*client.Client) + + Worker.ID = d.Id() + + updatedWorker, err := client.Workers.Update(Worker) + if err != nil { + return diag.FromErr(err) + } + + d.SetId(updatedWorker.GetID()) + + return nil +} diff --git a/octopusdeploy/schema_kubernetes_agent_worker.go b/octopusdeploy/schema_kubernetes_agent_worker.go new file mode 100644 index 000000000..0b8c892af --- /dev/null +++ b/octopusdeploy/schema_kubernetes_agent_worker.go @@ -0,0 +1,175 @@ +package octopusdeploy + +import ( + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "net/url" +) + +func expandKubernetesAgentWorker(kubernetesAgent *schema.ResourceData) *machines.Worker { + uri, _ := url.Parse(kubernetesAgent.Get("uri").(string)) + thumbprint := kubernetesAgent.Get("thumbprint").(string) + + workerPoolIds := kubernetesAgent.Get("worker_pool_ids").([]string) + communicationsMode := kubernetesAgent.Get("communication_mode").(string) + upgradeLocked := kubernetesAgent.Get("upgrade_locked").(bool) + var endpoint machines.IEndpoint = machines.NewKubernetesTentacleEndpoint(uri, thumbprint, upgradeLocked, communicationsMode, "") + + name := kubernetesAgent.Get("name").(string) + Worker := machines.NewWorker(name, endpoint) + + Worker.IsDisabled = kubernetesAgent.Get("is_disabled").(bool) + Worker.Thumbprint = thumbprint + Worker.WorkerPoolIDs = workerPoolIds + + Worker.SpaceID = kubernetesAgent.Get("space_id").(string) + + return Worker +} + +func flattenKubernetesAgentWorker(Worker *machines.Worker) map[string]interface{} { + if Worker == nil { + return nil + } + + if Worker.Endpoint.GetCommunicationStyle() != "KubernetesTentacle" { + return nil + } + + endpoint := Worker.Endpoint.(*machines.KubernetesTentacleEndpoint) + + flattenedWorker := map[string]interface{}{} + flattenedWorker["id"] = Worker.GetID() + flattenedWorker["space_id"] = Worker.SpaceID + flattenedWorker["name"] = Worker.Name + flattenedWorker["machine_policy_id"] = Worker.MachinePolicyID + flattenedWorker["is_disabled"] = Worker.IsDisabled + + flattenedWorker["thumbprint"] = endpoint.TentacleEndpointConfiguration.Thumbprint + flattenedWorker["uri"] = endpoint.TentacleEndpointConfiguration.URI.String() + flattenedWorker["communication_mode"] = endpoint.TentacleEndpointConfiguration.CommunicationMode + flattenedWorker["default_namespace"] = endpoint.DefaultNamespace + flattenedWorker["worker_pool_ids"] = Worker.WorkerPoolIDs + + if endpoint.KubernetesAgentDetails != nil { + flattenedWorker["agent_version"] = endpoint.KubernetesAgentDetails.AgentVersion + flattenedWorker["agent_tentacle_version"] = endpoint.KubernetesAgentDetails.TentacleVersion + flattenedWorker["agent_upgrade_status"] = endpoint.KubernetesAgentDetails.UpgradeStatus + flattenedWorker["agent_helm_release_name"] = endpoint.KubernetesAgentDetails.HelmReleaseName + flattenedWorker["agent_kubernetes_namespace"] = endpoint.KubernetesAgentDetails.KubernetesNamespace + } + + return flattenedWorker +} + +func getKubernetesAgentWorkerSchema() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "id": getIDSchema(), + "space_id": getSpaceIDSchema(), + "name": getNameSchema(true), + "environments": { + Description: "A list of environment IDs this Kubernetes agent can deploy to.", + Elem: &schema.Schema{Type: schema.TypeString}, + MinItems: 1, + Required: true, + Type: schema.TypeList, + }, + "roles": { + Description: "A list of target roles that are associated to this Kubernetes agent.", + Elem: &schema.Schema{Type: schema.TypeString}, + MinItems: 1, + Required: true, + Type: schema.TypeList, + }, + "tenanted_deployment_participation": getTenantedDeploymentSchema(), + "tenants": getTenantsSchema(), + "tenant_tags": getTenantTagsSchema(), + "communication_mode": { + Optional: true, + Description: "The communication mode used by the Kubernetes agent to communicate with Octopus Server. Currently, the only supported value is 'Polling'.", + Type: schema.TypeString, + Default: "Polling", + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"Polling"}, false)), + }, + "machine_policy_id": { + Description: "Optional ID of the machine policy that the Kubernetes agent will use. If not provided the default machine policy will be used.", + Computed: true, + Optional: true, + Type: schema.TypeString, + }, + "thumbprint": { + Description: "The thumbprint of the Kubernetes agent's certificate used by server to verify the identity of the agent. This is the same thumbprint that was used when installing the agent.", + Required: true, + Type: schema.TypeString, + }, + "uri": { + Description: "The URI of the Kubernetes agent's used by the server to queue messages. This is the same subscription uri that was used when installing the agent.", + Required: true, + Type: schema.TypeString, + }, + "default_namespace": { + Description: "Optional default namespace that will be used when using Kubernetes deployment steps, can be overrides within step configurations.", + Computed: true, + Optional: true, + Type: schema.TypeString, + }, + "upgrade_locked": { + Description: "If enabled the Kubernetes agent will not automatically upgrade and will stay on the currently installed version, even if the associated machine policy is configured to automatically upgrade.", + Optional: true, + Type: schema.TypeBool, + }, + "is_disabled": { + Description: "Whether the Kubernetes agent is disabled. If the agent is disabled, it will not be included in any deployments.", + Optional: true, + Default: false, + Type: schema.TypeBool, + }, + + // Read-only Values + "agent_version": { + Description: "Current Helm chart version of the agent.", + Computed: true, + Type: schema.TypeString, + }, + "agent_tentacle_version": { + Description: "Current Tentacle version of the agent", + Computed: true, + Type: schema.TypeString, + }, + "agent_upgrade_status": { + Description: "Current upgrade availability status of the agent. One of 'NoUpgrades', 'UpgradeAvailable', 'UpgradeSuggested', 'UpgradeRequired'", + Computed: true, + Type: schema.TypeString, + }, + "agent_helm_release_name": { + Description: "Name of the Helm release that the agent belongs to.", + Computed: true, + Type: schema.TypeString, + }, + "agent_kubernetes_namespace": { + Description: "Name of the Kubernetes namespace where the agent is installed.", + Computed: true, + Type: schema.TypeString, + }, + } +} + +func getKubernetesAgentWorkerDataSchema() map[string]*schema.Schema { + dataSchema := getKubernetesAgentWorkerSchema() + setDataSchema(&dataSchema) + + WorkerDataSchema := getWorkerDataSchema() + WorkerDataSchema["kubernetes_agent_deployment_targets"] = &schema.Schema{ + Computed: true, + Description: "A list of kubernetes agent deployment targets that match the filter(s).", + Elem: &schema.Resource{Schema: dataSchema}, + Optional: true, + Type: schema.TypeList, + } + + delete(WorkerDataSchema, "communication_styles") + delete(WorkerDataSchema, "deployment_targets") + WorkerDataSchema["id"] = getDataSchemaID() + return WorkerDataSchema +} From 74eb654f0a98717199a3773184d88cb897d4387c Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Wed, 26 Jun 2024 11:37:53 +1000 Subject: [PATCH 02/34] create schema_worker --- octopusdeploy/schema_worker.go | 202 +++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 octopusdeploy/schema_worker.go diff --git a/octopusdeploy/schema_worker.go b/octopusdeploy/schema_worker.go new file mode 100644 index 000000000..65ce9496a --- /dev/null +++ b/octopusdeploy/schema_worker.go @@ -0,0 +1,202 @@ +package octopusdeploy + +import ( + "context" + "fmt" + + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func expandWorker(d *schema.ResourceData) *machines.Worker { + endpoint := expandEndpoint(d.Get("endpoint")) + name := d.Get("name").(string) + + worker := machines.NewWorker(name, endpoint) + worker.ID = d.Id() + + if v, ok := d.GetOk("machine_policy_id"); ok { + worker.MachinePolicyID = v.(string) + } + + if v, ok := d.GetOk("is_disabled"); ok { + worker.IsDisabled = v.(bool) + } + + if v, ok := d.GetOk("thumbprint"); ok { + worker.Thumbprint = v.(string) + } + + if v, ok := d.GetOk("uri"); ok { + worker.URI = v.(string) + } + + if v, ok := d.GetOk("space_id"); ok { + worker.SpaceID = v.(string) + } + + if v, ok := d.GetOk("thumbprint"); ok { + worker.Thumbprint = v.(string) + } + + worker.WorkerPoolIDs = getSliceFromTerraformTypeList(d.Get("worker_pool_ids")) + + return worker +} + +func flattenWorker(worker *machines.Worker) map[string]interface{} { + if worker == nil { + return nil + } + + endpointResource, _ := machines.ToEndpointResource(worker.Endpoint) + + return map[string]interface{}{ + "endpoint": flattenEndpointResource(endpointResource), + "has_latest_calamari": worker.HasLatestCalamari, + "health_status": worker.HealthStatus, + "id": worker.GetID(), + "is_disabled": worker.IsDisabled, + "is_in_process": worker.IsInProcess, + "machine_policy_id": worker.MachinePolicyID, + "name": worker.Name, + "operating_system": worker.OperatingSystem, + "shell_name": worker.ShellName, + "shell_version": worker.ShellVersion, + "space_id": worker.SpaceID, + "status": worker.Status, + "status_summary": worker.StatusSummary, + "thumbprint": worker.Thumbprint, + "uri": worker.URI, + "worker_pool_ids": worker.WorkerPoolIDs, + } +} + +func getWorkerDataSchema() map[string]*schema.Schema { + dataSchema := getWorkerSchema() + setDataSchema(&dataSchema) + + return map[string]*schema.Schema{ + "communication_styles": getQueryCommunicationStyles(), + "deployment_id": getQueryDeploymentID(), + "workers": { + Computed: true, + Description: "A list of deployment targets that match the filter(s).", + Elem: &schema.Resource{Schema: dataSchema}, + Optional: true, + Type: schema.TypeList, + }, + "health_statuses": getQueryHealthStatuses(), + "ids": getQueryIDs(), + "is_disabled": getQueryIsDisabled(), + "name": getQueryName(), + "partial_name": getQueryPartialName(), + "roles": getQueryRoles(), + "shell_names": getQueryShellNames(), + "skip": getQuerySkip(), + "take": getQueryTake(), + "thumbprint": getQueryThumbprint(), + "space_id": getSpaceIDSchema(), + } +} + +func getWorkerSchema() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "endpoint": { + Computed: true, + Elem: &schema.Resource{Schema: getEndpointSchema()}, + MinItems: 1, + Optional: true, + Type: schema.TypeList, + }, + "has_latest_calamari": { + Computed: true, + Type: schema.TypeBool, + }, + "health_status": getHealthStatusSchema(), + "id": getIDSchema(), + "is_disabled": { + Computed: true, + Optional: true, + Type: schema.TypeBool, + }, + "is_in_process": { + Computed: true, + Type: schema.TypeBool, + }, + "machine_policy_id": { + Computed: true, + Optional: true, + Type: schema.TypeString, + }, + "name": getNameSchema(true), + "operating_system": { + Computed: true, + Optional: true, + Type: schema.TypeString, + }, + "shell_name": { + Computed: true, + Optional: true, + Type: schema.TypeString, + }, + "shell_version": { + Computed: true, + Optional: true, + Type: schema.TypeString, + }, + "space_id": getSpaceIDSchema(), + "status": getStatusSchema(), + "status_summary": getStatusSummarySchema(), + "thumbprint": { + Computed: true, + Optional: true, + Type: schema.TypeString, + }, + "uri": { + Computed: true, + Optional: true, + Type: schema.TypeString, + }, + "worker_pool_ids": { + Elem: &schema.Schema{Type: schema.TypeString}, + MinItems: 1, + Required: true, + Type: schema.TypeList, + }, + } +} + +func setWorker(ctx context.Context, d *schema.ResourceData, worker *machines.Worker) error { + d.Set("has_latest_calamari", worker.HasLatestCalamari) + d.Set("health_status", worker.HealthStatus) + d.Set("is_disabled", worker.IsDisabled) + d.Set("is_in_process", worker.IsInProcess) + d.Set("machine_policy_id", worker.MachinePolicyID) + d.Set("name", worker.Name) + d.Set("operating_system", worker.OperatingSystem) + d.Set("shell_name", worker.ShellName) + d.Set("shell_version", worker.ShellVersion) + d.Set("space_id", worker.SpaceID) + d.Set("status", worker.Status) + d.Set("status_summary", worker.StatusSummary) + d.Set("thumbprint", worker.Thumbprint) + d.Set("uri", worker.URI) + d.Set("space_id", worker.SpaceID) + d.Set("worker_pool_ids", worker.WorkerPoolIDs) + + endpointResource, err := machines.ToEndpointResource(worker.Endpoint) + if err != nil { + return fmt.Errorf("error setting endpoint: %s", err) + } + + if d.Get("endpoint") != nil { + if err := d.Set("endpoint", flattenEndpointResource(endpointResource)); err != nil { + return fmt.Errorf("error setting endpoint: %s", err) + } + } + + d.SetId(worker.GetID()) + + return nil +} From cc236240a2578cae201ac8ddfa92cf9e4c49018b Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Wed, 26 Jun 2024 14:23:04 +1000 Subject: [PATCH 03/34] adding examples I think --- terraform/58-k8sworker/config.tf | 5 +++++ terraform/58-k8sworker/provider.tf | 5 +++++ terraform/58-k8sworker/provider_vars.tf | 18 ++++++++++++++++++ terraform/58-k8sworker/space.tf | 3 +++ .../58-k8sworker/tentacle_certificates.tf | 11 +++++++++++ 5 files changed, 42 insertions(+) create mode 100644 terraform/58-k8sworker/config.tf create mode 100644 terraform/58-k8sworker/provider.tf create mode 100644 terraform/58-k8sworker/provider_vars.tf create mode 100644 terraform/58-k8sworker/space.tf create mode 100644 terraform/58-k8sworker/tentacle_certificates.tf diff --git a/terraform/58-k8sworker/config.tf b/terraform/58-k8sworker/config.tf new file mode 100644 index 000000000..2113da144 --- /dev/null +++ b/terraform/58-k8sworker/config.tf @@ -0,0 +1,5 @@ +terraform { + required_providers { + octopusdeploy = { source = "OctopusDeployLabs/octopusdeploy", version = "0.18.1" } + } +} diff --git a/terraform/58-k8sworker/provider.tf b/terraform/58-k8sworker/provider.tf new file mode 100644 index 000000000..a04197720 --- /dev/null +++ b/terraform/58-k8sworker/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/58-k8sworker/provider_vars.tf b/terraform/58-k8sworker/provider_vars.tf new file mode 100644 index 000000000..c7d93fe40 --- /dev/null +++ b/terraform/58-k8sworker/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/58-k8sworker/space.tf b/terraform/58-k8sworker/space.tf new file mode 100644 index 000000000..ee59bdc80 --- /dev/null +++ b/terraform/58-k8sworker/space.tf @@ -0,0 +1,3 @@ +output "octopus_space_id" { + value = var.octopus_space_id +} diff --git a/terraform/58-k8sworker/tentacle_certificates.tf b/terraform/58-k8sworker/tentacle_certificates.tf new file mode 100644 index 000000000..576be8c0b --- /dev/null +++ b/terraform/58-k8sworker/tentacle_certificates.tf @@ -0,0 +1,11 @@ +resource "octopusdeploy_tentacle_certificate" "base" {} + +resource "octopusdeploy_tentacle_certificate" "optional" { + dependencies = { + "base_id" = octopusdeploy_tentacle_certificate.base.id + } +} + +output "base_certificate_thumbprint" { + value = octopusdeploy_tentacle_certificate.base.thumbprint +} \ No newline at end of file From e3b972fe58376b2b3c0dde209de308a3fee941b6 Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Wed, 26 Jun 2024 16:28:45 +1000 Subject: [PATCH 04/34] might be working --- .run/Run provider.run.xml | 12 ----- docs/resources/kubernetes_agent_worker.md | 2 +- .../data_source_kubernetes_agent_workers.go | 51 +++++++++++++++++++ octopusdeploy/provider.go | 2 + .../schema_kubernetes_agent_worker.go | 38 +++++--------- octopusdeploy/schema_worker.go | 3 +- 6 files changed, 67 insertions(+), 41 deletions(-) delete mode 100644 .run/Run provider.run.xml create mode 100644 octopusdeploy/data_source_kubernetes_agent_workers.go diff --git a/.run/Run provider.run.xml b/.run/Run provider.run.xml deleted file mode 100644 index 165690b7a..000000000 --- a/.run/Run provider.run.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/docs/resources/kubernetes_agent_worker.md b/docs/resources/kubernetes_agent_worker.md index 26b14474a..f31b15c44 100644 --- a/docs/resources/kubernetes_agent_worker.md +++ b/docs/resources/kubernetes_agent_worker.md @@ -67,5 +67,5 @@ resource "octopusdeploy_kubernetes_agent_worker" "optionals" { Import is supported using the following syntax: ```shell -terraform import [options] octopusdeploy_kubernetes_agent_deployment_target. +terraform import [options] octopusdeploy_kubernetes_agent_worker. ``` diff --git a/octopusdeploy/data_source_kubernetes_agent_workers.go b/octopusdeploy/data_source_kubernetes_agent_workers.go new file mode 100644 index 000000000..459492bbd --- /dev/null +++ b/octopusdeploy/data_source_kubernetes_agent_workers.go @@ -0,0 +1,51 @@ +package octopusdeploy + +import ( + "context" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "time" +) + +func dataSourceKubernetesAgentWorkers() *schema.Resource { + return &schema.Resource{ + Description: "Provides information about existing kubernetes agent deployment targets.", + ReadContext: dataSourceKubernetesAgentDeploymentTargetsRead, + Schema: getKubernetesAgentDeploymentTargetDataSchema(), + } +} + +func dataSourceKubernetesAgentWorkersRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + query := machines.WorkersQuery{ + CommunicationStyles: []string{"KubernetesTentacle"}, + HealthStatuses: expandArray(d.Get("health_statuses").([]interface{})), + IDs: expandArray(d.Get("ids").([]interface{})), + IsDisabled: d.Get("is_disabled").(bool), + Name: d.Get("name").(string), + PartialName: d.Get("partial_name").(string), + ShellNames: expandArray(d.Get("shell_names").([]interface{})), + Skip: d.Get("skip").(int), + Take: d.Get("take").(int), + Thumbprint: d.Get("thumbprint").(string), + } + + client := m.(*client.Client) + existingWorkers, err := client.Workers.Get(query) + if err != nil { + return diag.FromErr(err) + } + + flattenedKubernetesAgents := []interface{}{} + for _, worker := range existingWorkers.Items { + flattenedKubernetesAgents = append(flattenedKubernetesAgents, flattenKubernetesAgentWorker(worker)) + } + + err = d.Set("kubernetes_agent_workers", flattenedKubernetesAgents) + if err != nil { + return diag.FromErr(err) + } + d.SetId("KubernetesAgentDeploymentWorkers " + time.Now().UTC().String()) + return nil +} diff --git a/octopusdeploy/provider.go b/octopusdeploy/provider.go index 1d5386556..e26c7a93b 100644 --- a/octopusdeploy/provider.go +++ b/octopusdeploy/provider.go @@ -22,6 +22,7 @@ func Provider() *schema.Provider { "octopusdeploy_feeds": dataSourceFeeds(), "octopusdeploy_git_credentials": dataSourceGitCredentials(), "octopusdeploy_kubernetes_agent_deployment_targets": dataSourceKubernetesAgentDeploymentTargets(), + "octopusdeploy_kubernetes_agent_workers": dataSourceKubernetesAgentWorkers(), "octopusdeploy_kubernetes_cluster_deployment_targets": dataSourceKubernetesClusterDeploymentTargets(), "octopusdeploy_library_variable_sets": dataSourceLibraryVariableSet(), "octopusdeploy_lifecycles": dataSourceLifecycles(), @@ -66,6 +67,7 @@ func Provider() *schema.Provider { "octopusdeploy_gcp_account": resourceGoogleCloudPlatformAccount(), "octopusdeploy_helm_feed": resourceHelmFeed(), "octopusdeploy_kubernetes_agent_deployment_target": resourceKubernetesAgentDeploymentTarget(), + "octopusdeploy_kubernetes_agent_worker": resourceKubernetesAgentWorker(), "octopusdeploy_kubernetes_cluster_deployment_target": resourceKubernetesClusterDeploymentTarget(), "octopusdeploy_library_variable_set": resourceLibraryVariableSet(), "octopusdeploy_lifecycle": resourceLifecycle(), diff --git a/octopusdeploy/schema_kubernetes_agent_worker.go b/octopusdeploy/schema_kubernetes_agent_worker.go index 0b8c892af..5d78ca1ef 100644 --- a/octopusdeploy/schema_kubernetes_agent_worker.go +++ b/octopusdeploy/schema_kubernetes_agent_worker.go @@ -65,23 +65,9 @@ func flattenKubernetesAgentWorker(Worker *machines.Worker) map[string]interface{ func getKubernetesAgentWorkerSchema() map[string]*schema.Schema { return map[string]*schema.Schema{ - "id": getIDSchema(), - "space_id": getSpaceIDSchema(), - "name": getNameSchema(true), - "environments": { - Description: "A list of environment IDs this Kubernetes agent can deploy to.", - Elem: &schema.Schema{Type: schema.TypeString}, - MinItems: 1, - Required: true, - Type: schema.TypeList, - }, - "roles": { - Description: "A list of target roles that are associated to this Kubernetes agent.", - Elem: &schema.Schema{Type: schema.TypeString}, - MinItems: 1, - Required: true, - Type: schema.TypeList, - }, + "id": getIDSchema(), + "space_id": getSpaceIDSchema(), + "name": getNameSchema(true), "tenanted_deployment_participation": getTenantedDeploymentSchema(), "tenants": getTenantsSchema(), "tenant_tags": getTenantTagsSchema(), @@ -108,12 +94,6 @@ func getKubernetesAgentWorkerSchema() map[string]*schema.Schema { Required: true, Type: schema.TypeString, }, - "default_namespace": { - Description: "Optional default namespace that will be used when using Kubernetes deployment steps, can be overrides within step configurations.", - Computed: true, - Optional: true, - Type: schema.TypeString, - }, "upgrade_locked": { Description: "If enabled the Kubernetes agent will not automatically upgrade and will stay on the currently installed version, even if the associated machine policy is configured to automatically upgrade.", Optional: true, @@ -125,6 +105,12 @@ func getKubernetesAgentWorkerSchema() map[string]*schema.Schema { Default: false, Type: schema.TypeBool, }, + "worker_pool_ids": { + Elem: &schema.Schema{Type: schema.TypeString}, + MinItems: 1, + Required: true, + Type: schema.TypeList, + }, // Read-only Values "agent_version": { @@ -160,16 +146,16 @@ func getKubernetesAgentWorkerDataSchema() map[string]*schema.Schema { setDataSchema(&dataSchema) WorkerDataSchema := getWorkerDataSchema() - WorkerDataSchema["kubernetes_agent_deployment_targets"] = &schema.Schema{ + WorkerDataSchema["kubernetes_agent_workers"] = &schema.Schema{ Computed: true, - Description: "A list of kubernetes agent deployment targets that match the filter(s).", + Description: "A list of kubernetes agent workers that match the filter(s).", Elem: &schema.Resource{Schema: dataSchema}, Optional: true, Type: schema.TypeList, } delete(WorkerDataSchema, "communication_styles") - delete(WorkerDataSchema, "deployment_targets") + delete(WorkerDataSchema, "workers") WorkerDataSchema["id"] = getDataSchemaID() return WorkerDataSchema } diff --git a/octopusdeploy/schema_worker.go b/octopusdeploy/schema_worker.go index 65ce9496a..56822960a 100644 --- a/octopusdeploy/schema_worker.go +++ b/octopusdeploy/schema_worker.go @@ -78,10 +78,9 @@ func getWorkerDataSchema() map[string]*schema.Schema { return map[string]*schema.Schema{ "communication_styles": getQueryCommunicationStyles(), - "deployment_id": getQueryDeploymentID(), "workers": { Computed: true, - Description: "A list of deployment targets that match the filter(s).", + Description: "A list of workers that match the filter(s).", Elem: &schema.Resource{Schema: dataSchema}, Optional: true, Type: schema.TypeList, From cea6f0fa037bf9e4237c62a6827aea7889031714 Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Thu, 27 Jun 2024 08:20:16 +1000 Subject: [PATCH 05/34] don't lose file --- .run/Run provider.run.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .run/Run provider.run.xml diff --git a/.run/Run provider.run.xml b/.run/Run provider.run.xml new file mode 100644 index 000000000..165690b7a --- /dev/null +++ b/.run/Run provider.run.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file From e60707ae325b67716347117a6f3d625e1470237c Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Thu, 27 Jun 2024 08:39:15 +1000 Subject: [PATCH 06/34] personal review of production code --- docs/resources/kubernetes_agent_worker.md | 17 ++++++----------- .../data_source_kubernetes_agent_workers.go | 8 ++++---- .../resource_kubernetes_agent_worker.go | 4 ++-- octopusdeploy/schema_kubernetes_agent_worker.go | 11 ++++------- 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/docs/resources/kubernetes_agent_worker.md b/docs/resources/kubernetes_agent_worker.md index f31b15c44..f41287e7f 100644 --- a/docs/resources/kubernetes_agent_worker.md +++ b/docs/resources/kubernetes_agent_worker.md @@ -1,13 +1,13 @@ --- -page_title: "octopusdeploy_kubernetes_agent_deployment_target Resource - terraform-provider-octopusdeploy" -subcategory: "Deployment Targets" +page_title: "octopusdeploy_kubernetes_agent_worker Resource - terraform-provider-octopusdeploy" +subcategory: "Workers" description: |- - This resource manages Kubernetes agent deployment targets in Octopus Deploy. + This resource manages Kubernetes agent workers in Octopus Deploy. --- -# octopusdeploy_kubernetes_agent_deployment_target (Resource) +# octopusdeploy_kubernetes_agent_worker (Resource) -This resource manages Kubernetes agent deployment targets in Octopus Deploy. +This resource manages Kubernetes agent workers in Octopus Deploy. ## Example Usage @@ -20,12 +20,11 @@ resource "octopusdeploy_kubernetes_agent_worker" "minimal" { } resource "octopusdeploy_kubernetes_agent_worker" "optionals" { - name = "agent-optionals" + name = "agent-optionals" worker_pools = ["worker-pools-1"] thumbprint = "96203ED84246201C26A2F4360D7CBC36AC1D232D" uri = "poll://kcxzcv2fpsxkn6tk9u6d/" machine_policy_id = "machinepolicies-1" - default_namespace = "kubernetes-namespace" upgrade_locked = true is_disabled = true } @@ -44,14 +43,10 @@ resource "octopusdeploy_kubernetes_agent_worker" "optionals" { ### Optional - `communication_mode` (String) The communication mode used by the Kubernetes agent to communicate with Octopus Server. Currently, the only supported value is 'Polling'. -- `default_namespace` (String) Optional default namespace that will be used when using Kubernetes deployment steps, can be overrides within step configurations. - `id` (String) The unique ID for this resource. - `is_disabled` (Boolean) Whether the Kubernetes agent is disabled. If the agent is disabled, it will not be included in any deployments. - `machine_policy_id` (String) Optional ID of the machine policy that the Kubernetes agent will use. If not provided the default machine policy will be used. - `space_id` (String) The space ID associated with this resource. -- `tenant_tags` (List of String) A list of tenant tags associated with this resource. -- `tenanted_deployment_participation` (String) The tenanted deployment mode of the resource. Valid account types are `Untenanted`, `TenantedOrUntenanted`, or `Tenanted`. -- `tenants` (List of String) A list of tenant IDs associated with this resource. - `upgrade_locked` (Boolean) If enabled the Kubernetes agent will not automatically upgrade and will stay on the currently installed version, even if the associated machine policy is configured to automatically upgrade. ### Read-Only diff --git a/octopusdeploy/data_source_kubernetes_agent_workers.go b/octopusdeploy/data_source_kubernetes_agent_workers.go index 459492bbd..c270d7c3e 100644 --- a/octopusdeploy/data_source_kubernetes_agent_workers.go +++ b/octopusdeploy/data_source_kubernetes_agent_workers.go @@ -11,9 +11,9 @@ import ( func dataSourceKubernetesAgentWorkers() *schema.Resource { return &schema.Resource{ - Description: "Provides information about existing kubernetes agent deployment targets.", - ReadContext: dataSourceKubernetesAgentDeploymentTargetsRead, - Schema: getKubernetesAgentDeploymentTargetDataSchema(), + Description: "Provides information about existing kubernetes agent workers.", + ReadContext: dataSourceKubernetesAgentWorkersRead, + Schema: getKubernetesAgentWorkerDataSchema(), } } @@ -46,6 +46,6 @@ func dataSourceKubernetesAgentWorkersRead(ctx context.Context, d *schema.Resourc if err != nil { return diag.FromErr(err) } - d.SetId("KubernetesAgentDeploymentWorkers " + time.Now().UTC().String()) + d.SetId("KubernetesAgentWorkers " + time.Now().UTC().String()) return nil } diff --git a/octopusdeploy/resource_kubernetes_agent_worker.go b/octopusdeploy/resource_kubernetes_agent_worker.go index b12648266..ed5fab11b 100644 --- a/octopusdeploy/resource_kubernetes_agent_worker.go +++ b/octopusdeploy/resource_kubernetes_agent_worker.go @@ -12,7 +12,7 @@ func resourceKubernetesAgentWorker() *schema.Resource { return &schema.Resource{ CreateContext: resourceKubernetesAgentWorkerCreate, DeleteContext: resourceKubernetesAgentWorkerDelete, - Description: "This resource manages Kubernetes agent deployment targets in Octopus Deploy.", + Description: "This resource manages Kubernetes agent workers in Octopus Deploy.", Importer: getImporter(), ReadContext: resourceKubernetesAgentWorkerRead, Schema: getKubernetesAgentWorkerSchema(), @@ -36,7 +36,7 @@ func resourceKubernetesAgentWorkerRead(ctx context.Context, d *schema.ResourceDa client := m.(*client.Client) Worker, err := client.Workers.GetByID(d.Id()) if err != nil { - return errors.ProcessApiError(ctx, d, err, "kubernetes tentacle deployment target") + return errors.ProcessApiError(ctx, d, err, "kubernetes tentacle worker") } flattenedKubernetesAgentWorker := flattenKubernetesAgentWorker(Worker) diff --git a/octopusdeploy/schema_kubernetes_agent_worker.go b/octopusdeploy/schema_kubernetes_agent_worker.go index 5d78ca1ef..a76fcf6fe 100644 --- a/octopusdeploy/schema_kubernetes_agent_worker.go +++ b/octopusdeploy/schema_kubernetes_agent_worker.go @@ -49,7 +49,7 @@ func flattenKubernetesAgentWorker(Worker *machines.Worker) map[string]interface{ flattenedWorker["thumbprint"] = endpoint.TentacleEndpointConfiguration.Thumbprint flattenedWorker["uri"] = endpoint.TentacleEndpointConfiguration.URI.String() flattenedWorker["communication_mode"] = endpoint.TentacleEndpointConfiguration.CommunicationMode - flattenedWorker["default_namespace"] = endpoint.DefaultNamespace + flattenedWorker["default_namespace"] = "" flattenedWorker["worker_pool_ids"] = Worker.WorkerPoolIDs if endpoint.KubernetesAgentDetails != nil { @@ -65,12 +65,9 @@ func flattenKubernetesAgentWorker(Worker *machines.Worker) map[string]interface{ func getKubernetesAgentWorkerSchema() map[string]*schema.Schema { return map[string]*schema.Schema{ - "id": getIDSchema(), - "space_id": getSpaceIDSchema(), - "name": getNameSchema(true), - "tenanted_deployment_participation": getTenantedDeploymentSchema(), - "tenants": getTenantsSchema(), - "tenant_tags": getTenantTagsSchema(), + "id": getIDSchema(), + "space_id": getSpaceIDSchema(), + "name": getNameSchema(true), "communication_mode": { Optional: true, Description: "The communication mode used by the Kubernetes agent to communicate with Octopus Server. Currently, the only supported value is 'Polling'.", From 72fd4c78888cfe29896e7c63d3919a1f3b8bcede Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Thu, 27 Jun 2024 13:28:48 +1000 Subject: [PATCH 07/34] move files around for testing --- .../58-k8sworker/tentacle_certificates.tf | 11 ------ .../config.tf | 0 .../kubernetes_agent_workers.tf | 18 +++++++++ .../58-kubernetesagentworker/machinepolicy.tf | 39 +++++++++++++++++++ .../provider.tf | 0 .../provider_vars.tf | 0 .../space.tf | 0 .../58-kubernetesagentworker/workerpool.tf | 6 +++ 8 files changed, 63 insertions(+), 11 deletions(-) delete mode 100644 terraform/58-k8sworker/tentacle_certificates.tf rename terraform/{58-k8sworker => 58-kubernetesagentworker}/config.tf (100%) create mode 100644 terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf create mode 100644 terraform/58-kubernetesagentworker/machinepolicy.tf rename terraform/{58-k8sworker => 58-kubernetesagentworker}/provider.tf (100%) rename terraform/{58-k8sworker => 58-kubernetesagentworker}/provider_vars.tf (100%) rename terraform/{58-k8sworker => 58-kubernetesagentworker}/space.tf (100%) create mode 100644 terraform/58-kubernetesagentworker/workerpool.tf diff --git a/terraform/58-k8sworker/tentacle_certificates.tf b/terraform/58-k8sworker/tentacle_certificates.tf deleted file mode 100644 index 576be8c0b..000000000 --- a/terraform/58-k8sworker/tentacle_certificates.tf +++ /dev/null @@ -1,11 +0,0 @@ -resource "octopusdeploy_tentacle_certificate" "base" {} - -resource "octopusdeploy_tentacle_certificate" "optional" { - dependencies = { - "base_id" = octopusdeploy_tentacle_certificate.base.id - } -} - -output "base_certificate_thumbprint" { - value = octopusdeploy_tentacle_certificate.base.thumbprint -} \ No newline at end of file diff --git a/terraform/58-k8sworker/config.tf b/terraform/58-kubernetesagentworker/config.tf similarity index 100% rename from terraform/58-k8sworker/config.tf rename to terraform/58-kubernetesagentworker/config.tf diff --git a/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf b/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf new file mode 100644 index 000000000..b12250c2a --- /dev/null +++ b/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf @@ -0,0 +1,18 @@ +resource "octopusdeploy_kubernetes_agent_worker" "agent_with_minimum" { + name = "minimum-agent" + worker_pool_ids = [octopusdeploy_static_worker_pool.workerpool_docker.id] + uri = "poll://kcxzcv2fpsxkn6tk9u6d/" + thumbprint = "96203ED84246201C26A2F4360D7CBC36AC1D232D" +} + +resource "octopusdeploy_kubernetes_agent_worker" "agent_with_optional" { + name = "optional-agent" + machine_policy_id = octopusdeploy_machine_policy.machinepolicy_testing.id + worker_pool_ids = [octopusdeploy_static_worker_pool.workerpool_docker.id] + communication_mode = "Polling" + uri = "poll://kcxzcv2fpsxkn6tk9u6d/" + thumbprint = "96203ED84246201C26A2F4360D7CBC36AC1D232D" + default_namespace = "kubernetes-namespace" + is_disabled = true + upgrade_locked = true +} \ No newline at end of file diff --git a/terraform/58-kubernetesagentworker/machinepolicy.tf b/terraform/58-kubernetesagentworker/machinepolicy.tf new file mode 100644 index 000000000..b3ef159d8 --- /dev/null +++ b/terraform/58-kubernetesagentworker/machinepolicy.tf @@ -0,0 +1,39 @@ +resource "octopusdeploy_machine_policy" "machinepolicy_testing" { + name = "Testing" + description = "test machine policy" + connection_connect_timeout = 60000000000 + connection_retry_count_limit = 5 + connection_retry_sleep_interval = 100000000 + connection_retry_time_limit = 300000000000 + + machine_cleanup_policy { + delete_machines_behavior = "DeleteUnavailableMachines" + delete_machines_elapsed_timespan = 1200000000000 + } + + machine_connectivity_policy { + machine_connectivity_behavior = "ExpectedToBeOnline" + } + + machine_health_check_policy { + + bash_health_check_policy { + run_type = "Inline" + script_body = "" + } + + powershell_health_check_policy { + run_type = "Inline" + script_body = "$freeDiskSpaceThreshold = 5GB\r\n\r\nTry {\r\n\tGet-WmiObject win32_LogicalDisk -ErrorAction Stop | ? { ($_.DriveType -eq 3) -and ($_.FreeSpace -ne $null)} | % { CheckDriveCapacity @{Name =$_.DeviceId; FreeSpace=$_.FreeSpace} }\r\n} Catch [System.Runtime.InteropServices.COMException] {\r\n\tGet-WmiObject win32_Volume | ? { ($_.DriveType -eq 3) -and ($_.FreeSpace -ne $null) -and ($_.DriveLetter -ne $null)} | % { CheckDriveCapacity @{Name =$_.DriveLetter; FreeSpace=$_.FreeSpace} }\r\n\tGet-WmiObject Win32_MappedLogicalDisk | ? { ($_.FreeSpace -ne $null) -and ($_.DeviceId -ne $null)} | % { CheckDriveCapacity @{Name =$_.DeviceId; FreeSpace=$_.FreeSpace} }\t\r\n}" + } + + health_check_cron_timezone = "UTC" + health_check_interval = 600000000000 + health_check_type = "RunScript" + } + + machine_update_policy { + calamari_update_behavior = "UpdateOnDeployment" + tentacle_update_behavior = "NeverUpdate" + } +} \ No newline at end of file diff --git a/terraform/58-k8sworker/provider.tf b/terraform/58-kubernetesagentworker/provider.tf similarity index 100% rename from terraform/58-k8sworker/provider.tf rename to terraform/58-kubernetesagentworker/provider.tf diff --git a/terraform/58-k8sworker/provider_vars.tf b/terraform/58-kubernetesagentworker/provider_vars.tf similarity index 100% rename from terraform/58-k8sworker/provider_vars.tf rename to terraform/58-kubernetesagentworker/provider_vars.tf diff --git a/terraform/58-k8sworker/space.tf b/terraform/58-kubernetesagentworker/space.tf similarity index 100% rename from terraform/58-k8sworker/space.tf rename to terraform/58-kubernetesagentworker/space.tf diff --git a/terraform/58-kubernetesagentworker/workerpool.tf b/terraform/58-kubernetesagentworker/workerpool.tf new file mode 100644 index 000000000..c1fd253fe --- /dev/null +++ b/terraform/58-kubernetesagentworker/workerpool.tf @@ -0,0 +1,6 @@ +resource "octopusdeploy_static_worker_pool" "workerpool_docker" { + name = "Docker" + description = "A test worker pool" + is_default = false + sort_order = 3 +} From 46c29f201e8031d5a2bdae04c0e349ae47013c77 Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Thu, 27 Jun 2024 14:35:07 +1000 Subject: [PATCH 08/34] updated integration test --- integration_test.go | 56 +++++++++++++++++++ .../kubernetes_agent_workers.tf | 3 +- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/integration_test.go b/integration_test.go index 228b6e2e8..2a269a3e9 100644 --- a/integration_test.go +++ b/integration_test.go @@ -3885,3 +3885,59 @@ func TestTentacleCertificateResource(t *testing.T) { return nil }) } + +func TestKubernetesAgentWorkerResource(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", "58-kubernetesagentworker", []string{}) + + if err != nil { + return err + } + + // Assert + client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) + query := machines.WorkersQuery{ + CommunicationStyles: []string{"Polling"}, + Skip: 0, + Take: 3, + } + + resources, err := client.Workers.Get(query) + if err != nil { + return err + } + + if len(resources.Items) != 2 { + t.Fatalf("Space must have two workers (both KubernetesTentacles)") + } + + optionalAgentName := "optional-agent" + optionalAgentIndex := stdslices.IndexFunc(resources.Items, func(t *machines.Worker) bool { return t.Name == optionalAgentName }) + optionalAgentWorker := resources.Items[optionalAgentIndex] + optionalAgentEndpoint := optionalAgentWorker.Endpoint.(*machines.KubernetesTentacleEndpoint) + if optionalAgentWorker.IsDisabled { + t.Fatalf("Expected \"%s\" to not be disabled", optionalAgentName) + } + + if !optionalAgentEndpoint.UpgradeLocked { + t.Fatalf("Expected \"%s\" to have upgrade locked", optionalAgentName) + } + + fullAgentName := "agent_with_optional" + fullAgentIndex := stdslices.IndexFunc(resources.Items, func(t *machines.Worker) bool { return t.Name == fullAgentName }) + fullAgentWorker := resources.Items[fullAgentIndex] + + if !fullAgentWorker.IsDisabled { + t.Fatalf("Expected \"%s\" to be disabled", fullAgentName) + } + + fullAgentEndpoint := fullAgentWorker.Endpoint.(*machines.KubernetesTentacleEndpoint) + if fullAgentEndpoint.UpgradeLocked { + t.Fatalf("Expected \"%s\" to not have upgrade locked", fullAgentName) + } + + return nil + }) +} diff --git a/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf b/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf index b12250c2a..1a1e6a540 100644 --- a/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf +++ b/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf @@ -12,7 +12,6 @@ resource "octopusdeploy_kubernetes_agent_worker" "agent_with_optional" { communication_mode = "Polling" uri = "poll://kcxzcv2fpsxkn6tk9u6d/" thumbprint = "96203ED84246201C26A2F4360D7CBC36AC1D232D" - default_namespace = "kubernetes-namespace" is_disabled = true - upgrade_locked = true + upgrade_locked = false } \ No newline at end of file From c183325cea55907ffecb9a8678dc6e7c0fc4fe00 Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Thu, 27 Jun 2024 15:51:28 +1000 Subject: [PATCH 09/34] trying to get workerpool_ids working again --- octopusdeploy/schema_kubernetes_agent_worker.go | 6 ++---- .../58-kubernetesagentworker/kubernetes_agent_workers.tf | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/octopusdeploy/schema_kubernetes_agent_worker.go b/octopusdeploy/schema_kubernetes_agent_worker.go index a76fcf6fe..80c0c7840 100644 --- a/octopusdeploy/schema_kubernetes_agent_worker.go +++ b/octopusdeploy/schema_kubernetes_agent_worker.go @@ -10,8 +10,7 @@ import ( func expandKubernetesAgentWorker(kubernetesAgent *schema.ResourceData) *machines.Worker { uri, _ := url.Parse(kubernetesAgent.Get("uri").(string)) thumbprint := kubernetesAgent.Get("thumbprint").(string) - - workerPoolIds := kubernetesAgent.Get("worker_pool_ids").([]string) + communicationsMode := kubernetesAgent.Get("communication_mode").(string) upgradeLocked := kubernetesAgent.Get("upgrade_locked").(bool) var endpoint machines.IEndpoint = machines.NewKubernetesTentacleEndpoint(uri, thumbprint, upgradeLocked, communicationsMode, "") @@ -21,7 +20,7 @@ func expandKubernetesAgentWorker(kubernetesAgent *schema.ResourceData) *machines Worker.IsDisabled = kubernetesAgent.Get("is_disabled").(bool) Worker.Thumbprint = thumbprint - Worker.WorkerPoolIDs = workerPoolIds + Worker.WorkerPoolIDs = getSliceFromTerraformTypeList(kubernetesAgent.Get("worker_pool_ids")) Worker.SpaceID = kubernetesAgent.Get("space_id").(string) @@ -49,7 +48,6 @@ func flattenKubernetesAgentWorker(Worker *machines.Worker) map[string]interface{ flattenedWorker["thumbprint"] = endpoint.TentacleEndpointConfiguration.Thumbprint flattenedWorker["uri"] = endpoint.TentacleEndpointConfiguration.URI.String() flattenedWorker["communication_mode"] = endpoint.TentacleEndpointConfiguration.CommunicationMode - flattenedWorker["default_namespace"] = "" flattenedWorker["worker_pool_ids"] = Worker.WorkerPoolIDs if endpoint.KubernetesAgentDetails != nil { diff --git a/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf b/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf index 1a1e6a540..5c4488a3e 100644 --- a/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf +++ b/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf @@ -8,7 +8,7 @@ resource "octopusdeploy_kubernetes_agent_worker" "agent_with_minimum" { resource "octopusdeploy_kubernetes_agent_worker" "agent_with_optional" { name = "optional-agent" machine_policy_id = octopusdeploy_machine_policy.machinepolicy_testing.id - worker_pool_ids = [octopusdeploy_static_worker_pool.workerpool_docker.id] + worker_pool_ids = [octopusdeploy_static_worker_pool.workerpool_docker.id] communication_mode = "Polling" uri = "poll://kcxzcv2fpsxkn6tk9u6d/" thumbprint = "96203ED84246201C26A2F4360D7CBC36AC1D232D" From cb50746d4183701673aa604db3cfe5d35f3ca651 Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Thu, 27 Jun 2024 16:52:35 +1000 Subject: [PATCH 10/34] force worker to on in int tests --- .github/workflows/integration-tests.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml index be1e27f9a..287947e71 100644 --- a/.github/workflows/integration-tests.yaml +++ b/.github/workflows/integration-tests.yaml @@ -97,6 +97,7 @@ jobs: GOMAXPROCS: 1 OCTOTESTVERSION: latest OCTOTESTIMAGEURL: docker.packages.octopushq.com/octopusdeploy/octopusdeploy + OCTOPUS__FeatureToggles__KubernetesAgentAsWorkerFeatureToggle: true - name: Upload test artifacts uses: actions/upload-artifact@v3 with: From 949a1b69dc10b6ce33f8e763d0b3cab6b8d87cae Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Mon, 1 Jul 2024 16:35:08 +1000 Subject: [PATCH 11/34] no idea --- integration_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/integration_test.go b/integration_test.go index 2a269a3e9..a4b24c323 100644 --- a/integration_test.go +++ b/integration_test.go @@ -71,6 +71,8 @@ import ( "k8s.io/utils/strings/slices" ) +replace github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240502041300-f71244db277d => /Users/kevintchang/Code/OctopusTerraformTestFramework + // TestSpaceResource verifies that a space can be reimported with the correct settings func TestSpaceResource(t *testing.T) { testFramework := test.OctopusContainerTest{} From b04c7ea0213d0fe5c56a6ec00731c942b2b6913a Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Tue, 16 Jul 2024 13:56:50 +1000 Subject: [PATCH 12/34] pre merge --- go.mod | 18 ++++++++++-------- go.sum | 38 ++++++++++++++++++-------------------- integration_test.go | 4 ++-- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/go.mod b/go.mod index 9517c6302..b2cf4c3c2 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,8 @@ module github.com/OctopusDeploy/terraform-provider-octopusdeploy go 1.21 +replace github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240502041300-f71244db277d => /Users/trent/projects/OctopusTerraformTestFramework + require ( github.com/OctopusDeploy/go-octopusdeploy/v2 v2.43.0 github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240502041300-f71244db277d @@ -14,7 +16,7 @@ require ( github.com/hashicorp/terraform-plugin-sdk/v2 v2.25.0 github.com/stretchr/testify v1.9.0 golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea - golang.org/x/text v0.13.0 + golang.org/x/text v0.14.0 k8s.io/utils v0.0.0-20230505201702-9f6742963106 software.sslmate.com/src/go-pkcs12 v0.4.0 ) @@ -43,7 +45,7 @@ require ( github.com/bgentry/speakeasy v0.1.0 // indirect github.com/buger/jsonparser v1.1.1 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect - github.com/containerd/containerd v1.7.12 // indirect + github.com/containerd/containerd v1.7.15 // indirect github.com/containerd/log v0.1.0 // indirect github.com/cpuguy83/dockercfg v0.3.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect @@ -62,7 +64,7 @@ require ( github.com/go-playground/validator/v10 v10.11.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect - github.com/golang/protobuf v1.5.3 // indirect + github.com/golang/protobuf v1.5.4 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/google/s2a-go v0.1.4 // indirect @@ -127,7 +129,7 @@ require ( github.com/shopspring/decimal v1.3.1 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/spf13/cast v1.5.0 // indirect - github.com/testcontainers/testcontainers-go v0.30.0 // indirect + github.com/testcontainers/testcontainers-go v0.31.0 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect github.com/tmccombs/hcl2json v0.3.6 // indirect @@ -143,19 +145,19 @@ require ( go.opentelemetry.io/otel v1.24.0 // indirect go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect - golang.org/x/crypto v0.14.0 // indirect + golang.org/x/crypto v0.22.0 // indirect golang.org/x/mod v0.16.0 // indirect - golang.org/x/net v0.17.0 // indirect + golang.org/x/net v0.21.0 // indirect golang.org/x/oauth2 v0.10.0 // indirect golang.org/x/sync v0.3.0 // indirect - golang.org/x/sys v0.16.0 // indirect + golang.org/x/sys v0.19.0 // indirect golang.org/x/tools v0.13.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/api v0.126.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230731190214-cbb8c96f2d6d // indirect google.golang.org/grpc v1.58.3 // indirect google.golang.org/protobuf v1.33.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 3987b9306..c9d48ba88 100644 --- a/go.sum +++ b/go.sum @@ -70,8 +70,6 @@ github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7 github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYxPRqGcpAD9w= github.com/OctopusDeploy/go-octopusdeploy/v2 v2.43.0 h1:fYwGBqG88xy3qHp5j1ySCztdqfw2NLfg2yp0N3XcBYg= github.com/OctopusDeploy/go-octopusdeploy/v2 v2.43.0/go.mod h1:GZmFu6LmN8Yg0tEoZx3ytk9FnaH+84cWm7u5TdWZC6E= -github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240502041300-f71244db277d h1:E0Rm52/XBlVzdkHET/+Js1FVVgf5/0oRk1tNkI4jcyk= -github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240502041300-f71244db277d/go.mod h1:Nyg+7cyTrSQ/lMIy5YY1UdJekRuoMWf4uHIPfaGmgTM= github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ= github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo= github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk= @@ -126,8 +124,8 @@ github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XP github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= -github.com/containerd/containerd v1.7.12 h1:+KQsnv4VnzyxWcfO9mlxxELaoztsDEjOuCMPAuPqgU0= -github.com/containerd/containerd v1.7.12/go.mod h1:/5OMpE1p0ylxtEUGY8kuCYkDRzJm9NO1TFMWjUpdevk= +github.com/containerd/containerd v1.7.15 h1:afEHXdil9iAm03BmhjzKyXnnEBtjaLJefdU7DV0IFes= +github.com/containerd/containerd v1.7.15/go.mod h1:ISzRRTMF8EXNpJlTzyr2XMhN+j9K302C21/+cr3kUnY= github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= github.com/cpuguy83/dockercfg v0.3.1 h1:/FpZ+JaygUR/lZP2NlFI2DVfrOEMAIKP5wWEJdoYe9E= @@ -232,8 +230,8 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -545,8 +543,8 @@ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/testcontainers/testcontainers-go v0.30.0 h1:jmn/XS22q4YRrcMwWg0pAwlClzs/abopbsBzrepyc4E= -github.com/testcontainers/testcontainers-go v0.30.0/go.mod h1:K+kHNGiM5zjklKjgTtcrEetF3uhWbMUyqAQoyoh8Pf0= +github.com/testcontainers/testcontainers-go v0.31.0 h1:W0VwIhcEVhRflwL9as3dhY6jXjVCA27AkmbnZ+UTh3U= +github.com/testcontainers/testcontainers-go v0.31.0/go.mod h1:D2lAoA0zUFiSY+eAflqK5mcUx/A5hrrORaEQrd0SefI= github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= @@ -625,8 +623,8 @@ golang.org/x/crypto v0.0.0-20220314234659-1baeb1ce4c0b/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= -golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= +golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -702,8 +700,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -779,15 +777,15 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= -golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= -golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= +golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= +golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -799,8 +797,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -922,8 +920,8 @@ google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 h1:Z0hjGZePRE0ZBWo google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98/go.mod h1:S7mY02OqCJTD0E1OiQy1F72PWFB4bZJ87cAtLPYgDR0= google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 h1:FmF5cCW94Ij59cfpoLiwTgodWmm60eEV0CjlsVg2fuw= google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98/go.mod h1:rsr7RhLuwsDKL7RmgDDCUc6yaGr1iqceVb5Wv6f6YvQ= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 h1:bVf09lpb+OJbByTj913DRJioFFAjf/ZGxEz7MajTp2U= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230731190214-cbb8c96f2d6d h1:pgIUhmqwKOUlnKna4r6amKdUngdL8DrkpFeV8+VBElY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230731190214-cbb8c96f2d6d/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= google.golang.org/grpc v1.8.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= diff --git a/integration_test.go b/integration_test.go index a4b24c323..2f2f3efb9 100644 --- a/integration_test.go +++ b/integration_test.go @@ -71,8 +71,6 @@ import ( "k8s.io/utils/strings/slices" ) -replace github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240502041300-f71244db277d => /Users/kevintchang/Code/OctopusTerraformTestFramework - // TestSpaceResource verifies that a space can be reimported with the correct settings func TestSpaceResource(t *testing.T) { testFramework := test.OctopusContainerTest{} @@ -3889,6 +3887,8 @@ func TestTentacleCertificateResource(t *testing.T) { } func TestKubernetesAgentWorkerResource(t *testing.T) { + customEnv := make(map[string]string) + customEnv["Octopus"] testFramework := test.OctopusContainerTest{} testFramework.ArrangeTest(t, func(t *testing.T, container *test.OctopusContainer, spaceClient *client.Client) error { // Act From 6432d3bf1a7ac39aaf9e587577e3aae3fceb06cb Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Fri, 19 Jul 2024 13:13:54 +1000 Subject: [PATCH 13/34] use newer test framework --- go.mod | 20 ++++++++++---------- go.sum | 46 ++++++++++++++++++++++----------------------- integration_test.go | 9 ++++++--- 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/go.mod b/go.mod index 1f5e5694d..affa1f49d 100644 --- a/go.mod +++ b/go.mod @@ -2,11 +2,9 @@ module github.com/OctopusDeploy/terraform-provider-octopusdeploy go 1.21 -replace github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240502041300-f71244db277d => /Users/trent/projects/OctopusTerraformTestFramework - require ( github.com/OctopusDeploy/go-octopusdeploy/v2 v2.43.0 - github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240622231527-24df7b6eaa48 + github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240718055636-f42871b46363 github.com/google/uuid v1.6.0 github.com/gruntwork-io/terratest v0.41.11 github.com/hashicorp/go-cty v1.4.1-0.20200723130312-85980079f637 @@ -31,8 +29,8 @@ require ( github.com/Masterminds/goutils v1.1.1 // indirect github.com/Masterminds/semver/v3 v3.2.0 // indirect github.com/Masterminds/sprig/v3 v3.2.3 // indirect - github.com/Microsoft/go-winio v0.6.1 // indirect - github.com/Microsoft/hcsshim v0.11.4 // indirect + github.com/Microsoft/go-winio v0.6.2 // indirect + github.com/Microsoft/hcsshim v0.11.5 // indirect github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect github.com/agext/levenshtein v1.2.3 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect @@ -45,13 +43,14 @@ require ( github.com/buger/jsonparser v1.1.1 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/cloudflare/circl v1.3.7 // indirect - github.com/containerd/containerd v1.7.15 // indirect + github.com/containerd/containerd v1.7.18 // indirect + github.com/containerd/errdefs v0.1.0 // indirect github.com/containerd/log v0.1.0 // indirect github.com/cpuguy83/dockercfg v0.3.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dghubble/sling v1.4.1 // indirect - github.com/distribution/reference v0.5.0 // indirect - github.com/docker/docker v25.0.5+incompatible // indirect + github.com/distribution/reference v0.6.0 // indirect + github.com/docker/docker v27.0.3+incompatible // indirect github.com/docker/go-connections v0.5.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/fatih/color v1.16.0 // indirect @@ -93,7 +92,7 @@ require ( github.com/imdario/mergo v0.3.15 // indirect github.com/jinzhu/copier v0.3.5 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect - github.com/klauspost/compress v1.16.0 // indirect + github.com/klauspost/compress v1.17.4 // indirect github.com/leodido/go-urn v1.2.2 // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/magiconair/properties v1.8.7 // indirect @@ -108,6 +107,7 @@ require ( github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect + github.com/moby/docker-image-spec v1.3.1 // indirect github.com/moby/patternmatcher v0.6.0 // indirect github.com/moby/sys/sequential v0.5.0 // indirect github.com/moby/sys/user v0.1.0 // indirect @@ -127,7 +127,7 @@ require ( github.com/shopspring/decimal v1.3.1 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/spf13/cast v1.5.0 // indirect - github.com/testcontainers/testcontainers-go v0.31.0 // indirect + github.com/testcontainers/testcontainers-go v0.32.0 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect github.com/tmccombs/hcl2json v0.3.6 // indirect diff --git a/go.sum b/go.sum index 795d2a3cf..c4124620a 100644 --- a/go.sum +++ b/go.sum @@ -34,16 +34,14 @@ github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYr github.com/Masterminds/sprig/v3 v3.2.1/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFPhxNuwnnxkKlk= github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA= github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM= -github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= -github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= -github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8= -github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYxPRqGcpAD9w= +github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= +github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= +github.com/Microsoft/hcsshim v0.11.5 h1:haEcLNpj9Ka1gd3B3tAEs9CpE0c+1IhoL59w/exYU38= +github.com/Microsoft/hcsshim v0.11.5/go.mod h1:MV8xMfmECjl5HdO7U/3/hFVnkmSBjAjmA09d4bExKcU= github.com/OctopusDeploy/go-octopusdeploy/v2 v2.43.0 h1:fYwGBqG88xy3qHp5j1ySCztdqfw2NLfg2yp0N3XcBYg= github.com/OctopusDeploy/go-octopusdeploy/v2 v2.43.0/go.mod h1:GZmFu6LmN8Yg0tEoZx3ytk9FnaH+84cWm7u5TdWZC6E= -github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240502041300-f71244db277d h1:E0Rm52/XBlVzdkHET/+Js1FVVgf5/0oRk1tNkI4jcyk= -github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240502041300-f71244db277d/go.mod h1:Nyg+7cyTrSQ/lMIy5YY1UdJekRuoMWf4uHIPfaGmgTM= -github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240622231527-24df7b6eaa48 h1:lxcmT+JUYCe2pA7owBK47/z0jY3va03yl1sQA3n0/Xo= -github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240622231527-24df7b6eaa48/go.mod h1:/QwYrEWP690YoKAR9lUVEv2y1Ta0HY08OaWb4LMZCAw= +github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240718055636-f42871b46363 h1:dBe8x8+XwanocHxpPEukOEBt/ubpvnCaobbRqpDGLOw= +github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240718055636-f42871b46363/go.mod h1:Oq9KbiRNDBB5jFmrwnrgLX0urIqR/1ptY18TzkqXm7M= github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg= github.com/ProtonMail/go-crypto v1.1.0-alpha.2/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= @@ -83,10 +81,10 @@ github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBS github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa h1:jQCWAUqqlij9Pgj2i/PB79y4KOPYVyFYdROxgaCwdTQ= github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa/go.mod h1:x/1Gn8zydmfq8dk6e9PdstVsDgu9RuyIIJqAaF//0IM= -github.com/containerd/containerd v1.7.12 h1:+KQsnv4VnzyxWcfO9mlxxELaoztsDEjOuCMPAuPqgU0= -github.com/containerd/containerd v1.7.12/go.mod h1:/5OMpE1p0ylxtEUGY8kuCYkDRzJm9NO1TFMWjUpdevk= -github.com/containerd/containerd v1.7.15 h1:afEHXdil9iAm03BmhjzKyXnnEBtjaLJefdU7DV0IFes= -github.com/containerd/containerd v1.7.15/go.mod h1:ISzRRTMF8EXNpJlTzyr2XMhN+j9K302C21/+cr3kUnY= +github.com/containerd/containerd v1.7.18 h1:jqjZTQNfXGoEaZdW1WwPU0RqSn1Bm2Ay/KJPUuO8nao= +github.com/containerd/containerd v1.7.18/go.mod h1:IYEk9/IO6wAPUz2bCMVUbsfXjzw5UNP5fLz4PsUygQ4= +github.com/containerd/errdefs v0.1.0 h1:m0wCRBiu1WJT/Fr+iOoQHMQS/eP5myQ8lCv4Dz5ZURM= +github.com/containerd/errdefs v0.1.0/go.mod h1:YgWiiHtLmSeBrvpw+UfPijzbLaB77mEG1WwJTDETIV0= github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= github.com/cpuguy83/dockercfg v0.3.1 h1:/FpZ+JaygUR/lZP2NlFI2DVfrOEMAIKP5wWEJdoYe9E= @@ -101,10 +99,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dghubble/sling v1.4.1 h1:AxjTubpVyozMvbBCtXcsWEyGGgUZutC5YGrfxPNVOcQ= github.com/dghubble/sling v1.4.1/go.mod h1:QoMB1KL3GAo+7HsD8Itd6S+6tW91who8BGZzuLvpOyc= -github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0= -github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= -github.com/docker/docker v25.0.5+incompatible h1:UmQydMduGkrD5nQde1mecF/YnSbTOaPeFIeP5C4W+DE= -github.com/docker/docker v25.0.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= +github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= +github.com/docker/docker v27.0.3+incompatible h1:aBGI9TeQ4MPlhquTQKq9XbK79rKFVwXNUAYz9aXyEBE= +github.com/docker/docker v27.0.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c= github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= @@ -294,8 +292,8 @@ github.com/kinbiko/jsonassert v1.1.1/go.mod h1:NO4lzrogohtIdNUNzx8sdzB55M4R4Q1bs github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.11.2/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= -github.com/klauspost/compress v1.16.0 h1:iULayQNOReoYUe+1qtKOqw9CwJv3aNQu8ivo7lw1HU4= -github.com/klauspost/compress v1.16.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4= +github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= @@ -348,6 +346,8 @@ github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= +github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo= github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk= github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc= @@ -421,10 +421,8 @@ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/testcontainers/testcontainers-go v0.30.0 h1:jmn/XS22q4YRrcMwWg0pAwlClzs/abopbsBzrepyc4E= -github.com/testcontainers/testcontainers-go v0.30.0/go.mod h1:K+kHNGiM5zjklKjgTtcrEetF3uhWbMUyqAQoyoh8Pf0= -github.com/testcontainers/testcontainers-go v0.31.0 h1:W0VwIhcEVhRflwL9as3dhY6jXjVCA27AkmbnZ+UTh3U= -github.com/testcontainers/testcontainers-go v0.31.0/go.mod h1:D2lAoA0zUFiSY+eAflqK5mcUx/A5hrrORaEQrd0SefI= +github.com/testcontainers/testcontainers-go v0.32.0 h1:ug1aK08L3gCHdhknlTTwWjPHPS+/alvLJU/DRxTD/ME= +github.com/testcontainers/testcontainers-go v0.32.0/go.mod h1:CRHrzHLQhlXUsa5gXjTOfqIEJcrK5+xMDmBr/WMI88E= github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= @@ -684,8 +682,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gotest.tools/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY= -gotest.tools/v3 v3.5.0/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= +gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= +gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/integration_test.go b/integration_test.go index 904bf91b9..0a023ab9e 100644 --- a/integration_test.go +++ b/integration_test.go @@ -3850,9 +3850,12 @@ func TestTentacleCertificateResource(t *testing.T) { } func TestKubernetesAgentWorkerResource(t *testing.T) { - customEnv := make(map[string]string) - customEnv["Octopus"] - testFramework := test.OctopusContainerTest{} + testFramework := test.OctopusContainerTest{ + CustomEnvironment: Env: map[string]string{ + "OCTOPUS__FeatureToggles__KubernetesAgentAsWorkerFeatureToggle": "true", + }, +} + testFramework.CustomEnvironment = customEnv testFramework.ArrangeTest(t, func(t *testing.T, container *test.OctopusContainer, spaceClient *client.Client) error { // Act newSpaceId, err := testFramework.Act(t, container, "./terraform", "58-kubernetesagentworker", []string{}) From ae82ee0fc04512dfd7379218284c05d1271f1a7c Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Fri, 19 Jul 2024 13:17:18 +1000 Subject: [PATCH 14/34] new framework for test --- integration_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/integration_test.go b/integration_test.go index 0a023ab9e..e5ebf2784 100644 --- a/integration_test.go +++ b/integration_test.go @@ -3851,11 +3851,10 @@ func TestTentacleCertificateResource(t *testing.T) { func TestKubernetesAgentWorkerResource(t *testing.T) { testFramework := test.OctopusContainerTest{ - CustomEnvironment: Env: map[string]string{ - "OCTOPUS__FeatureToggles__KubernetesAgentAsWorkerFeatureToggle": "true", - }, -} - testFramework.CustomEnvironment = customEnv + CustomEnvironment: map[string]string{ + "OCTOPUS__FeatureToggles__KubernetesAgentAsWorkerFeatureToggle": "true", + }, + } testFramework.ArrangeTest(t, func(t *testing.T, container *test.OctopusContainer, spaceClient *client.Client) error { // Act newSpaceId, err := testFramework.Act(t, container, "./terraform", "58-kubernetesagentworker", []string{}) From 3955a958463badb48a7cf2cb43a061f70710ff20 Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Fri, 19 Jul 2024 14:25:25 +1000 Subject: [PATCH 15/34] add some help output --- integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_test.go b/integration_test.go index e5ebf2784..f5f8706b4 100644 --- a/integration_test.go +++ b/integration_test.go @@ -3877,7 +3877,7 @@ func TestKubernetesAgentWorkerResource(t *testing.T) { } if len(resources.Items) != 2 { - t.Fatalf("Space must have two workers (both KubernetesTentacles)") + t.Fatalf("Space must have two workers (both KubernetesTentacles), instead found %v", resources.Items) } optionalAgentName := "optional-agent" From 9215277837dcabca896bb84543e5a72b1aa3a9d2 Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Fri, 19 Jul 2024 15:13:44 +1000 Subject: [PATCH 16/34] change comms style --- integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_test.go b/integration_test.go index f5f8706b4..32e430d9e 100644 --- a/integration_test.go +++ b/integration_test.go @@ -3866,7 +3866,7 @@ func TestKubernetesAgentWorkerResource(t *testing.T) { // Assert client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) query := machines.WorkersQuery{ - CommunicationStyles: []string{"Polling"}, + CommunicationStyles: []string{"KubernetesTentacle"}, Skip: 0, Take: 3, } From 3153a42134ae4af855a3b648db79843c4cb2634f Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Mon, 22 Jul 2024 09:33:50 +1000 Subject: [PATCH 17/34] fix enabled/disabled --- integration_test.go | 9 +++++---- .../58-kubernetesagentworker/kubernetes_agent_workers.tf | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/integration_test.go b/integration_test.go index 32e430d9e..25e08fd58 100644 --- a/integration_test.go +++ b/integration_test.go @@ -3855,6 +3855,7 @@ func TestKubernetesAgentWorkerResource(t *testing.T) { "OCTOPUS__FeatureToggles__KubernetesAgentAsWorkerFeatureToggle": "true", }, } + testFramework.ArrangeTest(t, func(t *testing.T, container *test.OctopusContainer, spaceClient *client.Client) error { // Act newSpaceId, err := testFramework.Act(t, container, "./terraform", "58-kubernetesagentworker", []string{}) @@ -3884,8 +3885,8 @@ func TestKubernetesAgentWorkerResource(t *testing.T) { optionalAgentIndex := stdslices.IndexFunc(resources.Items, func(t *machines.Worker) bool { return t.Name == optionalAgentName }) optionalAgentWorker := resources.Items[optionalAgentIndex] optionalAgentEndpoint := optionalAgentWorker.Endpoint.(*machines.KubernetesTentacleEndpoint) - if optionalAgentWorker.IsDisabled { - t.Fatalf("Expected \"%s\" to not be disabled", optionalAgentName) + if !optionalAgentWorker.IsDisabled { + t.Fatalf("Expected \"%s\" to be disabled", optionalAgentName) } if !optionalAgentEndpoint.UpgradeLocked { @@ -3896,8 +3897,8 @@ func TestKubernetesAgentWorkerResource(t *testing.T) { fullAgentIndex := stdslices.IndexFunc(resources.Items, func(t *machines.Worker) bool { return t.Name == fullAgentName }) fullAgentWorker := resources.Items[fullAgentIndex] - if !fullAgentWorker.IsDisabled { - t.Fatalf("Expected \"%s\" to be disabled", fullAgentName) + if fullAgentWorker.IsDisabled { + t.Fatalf("Expected \"%s\" to be enabled", fullAgentName) } fullAgentEndpoint := fullAgentWorker.Endpoint.(*machines.KubernetesTentacleEndpoint) diff --git a/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf b/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf index 5c4488a3e..4eb9e2199 100644 --- a/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf +++ b/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf @@ -12,6 +12,6 @@ resource "octopusdeploy_kubernetes_agent_worker" "agent_with_optional" { communication_mode = "Polling" uri = "poll://kcxzcv2fpsxkn6tk9u6d/" thumbprint = "96203ED84246201C26A2F4360D7CBC36AC1D232D" - is_disabled = true + is_disabled = false upgrade_locked = false } \ No newline at end of file From ea9b891e969a7163cc3916e2693d2fb39c62c5f2 Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Mon, 22 Jul 2024 10:05:30 +1000 Subject: [PATCH 18/34] fix naming --- integration_test.go | 4 ++-- .../58-kubernetesagentworker/kubernetes_agent_workers.tf | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/integration_test.go b/integration_test.go index 25e08fd58..3e3af8676 100644 --- a/integration_test.go +++ b/integration_test.go @@ -3881,7 +3881,7 @@ func TestKubernetesAgentWorkerResource(t *testing.T) { t.Fatalf("Space must have two workers (both KubernetesTentacles), instead found %v", resources.Items) } - optionalAgentName := "optional-agent" + optionalAgentName := "minimum-agent" optionalAgentIndex := stdslices.IndexFunc(resources.Items, func(t *machines.Worker) bool { return t.Name == optionalAgentName }) optionalAgentWorker := resources.Items[optionalAgentIndex] optionalAgentEndpoint := optionalAgentWorker.Endpoint.(*machines.KubernetesTentacleEndpoint) @@ -3893,7 +3893,7 @@ func TestKubernetesAgentWorkerResource(t *testing.T) { t.Fatalf("Expected \"%s\" to have upgrade locked", optionalAgentName) } - fullAgentName := "agent_with_optional" + fullAgentName := "agent-with-optionals" fullAgentIndex := stdslices.IndexFunc(resources.Items, func(t *machines.Worker) bool { return t.Name == fullAgentName }) fullAgentWorker := resources.Items[fullAgentIndex] diff --git a/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf b/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf index 4eb9e2199..12e46e931 100644 --- a/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf +++ b/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf @@ -6,7 +6,7 @@ resource "octopusdeploy_kubernetes_agent_worker" "agent_with_minimum" { } resource "octopusdeploy_kubernetes_agent_worker" "agent_with_optional" { - name = "optional-agent" + name = "agent-with-optionals" machine_policy_id = octopusdeploy_machine_policy.machinepolicy_testing.id worker_pool_ids = [octopusdeploy_static_worker_pool.workerpool_docker.id] communication_mode = "Polling" From 142eeeb1a770ab068fc2886d0136d5c1aaee619a Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Mon, 22 Jul 2024 12:03:13 +1000 Subject: [PATCH 19/34] flip it all around again --- integration_test.go | 8 ++++---- octopusdeploy/schema_kubernetes_agent_worker.go | 2 +- .../58-kubernetesagentworker/kubernetes_agent_workers.tf | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/integration_test.go b/integration_test.go index 3e3af8676..89fac8084 100644 --- a/integration_test.go +++ b/integration_test.go @@ -3885,8 +3885,8 @@ func TestKubernetesAgentWorkerResource(t *testing.T) { optionalAgentIndex := stdslices.IndexFunc(resources.Items, func(t *machines.Worker) bool { return t.Name == optionalAgentName }) optionalAgentWorker := resources.Items[optionalAgentIndex] optionalAgentEndpoint := optionalAgentWorker.Endpoint.(*machines.KubernetesTentacleEndpoint) - if !optionalAgentWorker.IsDisabled { - t.Fatalf("Expected \"%s\" to be disabled", optionalAgentName) + if optionalAgentWorker.IsDisabled { + t.Fatalf("Expected \"%s\" to be enabled", optionalAgentName) } if !optionalAgentEndpoint.UpgradeLocked { @@ -3897,8 +3897,8 @@ func TestKubernetesAgentWorkerResource(t *testing.T) { fullAgentIndex := stdslices.IndexFunc(resources.Items, func(t *machines.Worker) bool { return t.Name == fullAgentName }) fullAgentWorker := resources.Items[fullAgentIndex] - if fullAgentWorker.IsDisabled { - t.Fatalf("Expected \"%s\" to be enabled", fullAgentName) + if !fullAgentWorker.IsDisabled { + t.Fatalf("Expected \"%s\" to be disabled", fullAgentName) } fullAgentEndpoint := fullAgentWorker.Endpoint.(*machines.KubernetesTentacleEndpoint) diff --git a/octopusdeploy/schema_kubernetes_agent_worker.go b/octopusdeploy/schema_kubernetes_agent_worker.go index 80c0c7840..fedec1f9c 100644 --- a/octopusdeploy/schema_kubernetes_agent_worker.go +++ b/octopusdeploy/schema_kubernetes_agent_worker.go @@ -10,7 +10,7 @@ import ( func expandKubernetesAgentWorker(kubernetesAgent *schema.ResourceData) *machines.Worker { uri, _ := url.Parse(kubernetesAgent.Get("uri").(string)) thumbprint := kubernetesAgent.Get("thumbprint").(string) - + communicationsMode := kubernetesAgent.Get("communication_mode").(string) upgradeLocked := kubernetesAgent.Get("upgrade_locked").(bool) var endpoint machines.IEndpoint = machines.NewKubernetesTentacleEndpoint(uri, thumbprint, upgradeLocked, communicationsMode, "") diff --git a/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf b/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf index 12e46e931..18a00d0f0 100644 --- a/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf +++ b/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf @@ -12,6 +12,6 @@ resource "octopusdeploy_kubernetes_agent_worker" "agent_with_optional" { communication_mode = "Polling" uri = "poll://kcxzcv2fpsxkn6tk9u6d/" thumbprint = "96203ED84246201C26A2F4360D7CBC36AC1D232D" - is_disabled = false + is_disabled = true upgrade_locked = false } \ No newline at end of file From 1631a561093326a23c58d458ea2abfcd180c96b8 Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Mon, 22 Jul 2024 14:14:28 +1000 Subject: [PATCH 20/34] ensure upgrade locked is false by default --- integration_test.go | 8 ++++---- .../58-kubernetesagentworker/kubernetes_agent_workers.tf | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/integration_test.go b/integration_test.go index 89fac8084..4ffcf823f 100644 --- a/integration_test.go +++ b/integration_test.go @@ -3889,8 +3889,8 @@ func TestKubernetesAgentWorkerResource(t *testing.T) { t.Fatalf("Expected \"%s\" to be enabled", optionalAgentName) } - if !optionalAgentEndpoint.UpgradeLocked { - t.Fatalf("Expected \"%s\" to have upgrade locked", optionalAgentName) + if optionalAgentEndpoint.UpgradeLocked { + t.Fatalf("Expected \"%s\" to not be upgrade locked", optionalAgentName) } fullAgentName := "agent-with-optionals" @@ -3902,8 +3902,8 @@ func TestKubernetesAgentWorkerResource(t *testing.T) { } fullAgentEndpoint := fullAgentWorker.Endpoint.(*machines.KubernetesTentacleEndpoint) - if fullAgentEndpoint.UpgradeLocked { - t.Fatalf("Expected \"%s\" to not have upgrade locked", fullAgentName) + if !fullAgentEndpoint.UpgradeLocked { + t.Fatalf("Expected \"%s\" to be upgrade locked", fullAgentName) } return nil diff --git a/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf b/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf index 18a00d0f0..2afaa3c8d 100644 --- a/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf +++ b/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf @@ -13,5 +13,5 @@ resource "octopusdeploy_kubernetes_agent_worker" "agent_with_optional" { uri = "poll://kcxzcv2fpsxkn6tk9u6d/" thumbprint = "96203ED84246201C26A2F4360D7CBC36AC1D232D" is_disabled = true - upgrade_locked = false + upgrade_locked = true } \ No newline at end of file From fcd96a8c02e3a8474c02a725428548b553b9ff3b Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Mon, 22 Jul 2024 14:19:35 +1000 Subject: [PATCH 21/34] revert workflow file --- .github/workflows/integration-tests.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml index 287947e71..be1e27f9a 100644 --- a/.github/workflows/integration-tests.yaml +++ b/.github/workflows/integration-tests.yaml @@ -97,7 +97,6 @@ jobs: GOMAXPROCS: 1 OCTOTESTVERSION: latest OCTOTESTIMAGEURL: docker.packages.octopushq.com/octopusdeploy/octopusdeploy - OCTOPUS__FeatureToggles__KubernetesAgentAsWorkerFeatureToggle: true - name: Upload test artifacts uses: actions/upload-artifact@v3 with: From 7ef0bb63ced1433b345c7c87df0ea29a84e3b2e9 Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Fri, 16 Aug 2024 10:50:18 +1000 Subject: [PATCH 22/34] not sure what was done in this commit - maybe drop? --- integration_test.go | 61 ---------------- integration_test_readme.md | 2 +- ...ubernetes_agent_worker_integration_test.go | 72 +++++++++++++++++++ .../schema_kubernetes_agent_worker.go | 9 +-- .../workers_data_source.tf | 6 ++ 5 files changed, 84 insertions(+), 66 deletions(-) create mode 100644 octopusdeploy/resource_kubernetes_agent_worker_integration_test.go create mode 100644 terraform/58-kubernetesagentworker/workers_data_source.tf diff --git a/integration_test.go b/integration_test.go index 4ffcf823f..d3e051029 100644 --- a/integration_test.go +++ b/integration_test.go @@ -3848,64 +3848,3 @@ func TestTentacleCertificateResource(t *testing.T) { return nil }) } - -func TestKubernetesAgentWorkerResource(t *testing.T) { - testFramework := test.OctopusContainerTest{ - CustomEnvironment: map[string]string{ - "OCTOPUS__FeatureToggles__KubernetesAgentAsWorkerFeatureToggle": "true", - }, - } - - testFramework.ArrangeTest(t, func(t *testing.T, container *test.OctopusContainer, spaceClient *client.Client) error { - // Act - newSpaceId, err := testFramework.Act(t, container, "./terraform", "58-kubernetesagentworker", []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := machines.WorkersQuery{ - CommunicationStyles: []string{"KubernetesTentacle"}, - Skip: 0, - Take: 3, - } - - resources, err := client.Workers.Get(query) - if err != nil { - return err - } - - if len(resources.Items) != 2 { - t.Fatalf("Space must have two workers (both KubernetesTentacles), instead found %v", resources.Items) - } - - optionalAgentName := "minimum-agent" - optionalAgentIndex := stdslices.IndexFunc(resources.Items, func(t *machines.Worker) bool { return t.Name == optionalAgentName }) - optionalAgentWorker := resources.Items[optionalAgentIndex] - optionalAgentEndpoint := optionalAgentWorker.Endpoint.(*machines.KubernetesTentacleEndpoint) - if optionalAgentWorker.IsDisabled { - t.Fatalf("Expected \"%s\" to be enabled", optionalAgentName) - } - - if optionalAgentEndpoint.UpgradeLocked { - t.Fatalf("Expected \"%s\" to not be upgrade locked", optionalAgentName) - } - - fullAgentName := "agent-with-optionals" - fullAgentIndex := stdslices.IndexFunc(resources.Items, func(t *machines.Worker) bool { return t.Name == fullAgentName }) - fullAgentWorker := resources.Items[fullAgentIndex] - - if !fullAgentWorker.IsDisabled { - t.Fatalf("Expected \"%s\" to be disabled", fullAgentName) - } - - fullAgentEndpoint := fullAgentWorker.Endpoint.(*machines.KubernetesTentacleEndpoint) - if !fullAgentEndpoint.UpgradeLocked { - t.Fatalf("Expected \"%s\" to be upgrade locked", fullAgentName) - } - - return nil - }) -} diff --git a/integration_test_readme.md b/integration_test_readme.md index 21b5e66f5..cdf9759aa 100644 --- a/integration_test_readme.md +++ b/integration_test_readme.md @@ -8,7 +8,7 @@ of the git repo: dev_overrides { "octopusdeploylabs/octopusdeploy" = "/var/home/yourname/Code/terraform-provider-octopusdeploy" } - +Ø direct {} } diff --git a/octopusdeploy/resource_kubernetes_agent_worker_integration_test.go b/octopusdeploy/resource_kubernetes_agent_worker_integration_test.go new file mode 100644 index 000000000..87f883e59 --- /dev/null +++ b/octopusdeploy/resource_kubernetes_agent_worker_integration_test.go @@ -0,0 +1,72 @@ +package octopusdeploy + +import ( + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines" + "github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework/test" + "path/filepath" + stdslices "slices" + "testing" +) + +func TestKubernetesAgentWorkerResource(t *testing.T) { + testFramework := test.OctopusContainerTest{ + CustomEnvironment: map[string]string{ + "OCTOPUS__FeatureToggles__KubernetesAgentAsWorkerFeatureToggle": "true", + }, + } + _, err := testFramework.Act(t, octoContainer, "../terraform", "58-kubernetesagentworker", []string{}) + if err != nil { + t.Fatal(err.Error()) + } + + // Assert + query := machines.WorkersQuery{ + CommunicationStyles: []string{"KubernetesTentacle"}, + Skip: 0, + Take: 3, + } + + resources, err := octoClient.Workers.Get(query) + if err != nil { + t.Fatal(err.Error()) + } + + if len(resources.Items) != 2 { + t.Fatalf("Space must have two workers (both KubernetesTentacles), instead found %v", resources.Items) + } + + optionalAgentName := "minimum-agent" + optionalAgentIndex := stdslices.IndexFunc(resources.Items, func(t *machines.Worker) bool { return t.Name == optionalAgentName }) + optionalAgentWorker := resources.Items[optionalAgentIndex] + optionalAgentEndpoint := optionalAgentWorker.Endpoint.(*machines.KubernetesTentacleEndpoint) + if optionalAgentWorker.IsDisabled { + t.Fatalf("Expected \"%s\" to be enabled", optionalAgentName) + } + + if optionalAgentEndpoint.UpgradeLocked { + t.Fatalf("Expected \"%s\" to not be upgrade locked", optionalAgentName) + } + + fullAgentName := "agent-with-optionals" + fullAgentIndex := stdslices.IndexFunc(resources.Items, func(t *machines.Worker) bool { return t.Name == fullAgentName }) + fullAgentWorker := resources.Items[fullAgentIndex] + + if !fullAgentWorker.IsDisabled { + t.Fatalf("Expected \"%s\" to be disabled", fullAgentName) + } + + fullAgentEndpoint := fullAgentWorker.Endpoint.(*machines.KubernetesTentacleEndpoint) + if !fullAgentEndpoint.UpgradeLocked { + t.Fatalf("Expected \"%s\" to be upgrade locked", fullAgentName) + } + + lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "58-kubernetesagentworker"), "data_lookup") + + if err != nil { + t.Fatal("Failed to query for created k8s workers") + } + + if len(lookup) > 5 { + t.Fatal("Failed to query for created k8s workers") + } +} diff --git a/octopusdeploy/schema_kubernetes_agent_worker.go b/octopusdeploy/schema_kubernetes_agent_worker.go index fedec1f9c..a00df428a 100644 --- a/octopusdeploy/schema_kubernetes_agent_worker.go +++ b/octopusdeploy/schema_kubernetes_agent_worker.go @@ -101,10 +101,11 @@ func getKubernetesAgentWorkerSchema() map[string]*schema.Schema { Type: schema.TypeBool, }, "worker_pool_ids": { - Elem: &schema.Schema{Type: schema.TypeString}, - MinItems: 1, - Required: true, - Type: schema.TypeList, + Description: "A list of worker pool Ids specifying the pools in which this worker belongs", + Elem: &schema.Schema{Type: schema.TypeString}, + MinItems: 1, + Required: true, + Type: schema.TypeList, }, // Read-only Values diff --git a/terraform/58-kubernetesagentworker/workers_data_source.tf b/terraform/58-kubernetesagentworker/workers_data_source.tf new file mode 100644 index 000000000..56fc2f773 --- /dev/null +++ b/terraform/58-kubernetesagentworker/workers_data_source.tf @@ -0,0 +1,6 @@ +data "octopusdeploy_kubernetes_agent_workers" "all_workers" { +} + +output "data_lookup" { + value = data.octopusdeploy_kubernetes_agent_workers.all_workers +} \ No newline at end of file From 1d7e1cd74b65b5e174c32be894d3affe6ac618f9 Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Fri, 16 Aug 2024 11:02:12 +1000 Subject: [PATCH 23/34] hack container creation into int test --- ...rce_kubernetes_agent_worker_integration_test.go | 14 ++++++++++++++ octopusdeploy/testing_container_test.go | 1 + 2 files changed, 15 insertions(+) diff --git a/octopusdeploy/resource_kubernetes_agent_worker_integration_test.go b/octopusdeploy/resource_kubernetes_agent_worker_integration_test.go index 87f883e59..13816f1e0 100644 --- a/octopusdeploy/resource_kubernetes_agent_worker_integration_test.go +++ b/octopusdeploy/resource_kubernetes_agent_worker_integration_test.go @@ -3,6 +3,8 @@ package octopusdeploy import ( "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines" "github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework/test" + "log" + "os" "path/filepath" stdslices "slices" "testing" @@ -14,6 +16,18 @@ func TestKubernetesAgentWorkerResource(t *testing.T) { "OCTOPUS__FeatureToggles__KubernetesAgentAsWorkerFeatureToggle": "true", }, } + + // If local - use local, otherwise create a new container + if os.Getenv("TF_ACC_LOCAL") == "" { + octoContainer, octoClient, sqlServerContainer, network, err = testFramework.ArrangeContainer() + if err != nil { + log.Printf("Failed to arrange containers: (%s)", err.Error()) + } + os.Setenv("OCTOPUS_URL", octoContainer.URI) + os.Setenv("OCTOPUS_APIKEY", test.ApiKey) + os.Setenv("TF_ACC", "1") + } + _, err := testFramework.Act(t, octoContainer, "../terraform", "58-kubernetesagentworker", []string{}) if err != nil { t.Fatal(err.Error()) diff --git a/octopusdeploy/testing_container_test.go b/octopusdeploy/testing_container_test.go index 1f37ad0a3..324b52ab9 100644 --- a/octopusdeploy/testing_container_test.go +++ b/octopusdeploy/testing_container_test.go @@ -63,6 +63,7 @@ func TestMain(m *testing.M) { URI: url, } } + code := m.Run() os.Exit(code) } From 8c7d0c0dbfdf8f0a520a6a6107b716986e95e539 Mon Sep 17 00:00:00 2001 From: Kevin Tchang Date: Tue, 20 Aug 2024 11:44:30 +1000 Subject: [PATCH 24/34] update test to conform with the new way of integration testing --- integration_test.go | 3850 ----------------- ...ubernetes_agent_worker_integration_test.go | 65 +- .../kubernetes_agent_workers.tf | 2 +- .../58-kubernetesagentworker/provider.tf | 4 +- .../58-kubernetesagentworker/provider_vars.tf | 14 +- .../58-kubernetesagentworker/workerpool.tf | 7 + .../workers_data_source.tf | 6 - .../58a-kubernetesagentworkerds/config.tf | 5 + .../kubernetes_agent_workers.tf | 10 + .../58a-kubernetesagentworkerds/provider.tf | 5 + .../provider_vars.tf | 30 + .../58a-kubernetesagentworkerds/space.tf | 3 + 12 files changed, 119 insertions(+), 3882 deletions(-) delete mode 100644 integration_test.go delete mode 100644 terraform/58-kubernetesagentworker/workers_data_source.tf create mode 100644 terraform/58a-kubernetesagentworkerds/config.tf create mode 100644 terraform/58a-kubernetesagentworkerds/kubernetes_agent_workers.tf create mode 100644 terraform/58a-kubernetesagentworkerds/provider.tf create mode 100644 terraform/58a-kubernetesagentworkerds/provider_vars.tf create mode 100644 terraform/58a-kubernetesagentworkerds/space.tf diff --git a/integration_test.go b/integration_test.go deleted file mode 100644 index d3e051029..000000000 --- a/integration_test.go +++ /dev/null @@ -1,3850 +0,0 @@ -package main - -import ( - "fmt" - "net/url" - "os" - "path/filepath" - "sort" - "strings" - "testing" - - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/deployments" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/triggers" - - stdslices "slices" - - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/accounts" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/certificates" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/channels" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/environments" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/feeds" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/filters" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/lifecycles" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/projectgroups" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/projects" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/spaces" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/tagsets" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/teams" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/tenants" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/users" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/variables" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/workerpools" - "github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework/octoclient" - "github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework/test" - "k8s.io/utils/strings/slices" -) - -// TestSpaceResource verifies that a space can be reimported with the correct settings -func TestSpaceResource(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", "1-singlespace", []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, "", test.ApiKey) - query := spaces.SpacesQuery{ - IDs: []string{newSpaceId}, - Skip: 0, - Take: 1, - } - spaces, err := client.Spaces.Get(query) - space := spaces.Items[0] - - if err != nil { - return err - } - - if space.Description != "TestSpaceResource" { - t.Fatalf("New space must have the name \"TestSpaceResource\"") - } - - if space.IsDefault { - t.Fatalf("New space must not be the default one") - } - - if space.TaskQueueStopped { - t.Fatalf("New space must not have the task queue stopped") - } - - if slices.Index(space.SpaceManagersTeams, "teams-administrators") == -1 { - t.Fatalf("New space must have teams-administrators as a manager team") - } - - return nil - }) -} - -// TestProjectGroupResource verifies that a project group can be reimported with the correct settings -func TestProjectGroupResource(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", "2-projectgroup", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "2a-projectgroupds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := projectgroups.ProjectGroupsQuery{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := client.ProjectGroups.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a project group called \"Test\"") - } - resource := resources.Items[0] - - if resource.Description != "Test Description" { - t.Fatalf("The project group must be have a description of \"Test Description\"") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "2a-projectgroupds"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestAwsAccountExport verifies that an AWS account can be reimported with the correct settings -func TestAwsAccountExport(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", "3-awsaccount", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "3a-awsaccountds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := accounts.AccountsQuery{ - PartialName: "AWS Account", - Skip: 0, - Take: 1, - } - - resources, err := client.Accounts.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have an account called \"AWS Account\"") - } - resource := resources.Items[0].(*accounts.AmazonWebServicesAccount) - - if resource.AccessKey != "ABCDEFGHIJKLMNOPQRST" { - t.Fatalf("The account must have an access key of \"ABCDEFGHIJKLMNOPQRST\"") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "3a-awsaccountds"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestAzureAccountResource verifies that an Azure account can be reimported with the correct settings -func TestAzureAccountResource(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", "4-azureaccount", []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := accounts.AccountsQuery{ - PartialName: "Azure", - Skip: 0, - Take: 1, - } - - resources, err := client.Accounts.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have an account called \"Azure\"") - } - resource := resources.Items[0].(*accounts.AzureServicePrincipalAccount) - - if fmt.Sprint(resource.SubscriptionID) != "95bf77d2-64b1-4ed2-9de1-b5451e3881f5" { - t.Fatalf("The account must be have a client ID of \"95bf77d2-64b1-4ed2-9de1-b5451e3881f5\"") - } - - if fmt.Sprint(resource.TenantID) != "18eb006b-c3c8-4a72-93cd-fe4b293f82ee" { - t.Fatalf("The account must be have a client ID of \"18eb006b-c3c8-4a72-93cd-fe4b293f82ee\"") - } - - if resource.Description != "Azure Account" { - t.Fatalf("The account must be have a description of \"Azure Account\"") - } - - if resource.TenantedDeploymentMode != "Untenanted" { - t.Fatalf("The account must be have a tenanted deployment participation of \"Untenanted\"") - } - - return nil - }) -} - -// TestUsernamePasswordAccountResource verifies that a username/password account can be reimported with the correct settings -func TestUsernamePasswordAccountResource(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", "5-userpassaccount", []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := accounts.AccountsQuery{ - PartialName: "GKE", - Skip: 0, - Take: 1, - } - - resources, err := client.Accounts.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have an account called \"GKE\"") - } - resource := resources.Items[0].(*accounts.UsernamePasswordAccount) - - if resource.Username != "admin" { - t.Fatalf("The account must be have a username of \"admin\"") - } - - if !resource.Password.HasValue { - t.Fatalf("The account must be have a password") - } - - if resource.Description != "A test account" { - t.Fatalf("The account must be have a description of \"A test account\"") - } - - if resource.TenantedDeploymentMode != "Untenanted" { - t.Fatalf("The account must be have a tenanted deployment participation of \"Untenanted\"") - } - - if len(resource.TenantTags) != 0 { - t.Fatalf("The account must be have no tenant tags") - } - - return nil - }) -} - -// TestGcpAccountResource verifies that a GCP account can be reimported with the correct settings -func TestGcpAccountResource(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", "6-gcpaccount", []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := accounts.AccountsQuery{ - PartialName: "Google", - Skip: 0, - Take: 1, - } - - resources, err := client.Accounts.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have an account called \"Google\"") - } - resource := resources.Items[0].(*accounts.GoogleCloudPlatformAccount) - - if !resource.JsonKey.HasValue { - t.Fatalf("The account must be have a JSON key") - } - - if resource.Description != "A test account" { - t.Fatalf("The account must be have a description of \"A test account\"") - } - - if resource.TenantedDeploymentMode != "Untenanted" { - t.Fatalf("The account must be have a tenanted deployment participation of \"Untenanted\"") - } - - if len(resource.TenantTags) != 0 { - t.Fatalf("The account must be have no tenant tags") - } - - return nil - }) -} - -// TestSshAccountResource verifies that an SSH account can be reimported with the correct settings -func TestSshAccountResource(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", "7-sshaccount", []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := accounts.AccountsQuery{ - PartialName: "SSH", - Skip: 0, - Take: 1, - } - - resources, err := client.Accounts.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have an account called \"SSH\"") - } - resource := resources.Items[0].(*accounts.SSHKeyAccount) - - if resource.AccountType != "SshKeyPair" { - t.Fatal("The account must be have a type of \"SshKeyPair\"") - } - - if resource.Username != "admin" { - t.Fatal("The account must be have a username of \"admin\"") - } - - if resource.Description != "A test account" { - // This appears to be a bug in the provider where the description is not set - t.Log("BUG: The account must be have a description of \"A test account\"") - } - - if resource.TenantedDeploymentMode != "Untenanted" { - t.Fatal("The account must be have a tenanted deployment participation of \"Untenanted\"") - } - - if len(resource.TenantTags) != 0 { - t.Fatal("The account must be have no tenant tags") - } - - if len(resource.EnvironmentIDs) == 0 { - t.Fatal("The account must have environments") - } - - return nil - }) -} - -// TestAzureSubscriptionAccountResource verifies that an azure account can be reimported with the correct settings -func TestAzureSubscriptionAccountResource(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", "8-azuresubscriptionaccount", []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := accounts.AccountsQuery{ - PartialName: "Subscription", - Skip: 0, - Take: 1, - } - - resources, err := client.Accounts.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have an account called \"Subscription\"") - } - resource := resources.Items[0].(*accounts.AzureSubscriptionAccount) - - if resource.AccountType != "AzureSubscription" { - t.Fatal("The account must be have a type of \"AzureSubscription\"") - } - - if resource.Description != "A test account" { - t.Fatal("The account must be have a description of \"A test account\"") - } - - if resource.TenantedDeploymentMode != "Untenanted" { - t.Fatal("The account must be have a tenanted deployment participation of \"Untenanted\"") - } - - if len(resource.TenantTags) != 0 { - t.Fatal("The account must be have no tenant tags") - } - - return nil - }) -} - -// TestTokenAccountResource verifies that a token account can be reimported with the correct settings -func TestTokenAccountResource(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", "9-tokenaccount", []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := accounts.AccountsQuery{ - PartialName: "Token", - Skip: 0, - Take: 1, - } - - resources, err := client.Accounts.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have an account called \"Token\"") - } - resource := resources.Items[0].(*accounts.TokenAccount) - - if resource.AccountType != "Token" { - t.Fatal("The account must be have a type of \"Token\"") - } - - if !resource.Token.HasValue { - t.Fatal("The account must be have a token") - } - - if resource.Description != "A test account" { - t.Fatal("The account must be have a description of \"A test account\"") - } - - if resource.TenantedDeploymentMode != "Untenanted" { - t.Fatal("The account must be have a tenanted deployment participation of \"Untenanted\"") - } - - if len(resource.TenantTags) != 0 { - t.Fatal("The account must be have no tenant tags") - } - - return nil - }) -} - -// TestHelmFeedResource verifies that a helm feed can be reimported with the correct settings -func TestHelmFeedResource(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", "10-helmfeed", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "10a-helmfeedds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := feeds.FeedsQuery{ - PartialName: "Helm", - Skip: 0, - Take: 1, - } - - resources, err := client.Feeds.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have an feed called \"Helm\"") - } - resource := resources.Items[0].(*feeds.HelmFeed) - - if resource.FeedType != "Helm" { - t.Fatal("The feed must have a type of \"Helm\"") - } - - if resource.Username != "username" { - t.Fatal("The feed must have a username of \"username\"") - } - - if resource.FeedURI != "https://charts.helm.sh/stable/" { - t.Fatal("The feed must be have a URI of \"https://charts.helm.sh/stable/\"") - } - - foundExecutionTarget := false - foundNotAcquired := false - for _, o := range resource.PackageAcquisitionLocationOptions { - if o == "ExecutionTarget" { - foundExecutionTarget = true - } - - if o == "NotAcquired" { - foundNotAcquired = true - } - } - - if !(foundExecutionTarget && foundNotAcquired) { - t.Fatal("The feed must be have a PackageAcquisitionLocationOptions including \"ExecutionTarget\" and \"NotAcquired\"") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "10a-helmfeedds"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestDockerFeedResource verifies that a docker feed can be reimported with the correct settings -func TestDockerFeedResource(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", "11-dockerfeed", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "11a-dockerfeedds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := feeds.FeedsQuery{ - PartialName: "Docker", - Skip: 0, - Take: 1, - } - - resources, err := client.Feeds.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have an feed called \"Docker\"") - } - resource := resources.Items[0].(*feeds.DockerContainerRegistry) - - if resource.FeedType != "Docker" { - t.Fatal("The feed must have a type of \"Docker\"") - } - - if resource.Username != "username" { - t.Fatal("The feed must have a username of \"username\"") - } - - if resource.APIVersion != "v1" { - t.Fatal("The feed must be have a API version of \"v1\"") - } - - if resource.FeedURI != "https://index.docker.io" { - t.Fatal("The feed must be have a feed uri of \"https://index.docker.io\"") - } - - foundExecutionTarget := false - foundNotAcquired := false - for _, o := range resource.PackageAcquisitionLocationOptions { - if o == "ExecutionTarget" { - foundExecutionTarget = true - } - - if o == "NotAcquired" { - foundNotAcquired = true - } - } - - if !(foundExecutionTarget && foundNotAcquired) { - t.Fatal("The feed must be have a PackageAcquisitionLocationOptions including \"ExecutionTarget\" and \"NotAcquired\"") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "11a-dockerfeedds"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestEcrFeedResource verifies that a ecr feed can be reimported with the correct settings -func TestEcrFeedResource(t *testing.T) { - if os.Getenv("ECR_ACCESS_KEY") == "" { - t.Fatal("The ECR_ACCESS_KEY environment variable must be set a valid AWS access key") - } - - if os.Getenv("ECR_SECRET_KEY") == "" { - t.Fatal("The ECR_SECRET_KEY environment variable must be set a valid AWS secret key") - } - - 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", "12-ecrfeed", []string{ - "-var=feed_ecr_access_key=" + os.Getenv("ECR_ACCESS_KEY"), - "-var=feed_ecr_secret_key=" + os.Getenv("ECR_SECRET_KEY"), - }) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "12a-ecrfeedds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := feeds.FeedsQuery{ - PartialName: "ECR", - Skip: 0, - Take: 1, - } - - resources, err := client.Feeds.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have an feed called \"ECR\"") - } - resource := resources.Items[0].(*feeds.AwsElasticContainerRegistry) - - if resource.FeedType != "AwsElasticContainerRegistry" { - t.Fatal("The feed must have a type of \"AwsElasticContainerRegistry\" (was \"" + resource.FeedType + "\"") - } - - if resource.AccessKey != os.Getenv("ECR_ACCESS_KEY") { - t.Fatal("The feed must have a access key of \"" + os.Getenv("ECR_ACCESS_KEY") + "\" (was \"" + resource.AccessKey + "\"") - } - - if resource.Region != "us-east-1" { - t.Fatal("The feed must have a region of \"us-east-1\" (was \"" + resource.Region + "\"") - } - - foundExecutionTarget := false - foundNotAcquired := false - for _, o := range resource.PackageAcquisitionLocationOptions { - if o == "ExecutionTarget" { - foundExecutionTarget = true - } - - if o == "NotAcquired" { - foundNotAcquired = true - } - } - - if !(foundExecutionTarget && foundNotAcquired) { - t.Fatal("The feed must be have a PackageAcquisitionLocationOptions including \"ExecutionTarget\" and \"NotAcquired\"") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "12a-ecrfeedds"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestMavenFeedResource verifies that a maven feed can be reimported with the correct settings -func TestMavenFeedResource(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", "13-mavenfeed", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "13a-mavenfeedds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := feeds.FeedsQuery{ - PartialName: "Maven", - Skip: 0, - Take: 1, - } - - resources, err := client.Feeds.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have an feed called \"Maven\"") - } - resource := resources.Items[0].(*feeds.MavenFeed) - - if resource.FeedType != "Maven" { - t.Fatal("The feed must have a type of \"Maven\"") - } - - if resource.Username != "username" { - t.Fatal("The feed must have a username of \"username\"") - } - - if resource.DownloadAttempts != 5 { - t.Fatal("The feed must be have a downloads attempts set to \"5\"") - } - - if resource.DownloadRetryBackoffSeconds != 10 { - t.Fatal("The feed must be have a downloads retry backoff set to \"10\"") - } - - if resource.FeedURI != "https://repo.maven.apache.org/maven2/" { - t.Fatal("The feed must be have a feed uri of \"https://repo.maven.apache.org/maven2/\"") - } - - foundExecutionTarget := false - foundServer := false - for _, o := range resource.PackageAcquisitionLocationOptions { - if o == "ExecutionTarget" { - foundExecutionTarget = true - } - - if o == "Server" { - foundServer = true - } - } - - if !(foundExecutionTarget && foundServer) { - t.Fatal("The feed must be have a PackageAcquisitionLocationOptions including \"ExecutionTarget\" and \"Server\"") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "13a-mavenfeedds"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestNugetFeedResource verifies that a nuget feed can be reimported with the correct settings -func TestNugetFeedResource(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", "14-nugetfeed", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "14a-nugetfeedds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := feeds.FeedsQuery{ - PartialName: "Nuget", - Skip: 0, - Take: 1, - } - - resources, err := client.Feeds.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have an feed called \"Nuget\"") - } - resource := resources.Items[0].(*feeds.NuGetFeed) - - if resource.FeedType != "NuGet" { - t.Fatal("The feed must have a type of \"NuGet\"") - } - - if !resource.EnhancedMode { - t.Fatal("The feed must have enhanced mode set to true") - } - - if resource.Username != "username" { - t.Fatal("The feed must have a username of \"username\"") - } - - if resource.DownloadAttempts != 5 { - t.Fatal("The feed must be have a downloads attempts set to \"5\"") - } - - if resource.DownloadRetryBackoffSeconds != 10 { - t.Fatal("The feed must be have a downloads retry backoff set to \"10\"") - } - - if resource.FeedURI != "https://index.docker.io" { - t.Fatal("The feed must be have a feed uri of \"https://index.docker.io\"") - } - - foundExecutionTarget := false - foundServer := false - for _, o := range resource.PackageAcquisitionLocationOptions { - if o == "ExecutionTarget" { - foundExecutionTarget = true - } - - if o == "Server" { - foundServer = true - } - } - - if !(foundExecutionTarget && foundServer) { - t.Fatal("The feed must be have a PackageAcquisitionLocationOptions including \"ExecutionTarget\" and \"Server\"") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "14a-nugetfeedds"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestWorkerPoolResource verifies that a static worker pool can be reimported with the correct settings -func TestWorkerPoolResource(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", "15-workerpool", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "15a-workerpoolds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := workerpools.WorkerPoolsQuery{ - PartialName: "Docker", - Skip: 0, - Take: 1, - } - - resources, err := client.WorkerPools.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a worker pool called \"Docker\"") - } - resource := resources.Items[0].(*workerpools.StaticWorkerPool) - - if resource.WorkerPoolType != "StaticWorkerPool" { - t.Fatal("The worker pool must be have a type of \"StaticWorkerPool\" (was \"" + resource.WorkerPoolType + "\"") - } - - if resource.Description != "A test worker pool" { - t.Fatal("The worker pool must be have a description of \"A test worker pool\" (was \"" + resource.Description + "\"") - } - - if resource.SortOrder != 3 { - t.Fatal("The worker pool must be have a sort order of \"3\" (was \"" + fmt.Sprint(resource.SortOrder) + "\"") - } - - if resource.IsDefault { - t.Fatal("The worker pool must be must not be the default") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "15a-workerpoolds"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestEnvironmentResource verifies that an environment can be reimported with the correct settings -func TestEnvironmentResource(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", "16-environment", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "16a-environmentlookup"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := environments.EnvironmentsQuery{ - PartialName: "Development", - Skip: 0, - Take: 1, - } - - resources, err := client.Environments.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have an environment called \"Development\"") - } - resource := resources.Items[0] - - if resource.Description != "A test environment" { - t.Fatal("The environment must be have a description of \"A test environment\" (was \"" + resource.Description + "\"") - } - - if !resource.AllowDynamicInfrastructure { - t.Fatal("The environment must have dynamic infrastructure enabled.") - } - - if resource.UseGuidedFailure { - t.Fatal("The environment must not have guided failure enabled.") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "16a-environmentlookup"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The environment lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestLifecycleResource verifies that a lifecycle can be reimported with the correct settings -func TestLifecycleResource(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", "17-lifecycle", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "17a-lifecycleds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := lifecycles.Query{ - PartialName: "Simple", - Skip: 0, - Take: 1, - } - - resources, err := client.Lifecycles.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have an environment called \"Simple\"") - } - resource := resources.Items[0] - - if resource.Description != "A test lifecycle" { - t.Fatal("The lifecycle must be have a description of \"A test lifecycle\" (was \"" + resource.Description + "\")") - } - - if resource.TentacleRetentionPolicy.QuantityToKeep != 30 { - t.Fatal("The lifecycle must be have a tentacle retention policy of \"30\" (was \"" + fmt.Sprint(resource.TentacleRetentionPolicy.QuantityToKeep) + "\")") - } - - if resource.TentacleRetentionPolicy.ShouldKeepForever { - t.Fatal("The lifecycle must be have a tentacle retention not set to keep forever") - } - - if resource.TentacleRetentionPolicy.Unit != "Items" { - t.Fatal("The lifecycle must be have a tentacle retention unit set to \"Items\" (was \"" + resource.TentacleRetentionPolicy.Unit + "\")") - } - - if resource.ReleaseRetentionPolicy.QuantityToKeep != 1 { - t.Fatal("The lifecycle must be have a release retention policy of \"1\" (was \"" + fmt.Sprint(resource.ReleaseRetentionPolicy.QuantityToKeep) + "\")") - } - - if !resource.ReleaseRetentionPolicy.ShouldKeepForever { - t.Log("BUG: The lifecycle must be have a release retention set to keep forever (known bug - the provider creates this field as false)") - } - - if resource.ReleaseRetentionPolicy.Unit != "Days" { - t.Fatal("The lifecycle must be have a release retention unit set to \"Days\" (was \"" + resource.ReleaseRetentionPolicy.Unit + "\")") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "17a-lifecycleds"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestVariableSetResource verifies that a variable set can be reimported with the correct settings -func TestVariableSetResource(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", "18-variableset", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "18a-variablesetds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := variables.LibraryVariablesQuery{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := client.LibraryVariableSets.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a library variable set called \"Test\"") - } - resource := resources.Items[0] - - if resource.Description != "Test variable set" { - t.Fatal("The library variable set must be have a description of \"Test variable set\" (was \"" + resource.Description + "\")") - } - - variableSet, err := client.Variables.GetAll(resource.ID) - - if len(variableSet.Variables) != 1 { - t.Fatal("The library variable set must have one associated variable") - } - - if variableSet.Variables[0].Name != "Test.Variable" { - t.Fatal("The library variable set variable must have a name of \"Test.Variable\"") - } - - if variableSet.Variables[0].Type != "String" { - t.Fatal("The library variable set variable must have a type of \"String\"") - } - - if variableSet.Variables[0].Description != "Test variable" { - t.Fatal("The library variable set variable must have a description of \"Test variable\"") - } - - if variableSet.Variables[0].Value != "test" { - t.Fatal("The library variable set variable must have a value of \"test\"") - } - - if variableSet.Variables[0].IsSensitive { - t.Fatal("The library variable set variable must not be sensitive") - } - - if !variableSet.Variables[0].IsEditable { - t.Fatal("The library variable set variable must be editable") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "18a-variablesetds"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestProjectResource verifies that a project can be reimported with the correct settings -func TestProjectResource(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", "19-project", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "19a-projectds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := projects.ProjectsQuery{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := client.Projects.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a project called \"Test\"") - } - resource := resources.Items[0] - - if resource.Description != "Test project" { - t.Fatal("The project must be have a description of \"Test project\" (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") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "19a-projectds"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -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 - } - - // 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{} - testFramework.ArrangeTest(t, func(t *testing.T, container *test.OctopusContainer, spaceClient *client.Client) error { - // Act - newSpaceId, err := testFramework.Act(t, container, "./terraform", "20-channel", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "20a-channelds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := channels.Query{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := client.Channels.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a channel called \"Test\"") - } - resource := resources.Items[0] - - if resource.Description != "Test channel" { - t.Fatal("The channel must be have a description of \"Test channel\" (was \"" + resource.Description + "\")") - } - - if !resource.IsDefault { - t.Fatal("The channel must be be the default") - } - - if len(resource.Rules) != 1 { - t.Fatal("The channel must have one rule") - } - - if resource.Rules[0].Tag != "^$" { - t.Fatal("The channel rule must be have a tag of \"^$\" (was \"" + resource.Rules[0].Tag + "\")") - } - - if resource.Rules[0].ActionPackages[0].DeploymentAction != "Test" { - t.Fatal("The channel rule action step must be be set to \"Test\" (was \"" + resource.Rules[0].ActionPackages[0].DeploymentAction + "\")") - } - - if resource.Rules[0].ActionPackages[0].PackageReference != "test" { - t.Fatal("The channel rule action package must be be set to \"test\" (was \"" + resource.Rules[0].ActionPackages[0].PackageReference + "\")") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "20a-channelds"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The environment lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestTagSetResource verifies that a tag set can be reimported with the correct settings -func TestTagSetResource(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", "21-tagset", []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := tagsets.TagSetsQuery{ - PartialName: "tag1", - Skip: 0, - Take: 1, - } - - resources, err := client.TagSets.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a tag set called \"tag1\"") - } - resource := resources.Items[0] - - if resource.Description != "Test tagset" { - t.Fatal("The tag set must be have a description of \"Test tagset\" (was \"" + resource.Description + "\")") - } - - if resource.SortOrder != 0 { - t.Fatal("The tag set must be have a sort order of \"0\" (was \"" + fmt.Sprint(resource.SortOrder) + "\")") - } - - tagAFound := false - for _, u := range resource.Tags { - if u.Name == "a" { - tagAFound = true - - if u.Description != "tag a" { - t.Fatal("The tag a must be have a description of \"tag a\" (was \"" + u.Description + "\")") - } - - if u.Color != "#333333" { - t.Fatal("The tag a must be have a color of \"#333333\" (was \"" + u.Color + "\")") - } - - if u.SortOrder != 2 { - t.Fatal("The tag a must be have a sort order of \"2\" (was \"" + fmt.Sprint(u.SortOrder) + "\")") - } - } - } - - if !tagAFound { - t.Fatal("Tag Set must have an tag called \"a\"") - } - - return nil - }) -} - -// TestGitCredentialsResource verifies that a git credential can be reimported with the correct settings -func TestGitCredentialsResource(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", "22-gitcredentialtest", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "22a-gitcredentialtestds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "22a-gitcredentialtestds"), "data_lookup") - - if err != nil { - return err - } - - if lookup == "" { - t.Fatal("The target lookup did not succeed.") - } - - return nil - }) -} - -// TestScriptModuleResource verifies that a script module set can be reimported with the correct settings -func TestScriptModuleResource(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", "23-scriptmodule", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "23a-scriptmoduleds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := variables.LibraryVariablesQuery{ - PartialName: "Test2", - Skip: 0, - Take: 1, - } - - resources, err := client.LibraryVariableSets.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a library variable set called \"Test2\"") - } - resource := resources.Items[0] - - if resource.Description != "Test script module" { - t.Fatal("The library variable set must be have a description of \"Test script module\" (was \"" + resource.Description + "\")") - } - - variables, err := client.Variables.GetAll(resource.ID) - - if len(variables.Variables) != 2 { - t.Fatal("The library variable set must have two associated variables") - } - - foundScript := false - foundLanguage := false - for _, u := range variables.Variables { - if u.Name == "Octopus.Script.Module[Test2]" { - foundScript = true - - if u.Type != "String" { - t.Fatal("The library variable set variable must have a type of \"String\"") - } - - if u.Value != "echo \"hi\"" { - t.Fatal("The library variable set variable must have a value of \"\"echo \\\"hi\\\"\"\"") - } - - if u.IsSensitive { - t.Fatal("The library variable set variable must not be sensitive") - } - - if !u.IsEditable { - t.Fatal("The library variable set variable must be editable") - } - } - - if u.Name == "Octopus.Script.Module.Language[Test2]" { - foundLanguage = true - - if u.Type != "String" { - t.Fatal("The library variable set variable must have a type of \"String\"") - } - - if u.Value != "PowerShell" { - t.Fatal("The library variable set variable must have a value of \"PowerShell\"") - } - - if u.IsSensitive { - t.Fatal("The library variable set variable must not be sensitive") - } - - if !u.IsEditable { - t.Fatal("The library variable set variable must be editable") - } - } - } - - if !foundLanguage || !foundScript { - t.Fatal("Script module must create two variables for script and language") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "23a-scriptmoduleds"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestTenantsResource verifies that a git credential can be reimported with the correct settings -func TestTenantsResource(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", "24-tenants", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "24a-tenantsds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := tenants.TenantsQuery{ - PartialName: "Team A", - Skip: 0, - Take: 1, - } - - resources, err := client.Tenants.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a tenant called \"Team A\"") - } - resource := resources.Items[0] - - if resource.Description != "Test tenant" { - t.Fatal("The tenant must be have a description of \"tTest tenant\" (was \"" + resource.Description + "\")") - } - - if len(resource.TenantTags) != 2 { - t.Fatal("The tenant must have two tags") - } - - if len(resource.ProjectEnvironments) != 1 { - t.Fatal("The tenant must have one project environment") - } - - for _, u := range resource.ProjectEnvironments { - if len(u) != 3 { - t.Fatal("The tenant must have be linked to three environments") - } - } - - // Verify the environment data lookups work - tagsets, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "24a-tenantsds"), "tagsets") - - if err != nil { - return err - } - - if tagsets == "" { - t.Fatal("The tagset lookup failed.") - } - - tenants, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "24a-tenantsds"), "tenants_lookup") - - if err != nil { - return err - } - - if tenants != resource.ID { - t.Fatal("The target lookup did not succeed. Lookup value was \"" + tenants + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestCertificateResource verifies that a certificate can be reimported with the correct settings -func TestCertificateResource(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", "25-certificates", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "25a-certificatesds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := certificates.CertificatesQuery{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := client.Certificates.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a certificate called \"Test\"") - } - resource := resources.Items[0] - - if resource.Notes != "A test certificate" { - t.Fatal("The tenant must be have a description of \"A test certificate\" (was \"" + resource.Notes + "\")") - } - - if resource.TenantedDeploymentMode != "Untenanted" { - t.Fatal("The tenant must be have a tenant participation of \"Untenanted\" (was \"" + resource.TenantedDeploymentMode + "\")") - } - - if resource.SubjectDistinguishedName != "CN=test.com" { - t.Fatal("The tenant must be have a subject distinguished name of \"CN=test.com\" (was \"" + resource.SubjectDistinguishedName + "\")") - } - - if len(resource.EnvironmentIDs) != 0 { - t.Fatal("The tenant must have one project environment") - } - - if len(resource.TenantTags) != 0 { - t.Fatal("The tenant must have no tenant tags") - } - - if len(resource.TenantIDs) != 0 { - t.Fatal("The tenant must have no tenants") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "25a-certificatesds"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The environment lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestTenantVariablesResource verifies that a tenant variables can be reimported with the correct settings -func TestTenantVariablesResource(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", "26-tenant_variables", []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - collection, err := client.TenantVariables.GetAll() - if err != nil { - return err - } - - resourceName := "Test" - found := false - for _, tenantVariable := range collection { - for _, project := range tenantVariable.ProjectVariables { - if project.ProjectName == resourceName { - for _, variables := range project.Variables { - for _, value := range variables { - // we expect one project variable to be defined - found = true - if value.Value != "my value" { - t.Fatal("The tenant project variable must have a value of \"my value\" (was \"" + value.Value + "\")") - } - } - } - } - } - } - - if !found { - t.Fatal("Space must have an tenant project variable for the project called \"" + resourceName + "\"") - } - - return nil - }) -} - -// TestMachinePolicyResource verifies that a machine policies can be reimported with the correct settings -func TestMachinePolicyResource(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", "27-machinepolicy", []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := machines.MachinePoliciesQuery{ - PartialName: "Testing", - Skip: 0, - Take: 1, - } - - resources, err := client.MachinePolicies.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a machine policy called \"Testing\"") - } - resource := resources.Items[0] - - if resource.Description != "test machine policy" { - t.Fatal("The machine policy must have a description of \"test machine policy\" (was \"" + resource.Description + "\")") - } - - if resource.ConnectionConnectTimeout.Minutes() != 1 { - t.Fatal("The machine policy must have a ConnectionConnectTimeout of \"00:01:00\" (was \"" + fmt.Sprint(resource.ConnectionConnectTimeout) + "\")") - } - - if resource.ConnectionRetryCountLimit != 5 { - t.Fatal("The machine policy must have a ConnectionRetryCountLimit of \"5\" (was \"" + fmt.Sprint(resource.ConnectionRetryCountLimit) + "\")") - } - - if resource.ConnectionRetrySleepInterval.Seconds() != 1 { - t.Fatal("The machine policy must have a ConnectionRetrySleepInterval of \"00:00:01\" (was \"" + fmt.Sprint(resource.ConnectionRetrySleepInterval) + "\")") - } - - if resource.ConnectionRetryTimeLimit.Minutes() != 5 { - t.Fatal("The machine policy must have a ConnectionRetryTimeLimit of \"00:05:00\" (was \"" + fmt.Sprint(resource.ConnectionRetryTimeLimit) + "\")") - } - - if resource.MachineCleanupPolicy.DeleteMachinesElapsedTimeSpan.Minutes() != 20 { - t.Fatal("The machine policy must have a DeleteMachinesElapsedTimeSpan of \"00:20:00\" (was \"" + fmt.Sprint(resource.MachineCleanupPolicy.DeleteMachinesElapsedTimeSpan) + "\")") - } - - if resource.MachineCleanupPolicy.DeleteMachinesBehavior != "DeleteUnavailableMachines" { - t.Fatal("The machine policy must have a MachineCleanupPolicy.DeleteMachinesBehavior of \"DeleteUnavailableMachines\" (was \"" + resource.MachineCleanupPolicy.DeleteMachinesBehavior + "\")") - } - - if resource.MachineConnectivityPolicy.MachineConnectivityBehavior != "ExpectedToBeOnline" { - t.Fatal("The machine policy must have a MachineConnectivityPolicy.MachineConnectivityBehavior of \"ExpectedToBeOnline\" (was \"" + resource.MachineConnectivityPolicy.MachineConnectivityBehavior + "\")") - } - - if resource.MachineHealthCheckPolicy.BashHealthCheckPolicy.RunType != "Inline" { - t.Fatal("The machine policy must have a MachineHealthCheckPolicy.BashHealthCheckPolicy.RunType of \"Inline\" (was \"" + resource.MachineHealthCheckPolicy.BashHealthCheckPolicy.RunType + "\")") - } - - if *resource.MachineHealthCheckPolicy.BashHealthCheckPolicy.ScriptBody != "" { - t.Fatal("The machine policy must have a MachineHealthCheckPolicy.BashHealthCheckPolicy.ScriptBody of \"\" (was \"" + *resource.MachineHealthCheckPolicy.BashHealthCheckPolicy.ScriptBody + "\")") - } - - if resource.MachineHealthCheckPolicy.PowerShellHealthCheckPolicy.RunType != "Inline" { - t.Fatal("The machine policy must have a MachineHealthCheckPolicy.PowerShellHealthCheckPolicy.RunType of \"Inline\" (was \"" + resource.MachineHealthCheckPolicy.PowerShellHealthCheckPolicy.RunType + "\")") - } - - if strings.HasPrefix(*resource.MachineHealthCheckPolicy.BashHealthCheckPolicy.ScriptBody, "$freeDiskSpaceThreshold") { - t.Fatal("The machine policy must have a MachineHealthCheckPolicy.PowerShellHealthCheckPolicy.ScriptBody to start with \"$freeDiskSpaceThreshold\" (was \"" + *resource.MachineHealthCheckPolicy.PowerShellHealthCheckPolicy.ScriptBody + "\")") - } - - if resource.MachineHealthCheckPolicy.HealthCheckCronTimezone != "UTC" { - t.Fatal("The machine policy must have a MachineHealthCheckPolicy.HealthCheckCronTimezone of \"UTC\" (was \"" + resource.MachineHealthCheckPolicy.HealthCheckCronTimezone + "\")") - } - - if resource.MachineHealthCheckPolicy.HealthCheckCron != "" { - t.Fatal("The machine policy must have a MachineHealthCheckPolicy.HealthCheckCron of \"\" (was \"" + resource.MachineHealthCheckPolicy.HealthCheckCron + "\")") - } - - if resource.MachineHealthCheckPolicy.HealthCheckType != "RunScript" { - t.Fatal("The machine policy must have a MachineHealthCheckPolicy.HealthCheckType of \"RunScript\" (was \"" + resource.MachineHealthCheckPolicy.HealthCheckType + "\")") - } - - if resource.MachineHealthCheckPolicy.HealthCheckInterval.Minutes() != 10 { - t.Fatal("The machine policy must have a MachineHealthCheckPolicy.HealthCheckInterval of \"00:10:00\" (was \"" + fmt.Sprint(resource.MachineHealthCheckPolicy.HealthCheckInterval) + "\")") - } - - if resource.MachineUpdatePolicy.CalamariUpdateBehavior != "UpdateAlways" { - t.Fatal("The machine policy must have a MachineUpdatePolicy.CalamariUpdateBehavior of \"UpdateAlways\" (was \"" + resource.MachineUpdatePolicy.CalamariUpdateBehavior + "\")") - } - - if resource.MachineUpdatePolicy.TentacleUpdateBehavior != "Update" { - t.Fatal("The machine policy must have a MachineUpdatePolicy.TentacleUpdateBehavior of \"Update\" (was \"" + resource.MachineUpdatePolicy.CalamariUpdateBehavior + "\")") - } - - if resource.MachineUpdatePolicy.KubernetesAgentUpdateBehavior != "NeverUpdate" { - t.Fatal("The machine policy must have a MachineUpdatePolicy.KubernetesAgentUpdateBehavior of \"NeverUpdate\" (was \"" + resource.MachineUpdatePolicy.CalamariUpdateBehavior + "\")") - } - - return nil - }) -} - -// TestProjectTriggerResource verifies that a project trigger can be reimported with the correct settings -func TestProjectTriggerResource(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", "28-projecttrigger", []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := projects.ProjectsQuery{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := client.Projects.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a project called \"Test\"") - } - resource := resources.Items[0] - - trigger, err := client.ProjectTriggers.GetByProjectID(resource.ID) - - if err != nil { - return err - } - - if trigger[0].Name != "test" { - t.Fatal("The project must have a trigger called \"test\" (was \"" + trigger[0].Name + "\")") - } - - if trigger[0].Filter.GetFilterType() != filters.MachineFilter { - t.Fatal("The project trigger must have Filter.FilterType set to \"MachineFilter\" (was \"" + fmt.Sprint(trigger[0].Filter.GetFilterType()) + "\")") - } - - return nil - }) -} - -// TestK8sTargetResource verifies that a k8s machine can be reimported with the correct settings -func TestK8sTargetResource(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", "29-k8starget", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "29a-k8stargetds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := machines.MachinesQuery{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := client.Machines.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a machine called \"Test\"") - } - resource := resources.Items[0] - - if fmt.Sprint(resource.Endpoint.(*machines.KubernetesEndpoint).ClusterURL) != "https://cluster" { - t.Fatal("The machine must have a Endpoint.ClusterUrl of \"https://cluster\" (was \"" + fmt.Sprint(resource.Endpoint.(*machines.KubernetesEndpoint).ClusterURL) + "\")") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "29a-k8stargetds"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestSshTargetResource verifies that a ssh machine can be reimported with the correct settings -func TestSshTargetResource(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", "30-sshtarget", []string{ - "-var=account_ec2_sydney=LS0tLS1CRUdJTiBFTkNSWVBURUQgUFJJVkFURSBLRVktLS0tLQpNSUlKbkRCT0Jna3Foa2lHOXcwQkJRMHdRVEFwQmdrcWhraUc5dzBCQlF3d0hBUUlwNEUxV1ZrejJEd0NBZ2dBCk1Bd0dDQ3FHU0liM0RRSUpCUUF3RkFZSUtvWklodmNOQXdjRUNIemFuVE1QbHA4ZkJJSUpTSncrdW5BL2ZaVFUKRGdrdWk2QnhOY0REUFg3UHZJZmNXU1dTc3V3YWRhYXdkVEdjY1JVd3pGNTNmRWJTUXJBYzJuWFkwUWVVcU1wcAo4QmdXUUthWlB3MEdqck5OQVJaTy9QYklxaU5ERFMybVRSekZidzREcFY5aDdlblZjL1ZPNlhJdzlxYVYzendlCnhEejdZSkJ2ckhmWHNmTmx1blErYTZGdlRUVkVyWkE1Ukp1dEZUVnhUWVR1Z3lvWWNXZzAzQWlsMDh3eDhyTHkKUkgvTjNjRlEzaEtLcVZuSHQvdnNZUUhTMnJJYkt0RTluelFPWDRxRDdVYXM3Z0c0L2ZkcmZQZjZFWTR1aGpBcApUeGZRTDUzcTBQZG85T09MZlRReFRxakVNaFpidjV1aEN5d0N2VHdWTmVLZ2MzN1pqdDNPSjI3NTB3U2t1TFZvCnllR0VaQmtML1VONjJjTUJuYlFsSTEzR2FXejBHZ0NJNGkwS3UvRmE4aHJZQTQwcHVFdkEwZFBYcVFGMDhYbFYKM1RJUEhGRWdBWlJpTmpJWmFyQW00THdnL1F4Z203OUR1SVM3VHh6RCtpN1pNSmsydjI1ck14Ly9MMXNNUFBtOQpWaXBwVnpLZmpqRmpwTDVjcVJucC9UdUZSVWpHaDZWMFBXVVk1eTVzYjJBWHpuSGZVd1lqeFNoUjBKWXpXejAwCjNHbklwNnlJa1UvL3dFVGJLcVliMjd0RjdETm1WMUxXQzl0ell1dm4yK2EwQkpnU0Jlc3c4WFJ1WWorQS92bVcKWk1YbkF2anZXR3RBUzA4d0ZOV3F3QUtMbzJYUHBXWGVMa3BZUHo1ZnY2QnJaNVNwYTg4UFhsa1VmOVF0VHRobwprZFlGOWVMdk5hTXpSSWJhbmRGWjdLcHUvN2I3L0tDWE9rMUhMOUxvdEpwY2tJdTAxWS81TnQwOHp5cEVQQ1RzClVGWG5DODNqK2tWMktndG5XcXlEL2k3Z1dwaHJSK0IrNE9tM3VZU1RuY042a2d6ZkV3WldpUVA3ZkpiNlYwTHoKc29yU09sK2g2WDRsMC9oRVdScktVQTBrOXpPZU9TQXhlbmpVUXFReWdUd0RqQTJWbTdSZXI2ZElDMVBwNmVETgpBVEJ0ME1NZjJJTytxbTJtK0VLd1FVSXY4ZXdpdEpab016MFBaOHB6WEM0ZFMyRTErZzZmbnE2UGJ5WWRISDJnCmVraXk4Y2duVVJmdHJFaVoyMUxpMWdpdTJaeVM5QUc0Z1ZuT0E1Y05oSzZtRDJUaGl5UUl2M09yUDA0aDFTNlEKQUdGeGJONEhZK0tCYnVITTYwRG1PQXR5c3o4QkJheHFwWjlXQkVhV01ubFB6eEI2SnFqTGJrZ1BkQ2wycytUWAphcWx0UDd6QkpaenVTeVNQc2tQR1NBREUvaEF4eDJFM1RQeWNhQlhQRVFUM2VkZmNsM09nYXRmeHBSYXJLV09PCnFHM2lteW42ZzJiNjhWTlBDSnBTYTNKZ1Axb0NNVlBpa2RCSEdSVUV3N2dXTlJVOFpXRVJuS292M2c0MnQ4dkEKU2Z0a3VMdkhoUnlPQW91SUVsNjJIems0WC9CeVVOQ2J3MW50RzFQeHpSaERaV2dPaVhPNi94WFByRlpKa3BtcQpZUUE5dW83OVdKZy9zSWxucFJCdFlUbUh4eU9mNk12R2svdXlkZExkcmZ6MHB6QUVmWm11YTVocWh5M2Y4YlNJCmpxMlJwUHE3eHJ1Y2djbFAwTWFjdHkrbm9wa0N4M0lNRUE4NE9MQ3dxZjVtemtwY0U1M3hGaU1hcXZTK0dHZmkKZlZnUGpXTXRzMFhjdEtCV2tUbVFFN3MxSE5EV0g1dlpJaDY2WTZncXR0cjU2VGdtcHRLWHBVdUJ1MEdERFBQbwp1aGI4TnVRRjZwNHNoM1dDbXlzTU9uSW5jaXRxZWE4NTFEMmloK2lIY3VqcnJidkVYZGtjMnlxUHBtK3Q3SXBvCm1zWkxVemdXRlZpNWY3KzZiZU56dGJ3T2tmYmdlQVAyaklHTzdtR1pKWWM0L1d1eXBqeVRKNlBQVC9IMUc3K3QKUTh5R3FDV3BzNFdQM2srR3hrbW90cnFROFcxa0J1RDJxTEdmSTdMMGZUVE9lWk0vQUZ1VDJVSkcxKzQ2czJVVwp2RlF2VUJmZ0dTWlh3c1VUeGJRTlZNaTJib1BCRkNxbUY2VmJTcmw2YVgrSm1NNVhySUlqUUhGUFZWVGxzeUtpClVDUC9PQTJOWlREdW9IcC9EM0s1Qjh5MlIyUTlqZlJ0RkcwL0dnMktCbCtObzdTbXlPcWlsUlNkZ1VJb0p5QkcKRGovZXJ4ZkZNMlc3WTVsNGZ2ZlNpdU1OZmlUTVdkY3cxSStnVkpGMC9mTHRpYkNoUlg0OTlIRWlXUHZkTGFKMwppcDJEYU9ReS9QZG5zK3hvaWlMNWtHV25BVUVwanNjWno0YU5DZFowOXRUb1FhK2RZd3g1R1ovNUtmbnVpTURnClBrWjNXalFpOVlZRWFXbVIvQ2JmMjAyRXdoNjdIZzVqWE5kb0RNendXT0V4RFNkVFFYZVdzUUI0LzNzcjE2S2MKeitGN2xhOXhHVEVhTDllQitwcjY5L2JjekJLMGVkNXUxYUgxcXR3cjcrMmliNmZDdlMyblRGQTM1ZG50YXZlUwp4VUJVZ0NzRzVhTTl4b2pIQ0o4RzRFMm9iRUEwUDg2SFlqZEJJSXF5U0txZWtQYmFybW4xR1JrdUVlbU5hTVdyCkM2bWZqUXR5V2ZMWnlSbUlhL1dkSVgzYXhqZHhYa3kydm4yNVV6MXZRNklrNnRJcktPYUJnRUY1cmYwY014dTUKN1BYeTk0dnc1QjE0Vlcra2JqQnkyY3hIajJhWnJEaE53UnVQNlpIckg5MHZuN2NmYjYwU0twRWxxdmZwdlN0VQpvQnVXQlFEUUE3bHpZajhhT3BHend3LzlYTjI5MGJrUnd4elVZRTBxOVl4bS9VSHJTNUlyRWtKSml2SUlEb3hICjF4VTVLd2ErbERvWDJNcERrZlBQVE9XSjVqZG8wbXNsN0dBTmc1WGhERnBpb2hFMEdSS2lGVytYcjBsYkJKU2oKUkxibytrbzhncXU2WHB0OWU4U0Y5OEJ4bFpEcFBVMG5PcGRrTmxwTVpKYVlpaUUzRjRFRG9DcE56bmxpY2JrcApjZ2FrcGVrbS9YS21RSlJxWElXci8wM29SdUVFTXBxZzlRbjdWRG8zR0FiUTlnNUR5U1Bid0xvT25xQ0V3WGFJCkF6alFzWU4rc3VRd2FqZHFUcEthZ1FCbWRaMmdNZDBTMTV1Ukt6c2wxOHgzK1JabmRiNWoxNjNuV0NkMlQ5VDgKald3NURISDgvVUFkSGZoOHh0RTJ6bWRHbEg5T3I5U2hIMzViMWgxVm8rU2pNMzRPeWpwVjB3TmNVL1psOTBUdAp1WnJwYnBwTXZCZUVmRzZTczVXVGhySm9LaGl0RkNwWlVqaDZvdnk3Mzd6ditKaUc4aDRBNG1GTmRPSUtBd0I0Cmp2Nms3V3poUVlEa2Q0ZXRoajNndVJCTGZQNThNVEJKaWhZemVINkUzclhjSGE5b0xnREgzczd4bU8yVEtUY24Kd3VIM3AvdC9WWFN3UGJ0QXBXUXdTRFNKSnA5WkF4S0Q1eVdmd3lTU2ZQVGtwM2c1b2NmKzBhSk1Kc2FkU3lwNQpNR1Vic1oxd1hTN2RXMDhOYXZ2WmpmbElNUm8wUFZDbkRVcFp1bjJuekhTRGJDSjB1M0ZYd1lFQzFFejlJUnN0ClJFbDdpdTZQRlVMSldSU0V0SzBKY1lLS0ltNXhQWHIvbTdPc2duMUNJL0F0cTkrWEFjODk1MGVxeTRwTFVQYkYKZkhFOFhVYWFzUU82MDJTeGpnOTZZaWJ3ZnFyTDF2Vjd1MitUYzJleUZ1N3oxUGRPZDQyWko5M2wvM3lOUW92egora0JuQVdObzZ3WnNKSitHNDZDODNYRVBLM0h1bGw1dFg2UDU4NUQ1b3o5U1oyZGlTd1FyVFN1THVSL0JCQUpVCmd1K2FITkJGRmVtUXNEL2QxMllud1h3d3FkZXVaMDVmQlFiWUREdldOM3daUjJJeHZpd1E0bjZjZWl3OUZ4QmcKbWlzMFBGY2NZOWl0SnJrYXlWQVVZUFZ3Sm5XSmZEK2pQNjJ3UWZJWmhhbFQrZDJpUzVQaDEwdWlMNHEvY1JuYgo1c1Mvc2o0Tm5QYmpxc1ZmZWlKTEh3PT0KLS0tLS1FTkQgRU5DUllQVEVEIFBSSVZBVEUgS0VZLS0tLS0K", - "-var=account_ec2_sydney_cert=whatever", - }) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "30a-sshtargetds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := machines.MachinesQuery{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := client.Machines.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a machine called \"Test\"") - } - resource := resources.Items[0] - - if resource.Endpoint.(*machines.SSHEndpoint).Host != "3.25.215.87" { - t.Fatal("The machine must have a Endpoint.Host of \"3.25.215.87\" (was \"" + resource.Endpoint.(*machines.SSHEndpoint).Host + "\")") - } - - if resource.Endpoint.(*machines.SSHEndpoint).DotNetCorePlatform != "linux-x64" { - t.Fatal("The machine must have a Endpoint.DotNetCorePlatform of \"linux-x64\" (was \"" + resource.Endpoint.(*machines.SSHEndpoint).DotNetCorePlatform + "\")") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "30a-sshtargetds"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestListeningTargetResource verifies that a listening machine can be reimported with the correct settings -func TestListeningTargetResource(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", "31-listeningtarget", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "31a-listeningtargetds"), newSpaceId, []string{}) - - if err != nil { - t.Log("BUG: listening targets data sources don't appear to work") - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := machines.MachinesQuery{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := client.Machines.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a machine called \"Test\"") - } - resource := resources.Items[0] - - if resource.URI != "https://tentacle/" { - t.Fatal("The machine must have a Uri of \"https://tentacle/\" (was \"" + resource.URI + "\")") - } - - if resource.Thumbprint != "55E05FD1B0F76E60F6DA103988056CE695685FD1" { - t.Fatal("The machine must have a Thumbprint of \"55E05FD1B0F76E60F6DA103988056CE695685FD1\" (was \"" + resource.Thumbprint + "\")") - } - - if len(resource.Roles) != 1 { - t.Fatal("The machine must have 1 role") - } - - if resource.Roles[0] != "vm" { - t.Fatal("The machine must have a role of \"vm\" (was \"" + resource.Roles[0] + "\")") - } - - if resource.TenantedDeploymentMode != "Untenanted" { - t.Fatal("The machine must have a TenantedDeploymentParticipation of \"Untenanted\" (was \"" + resource.TenantedDeploymentMode + "\")") - } - - return nil - }) -} - -// TestPollingTargetResource verifies that a polling machine can be reimported with the correct settings -func TestPollingTargetResource(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", "32-pollingtarget", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "32a-pollingtargetds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := machines.MachinesQuery{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := client.Machines.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a machine called \"Test\"") - } - resource := resources.Items[0] - - if resource.Endpoint.(*machines.PollingTentacleEndpoint).URI.Host != "abcdefghijklmnopqrst" { - t.Fatal("The machine must have a Uri of \"poll://abcdefghijklmnopqrst/\" (was \"" + resource.Endpoint.(*machines.PollingTentacleEndpoint).URI.Host + "\")") - } - - if resource.Thumbprint != "1854A302E5D9EAC1CAA3DA1F5249F82C28BB2B86" { - t.Fatal("The machine must have a Thumbprint of \"1854A302E5D9EAC1CAA3DA1F5249F82C28BB2B86\" (was \"" + resource.Thumbprint + "\")") - } - - if len(resource.Roles) != 1 { - t.Fatal("The machine must have 1 role") - } - - if resource.Roles[0] != "vm" { - t.Fatal("The machine must have a role of \"vm\" (was \"" + resource.Roles[0] + "\")") - } - - if resource.TenantedDeploymentMode != "Untenanted" { - t.Fatal("The machine must have a TenantedDeploymentParticipation of \"Untenanted\" (was \"" + resource.TenantedDeploymentMode + "\")") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "32a-pollingtargetds"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestCloudRegionTargetResource verifies that a cloud region can be reimported with the correct settings -func TestCloudRegionTargetResource(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", "33-cloudregiontarget", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "33a-cloudregiontargetds"), newSpaceId, []string{}) - - if err != nil { - t.Fatal("cloud region data source does not appear to work") - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := machines.MachinesQuery{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := client.Machines.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a machine called \"Test\"") - } - resource := resources.Items[0] - - if len(resource.Roles) != 1 { - t.Fatal("The machine must have 1 role") - } - - if resource.Roles[0] != "cloud" { - t.Fatal("The machine must have a role of \"cloud\" (was \"" + resource.Roles[0] + "\")") - } - - if resource.TenantedDeploymentMode != "Untenanted" { - t.Fatal("The machine must have a TenantedDeploymentParticipation of \"Untenanted\" (was \"" + resource.TenantedDeploymentMode + "\")") - } - - return nil - }) -} - -// TestOfflineDropTargetResource verifies that an offline drop can be reimported with the correct settings -func TestOfflineDropTargetResource(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", "34-offlinedroptarget", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "34a-offlinedroptargetds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := machines.MachinesQuery{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := client.Machines.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a machine called \"Test\"") - } - resource := resources.Items[0] - - if len(resource.Roles) != 1 { - t.Fatal("The machine must have 1 role") - } - - if resource.Roles[0] != "offline" { - t.Fatal("The machine must have a role of \"offline\" (was \"" + resource.Roles[0] + "\")") - } - - if resource.TenantedDeploymentMode != "Untenanted" { - t.Fatal("The machine must have a TenantedDeploymentParticipation of \"Untenanted\" (was \"" + resource.TenantedDeploymentMode + "\")") - } - - if resource.Endpoint.(*machines.OfflinePackageDropEndpoint).ApplicationsDirectory != "c:\\temp" { - t.Fatal("The machine must have a Endpoint.ApplicationsDirectory of \"c:\\temp\" (was \"" + resource.Endpoint.(*machines.OfflinePackageDropEndpoint).ApplicationsDirectory + "\")") - } - - if resource.Endpoint.(*machines.OfflinePackageDropEndpoint).WorkingDirectory != "c:\\temp" { - t.Fatal("The machine must have a Endpoint.OctopusWorkingDirectory of \"c:\\temp\" (was \"" + resource.Endpoint.(*machines.OfflinePackageDropEndpoint).WorkingDirectory + "\")") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "34a-offlinedroptargetds"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestAzureCloudServiceTargetResource verifies that a azure cloud service target can be reimported with the correct settings -func TestAzureCloudServiceTargetResource(t *testing.T) { - // I could not figure out a combination of properties that made the octopusdeploy_azure_subscription_account resource work - return - - 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", "35-azurecloudservicetarget", []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := machines.MachinesQuery{ - PartialName: "Azure", - Skip: 0, - Take: 1, - } - - resources, err := client.Machines.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a machine called \"Azure\"") - } - resource := resources.Items[0] - - if len(resource.Roles) != 1 { - t.Fatal("The machine must have 1 role") - } - - if resource.Roles[0] != "cloud" { - t.Fatal("The machine must have a role of \"cloud\" (was \"" + resource.Roles[0] + "\")") - } - - if resource.TenantedDeploymentMode != "Untenanted" { - t.Fatal("The machine must have a TenantedDeploymentParticipation of \"Untenanted\" (was \"" + resource.TenantedDeploymentMode + "\")") - } - - if resource.Endpoint.(*machines.AzureCloudServiceEndpoint).CloudServiceName != "servicename" { - t.Fatal("The machine must have a Endpoint.CloudServiceName of \"c:\\temp\" (was \"" + resource.Endpoint.(*machines.AzureCloudServiceEndpoint).CloudServiceName + "\")") - } - - if resource.Endpoint.(*machines.AzureCloudServiceEndpoint).StorageAccountName != "accountname" { - t.Fatal("The machine must have a Endpoint.StorageAccountName of \"accountname\" (was \"" + resource.Endpoint.(*machines.AzureCloudServiceEndpoint).StorageAccountName + "\")") - } - - if !resource.Endpoint.(*machines.AzureCloudServiceEndpoint).UseCurrentInstanceCount { - t.Fatal("The machine must have Endpoint.UseCurrentInstanceCount set") - } - - return nil - }) -} - -// TestAzureServiceFabricTargetResource verifies that a service fabric target can be reimported with the correct settings -func TestAzureServiceFabricTargetResource(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", "36-servicefabrictarget", []string{ - "-var=target_service_fabric=whatever", - }) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "36a-servicefabrictargetds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := machines.MachinesQuery{ - PartialName: "Service Fabric", - Skip: 0, - Take: 1, - } - - resources, err := client.Machines.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a machine called \"Service Fabric\"") - } - resource := resources.Items[0] - - if len(resource.Roles) != 1 { - t.Fatal("The machine must have 1 role") - } - - if resource.Roles[0] != "cloud" { - t.Fatal("The machine must have a role of \"cloud\" (was \"" + resource.Roles[0] + "\")") - } - - if resource.TenantedDeploymentMode != "Untenanted" { - t.Fatal("The machine must have a TenantedDeploymentParticipation of \"Untenanted\" (was \"" + resource.TenantedDeploymentMode + "\")") - } - - if resource.Endpoint.(*machines.AzureServiceFabricEndpoint).ConnectionEndpoint != "http://endpoint" { - t.Fatal("The machine must have a Endpoint.ConnectionEndpoint of \"http://endpoint\" (was \"" + resource.Endpoint.(*machines.AzureServiceFabricEndpoint).ConnectionEndpoint + "\")") - } - - if resource.Endpoint.(*machines.AzureServiceFabricEndpoint).AadCredentialType != "UserCredential" { - t.Fatal("The machine must have a Endpoint.AadCredentialType of \"UserCredential\" (was \"" + resource.Endpoint.(*machines.AzureServiceFabricEndpoint).AadCredentialType + "\")") - } - - if resource.Endpoint.(*machines.AzureServiceFabricEndpoint).AadUserCredentialUsername != "username" { - t.Fatal("The machine must have a Endpoint.AadUserCredentialUsername of \"username\" (was \"" + resource.Endpoint.(*machines.AzureServiceFabricEndpoint).AadUserCredentialUsername + "\")") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "36a-servicefabrictargetds"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestAzureWebAppTargetResource verifies that a web app target can be reimported with the correct settings -func TestAzureWebAppTargetResource(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", "37-webapptarget", []string{ - "-var=account_sales_account=whatever", - }) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "37a-webapptarget"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := machines.MachinesQuery{ - PartialName: "Web App", - Skip: 0, - Take: 1, - } - - resources, err := client.Machines.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a machine called \"Web App\"") - } - resource := resources.Items[0] - - if len(resource.Roles) != 1 { - t.Fatal("The machine must have 1 role") - } - - if resource.Roles[0] != "cloud" { - t.Fatal("The machine must have a role of \"cloud\" (was \"" + resource.Roles[0] + "\")") - } - - if resource.TenantedDeploymentMode != "Untenanted" { - t.Fatal("The machine must have a TenantedDeploymentParticipation of \"Untenanted\" (was \"" + resource.TenantedDeploymentMode + "\")") - } - - if resource.Endpoint.(*machines.AzureWebAppEndpoint).ResourceGroupName != "mattc-webapp" { - t.Fatal("The machine must have a Endpoint.ResourceGroupName of \"mattc-webapp\" (was \"" + resource.Endpoint.(*machines.AzureWebAppEndpoint).ResourceGroupName + "\")") - } - - if resource.Endpoint.(*machines.AzureWebAppEndpoint).WebAppName != "mattc-webapp" { - t.Fatal("The machine must have a Endpoint.WebAppName of \"mattc-webapp\" (was \"" + resource.Endpoint.(*machines.AzureWebAppEndpoint).WebAppName + "\")") - } - - if resource.Endpoint.(*machines.AzureWebAppEndpoint).WebAppSlotName != "slot1" { - t.Fatal("The machine must have a Endpoint.WebAppSlotName of \"slot1\" (was \"" + resource.Endpoint.(*machines.AzureWebAppEndpoint).WebAppSlotName + "\")") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "37a-webapptarget"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestProjectWithGitUsernameExport verifies that a project can be reimported with the correct git settings -func TestProjectWithGitUsernameExport(t *testing.T) { - if os.Getenv("GIT_CREDENTIAL") == "" { - t.Fatal("The GIT_CREDENTIAL environment variable must be set") - } - - if os.Getenv("GIT_USERNAME") == "" { - t.Fatal("The GIT_USERNAME environment variable must be set") - } - - testFramework := test.OctopusContainerTest{} - testFramework.ArrangeTest(t, func(t *testing.T, container *test.OctopusContainer, spaceClient *client.Client) error { - // Act - _, err := testFramework.Act(t, container, "./terraform", "39-projectgitusername", []string{ - "-var=project_git_password=" + os.Getenv("GIT_CREDENTIAL"), - "-var=project_git_username=" + os.Getenv("GIT_USERNAME"), - }) - - if err != nil { - return err - } - - // The client does not expose git credentials, so just test the import worked ok - - return nil - }) -} - -// TestProjectWithDollarSignsExport verifies that a project can be reimported with terraform string interpolation -func TestProjectWithDollarSignsExport(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", "40-escapedollar", []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := projects.ProjectsQuery{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := client.Projects.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a project called \"Test\"") - } - - return nil - }) -} - -// TestProjectTerraformInlineScriptExport verifies that a project can be reimported with a terraform inline template step. -// See https://github.com/OctopusDeployLabs/terraform-provider-octopusdeploy/issues/478 -func TestProjectTerraformInlineScriptExport(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", "41-terraforminlinescript", []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := projects.ProjectsQuery{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := client.Projects.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a project called \"Test\"") - } - resource := resources.Items[0] - - deploymentProcess, err := client.DeploymentProcesses.GetByID(resource.DeploymentProcessID) - - if deploymentProcess.Steps[0].Actions[0].Properties["Octopus.Action.Terraform.Template"].Value != "#test" { - t.Fatalf("The inline Terraform template must be set to \"#test\"") - } - - return nil - }) -} - -// TestProjectTerraformPackageScriptExport verifies that a project can be reimported with a terraform package template step. -// See https://github.com/OctopusDeployLabs/terraform-provider-octopusdeploy/issues/478 -func TestProjectTerraformPackageScriptExport(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", "42-terraformpackagescript", []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := projects.ProjectsQuery{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := client.Projects.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a project called \"Test\"") - } - resource := resources.Items[0] - - deploymentProcess, err := client.DeploymentProcesses.GetByID(resource.DeploymentProcessID) - - if deploymentProcess.Steps[0].Actions[0].Properties["Octopus.Action.Script.ScriptSource"].Value != "Package" { - t.Fatalf("The Terraform template must be set deploy files from a package") - } - - if deploymentProcess.Steps[0].Actions[0].Properties["Octopus.Action.Terraform.TemplateDirectory"].Value != "blah" { - t.Fatalf("The Terraform template directory must be set to \"blah\"") - } - - return nil - }) -} - -// TestProjectTerraformPackageScriptExport verifies that users and teams can be reimported -func TestUsersAndTeams(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", "43-users", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "43a-usersds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - - if err != nil { - return err - } - - err = func() error { - query := users.UsersQuery{ - Filter: "Service Account", - IDs: nil, - Skip: 0, - Take: 1, - } - - resources, err := client.Users.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a user called \"Service Account\"") - } - - resource := resources.Items[0] - - if resource.Username != "saccount" { - t.Fatalf("Account must have a username \"saccount\"") - } - - if resource.EmailAddress != "a@a.com" { - t.Fatalf("Account must have a email \"a@a.com\"") - } - - if !resource.IsService { - t.Fatalf("Account must be a service account") - } - - if !resource.IsActive { - t.Fatalf("Account must be active") - } - - return nil - }() - - if err != nil { - return err - } - - err = func() error { - query := users.UsersQuery{ - Filter: "Bob Smith", - IDs: nil, - Skip: 0, - Take: 1, - } - - resources, err := client.Users.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a user called \"Service Account\"") - } - - resource := resources.Items[0] - - if resource.Username != "bsmith" { - t.Fatalf("Regular account must have a username \"bsmith\"") - } - - if resource.EmailAddress != "bob.smith@example.com" { - t.Fatalf("Regular account must have a email \"bob.smith@example.com\"") - } - - if resource.IsService { - t.Fatalf("Account must not be a service account") - } - - if resource.IsActive { - t.Log("BUG: Account must not be active") - } - - return nil - }() - - if err != nil { - return err - } - - err = func() error { - query := teams.TeamsQuery{ - IDs: nil, - IncludeSystem: false, - PartialName: "Deployers", - Skip: 0, - Spaces: nil, - Take: 1, - } - - resources, err := client.Teams.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a team called \"Deployers\"") - } - - resource := resources.Items[0] - - if len(resource.MemberUserIDs) != 1 { - t.Fatalf("Team must have one user") - } - - return nil - }() - - if err != nil { - return err - } - - // Verify the environment data lookups work - teams, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "43a-usersds"), "teams_lookup") - - if err != nil { - return err - } - - if teams == "" { - t.Fatal("The teams lookup failed.") - } - - roles, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "43a-usersds"), "roles_lookup") - - if err != nil { - return err - } - - if roles == "" { - t.Fatal("The roles lookup failed.") - } - - users, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "43a-usersds"), "users_lookup") - - if err != nil { - return err - } - - if users == "" { - t.Fatal("The users lookup failed.") - } - - return nil - }) -} - -// TestGithubFeedResource verifies that a nuget feed can be reimported with the correct settings -func TestGithubFeedResource(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", "44-githubfeed", []string{}) - - if err != nil { - return err - } - - err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "44a-githubfeedds"), newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := feeds.FeedsQuery{ - PartialName: "Github", - Skip: 0, - Take: 1, - } - - resources, err := client.Feeds.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have an feed called \"Github\"") - } - resource := resources.Items[0].(*feeds.GitHubRepositoryFeed) - - if resource.FeedType != "GitHub" { - t.Fatal("The feed must have a type of \"GitHub\"") - } - - if resource.Username != "test-username" { - t.Fatal("The feed must have a username of \"test-username\"") - } - - if resource.DownloadAttempts != 1 { - t.Fatal("The feed must be have a downloads attempts set to \"1\"") - } - - if resource.DownloadRetryBackoffSeconds != 30 { - t.Fatal("The feed must be have a downloads retry backoff set to \"30\"") - } - - if resource.FeedURI != "https://api.github.com" { - t.Fatal("The feed must be have a feed uri of \"https://api.github.com\"") - } - - foundExecutionTarget := false - foundServer := false - for _, o := range resource.PackageAcquisitionLocationOptions { - if o == "ExecutionTarget" { - foundExecutionTarget = true - } - - if o == "Server" { - foundServer = true - } - } - - if !(foundExecutionTarget && foundServer) { - t.Fatal("The feed must be have a PackageAcquisitionLocationOptions including \"ExecutionTarget\" and \"Server\"") - } - - // Verify the environment data lookups work - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "44a-githubfeedds"), "data_lookup") - - if err != nil { - return err - } - - if lookup != resource.ID { - t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - } - - return nil - }) -} - -// TestProjectWithScriptActions verifies that a project with a plain script step can be applied and reapplied -func TestProjectWithScriptActions(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", "45-projectwithscriptactions", []string{}) - - if err != nil { - return err - } - - // Do a second apply to catch the scenario documented at https://github.com/OctopusDeployLabs/terraform-provider-octopusdeploy/issues/509 - err = testFramework.TerraformApply(t, filepath.Join("./terraform", "45-projectwithscriptactions"), container.URI, newSpaceId, []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := projects.ProjectsQuery{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := client.Projects.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a project called \"Test\"") - } - resource := resources.Items[0] - - if resource.Description != "Test project" { - t.Fatal("The project must be have a description of \"Test project\" (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") - } - - deploymentProcess, err := client.DeploymentProcesses.GetByID(resource.DeploymentProcessID) - if err != nil { - return err - } - if len(deploymentProcess.Steps) != 1 { - t.Fatal("The DeploymentProcess should have a single Deployment Step") - } - step := deploymentProcess.Steps[0] - - if len(step.Actions) != 3 { - t.Fatal("The DeploymentProcess should have a three Deployment Actions") - } - - if step.Actions[0].Name != "Pre Script Action" { - t.Fatal("The first Deployment Action should be name \"Pre Script Action\" (was \"" + step.Actions[0].Name + "\")") - } - if step.Actions[1].Name != "Hello world (using PowerShell)" { - t.Fatal("The second Deployment Action should be name \"Hello world (using PowerShell)\" (was \"" + step.Actions[1].Name + "\")") - } - if step.Actions[2].Name != "Post Script Action" { - t.Fatal("The third Deployment Action should be name \"Post Script Action\" (was \"" + step.Actions[2].Name + "\")") - } - - return nil - }) -} - -// TestRunbookResource verifies that a runbook can be reimported with the correct settings -func TestRunbookResource(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", "46-runbooks", []string{}) - - if err != nil { - return err - } - - //err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "46a-runbooks"), newSpaceId, []string{}) - // - //if err != nil { - // return err - //} - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - resources, err := client.Runbooks.GetAll() - if err != nil { - return err - } - - found := false - runbookId := "" - for _, r := range resources { - if r.Name == "Runbook" { - found = true - runbookId = r.ID - - if r.Description != "Test Runbook" { - t.Fatal("The runbook must be have a description of \"Test Runbook\" (was \"" + r.Description + "\")") - } - - if r.ConnectivityPolicy.AllowDeploymentsToNoTargets { - t.Fatal("The runbook must not have ConnectivityPolicy.AllowDeploymentsToNoTargets enabled") - } - - if r.ConnectivityPolicy.ExcludeUnhealthyTargets { - t.Fatal("The runbook must not have ConnectivityPolicy.AllowDeploymentsToNoTargets enabled") - } - - if r.ConnectivityPolicy.SkipMachineBehavior != "SkipUnavailableMachines" { - t.Log("BUG: The runbook must be have a ConnectivityPolicy.SkipMachineBehavior of \"SkipUnavailableMachines\" (was \"" + r.ConnectivityPolicy.SkipMachineBehavior + "\") - Known issue where the value returned by /api/Spaces-#/ProjectGroups/ProjectGroups-#/projects is different to /api/Spaces-/Projects") - } - - if r.RunRetentionPolicy.QuantityToKeep != 10 { - t.Fatal("The runbook must not have RunRetentionPolicy.QuantityToKeep of 10 (was \"" + fmt.Sprint(r.RunRetentionPolicy.QuantityToKeep) + "\")") - } - - if r.RunRetentionPolicy.ShouldKeepForever { - t.Fatal("The runbook must not have RunRetentionPolicy.ShouldKeepForever of false (was \"" + fmt.Sprint(r.RunRetentionPolicy.ShouldKeepForever) + "\")") - } - - if r.ConnectivityPolicy.SkipMachineBehavior != "SkipUnavailableMachines" { - t.Log("BUG: The runbook must be have a ConnectivityPolicy.SkipMachineBehavior of \"SkipUnavailableMachines\" (was \"" + r.ConnectivityPolicy.SkipMachineBehavior + "\") - Known issue where the value returned by /api/Spaces-#/ProjectGroups/ProjectGroups-#/projects is different to /api/Spaces-/Projects") - } - - if r.MultiTenancyMode != "Untenanted" { - t.Fatal("The runbook must be have a TenantedDeploymentMode of \"Untenanted\" (was \"" + r.MultiTenancyMode + "\")") - } - - if r.EnvironmentScope != "Specified" { - t.Fatal("The runbook must be have a EnvironmentScope of \"Specified\" (was \"" + r.EnvironmentScope + "\")") - } - - if len(r.Environments) != 1 { - t.Fatal("The runbook must be have a Environments array of 1 (was \"" + strings.Join(r.Environments, ", ") + "\")") - } - - if r.DefaultGuidedFailureMode != "EnvironmentDefault" { - t.Fatal("The runbook must be have a DefaultGuidedFailureMode of \"EnvironmentDefault\" (was \"" + r.DefaultGuidedFailureMode + "\")") - } - - if !r.ForcePackageDownload { - t.Log("BUG: The runbook must be have a ForcePackageDownload of \"true\" (was \"" + fmt.Sprint(r.ForcePackageDownload) + "\")") - } - - process, err := client.RunbookProcesses.GetByID(r.RunbookProcessID) - - if err != nil { - t.Fatal("Failed to retrieve the runbook process.") - } - - if len(process.Steps) != 1 { - t.Fatal("The runbook must be have a 1 step") - } - } - } - - if !found { - t.Fatalf("Space must have a runbook called \"Runbook\"") - } - - // There was an issue where deleting a runbook and reapplying the terraform module caused an error, so - // verify this process works. - client.Runbooks.DeleteByID(runbookId) - err = testFramework.TerraformApply(t, "./terraform/46-runbooks", container.URI, newSpaceId, []string{}) - - if err != nil { - t.Fatal("Failed to reapply the runbooks after deleting them.") - } - - // Verify the environment data lookups work - //lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "46a-runbooks"), "data_lookup") - // - //if err != nil { - // return err - //} - // - //if lookup != resource.ID { - // t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + resource.ID + "\".") - //} - - return nil - }) -} - -// TestK8sTargetResource verifies that a k8s machine can be reimported with the correct settings -func TestK8sTargetWithCertResource(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", "47-k8stargetwithcert", []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := machines.MachinesQuery{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := client.Machines.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a machine called \"Test\"") - } - resource := resources.Items[0] - - if fmt.Sprint(resource.Endpoint.(*machines.KubernetesEndpoint).ClusterURL) != "https://cluster" { - t.Fatal("The machine must have a Endpoint.ClusterUrl of \"https://cluster\" (was \"" + fmt.Sprint(resource.Endpoint.(*machines.KubernetesEndpoint).ClusterURL) + "\")") - } - - if fmt.Sprint(resource.Endpoint.(*machines.KubernetesEndpoint).Authentication.GetAuthenticationType()) != "KubernetesCertificate" { - t.Fatal("The machine must have a Endpoint.AuthenticationType of \"KubernetesCertificate\" (was \"" + fmt.Sprint(resource.Endpoint.(*machines.KubernetesEndpoint).Authentication.GetAuthenticationType()) + "\")") - } - - return nil - }) -} - -// TestK8sPodAuthTargetResource verifies that a k8s machine with pod auth can be reimported with the correct settings -func TestK8sPodAuthTargetResource(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", "48-k8stargetpodauth", []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := machines.MachinesQuery{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := client.Machines.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a machine called \"Test\"") - } - resource := resources.Items[0] - - if fmt.Sprint(resource.Endpoint.(*machines.KubernetesEndpoint).ClusterURL) != "https://cluster" { - t.Fatal("The machine must have a Endpoint.ClusterUrl of \"https://cluster\" (was \"" + fmt.Sprint(resource.Endpoint.(*machines.KubernetesEndpoint).ClusterURL) + "\")") - } - - if fmt.Sprint(resource.Endpoint.(*machines.KubernetesEndpoint).Authentication.GetAuthenticationType()) != "KubernetesPodService" { - t.Fatal("The machine must have a Endpoint.Authentication.AuthenticationType of \"KubernetesPodService\" (was \"" + fmt.Sprint(resource.Endpoint.(*machines.KubernetesEndpoint).Authentication.GetAuthenticationType()) + "\")") - } - - if fmt.Sprint(resource.Endpoint.(*machines.KubernetesEndpoint).Authentication.(*machines.KubernetesPodAuthentication).TokenPath) != "/var/run/secrets/kubernetes.io/serviceaccount/token" { - t.Fatal("The machine must have a Endpoint.Authentication.TokenPath of \"/var/run/secrets/kubernetes.io/serviceaccount/token\" (was \"" + fmt.Sprint(resource.Endpoint.(*machines.KubernetesEndpoint).Authentication.(*machines.KubernetesPodAuthentication).TokenPath) + "\")") - } - - if fmt.Sprint(resource.Endpoint.(*machines.KubernetesEndpoint).ClusterCertificatePath) != "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt" { - t.Fatal("The machine must have a Endpoint.ClusterCertificatePath of \"/var/run/secrets/kubernetes.io/serviceaccount/ca.crt\" (was \"" + fmt.Sprint(resource.Endpoint.(*machines.KubernetesEndpoint).ClusterCertificatePath) + "\")") - } - - 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.") - } - - for _, variable := range variableSet.Variables { - switch variable.Name { - case "UnscopedVariable": - if !variable.Scope.IsEmpty() { - t.Fatalf("Expected UnscopedVariable to have no scope values.") - } - case "ActionScopedVariable": - if len(variable.Scope.Actions) == 0 { - t.Fatalf("Expected ActionScopedVariable to have action scope.") - } - case "ChannelScopedVariable": - if len(variable.Scope.Channels) == 0 { - t.Fatalf("Expected ChannelScopedVariable to have channel scope.") - } - case "EnvironmentScopedVariable": - if len(variable.Scope.Environments) == 0 { - t.Fatalf("Expected EnvironmentScopedVariable to have environment scope.") - } - case "MachineScopedVariable": - if len(variable.Scope.Machines) == 0 { - t.Fatalf("Expected MachineScopedVariable to have machine scope.") - } - case "ProcessScopedVariable": - if len(variable.Scope.ProcessOwners) == 0 { - t.Fatalf("Expected ProcessScopedVariable to have process scope.") - } - case "RoleScopedVariable": - if len(variable.Scope.Roles) == 0 { - t.Fatalf("Expected RoleScopedVariable to have role scope.") - } - } - } - - return nil - }) -} - -// TestTerraformApplyStepWithWorkerPool verifies that a terraform apply step with a custom worker pool is deployed successfully -// See https://github.com/OctopusDeployLabs/terraform-provider-octopusdeploy/issues/601 -func TestTerraformApplyStepWithWorkerPool(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", "50-applyterraformtemplateaction", []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := projects.ProjectsQuery{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := projects.Get(client, newSpaceId, query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a project called \"Test\"") - } - resource := resources.Items[0] - - // Get worker pool - wpQuery := workerpools.WorkerPoolsQuery{ - PartialName: "Docker", - Skip: 0, - Take: 1, - } - - workerpools, err := workerpools.Get(client, newSpaceId, wpQuery) - if err != nil { - return err - } - - if len(workerpools.Items) == 0 { - t.Fatalf("Space must have a worker pool called \"Docker\"") - } - - // Get deployment process - process, err := deployments.GetDeploymentProcessByID(client, "", resource.DeploymentProcessID) - if err != nil { - return err - } - - // Worker pool must be assigned - if process.Steps[0].Actions[0].WorkerPool != workerpools.Items[0].GetID() { - t.Fatalf("Action must use the worker pool \"Docker\"") - } - - return nil - }) -} - -func TestDeploymentProcessWithGitDependency(t *testing.T) { - testFramework := test.OctopusContainerTest{} - testFramework.ArrangeTest(t, func(t *testing.T, container *test.OctopusContainer, spaceClient *client.Client) error { - newSpaceId, err := testFramework.Act(t, container, "./terraform", "51-deploymentprocesswithgitdependency", []string{}) - - if err != nil { - return err - } - - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - project, err := client.Projects.GetByName("Test") - deploymentProcess, err := deployments.GetDeploymentProcessByID(client, newSpaceId, project.DeploymentProcessID) - - if len(deploymentProcess.Steps) == 0 { - t.Fatalf("Expected deployment process to have steps.") - } - - expectedGitUri := "https://github.com/OctopusSamples/OctoPetShop.git" - expectedDefaultBranch := "main" - - for _, step := range deploymentProcess.Steps { - action := step.Actions[0] - - if len(action.GitDependencies) == 0 { - t.Fatalf(fmt.Sprint(action.Name) + " - Expected action to have git dependency configured.") - } - - gitDependency := action.GitDependencies[0] - - if fmt.Sprint(gitDependency.RepositoryUri) != expectedGitUri { - t.Fatalf(fmt.Sprint(action.Name) + " - Expected git dependency to have repository uri equal to " + fmt.Sprint(expectedGitUri)) - } - - if fmt.Sprint(gitDependency.DefaultBranch) != expectedDefaultBranch { - t.Fatalf(fmt.Sprint(action.Name) + " - Expected git dependency to have default branch equal to " + fmt.Sprint(expectedDefaultBranch)) - } - - if fmt.Sprint(gitDependency.GitCredentialType) == "Library" { - if len(strings.TrimSpace(gitDependency.GitCredentialId)) == 0 { - t.Fatalf(fmt.Sprint(action.Name) + " - Expected git dependency library type to have a defined git credential id.") - } - } else { - if len(strings.TrimSpace(gitDependency.GitCredentialId)) > 0 { - t.Fatalf(fmt.Sprint(action.Name) + " - Expected git dependency of non-library type to not have a defined git credential id.") - } - } - } - - return nil - }) -} - -func TestPackageFeedCreateReleaseTriggerResources(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", "52-packagefeedcreatereleasetrigger", []string{}) - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := projects.ProjectsQuery{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := client.Projects.Get(query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatal("Space must have a project called \"Test\"") - } - resource := resources.Items[0] - - project_triggers, err := client.ProjectTriggers.GetByProjectID(resource.ID) - - if err != nil { - return err - } - - tr1Name := "My first trigger" - tr2Name := "My second trigger" - tr3Name := "My third trigger" - - tr1Index := stdslices.IndexFunc(project_triggers, func(t *triggers.ProjectTrigger) bool { return t.Name == tr1Name }) - tr2Index := stdslices.IndexFunc(project_triggers, func(t *triggers.ProjectTrigger) bool { return t.Name == tr2Name }) - tr3Index := stdslices.IndexFunc(project_triggers, func(t *triggers.ProjectTrigger) bool { return t.Name == tr3Name }) - - if tr1Index == -1 || tr2Index == -1 || tr3Index == -1 { - t.Fatalf("Unable to find all triggers. Expecting there to be \"%s\", \"%s\", and \"%s\".", tr1Name, tr2Name, tr3Name) - } - - for _, triggerIndex := range []int{tr1Index, tr2Index, tr3Index} { - if project_triggers[triggerIndex].Filter.GetFilterType() != filters.FeedFilter { - t.Fatal("The project triggers must all be of \"FeedFilter\" type") - } - } - - if project_triggers[tr1Index].IsDisabled { - t.Fatalf("The trigger \"%s\" should not be disabled", tr1Name) - } - - if !project_triggers[tr2Index].IsDisabled { - t.Fatalf("The trigger \"%s\" should be disabled", tr2Name) - } - - if project_triggers[tr3Index].IsDisabled { - t.Fatalf("The trigger \"%s\" should not be disabled", tr3Name) - } - - tr1Filter := project_triggers[tr1Index].Filter.(*filters.FeedTriggerFilter) - tr2Filter := project_triggers[tr2Index].Filter.(*filters.FeedTriggerFilter) - tr3Filter := project_triggers[tr3Index].Filter.(*filters.FeedTriggerFilter) - - if len(tr1Filter.Packages) != 2 { - t.Fatalf("The trigger \"%s\" should have 2 package references", tr1Name) - } - - if len(tr2Filter.Packages) != 1 { - t.Fatalf("The trigger \"%s\" should have 1 package reference", tr2Name) - } - - if len(tr3Filter.Packages) != 3 { - t.Fatalf("The trigger \"%s\" should have 3 package reference", tr3Name) - } - - return nil - }) -} - -func TestProjectScheduledTriggerResources(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", "53-scheduledprojecttrigger", []string{}) - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := projects.ProjectsQuery{ - Skip: 0, - Take: 2, - } - - resources, err := client.Projects.Get(query) - if err != nil { - return err - } - - if len(resources.Items) != 2 { - t.Fatal("There must be exactly 2 projects in the space") - } - - nonTenantedProjectName := "Non Tenanted" - nonTenantedProjectIndex := stdslices.IndexFunc(resources.Items, func(t *projects.Project) bool { return t.Name == nonTenantedProjectName }) - nonTenantedProject := resources.Items[nonTenantedProjectIndex] - - tenantedProjectName := "Tenanted" - tenantedProjectIndex := stdslices.IndexFunc(resources.Items, func(t *projects.Project) bool { return t.Name == tenantedProjectName }) - tenantedProject := resources.Items[tenantedProjectIndex] - - projectTriggers, err := client.ProjectTriggers.GetAll() - if err != nil { - return err - } - - nonTenantedProjectTriggersCount := 0 - tenantedProjectTriggersCount := 0 - - for _, trigger := range projectTriggers { - if trigger.ProjectID == nonTenantedProject.ID { - nonTenantedProjectTriggersCount++ - } else if trigger.ProjectID == tenantedProject.ID { - tenantedProjectTriggersCount++ - } - } - - if nonTenantedProjectTriggersCount != 9 { - t.Fatal("Non Tenanted project should have exactly 8 project triggers and 1 runbook trigger, only found: " + fmt.Sprint(nonTenantedProjectTriggersCount)) - } - - if tenantedProjectTriggersCount != 2 { - t.Fatal("Tenanted project should have exactly 1 project trigger and 1 runbook trigger, only found: " + fmt.Sprint(tenantedProjectTriggersCount)) - } - - return nil - }) -} - -// TestUsernamePasswordVariableResource verifies that a project variable referencing a username/password account -// can be created -func TestUsernamePasswordVariableResource(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", "54-usernamepasswordvariable", []string{}) - - if err != nil { - return err - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := projects.ProjectsQuery{ - PartialName: "Test", - Skip: 0, - Take: 1, - } - - resources, err := projects.Get(client, newSpaceId, query) - if err != nil { - return err - } - - if len(resources.Items) == 0 { - t.Fatalf("Space must have a project called \"Test\"") - } - resource := resources.Items[0] - - projectVariables, err := variables.GetVariableSet(client, newSpaceId, resource.VariableSetID) - - if err != nil { - return err - } - - if len(projectVariables.Variables) != 1 { - t.Fatalf("The project must have 1 variable.") - } - - if projectVariables.Variables[0].Name != "UsernamePasswordVariable" { - t.Fatalf("The variable must be called UsernamePasswordVariable.") - } - - if projectVariables.Variables[0].Type != "UsernamePasswordAccount" { - t.Fatalf("The variable must have type of UsernamePasswordAccount.") - } - - return nil - }) -} - -func TestKubernetesDeploymentTargetResource(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 - } - - // Assert - client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey) - query := machines.MachinesQuery{ - DeploymentTargetTypes: []string{"KubernetesTentacle"}, - Skip: 0, - Take: 3, - } - - resources, err := machines.Get(client, newSpaceId, query) - if err != nil { - return err - } - - if len(resources.Items) != 3 { - t.Fatalf("Space must have three deployment targets with type KubernetesTentacle") - } - - optionalAgentName := "optional-agent" - optionalAgentIndex := stdslices.IndexFunc(resources.Items, func(t *machines.DeploymentTarget) bool { return t.Name == optionalAgentName }) - optionalAgentDeploymentTarget := resources.Items[optionalAgentIndex] - optionalAgentEndpoint := optionalAgentDeploymentTarget.Endpoint.(*machines.KubernetesTentacleEndpoint) - - expectedDefaultNamespace := "kubernetes-namespace" - if optionalAgentEndpoint.DefaultNamespace != expectedDefaultNamespace { - t.Fatalf("Expected \"%s\" to have a default namespace of \"%s\", instead has \"%s\"", optionalAgentName, expectedDefaultNamespace, optionalAgentEndpoint.DefaultNamespace) - } - - if !optionalAgentDeploymentTarget.IsDisabled { - t.Fatalf("Expected \"%s\" to be disabled", optionalAgentName) - } - - if !optionalAgentEndpoint.UpgradeLocked { - t.Fatalf("Expected \"%s\" to have upgrade locked", optionalAgentName) - } - - tenantedAgentName := "tenanted-agent" - tenantedAgentIndex := stdslices.IndexFunc(resources.Items, func(t *machines.DeploymentTarget) bool { return t.Name == tenantedAgentName }) - tenantedAgentDeploymentTarget := resources.Items[tenantedAgentIndex] - - if tenantedAgentDeploymentTarget.TenantedDeploymentMode != "Tenanted" { - t.Fatalf("Expected \"%s\" to be tenanted, but it was \"%s\"", tenantedAgentName, tenantedAgentDeploymentTarget.TenantedDeploymentMode) - } - - if len(tenantedAgentDeploymentTarget.TenantIDs) != 1 { - t.Fatalf("Expected \"%s\" to have 1 tenant, but it has %d", tenantedAgentName, len(tenantedAgentDeploymentTarget.TenantIDs)) - } - - if len(tenantedAgentDeploymentTarget.TenantTags) != 2 { - t.Fatalf("Expected \"%s\" to have 2 tenant tags, but it has %d", tenantedAgentName, len(tenantedAgentDeploymentTarget.TenantTags)) - } - - 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 - }) -} - -func TestPollingSubscriptionIdResource(t *testing.T) { - testFramework := test.OctopusContainerTest{} - testFramework.ArrangeTest(t, func(t *testing.T, container *test.OctopusContainer, spaceClient *client.Client) error { - // Act - _, err := testFramework.Act(t, container, "./terraform", "56-pollingsubscriptionid", []string{}) - - if err != nil { - return err - } - - baseIdLookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "56-pollingsubscriptionid"), "base_id") - if err != nil { - return err - } - - basePollingUriLookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "56-pollingsubscriptionid"), "base_polling_uri") - if err != nil { - return err - } - - parsedUri, err := url.Parse(basePollingUriLookup) - if parsedUri.Scheme != "poll" { - t.Fatalf("The polling URI scheme must be \"poll\" but instead received %s", parsedUri.Scheme) - } - - if parsedUri.Host != baseIdLookup { - t.Fatalf("The polling URI host must be the Subscription ID but instead received %s", parsedUri.Host) - } - - return nil - }) -} - -func TestTentacleCertificateResource(t *testing.T) { - testFramework := test.OctopusContainerTest{} - testFramework.ArrangeTest(t, func(t *testing.T, container *test.OctopusContainer, spaceClient *client.Client) error { - // Act - _, err := testFramework.Act(t, container, "./terraform", "57-tentaclecertificate", []string{}) - - if err != nil { - return err - } - - thumbprintLookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "57-tentaclecertificate"), "base_certificate_thumbprint") - if err != nil { - return err - } - - if thumbprintLookup == "" { - t.Fatalf("Expected a thumbprint to be returned in Terraform output") - } - - return nil - }) -} diff --git a/octopusdeploy/resource_kubernetes_agent_worker_integration_test.go b/octopusdeploy/resource_kubernetes_agent_worker_integration_test.go index 13816f1e0..a290691a6 100644 --- a/octopusdeploy/resource_kubernetes_agent_worker_integration_test.go +++ b/octopusdeploy/resource_kubernetes_agent_worker_integration_test.go @@ -1,13 +1,16 @@ package octopusdeploy import ( + "context" "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines" + "github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework/octoclient" "github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework/test" "log" "os" "path/filepath" stdslices "slices" "testing" + "time" ) func TestKubernetesAgentWorkerResource(t *testing.T) { @@ -17,30 +20,34 @@ func TestKubernetesAgentWorkerResource(t *testing.T) { }, } - // If local - use local, otherwise create a new container - if os.Getenv("TF_ACC_LOCAL") == "" { - octoContainer, octoClient, sqlServerContainer, network, err = testFramework.ArrangeContainer() - if err != nil { - log.Printf("Failed to arrange containers: (%s)", err.Error()) - } - os.Setenv("OCTOPUS_URL", octoContainer.URI) - os.Setenv("OCTOPUS_APIKEY", test.ApiKey) - os.Setenv("TF_ACC", "1") + // Use separate Octopus container as this test requires a custom environment variable to be set + octoContainer, octoClient, sqlServerContainer, network, err = testFramework.ArrangeContainer() + if err != nil { + log.Printf("Failed to arrange containers: (%s)", err.Error()) } + os.Setenv("TF_ACC", "1") + + inputVars := []string{"-var=octopus_server_58-kubernetesagentworker=" + octoContainer.URI, "-var=octopus_apikey_58-kubernetesagentworker=" + test.ApiKey} - _, err := testFramework.Act(t, octoContainer, "../terraform", "58-kubernetesagentworker", []string{}) + newSpaceId, err := testFramework.Act(t, octoContainer, "../terraform", "58-kubernetesagentworker", inputVars) + if err != nil { + t.Fatal(err.Error()) + } + + err = testFramework.TerraformInitAndApply(t, octoContainer, filepath.Join("../terraform", "58a-kubernetesagentworkerds"), newSpaceId, inputVars) if err != nil { t.Fatal(err.Error()) } // Assert + client, err := octoclient.CreateClient(octoContainer.URI, newSpaceId, key) query := machines.WorkersQuery{ CommunicationStyles: []string{"KubernetesTentacle"}, Skip: 0, Take: 3, } - resources, err := octoClient.Workers.Get(query) + resources, err := client.Workers.Get(query) if err != nil { t.Fatal(err.Error()) } @@ -49,16 +56,20 @@ func TestKubernetesAgentWorkerResource(t *testing.T) { t.Fatalf("Space must have two workers (both KubernetesTentacles), instead found %v", resources.Items) } - optionalAgentName := "minimum-agent" - optionalAgentIndex := stdslices.IndexFunc(resources.Items, func(t *machines.Worker) bool { return t.Name == optionalAgentName }) - optionalAgentWorker := resources.Items[optionalAgentIndex] - optionalAgentEndpoint := optionalAgentWorker.Endpoint.(*machines.KubernetesTentacleEndpoint) - if optionalAgentWorker.IsDisabled { - t.Fatalf("Expected \"%s\" to be enabled", optionalAgentName) + minimalAgentName := "minimum-agent" + minimalAgentIndex := stdslices.IndexFunc(resources.Items, func(t *machines.Worker) bool { return t.Name == minimalAgentName }) + minimalAgentWorker := resources.Items[minimalAgentIndex] + minimalAgentEndpoint := minimalAgentWorker.Endpoint.(*machines.KubernetesTentacleEndpoint) + if minimalAgentWorker.IsDisabled { + t.Fatalf("Expected \"%s\" to be enabled", minimalAgentName) } - if optionalAgentEndpoint.UpgradeLocked { - t.Fatalf("Expected \"%s\" to not be upgrade locked", optionalAgentName) + if minimalAgentEndpoint.UpgradeLocked { + t.Fatalf("Expected \"%s\" to not be upgrade locked", minimalAgentName) + } + + if len(minimalAgentWorker.WorkerPoolIDs) != 1 { + t.Fatalf("Expected \"%s\" to have one worker pool id", minimalAgentName) } fullAgentName := "agent-with-optionals" @@ -74,13 +85,23 @@ func TestKubernetesAgentWorkerResource(t *testing.T) { t.Fatalf("Expected \"%s\" to be upgrade locked", fullAgentName) } - lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "58-kubernetesagentworker"), "data_lookup") + if len(fullAgentWorker.WorkerPoolIDs) != 2 { + t.Fatalf("Expected \"%s\" to have two worker pool ids", fullAgentName) + } + _, err = testFramework.GetOutputVariable(t, filepath.Join("../terraform", "58a-kubernetesagentworkerds"), "data_lookup_kubernetes_worker_1_id") + _, err = testFramework.GetOutputVariable(t, filepath.Join("../terraform", "58a-kubernetesagentworkerds"), "data_lookup_kubernetes_worker_2_id") if err != nil { t.Fatal("Failed to query for created k8s workers") } - if len(lookup) > 5 { - t.Fatal("Failed to query for created k8s workers") + ctx := context.Background() + + // Waiting for the container logs to clear. + time.Sleep(5000 * time.Millisecond) + err = testFramework.CleanUp(ctx, octoContainer, sqlServerContainer, network) + + if err != nil { + log.Printf("Failed to clean up containers: (%s)", err.Error()) } } diff --git a/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf b/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf index 2afaa3c8d..dfec82c37 100644 --- a/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf +++ b/terraform/58-kubernetesagentworker/kubernetes_agent_workers.tf @@ -8,7 +8,7 @@ resource "octopusdeploy_kubernetes_agent_worker" "agent_with_minimum" { resource "octopusdeploy_kubernetes_agent_worker" "agent_with_optional" { name = "agent-with-optionals" machine_policy_id = octopusdeploy_machine_policy.machinepolicy_testing.id - worker_pool_ids = [octopusdeploy_static_worker_pool.workerpool_docker.id] + worker_pool_ids = [octopusdeploy_static_worker_pool.workerpool_docker.id, octopusdeploy_static_worker_pool.workerpool_example.id] communication_mode = "Polling" uri = "poll://kcxzcv2fpsxkn6tk9u6d/" thumbprint = "96203ED84246201C26A2F4360D7CBC36AC1D232D" diff --git a/terraform/58-kubernetesagentworker/provider.tf b/terraform/58-kubernetesagentworker/provider.tf index a04197720..d563e69b0 100644 --- a/terraform/58-kubernetesagentworker/provider.tf +++ b/terraform/58-kubernetesagentworker/provider.tf @@ -1,5 +1,5 @@ provider "octopusdeploy" { - address = "${var.octopus_server}" - api_key = "${var.octopus_apikey}" + address = "${var.octopus_server_58-kubernetesagentworker}" + api_key = "${var.octopus_apikey_58-kubernetesagentworker}" space_id = "${var.octopus_space_id}" } diff --git a/terraform/58-kubernetesagentworker/provider_vars.tf b/terraform/58-kubernetesagentworker/provider_vars.tf index c7d93fe40..96be8b1f5 100644 --- a/terraform/58-kubernetesagentworker/provider_vars.tf +++ b/terraform/58-kubernetesagentworker/provider_vars.tf @@ -2,9 +2,21 @@ variable "octopus_server" { type = string nullable = false sensitive = false - description = "The URL of the Octopus server e.g. https://myinstance.octopus.app." + description = "Not used for this test but need to be declared" } variable "octopus_apikey" { + type = string + nullable = false + sensitive = true + description = "Not used for this test but need to be declared" +} +variable "octopus_server_58-kubernetesagentworker" { + type = string + nullable = false + sensitive = false + description = "The URL of the Octopus server e.g. https://myinstance.octopus.app." +} +variable "octopus_apikey_58-kubernetesagentworker" { type = string nullable = false sensitive = true diff --git a/terraform/58-kubernetesagentworker/workerpool.tf b/terraform/58-kubernetesagentworker/workerpool.tf index c1fd253fe..a8ff2d101 100644 --- a/terraform/58-kubernetesagentworker/workerpool.tf +++ b/terraform/58-kubernetesagentworker/workerpool.tf @@ -4,3 +4,10 @@ resource "octopusdeploy_static_worker_pool" "workerpool_docker" { is_default = false sort_order = 3 } + +resource "octopusdeploy_static_worker_pool" "workerpool_example" { + name = "Example" + description = "My other example worker pool" + is_default = false + sort_order = 4 +} diff --git a/terraform/58-kubernetesagentworker/workers_data_source.tf b/terraform/58-kubernetesagentworker/workers_data_source.tf deleted file mode 100644 index 56fc2f773..000000000 --- a/terraform/58-kubernetesagentworker/workers_data_source.tf +++ /dev/null @@ -1,6 +0,0 @@ -data "octopusdeploy_kubernetes_agent_workers" "all_workers" { -} - -output "data_lookup" { - value = data.octopusdeploy_kubernetes_agent_workers.all_workers -} \ No newline at end of file diff --git a/terraform/58a-kubernetesagentworkerds/config.tf b/terraform/58a-kubernetesagentworkerds/config.tf new file mode 100644 index 000000000..2113da144 --- /dev/null +++ b/terraform/58a-kubernetesagentworkerds/config.tf @@ -0,0 +1,5 @@ +terraform { + required_providers { + octopusdeploy = { source = "OctopusDeployLabs/octopusdeploy", version = "0.18.1" } + } +} diff --git a/terraform/58a-kubernetesagentworkerds/kubernetes_agent_workers.tf b/terraform/58a-kubernetesagentworkerds/kubernetes_agent_workers.tf new file mode 100644 index 000000000..f3bad68eb --- /dev/null +++ b/terraform/58a-kubernetesagentworkerds/kubernetes_agent_workers.tf @@ -0,0 +1,10 @@ +data "octopusdeploy_kubernetes_agent_workers" "all_workers" { +} + +output "data_lookup_kubernetes_worker_1_id" { + value = data.octopusdeploy_kubernetes_agent_workers.all_workers.kubernetes_agent_workers[0].id +} + +output "data_lookup_kubernetes_worker_2_id" { + value = data.octopusdeploy_kubernetes_agent_workers.all_workers.kubernetes_agent_workers[1].id +} \ No newline at end of file diff --git a/terraform/58a-kubernetesagentworkerds/provider.tf b/terraform/58a-kubernetesagentworkerds/provider.tf new file mode 100644 index 000000000..d563e69b0 --- /dev/null +++ b/terraform/58a-kubernetesagentworkerds/provider.tf @@ -0,0 +1,5 @@ +provider "octopusdeploy" { + address = "${var.octopus_server_58-kubernetesagentworker}" + api_key = "${var.octopus_apikey_58-kubernetesagentworker}" + space_id = "${var.octopus_space_id}" +} diff --git a/terraform/58a-kubernetesagentworkerds/provider_vars.tf b/terraform/58a-kubernetesagentworkerds/provider_vars.tf new file mode 100644 index 000000000..96be8b1f5 --- /dev/null +++ b/terraform/58a-kubernetesagentworkerds/provider_vars.tf @@ -0,0 +1,30 @@ +variable "octopus_server" { + type = string + nullable = false + sensitive = false + description = "Not used for this test but need to be declared" +} +variable "octopus_apikey" { + type = string + nullable = false + sensitive = true + description = "Not used for this test but need to be declared" +} +variable "octopus_server_58-kubernetesagentworker" { + type = string + nullable = false + sensitive = false + description = "The URL of the Octopus server e.g. https://myinstance.octopus.app." +} +variable "octopus_apikey_58-kubernetesagentworker" { + 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/58a-kubernetesagentworkerds/space.tf b/terraform/58a-kubernetesagentworkerds/space.tf new file mode 100644 index 000000000..ee59bdc80 --- /dev/null +++ b/terraform/58a-kubernetesagentworkerds/space.tf @@ -0,0 +1,3 @@ +output "octopus_space_id" { + value = var.octopus_space_id +} From 140a672bc1c4e2cfa8eef2d7c60fdf89c22dd1af Mon Sep 17 00:00:00 2001 From: Kevin Tchang Date: Tue, 20 Aug 2024 12:06:43 +1000 Subject: [PATCH 25/34] regenerate docs --- docs/data-sources/kubernetes_agent_workers.md | 55 +++++++++++++++++++ docs/resources/kubernetes_agent_worker.md | 6 +- .../import.sh | 1 + .../resource.tf | 16 ++++++ 4 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 docs/data-sources/kubernetes_agent_workers.md create mode 100644 examples/resources/octopusdeploy_kubernetes_agent_worker/import.sh create mode 100644 examples/resources/octopusdeploy_kubernetes_agent_worker/resource.tf diff --git a/docs/data-sources/kubernetes_agent_workers.md b/docs/data-sources/kubernetes_agent_workers.md new file mode 100644 index 000000000..8f528528b --- /dev/null +++ b/docs/data-sources/kubernetes_agent_workers.md @@ -0,0 +1,55 @@ +--- +page_title: "octopusdeploy_kubernetes_agent_workers Data Source - terraform-provider-octopusdeploy" +subcategory: "Workers" +description: |- + Provides information about existing kubernetes agent workers. +--- + +# octopusdeploy_kubernetes_agent_workers (Data Source) + +Provides information about existing kubernetes agent workers. + + + + +## Schema + +### Optional + +- `health_statuses` (List of String) A filter to search by a list of health statuses of resources. Valid health statuses are `HasWarnings`, `Healthy`, `Unavailable`, `Unhealthy`, or `Unknown`. +- `ids` (List of String) A filter to search by a list of IDs. +- `is_disabled` (Boolean) A filter to search by the disabled status of a resource. +- `name` (String) A filter to search by name. +- `partial_name` (String) A filter to search by the partial match of a name. +- `roles` (List of String) A filter to search by a list of role IDs. +- `shell_names` (List of String) A list of shell names to match in the query and/or search +- `skip` (Number) A filter to specify the number of items to skip in the response. +- `space_id` (String) The space ID associated with this resource. +- `take` (Number) A filter to specify the number of items to take (or return) in the response. +- `thumbprint` (String) The thumbprint of the deployment target to match in the query and/or search + +### Read-Only + +- `id` (String) An auto-generated identifier that includes the timestamp when this data source was last modified. +- `kubernetes_agent_workers` (Block List) A list of kubernetes agent workers that match the filter(s). (see [below for nested schema](#nestedblock--kubernetes_agent_workers)) + + +### Nested Schema for `kubernetes_agent_workers` + +Read-Only: + +- `agent_helm_release_name` (String) Name of the Helm release that the agent belongs to. +- `agent_kubernetes_namespace` (String) Name of the Kubernetes namespace where the agent is installed. +- `agent_tentacle_version` (String) Current Tentacle version of the agent +- `agent_upgrade_status` (String) Current upgrade availability status of the agent. One of 'NoUpgrades', 'UpgradeAvailable', 'UpgradeSuggested', 'UpgradeRequired' +- `agent_version` (String) Current Helm chart version of the agent. +- `communication_mode` (String) The communication mode used by the Kubernetes agent to communicate with Octopus Server. Currently, the only supported value is 'Polling'. +- `id` (String) The unique ID for this resource. +- `is_disabled` (Boolean) Whether the Kubernetes agent is disabled. If the agent is disabled, it will not be included in any deployments. +- `machine_policy_id` (String) Optional ID of the machine policy that the Kubernetes agent will use. If not provided the default machine policy will be used. +- `name` (String) The name of this resource. +- `space_id` (String) The space ID associated with this resource. +- `thumbprint` (String) The thumbprint of the Kubernetes agent's certificate used by server to verify the identity of the agent. This is the same thumbprint that was used when installing the agent. +- `upgrade_locked` (Boolean) If enabled the Kubernetes agent will not automatically upgrade and will stay on the currently installed version, even if the associated machine policy is configured to automatically upgrade. +- `uri` (String) The URI of the Kubernetes agent's used by the server to queue messages. This is the same subscription uri that was used when installing the agent. +- `worker_pool_ids` (List of String) A list of worker pool Ids specifying the pools in which this worker belongs diff --git a/docs/resources/kubernetes_agent_worker.md b/docs/resources/kubernetes_agent_worker.md index f41287e7f..7b391bb09 100644 --- a/docs/resources/kubernetes_agent_worker.md +++ b/docs/resources/kubernetes_agent_worker.md @@ -21,7 +21,7 @@ resource "octopusdeploy_kubernetes_agent_worker" "minimal" { resource "octopusdeploy_kubernetes_agent_worker" "optionals" { name = "agent-optionals" - worker_pools = ["worker-pools-1"] + worker_pools = ["worker-pools-1", "worker-pools-3"] thumbprint = "96203ED84246201C26A2F4360D7CBC36AC1D232D" uri = "poll://kcxzcv2fpsxkn6tk9u6d/" machine_policy_id = "machinepolicies-1" @@ -29,16 +29,16 @@ resource "octopusdeploy_kubernetes_agent_worker" "optionals" { is_disabled = true } ``` + ## Schema ### Required -- `environments` (List of String) A list of environment IDs this Kubernetes agent can deploy to. - `name` (String) The name of this resource. -- `roles` (List of String) A list of target roles that are associated to this Kubernetes agent. - `thumbprint` (String) The thumbprint of the Kubernetes agent's certificate used by server to verify the identity of the agent. This is the same thumbprint that was used when installing the agent. - `uri` (String) The URI of the Kubernetes agent's used by the server to queue messages. This is the same subscription uri that was used when installing the agent. +- `worker_pool_ids` (List of String) A list of worker pool Ids specifying the pools in which this worker belongs ### Optional diff --git a/examples/resources/octopusdeploy_kubernetes_agent_worker/import.sh b/examples/resources/octopusdeploy_kubernetes_agent_worker/import.sh new file mode 100644 index 000000000..f3165103d --- /dev/null +++ b/examples/resources/octopusdeploy_kubernetes_agent_worker/import.sh @@ -0,0 +1 @@ +terraform import [options] octopusdeploy_kubernetes_agent_worker. \ No newline at end of file diff --git a/examples/resources/octopusdeploy_kubernetes_agent_worker/resource.tf b/examples/resources/octopusdeploy_kubernetes_agent_worker/resource.tf new file mode 100644 index 000000000..92fd1669b --- /dev/null +++ b/examples/resources/octopusdeploy_kubernetes_agent_worker/resource.tf @@ -0,0 +1,16 @@ +resource "octopusdeploy_kubernetes_agent_worker" "minimal" { + name = "agent-minimal" + worker_pools = ["worker-pools-1"] + thumbprint = "96203ED84246201C26A2F4360D7CBC36AC1D232D" + uri = "poll://kcxzcv2fpsxkn6tk9u6d/" +} + +resource "octopusdeploy_kubernetes_agent_worker" "optionals" { + name = "agent-optionals" + worker_pools = ["worker-pools-1", "worker-pools-3"] + thumbprint = "96203ED84246201C26A2F4360D7CBC36AC1D232D" + uri = "poll://kcxzcv2fpsxkn6tk9u6d/" + machine_policy_id = "machinepolicies-1" + upgrade_locked = true + is_disabled = true +} \ No newline at end of file From fbae2c20982dc0d01c49a56c782d6c5a35b294d8 Mon Sep 17 00:00:00 2001 From: Kevin Tchang Date: Tue, 20 Aug 2024 12:18:04 +1000 Subject: [PATCH 26/34] edit --- octopusdeploy/testing_container_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/octopusdeploy/testing_container_test.go b/octopusdeploy/testing_container_test.go index 324b52ab9..1f37ad0a3 100644 --- a/octopusdeploy/testing_container_test.go +++ b/octopusdeploy/testing_container_test.go @@ -63,7 +63,6 @@ func TestMain(m *testing.M) { URI: url, } } - code := m.Run() os.Exit(code) } From a4ffcd18017d61709e64ded2104cadd4cf3cb10b Mon Sep 17 00:00:00 2001 From: Kevin Tchang Date: Tue, 20 Aug 2024 12:19:38 +1000 Subject: [PATCH 27/34] remove random char --- integration_test_readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_test_readme.md b/integration_test_readme.md index cdf9759aa..21b5e66f5 100644 --- a/integration_test_readme.md +++ b/integration_test_readme.md @@ -8,7 +8,7 @@ of the git repo: dev_overrides { "octopusdeploylabs/octopusdeploy" = "/var/home/yourname/Code/terraform-provider-octopusdeploy" } -Ø + direct {} } From 653b443cfefbe17a7b86574a638b825badee7f3f Mon Sep 17 00:00:00 2001 From: Kevin Tchang Date: Tue, 20 Aug 2024 13:25:22 +1000 Subject: [PATCH 28/34] fix --- .../resource_kubernetes_agent_worker_integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octopusdeploy/resource_kubernetes_agent_worker_integration_test.go b/octopusdeploy/resource_kubernetes_agent_worker_integration_test.go index a290691a6..3db53bb01 100644 --- a/octopusdeploy/resource_kubernetes_agent_worker_integration_test.go +++ b/octopusdeploy/resource_kubernetes_agent_worker_integration_test.go @@ -40,7 +40,7 @@ func TestKubernetesAgentWorkerResource(t *testing.T) { } // Assert - client, err := octoclient.CreateClient(octoContainer.URI, newSpaceId, key) + client, err := octoclient.CreateClient(octoContainer.URI, newSpaceId, test.ApiKey) query := machines.WorkersQuery{ CommunicationStyles: []string{"KubernetesTentacle"}, Skip: 0, From 63b04120d65d8718ac8c47ea9c1d7c8b5ea80057 Mon Sep 17 00:00:00 2001 From: Kevin Tchang Date: Wed, 21 Aug 2024 13:48:36 +1000 Subject: [PATCH 29/34] use space aware go client functions --- go.mod | 2 +- go.sum | 4 ++-- octopusdeploy/resource_kubernetes_agent_worker.go | 13 +++++++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index cd8a3a059..1d574617d 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/OctopusDeploy/terraform-provider-octopusdeploy go 1.21 require ( - github.com/OctopusDeploy/go-octopusdeploy/v2 v2.49.2 + github.com/OctopusDeploy/go-octopusdeploy/v2 v2.50.0 github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240729041805-46db6fb717b4 github.com/google/uuid v1.6.0 github.com/hashicorp/go-cty v1.4.1-0.20200723130312-85980079f637 diff --git a/go.sum b/go.sum index cfe020223..066bca243 100644 --- a/go.sum +++ b/go.sum @@ -20,8 +20,8 @@ github.com/Microsoft/hcsshim v0.12.4 h1:Ev7YUMHAHoWNm+aDSPzc5W9s6E2jyL1szpVDJeZ/ github.com/Microsoft/hcsshim v0.12.4/go.mod h1:Iyl1WVpZzr+UkzjekHZbV8o5Z9ZkxNGx6CtY2Qg/JVQ= github.com/OctopusDeploy/go-octodiff v1.0.0 h1:U+ORg6azniwwYo+O44giOw6TiD5USk8S4VDhOQ0Ven0= github.com/OctopusDeploy/go-octodiff v1.0.0/go.mod h1:Mze0+EkOWTgTmi8++fyUc6r0aLZT7qD9gX+31t8MmIU= -github.com/OctopusDeploy/go-octopusdeploy/v2 v2.49.2 h1:ENd1MyQbYIDiW1ZyXRUcZr4OQ0d8j47I5a6DOT9Ez4o= -github.com/OctopusDeploy/go-octopusdeploy/v2 v2.49.2/go.mod h1:ggvOXzMnq+w0pLg6C9zdjz6YBaHfO3B3tqmmB7JQdaw= +github.com/OctopusDeploy/go-octopusdeploy/v2 v2.50.0 h1:rQiLEbqt/D3lPQw3pq9sXAW1C0WhVLrfN/h0cqUzaFY= +github.com/OctopusDeploy/go-octopusdeploy/v2 v2.50.0/go.mod h1:ggvOXzMnq+w0pLg6C9zdjz6YBaHfO3B3tqmmB7JQdaw= github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240729041805-46db6fb717b4 h1:QfbVf0bOIRMp/WHAWsuVDB7KHoWnRsGbvDuOf2ua7k4= github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240729041805-46db6fb717b4/go.mod h1:Oq9KbiRNDBB5jFmrwnrgLX0urIqR/1ptY18TzkqXm7M= github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg= diff --git a/octopusdeploy/resource_kubernetes_agent_worker.go b/octopusdeploy/resource_kubernetes_agent_worker.go index ed5fab11b..e761f3e13 100644 --- a/octopusdeploy/resource_kubernetes_agent_worker.go +++ b/octopusdeploy/resource_kubernetes_agent_worker.go @@ -3,6 +3,7 @@ package octopusdeploy import ( "context" "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/workers" "github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -23,7 +24,7 @@ func resourceKubernetesAgentWorker() *schema.Resource { func resourceKubernetesAgentWorkerCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { worker := expandKubernetesAgentWorker(d) client := m.(*client.Client) - createdWorker, err := client.Workers.Add(worker) + createdWorker, err := workers.Add(client, worker) if err != nil { return diag.FromErr(err) } @@ -34,7 +35,7 @@ func resourceKubernetesAgentWorkerCreate(ctx context.Context, d *schema.Resource func resourceKubernetesAgentWorkerRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*client.Client) - Worker, err := client.Workers.GetByID(d.Id()) + Worker, err := workers.GetByID(client, d.Get("space_id").(string), d.Id()) if err != nil { return errors.ProcessApiError(ctx, d, err, "kubernetes tentacle worker") } @@ -54,7 +55,7 @@ func resourceKubernetesAgentWorkerRead(ctx context.Context, d *schema.ResourceDa func resourceKubernetesAgentWorkerDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*client.Client) - if err := client.Workers.DeleteByID(d.Id()); err != nil { + if err := workers.DeleteByID(client, d.Get("space_id").(string), d.Id()); err != nil { return diag.FromErr(err) } d.SetId("") @@ -62,12 +63,12 @@ func resourceKubernetesAgentWorkerDelete(ctx context.Context, d *schema.Resource } func resourceKubernetesAgentWorkerUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - Worker := expandKubernetesAgentWorker(d) + worker := expandKubernetesAgentWorker(d) client := m.(*client.Client) - Worker.ID = d.Id() + worker.ID = d.Id() - updatedWorker, err := client.Workers.Update(Worker) + updatedWorker, err := workers.Update(client, worker) if err != nil { return diag.FromErr(err) } From 5cecf88c77b0927b3ce3518ae478da14d7d1dd8b Mon Sep 17 00:00:00 2001 From: Kevin Tchang Date: Wed, 21 Aug 2024 13:56:50 +1000 Subject: [PATCH 30/34] regenerate docs to pass the doc validation github action --- docs/data-sources/kubernetes_agent_workers.md | 3 ++- docs/resources/kubernetes_agent_worker.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/data-sources/kubernetes_agent_workers.md b/docs/data-sources/kubernetes_agent_workers.md index 8f528528b..732a53825 100644 --- a/docs/data-sources/kubernetes_agent_workers.md +++ b/docs/data-sources/kubernetes_agent_workers.md @@ -1,6 +1,7 @@ --- +# generated by https://github.com/hashicorp/terraform-plugin-docs page_title: "octopusdeploy_kubernetes_agent_workers Data Source - terraform-provider-octopusdeploy" -subcategory: "Workers" +subcategory: "" description: |- Provides information about existing kubernetes agent workers. --- diff --git a/docs/resources/kubernetes_agent_worker.md b/docs/resources/kubernetes_agent_worker.md index 7b391bb09..436f44c08 100644 --- a/docs/resources/kubernetes_agent_worker.md +++ b/docs/resources/kubernetes_agent_worker.md @@ -1,6 +1,7 @@ --- +# generated by https://github.com/hashicorp/terraform-plugin-docs page_title: "octopusdeploy_kubernetes_agent_worker Resource - terraform-provider-octopusdeploy" -subcategory: "Workers" +subcategory: "" description: |- This resource manages Kubernetes agent workers in Octopus Deploy. --- From 0dc91ee1c647bb082d2ff033a71b31a9f5e9eb3c Mon Sep 17 00:00:00 2001 From: Kevin Tchang Date: Wed, 21 Aug 2024 14:07:59 +1000 Subject: [PATCH 31/34] try add newline --- docs/data-sources/kubernetes_agent_workers.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/data-sources/kubernetes_agent_workers.md b/docs/data-sources/kubernetes_agent_workers.md index 732a53825..13e3d8b1b 100644 --- a/docs/data-sources/kubernetes_agent_workers.md +++ b/docs/data-sources/kubernetes_agent_workers.md @@ -54,3 +54,5 @@ Read-Only: - `upgrade_locked` (Boolean) If enabled the Kubernetes agent will not automatically upgrade and will stay on the currently installed version, even if the associated machine policy is configured to automatically upgrade. - `uri` (String) The URI of the Kubernetes agent's used by the server to queue messages. This is the same subscription uri that was used when installing the agent. - `worker_pool_ids` (List of String) A list of worker pool Ids specifying the pools in which this worker belongs + + From 7e4a4d7ee9374711d1d11dadb9dd4d9ed7e61a00 Mon Sep 17 00:00:00 2001 From: Kevin Tchang Date: Wed, 21 Aug 2024 14:17:16 +1000 Subject: [PATCH 32/34] isolate test container --- ...ource_kubernetes_agent_worker_integration_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/octopusdeploy/resource_kubernetes_agent_worker_integration_test.go b/octopusdeploy/resource_kubernetes_agent_worker_integration_test.go index 3db53bb01..d6c109563 100644 --- a/octopusdeploy/resource_kubernetes_agent_worker_integration_test.go +++ b/octopusdeploy/resource_kubernetes_agent_worker_integration_test.go @@ -21,26 +21,26 @@ func TestKubernetesAgentWorkerResource(t *testing.T) { } // Use separate Octopus container as this test requires a custom environment variable to be set - octoContainer, octoClient, sqlServerContainer, network, err = testFramework.ArrangeContainer() + testSpecificOctoContainer, _, testSpecificSqlServerContainer, testSpecificNetwork, err := testFramework.ArrangeContainer() if err != nil { log.Printf("Failed to arrange containers: (%s)", err.Error()) } os.Setenv("TF_ACC", "1") - inputVars := []string{"-var=octopus_server_58-kubernetesagentworker=" + octoContainer.URI, "-var=octopus_apikey_58-kubernetesagentworker=" + test.ApiKey} + inputVars := []string{"-var=octopus_server_58-kubernetesagentworker=" + testSpecificOctoContainer.URI, "-var=octopus_apikey_58-kubernetesagentworker=" + test.ApiKey} - newSpaceId, err := testFramework.Act(t, octoContainer, "../terraform", "58-kubernetesagentworker", inputVars) + newSpaceId, err := testFramework.Act(t, testSpecificOctoContainer, "../terraform", "58-kubernetesagentworker", inputVars) if err != nil { t.Fatal(err.Error()) } - err = testFramework.TerraformInitAndApply(t, octoContainer, filepath.Join("../terraform", "58a-kubernetesagentworkerds"), newSpaceId, inputVars) + err = testFramework.TerraformInitAndApply(t, testSpecificOctoContainer, filepath.Join("../terraform", "58a-kubernetesagentworkerds"), newSpaceId, inputVars) if err != nil { t.Fatal(err.Error()) } // Assert - client, err := octoclient.CreateClient(octoContainer.URI, newSpaceId, test.ApiKey) + client, err := octoclient.CreateClient(testSpecificOctoContainer.URI, newSpaceId, test.ApiKey) query := machines.WorkersQuery{ CommunicationStyles: []string{"KubernetesTentacle"}, Skip: 0, @@ -99,7 +99,7 @@ func TestKubernetesAgentWorkerResource(t *testing.T) { // Waiting for the container logs to clear. time.Sleep(5000 * time.Millisecond) - err = testFramework.CleanUp(ctx, octoContainer, sqlServerContainer, network) + err = testFramework.CleanUp(ctx, testSpecificOctoContainer, testSpecificSqlServerContainer, testSpecificNetwork) if err != nil { log.Printf("Failed to clean up containers: (%s)", err.Error()) From 318d6b906be0d8adfd618d8570ccb2171b9f91b2 Mon Sep 17 00:00:00 2001 From: Kevin Tchang Date: Fri, 23 Aug 2024 10:10:10 +1000 Subject: [PATCH 33/34] data source result must not be optional --- docs/data-sources/kubernetes_agent_workers.md | 36 +++++++++---------- .../schema_kubernetes_agent_worker.go | 2 +- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/docs/data-sources/kubernetes_agent_workers.md b/docs/data-sources/kubernetes_agent_workers.md index 13e3d8b1b..7aad25cba 100644 --- a/docs/data-sources/kubernetes_agent_workers.md +++ b/docs/data-sources/kubernetes_agent_workers.md @@ -32,27 +32,25 @@ Provides information about existing kubernetes agent workers. ### Read-Only - `id` (String) An auto-generated identifier that includes the timestamp when this data source was last modified. -- `kubernetes_agent_workers` (Block List) A list of kubernetes agent workers that match the filter(s). (see [below for nested schema](#nestedblock--kubernetes_agent_workers)) +- `kubernetes_agent_workers` (List of Object) A list of kubernetes agent workers that match the filter(s). (see [below for nested schema](#nestedatt--kubernetes_agent_workers)) - + ### Nested Schema for `kubernetes_agent_workers` Read-Only: -- `agent_helm_release_name` (String) Name of the Helm release that the agent belongs to. -- `agent_kubernetes_namespace` (String) Name of the Kubernetes namespace where the agent is installed. -- `agent_tentacle_version` (String) Current Tentacle version of the agent -- `agent_upgrade_status` (String) Current upgrade availability status of the agent. One of 'NoUpgrades', 'UpgradeAvailable', 'UpgradeSuggested', 'UpgradeRequired' -- `agent_version` (String) Current Helm chart version of the agent. -- `communication_mode` (String) The communication mode used by the Kubernetes agent to communicate with Octopus Server. Currently, the only supported value is 'Polling'. -- `id` (String) The unique ID for this resource. -- `is_disabled` (Boolean) Whether the Kubernetes agent is disabled. If the agent is disabled, it will not be included in any deployments. -- `machine_policy_id` (String) Optional ID of the machine policy that the Kubernetes agent will use. If not provided the default machine policy will be used. -- `name` (String) The name of this resource. -- `space_id` (String) The space ID associated with this resource. -- `thumbprint` (String) The thumbprint of the Kubernetes agent's certificate used by server to verify the identity of the agent. This is the same thumbprint that was used when installing the agent. -- `upgrade_locked` (Boolean) If enabled the Kubernetes agent will not automatically upgrade and will stay on the currently installed version, even if the associated machine policy is configured to automatically upgrade. -- `uri` (String) The URI of the Kubernetes agent's used by the server to queue messages. This is the same subscription uri that was used when installing the agent. -- `worker_pool_ids` (List of String) A list of worker pool Ids specifying the pools in which this worker belongs - - +- `agent_helm_release_name` (String) +- `agent_kubernetes_namespace` (String) +- `agent_tentacle_version` (String) +- `agent_upgrade_status` (String) +- `agent_version` (String) +- `communication_mode` (String) +- `id` (String) +- `is_disabled` (Boolean) +- `machine_policy_id` (String) +- `name` (String) +- `space_id` (String) +- `thumbprint` (String) +- `upgrade_locked` (Boolean) +- `uri` (String) +- `worker_pool_ids` (List of String) diff --git a/octopusdeploy/schema_kubernetes_agent_worker.go b/octopusdeploy/schema_kubernetes_agent_worker.go index a00df428a..8c6f1e753 100644 --- a/octopusdeploy/schema_kubernetes_agent_worker.go +++ b/octopusdeploy/schema_kubernetes_agent_worker.go @@ -146,7 +146,7 @@ func getKubernetesAgentWorkerDataSchema() map[string]*schema.Schema { Computed: true, Description: "A list of kubernetes agent workers that match the filter(s).", Elem: &schema.Resource{Schema: dataSchema}, - Optional: true, + Optional: false, Type: schema.TypeList, } From a7cfbf9579c0d6a78ff41f577978105e881c564c Mon Sep 17 00:00:00 2001 From: Kevin Tchang Date: Fri, 23 Aug 2024 10:13:35 +1000 Subject: [PATCH 34/34] put newline back so validate docs is happy --- docs/data-sources/kubernetes_agent_workers.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/data-sources/kubernetes_agent_workers.md b/docs/data-sources/kubernetes_agent_workers.md index 7aad25cba..332ac9598 100644 --- a/docs/data-sources/kubernetes_agent_workers.md +++ b/docs/data-sources/kubernetes_agent_workers.md @@ -54,3 +54,5 @@ Read-Only: - `upgrade_locked` (Boolean) - `uri` (String) - `worker_pool_ids` (List of String) + +