Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use a Step ID from a deployment_process in a project's versioning_strategy in the same module without a circular reference #544

Closed
Taha-cmd opened this issue Sep 27, 2023 · 2 comments · Fixed by #834
Labels

Comments

@Taha-cmd
Copy link

Describe the bug
I want my releases to be versioned the same as a package referenced by a step in my deployment process. We can configure that in the octopusdeploy_project.versioning_strategy.donor_package. However, this requires that the deployment_process already exists, which required the id from the project to be associated with. This causes a circular reference.

Steps to reproduce

terraform {
  required_version = "1.5.7"

  required_providers {
    octopusdeploy = {
      source  = "OctopusDeployLabs/octopusdeploy"
      version = "0.12.7"
    }
  }
}

provider "octopusdeploy" {
  address  = "<REDACTED>"
  api_key  = "<REDACTED>"
  space_id = "<REDACTED>"
}

resource "octopusdeploy_project" "project" {
  lifecycle_id     = "Lifecycles-1402"
  name             = "project"
  project_group_id = "ProjectGroups-1004"

  versioning_strategy {
    # donor_package_step_id = octopusdeploy_deployment_process.process.step[0].id # <- this is a circular reference
    donor_package {
      deployment_action = "Hello World" # <- this step does not exist yet
      package_reference = "Package"
    }
  }
}

resource "octopusdeploy_deployment_process" "process" {
  project_id = octopusdeploy_project.project.id

  step {
    name = "Hello World"

    run_script_action {
      name                               = "Hello World"
      is_disabled                        = false
      is_required                        = true
      script_body                        = "Write-Host 'hello world'"
      script_syntax                      = "PowerShell"
      can_be_used_for_project_versioning = true

      package {
        name                      = "Package"
        feed_id                   = "Feeds-1602"
        package_id                = local.package_id
        acquisition_location      = "Server"
        extract_during_deployment = true
      }
    }
  }
}

locals {
  package_id = "<REDACTED>"
}

Expected behavior
I should be able to configure the versioning strategy for green field deployments

Logs and other supporting information
Error: Octopus API error: Resource is not found or it doesn't exist in the current space context. Please contact your administrator for more information. []

Environment and versions:

  • OS: Windows
  • Octopus Server Version: 2023.3 Build 13019
  • Terraform Version: 1.5.7
  • Octopus Terraform Provider Version: 0.12.7
@henbeibi
Copy link
Contributor

I am having the same issue, is there any progress on this issue?

@mjhilton mjhilton added kind/bug Something isn't working area/deployment-processes labels Sep 18, 2024
@mjhilton mjhilton changed the title [Maybe Bug] Circular reference between project's versioning_strategy and deployment_process Cannot use a Step ID from a deployment_process in a project's versioning_strategy in the same module without a circular reference Sep 18, 2024
@domenicsim1
Copy link
Contributor

domenicsim1 commented Dec 4, 2024

Hello 👋,
A new resource has been created in v0.37.1 to get around the circular reference (see example below). This will allow you specify the versioning strategy for an associated project. Please keep in mind that because of the underlying problems related to issue #550 this resource has some edge cases:

  • sort order must be set on the deployment process step
  • If a step changes you will get an API error. You can get around this by removing the versioning strategy and restoring it after the changes have been applied to the step.

The experience for this resource will improve when we start fixing the underlying problems for the deployment process resource, planned for Q1 2025.

resource "octopusdeploy_project_group" "tp" {
  name        = "DevOps Projects"
  description = "My DevOps projects group"
}
resource "octopusdeploy_project" "tp" {
  name             = "My DevOps Project"
  description      = "test project"
  lifecycle_id     = "Lifecycles-1"
  project_group_id = octopusdeploy_project_group.tp.id
  depends_on  = [octopusdeploy_project_group.tp]
}
resource "octopusdeploy_deployment_process" "process" {
  project_id = octopusdeploy_project.tp.id
  step {
    name = "Hello World"
    target_roles        = [ "hello-world" ]
    start_trigger       = "StartAfterPrevious"
    package_requirement = "LetOctopusDecide"
    condition           = "Success"
    run_script_action {
      name                               = "Hello World"
      is_disabled                        = false
      is_required                        = true
      script_body                        = "Write-Host 'hello world'"
      script_syntax                      = "PowerShell"
      can_be_used_for_project_versioning = true
      sort_order = 1
      package {
        name                      = "Package"
        feed_id                   = "feeds-builtin"
        package_id                = "myExpressApp"
        acquisition_location      = "Server"
        extract_during_deployment = true
      }
    }
  }
  depends_on  = [octopusdeploy_project.tp]
}
resource "octopusdeploy_project_versioning_strategy" "tp" {
  project_id = octopusdeploy_project.tp.id
  space_id = octopusdeploy_project.tp.space_id
  donor_package_step_id = octopusdeploy_deployment_process.process.step[0].run_script_action[0].id
  donor_package = {
    deployment_action = "Hello World"
    package_reference = "Package"
  }
  depends_on = [
    octopusdeploy_project_group.tp,
    octopusdeploy_deployment_process.process
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants