terraform-provider-octopusdeploy icon indicating copy to clipboard operation
terraform-provider-octopusdeploy copied to clipboard

Field worker_pool_variable does not persist to deployment process action

Open nkilzer opened this issue 2 years ago • 0 comments
trafficstars

Describe the bug It is not possible to create a deployment process action step using a generic action block (necessary for actions that are not yet natively supported by the terraform provider) that uses a worker pool variable instead of a single worker pool id.

While a workaround is to set the value in the UI after creating the project, this value gets reset each time the project is applied since the steps and actions are recreated instead of being updated, which makes it difficult to manage a whole space with many projects from a single overall configuration.

Steps to reproduce

  1. Create a configuration with a project and a variable of type Worker Pool
  2. Add a step block + (generic) action block to the associated octopusdeploy_deployment_process 2.a In the observed case, the action_type is Octopus.KubernetesDeployContainers
  3. Set the field step/action/worker_pool_variable to the name of the worker pool variable
  4. Apply the configuration to an instance, and observe that the worker pool value remains on the default worker pool for the instance.

Expected behavior The worker_pool_variable setting should be applied to the step, and set the used worker pool.

Logs and other supporting information Output of Terraform Plan with new variable ("k8s.workers"), even after an apply cycle:

# module.app.octopusdeploy_deployment_process.process will be updated in-place
  ~ resource "octopusdeploy_deployment_process" "process" {
        id         = "deploymentprocess-Projects-21"
        # (3 unchanged attributes hidden)

      ~ step {
            id                  = "f7dff6f7-fd0d-4ef5-b1fb-b56e404c7ad0"
            name                = "Deploy app container"
            # (5 unchanged attributes hidden)

          ~ action {
                id                                 = "c8eee967-5947-43ba-b4d6-3c842976685c"
                name                               = "Deploy app container"
              + worker_pool_variable               = "k8s.workers"
                # (12 unchanged attributes hidden)

                # (2 unchanged blocks hidden)
            }
        }
      ~ step {
            id                  = "791f4313-c3a3-4eed-9015-7bca55bd3526"
            name                = "Deploy external ingress"
            # (5 unchanged attributes hidden)

          ~ action {
                id                                 = "c50e7494-4956-4d46-9462-d8d1b6a1bf05"
                name                               = "Deploy external ingress"
              + worker_pool_variable               = "k8s.workers"
                # (12 unchanged attributes hidden)

                # (1 unchanged block hidden)
            }
        }
    }

Screenshots image

Environment and versions:

  • OS: Linux (Debian, Docker on Windows)
  • Octopus Server Version: Octopus Cloud (v2023.2 build 2028)
  • Terraform Version: v1.4.0
  • Octopus Terraform Provider Version: v0.11.1

Additional context This appears to be due to not expanding worker_pool_variable in schema_deployment_action.go, along the lines of the expansion of worker_pool_id, but since the worker pool schema items are added dynamically, and are not part of the generic action schema, it's unclear if this is the correct place for it.

https://github.com/OctopusDeployLabs/terraform-provider-octopusdeploy/blob/main/octopusdeploy/schema_deployment_action.go#L447-L449

The value does appear to be flattened correctly by the provider when retrieving it from the server, so the plan doesn't show a diff. This results in a silent configuration change when the step/action pair are recreated (not updated, as is implied) during the apply phase.

Setting this property via the UI (at least for Octopus Cloud) also seems to have some additional interaction with the run_on_server field and Octopus.Action.RunOnServer property when replanning the configuration. The value of the property gets reset to true on the server, but when planning, the diff renders with a removal of the property from the state altogether (as shown in the first step here - only one of two was changed on the server).

# module.app.octopusdeploy_deployment_process.process will be updated in-place
  ~ resource "octopusdeploy_deployment_process" "process" {
        id         = "deploymentprocess-Projects-21"
        # (3 unchanged attributes hidden)

      ~ step {
            id                  = "00c8ff81-b0bb-41f8-9792-8b6fee6e8331"
            name                = "Deploy app container"
            # (5 unchanged attributes hidden)

          ~ action {
                id                                 = "69a26c54-533d-4d11-9dbf-d2111e16afa3"
                name                               = "Deploy app container"
              ~ properties                         = {
                  - "Octopus.Action.RunOnServer"                                  = "true" -> null
                    # (28 unchanged elements hidden)
                }
                # (12 unchanged attributes hidden)

                # (2 unchanged blocks hidden)
            }
        }
      ~ step {
            id                  = "21b27eae-922a-4f1c-835d-a677f0539ae8"
            name                = "Deploy external ingress"
            # (5 unchanged attributes hidden)

          ~ action {
                id                                 = "2dee5059-5f6e-4410-8969-ee681b329846"
                name                               = "Deploy external ingress"
              + worker_pool_variable               = "k8s.workers"
                # (12 unchanged attributes hidden)

                # (1 unchanged block hidden)
            }
        }
    }

If more information is required, please feel free to reach out. Thanks for the work so far on the provider!

nkilzer avatar Mar 16 '23 02:03 nkilzer