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

Cannot insert new steps into an existing `deployment_process` correctly #550

Open veochen-octopus opened 1 year ago

veochen-octopus commented 1 year ago

Describe the bug

Having created a deployment process with two steps, adding a new step in between the existing two steps will cause the new step to become a mixture of its own config + the original 2nd step.

Steps to reproduce

With a terraform file like the following:

resource "octopusdeploy_deployment_process" "example" {
  project_id = "Projects-61"
  step {
    name = "Hello world"
    run_script_action {
      can_be_used_for_project_versioning = false
      condition                          = "Success"
      is_disabled                        = false
      is_required                        = false
      name                               = "Hello world"
      script_syntax                      = "Bash"
      script_body                        = <<-EOT
          echo 'Hello world, using Bash'
          #TODO: Experiment with steps of your own :)
          echo '[Learn more about the types of steps available in Octopus](https://g.octopushq.com/OnboardingAddStepsLearnMore)'
        EOT
      run_on_server                      = true
      sort_order = 1
    }
  }

#   step {
#     name = "Dummy AWS CLI Step"
#     action {
#       name                  = "Dummy AWS CLI STep"
#       action_type           = "Octopus.AwsRunScript"
#       run_on_server         = true
#       environments          = ["Dev"]
#       excluded_environments = []
#       properties = {
#        "OctopusUseBundledTooling"                   = "False"
#        "Octopus.Action.Script.ScriptSource"         = "Inline",
#        "Octopus.Action.Script.Syntax"               = "PowerShell",
#        "Octopus.Action.Aws.AssumeRole"              = "False"
#        "Octopus.Action.AwsAccount.UserInstanceRole" = "True"
#        "Octopus.Action.Aws.Region"                  = "us-east-1"
#        "Octopus.Action.AwsAccount.Variable"         = "DanAWS"
#        "Octopus.Action.Script.ScriptBody"           = "Write-Host \"This is just a test\""
#        }
#        is_disabled = false
#      }
#    }

  step {
    name = "Plan to apply"
    action {
      name        = "Plan to apply"
      action_type = "Octopus.TerraformPlan"
      properties = {
        "Octopus.Action.Package.DownloadOnTentacle"             = "False"
        "Octopus.Action.Package.FeedId"                         = "feeds-builtin"
        "Octopus.Action.Package.PackageId"                      = "hello"
        "Octopus.Action.Terraform.TemplateDirectory"            = "terraform/infrastructure"
        "Octopus.Action.RunOnServer"                            = "False"
        "Octopus.Action.Terraform.PlanJsonOutput"               = "False"
        "Octopus.Action.Script.ScriptSource"                    = "Package"
        "Octopus.Action.Terraform.RunAutomaticFileSubstitution" = "False"
      }
    }
  }  
}
  1. Apply to create the deployment process with 2 steps
  2. Uncomment the 2nd step
  3. Apply to update the deployment process
  4. See error

Expected behavior Correctly updates the deployment process to have 3 steps that match the config file.

Logs and other supporting information

Error: octopus deploy api returned an error on endpoint /api/Spaces-1/projects/Projects-61/deploymentprocesses - [Providing a package is not valid for inline scripts.]
│
│   with octopusdeploy_deployment_process.example,
│   on test-steps.before.tf line 1, in resource "octopusdeploy_deployment_process" "example":
│    1: resource "octopusdeploy_deployment_process" "example" {

These are the action properties in the new step that TF sends to the server

Octopus.Action.Aws.AssumeRole: False
Octopus.Action.Aws.Region: us-east-1
Octopus.Action.AwsAccount.UserInstanceRole: True
Octopus.Action.AwsAccount.Variable: DanAWS
Octopus.Action.EnabledFeatures: 
Octopus.Action.Package.DownloadOnTentacle: False
Octopus.Action.Package.FeedId: feeds-builtin
Octopus.Action.Package.PackageId: hello
Octopus.Action.RunOnServer: True
Octopus.Action.Script.ScriptBody: Write-Host \"This is just a test\"
Octopus.Action.Script.ScriptSource: Inline
Octopus.Action.Script.Syntax: PowerShell
OctopusUseBundledTooling: False

Environment and versions:

michelle-luana commented 6 months ago

Another report [Internal Link]

mjhilton commented 1 month ago

Validated as still occurring.

Fixing this will be dependent on fixing the overall step sort order problem, which is dependent on the Terraform SDK -> Terraform Framework migration within the provider. That's on our radar to finish off this year, which should unlock a bunch of extra flexibility in how plan/apply works