OctopusDeployLabs / terraform-provider-octopusdeploy

Terraform Provider for Octopus Deploy :octopus:
https://registry.terraform.io/providers/OctopusDeployLabs/octopusdeploy
Mozilla Public License 2.0
83 stars 67 forks source link

Create kubectl script process problem #276

Open MiguelNdeCarvalho opened 2 years ago

MiguelNdeCarvalho commented 2 years ago

Describe the bug The first time I apply the code it works just fine. If I try to do another terraform apply it just fails.

Terraform code

resource "octopusdeploy_deployment_process" "all" {

  project_id = "Projects-41"
  step {
    name                = "Set image"
    condition           = "Success"
    package_requirement = "LetOctopusDecide"
    start_trigger       = "StartAfterPrevious"
    target_roles        = ["dev", "prod", "qa"]

    action {
      name           = "Deploy to K8s"
      is_required    = true
      action_type    = "Octopus.KubernetesRunScript"
      worker_pool_id = "WorkerPools-22"
      container {
        feed_id = "Feeds-1021"
        image   = "octopusdeploy/worker-tools:3.2.0-ubuntu.18.04"
      }
      properties = {
        run_on_server                                   = true
        "Octopus.Action.Script.ScriptBody"              = "kubectl set image deployment/nginx-deployment nginx=nginx:$(get_octopusvariable \"Octopus.Release.Number\")"
        "Octopus.Action.Script.Syntax"                  = "Bash"
        "Octopus.Action.KubernetesContainers.Namespace" = "teste"
      }
    }
  }
}

Logs and other supporting information terraform plan:

Terraform detected the following changes made outside of Terraform since the last "terraform apply":

  # octopusdeploy_deployment_process.all has been changed
  ~ resource "octopusdeploy_deployment_process" "all" {
        id         = "deploymentprocess-Projects-41"
        # (3 unchanged attributes hidden)

      ~ step {
            id                  = "aeb3b986-f27b-4c14-b57d-d890875292e0"
            name                = "Set image"
            # (5 unchanged attributes hidden)

          - action {
              - action_type                        = "Octopus.KubernetesRunScript" -> null
              - can_be_used_for_project_versioning = false -> null
              - channels                           = [] -> null
              - environments                       = [] -> null
              - excluded_environments              = [] -> null
              - features                           = [] -> null
              - is_disabled                        = false -> null
              - is_required                        = true -> null
              - name                               = "Deploy to K8s" -> null
              - properties                         = {
                  - "Octopus.Action.KubernetesContainers.Namespace" = "teste"
                  - "Octopus.Action.Script.ScriptBody"              = "kubectl set image deployment/nginx-deployment nginx=nginx:$(get_octopusvariable \"Octopus.Release.Number\")"
                  - "Octopus.Action.Script.Syntax"                  = "Bash"
                  - "run_on_server"                                 = "true"
                } -> null
              - run_on_server                      = false -> null
              - tenant_tags                        = [] -> null
              - worker_pool_id                     = "WorkerPools-22" -> null

              - container {
                  - feed_id = "Feeds-1021" -> null
                  - image   = "octopusdeploy/worker-tools:3.2.0-ubuntu.18.04" -> null
                }
            }

            # (1 unchanged block hidden)
        }
    }

Unless you have made equivalent changes to your configuration, or ignored the relevant attributes using ignore_changes, the following plan may
include actions to undo or respond to these changes.

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # octopusdeploy_deployment_process.all will be updated in-place
  ~ resource "octopusdeploy_deployment_process" "all" {
        id         = "deploymentprocess-Projects-41"
        # (3 unchanged attributes hidden)

      ~ step {
            id                  = "aeb3b986-f27b-4c14-b57d-d890875292e0"
            name                = "Set image"
            # (5 unchanged attributes hidden)

          + action {
              + action_type           = "Octopus.KubernetesRunScript"
              + channels              = (known after apply)
              + environments          = (known after apply)
              + excluded_environments = (known after apply)
              + features              = (known after apply)
              + is_disabled           = false
              + is_required           = true
              + name                  = "Deploy to K8s"
              + properties            = {
                  + "Octopus.Action.KubernetesContainers.Namespace" = "teste"
                  + "Octopus.Action.Script.ScriptBody"              = "kubectl set image deployment/nginx-deployment nginx=nginx:$(get_octopusvariable \"Octopus.Release.Number\")"
                  + "Octopus.Action.Script.Syntax"                  = "Bash"
                  + "run_on_server"                                 = "true"
                }
              + run_on_server         = false
              + tenant_tags           = (known after apply)
              + worker_pool_id        = "WorkerPools-22"

              + action_template {
                  + community_action_template_id = (known after apply)
                  + id                           = (known after apply)
                  + version                      = (known after apply)
                }

              + container {
                  + feed_id = "Feeds-1021"
                  + image   = "octopusdeploy/worker-tools:3.2.0-ubuntu.18.04"
                }

              + package {
                  + acquisition_location      = (known after apply)
                  + extract_during_deployment = (known after apply)
                  + feed_id                   = (known after apply)
                  + id                        = (known after apply)
                  + name                      = (known after apply)
                  + package_id                = (known after apply)
                  + properties                = (known after apply)
                }

              + primary_package {
                  + acquisition_location = (known after apply)
                  + feed_id              = (known after apply)
                  + id                   = (known after apply)
                  + name                 = (known after apply)
                  + package_id           = (known after apply)
                  + properties           = (known after apply)
                }
            }

            # (1 unchanged block hidden)
        }
    }

Plan: 0 to add, 1 to change, 0 to destroy.

terraform apply:

  # octopusdeploy_deployment_process.all has been changed
  ~ resource "octopusdeploy_deployment_process" "all" {
        id         = "deploymentprocess-Projects-41"
        # (3 unchanged attributes hidden)

      ~ step {
            id                  = "aeb3b986-f27b-4c14-b57d-d890875292e0"
            name                = "Set image"
            # (5 unchanged attributes hidden)

          - action {
              - action_type                        = "Octopus.KubernetesRunScript" -> null
              - can_be_used_for_project_versioning = false -> null
              - channels                           = [] -> null
              - environments                       = [] -> null
              - excluded_environments              = [] -> null
              - features                           = [] -> null
              - is_disabled                        = false -> null
              - is_required                        = true -> null
              - name                               = "Deploy to K8s" -> null
              - properties                         = {
                  - "Octopus.Action.KubernetesContainers.Namespace" = "teste"
                  - "Octopus.Action.Script.ScriptBody"              = "kubectl set image deployment/nginx-deployment nginx=nginx:$(get_octopusvariable \"Octopus.Release.Number\")"
                  - "Octopus.Action.Script.Syntax"                  = "Bash"
                  - "run_on_server"                                 = "true"
                } -> null
              - run_on_server                      = false -> null
              - tenant_tags                        = [] -> null
              - worker_pool_id                     = "WorkerPools-22" -> null

              - container {
                  - feed_id = "Feeds-1021" -> null
                  - image   = "octopusdeploy/worker-tools:3.2.0-ubuntu.18.04" -> null
                }
            }

            # (1 unchanged block hidden)
        }
    }

Unless you have made equivalent changes to your configuration, or ignored the relevant attributes using ignore_changes, the following plan may
include actions to undo or respond to these changes.

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # octopusdeploy_deployment_process.all will be updated in-place
  ~ resource "octopusdeploy_deployment_process" "all" {
        id         = "deploymentprocess-Projects-41"
        # (3 unchanged attributes hidden)

      ~ step {
            id                  = "aeb3b986-f27b-4c14-b57d-d890875292e0"
            name                = "Set image"
            # (5 unchanged attributes hidden)

          + action {
              + action_type           = "Octopus.KubernetesRunScript"
              + channels              = (known after apply)
              + environments          = (known after apply)
              + excluded_environments = (known after apply)
              + features              = (known after apply)
              + is_disabled           = false
              + is_required           = true
              + name                  = "Deploy to K8s"
              + properties            = {
                  + "Octopus.Action.KubernetesContainers.Namespace" = "teste"
                  + "Octopus.Action.Script.ScriptBody"              = "kubectl set image deployment/nginx-deployment nginx=nginx:$(get_octopusvariable \"Octopus.Release.Number\")"
                  + "Octopus.Action.Script.Syntax"                  = "Bash"
                  + "run_on_server"                                 = "true"
                }
              + run_on_server         = false
              + tenant_tags           = (known after apply)
              + worker_pool_id        = "WorkerPools-22"

              + action_template {
                  + community_action_template_id = (known after apply)
                  + id                           = (known after apply)
                  + version                      = (known after apply)
                }

              + container {
                  + feed_id = "Feeds-1021"
                  + image   = "octopusdeploy/worker-tools:3.2.0-ubuntu.18.04"
                }

              + package {
                  + acquisition_location      = (known after apply)
                  + extract_during_deployment = (known after apply)
                  + feed_id                   = (known after apply)
                  + id                        = (known after apply)
                  + name                      = (known after apply)
                  + package_id                = (known after apply)
                  + properties                = (known after apply)
                }

              + primary_package {
                  + acquisition_location = (known after apply)
                  + feed_id              = (known after apply)
                  + id                   = (known after apply)
                  + name                 = (known after apply)
                  + package_id           = (known after apply)
                  + properties           = (known after apply)
                }
            }

            # (1 unchanged block hidden)
        }
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

octopusdeploy_deployment_process.all: Modifying... [id=deploymentprocess-Projects-41]
╷
│ Error: octopus deploy api returned an error on endpoint /api/Spaces-1/deploymentprocesses/deploymentprocess-Projects-41 - [Providing a script body is not valid for scripts from a package. Providing a script syntax is not valid for scripts from a package. 'Package' was selected as the script-source but a primary package was not selected. Please provide a script file name. Action name 'Deploy to K8s' is already in use by another action in this deployment process. Action names must be unique.]
│ 
│   with octopusdeploy_deployment_process.all,
│   on deployment_process.tf line 1, in resource "octopusdeploy_deployment_process" "all":
│    1: resource "octopusdeploy_deployment_process" "all" {

Environment and versions:

peterprice commented 2 years ago

I've just noticed this myself, while trying to reapply a template containing an octopusdeploy_deployment_process with a generic action block:

Action name 'Apply a Terraform template' is already in use by another action in this deployment process. Action names must be unique.
pessoa commented 2 years ago

Also getting: Error: octopus deploy api returned an error on endpoint /api/Spaces-1/projects/Projects-39/deploymentprocesses - [Providing a script body is not valid for scripts from a package. Providing a script syntax is not valid for scripts from a package. 'Packag e' was selected as the script-source but a primary package was not selected. Please provide a script file name. when applying

# octopusdeploy_deployment_process.all["service"] will be updated in-place
 ~ resource "octopusdeploy_deployment_process" "all" {
       id         = "deploymentprocess-Projects-39"
       # (3 unchanged attributes hidden)

     ~ step {
           id                  = "X"
           name                = "Set image on for auth-service"
         ~ target_roles        = [
               # (2 unchanged elements hidden)
               "demo",
             + "test",
           ]
           # (4 unchanged attributes hidden)

           # (1 unchanged block hidden)
       }
       # (1 unchanged block hidden)
   }

I had to delete all the the process steps and apply again.

marco-os commented 1 year ago

I am also getting the same error. Deleting all the process steps and applying again works.

However, every terraform apply that touches the file where the code for this step is stored will run into the issue again. This makes the delete/re-apply workaround not sustainable for us, as we manage all our infrastructure entirely with terraform.