OctopusDeployLabs / terraform-provider-octopusdeploy

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

Updating a project with versioning or release creation based on a Package step fails #136

Open albanf opened 3 years ago

albanf commented 3 years ago

I'm trying to synchronize existing projects so that I can modify them later.

So I'm defining projects and deployment processes this way:

resource "octopusdeploy_project" "terraform-stack" {
  for_each = var.tf_projects
  name     = "Infrastructure - ${each.value.stack}"

  ...
}

resource "octopusdeploy_deployment_process" "terraform-stack" {
  for_each = var.tf_projects

  project_id = octopusdeploy_project.terraform-stack[each.key].id
  ...

  step {
    name                = "Package"
    ...
  }
}

And then running terraform import to map with existing resources.

When I run terraform apply, I get this error: 'Package' could not be deleted because it is used as part of the release creation strategy. I've tried defining the Package step with deploy_package_action, and with a standard action, both fail. I've tried to use the existing ids, although it's not practical because my goal would be to synchronize about 60 projects using the same deployment process, so I would like another "key" to match the steps, also so that steps can be re-ordered.

albanf commented 3 years ago

I made additional tests with a new project, instead of trying to import an existing project, and the result is the same.

resource "octopusdeploy_project" "test-project" {
  name = "Test basic project"

  lifecycle_id     = octopusdeploy_lifecycle.Default.id
}

resource "octopusdeploy_deployment_process" "test-project" {
  project_id = octopusdeploy_project.test-project.id

  step {
    name = "Package"

    target_roles = [
      "Servers"]
    properties   = {
      "Octopus.Action.TargetRoles" = "Servers"
    }

    deploy_package_action {
      name = "Package"
      can_be_used_for_project_versioning = true
      primary_package {
        feed_id = "feeds-builtin"
        package_id = "Application.Package"
      }
    }
  }
}

At that point it works, but I can see that every time I run terraform apply, the id of the step changes (I checked with the REST API, but it's probably also visible in terraform state show octopusdeploy_deployment_process.test-project.

Then once I change the project to this:

resource "octopusdeploy_project" "test-project" {
  name = "Test basic project"

  lifecycle_id     = octopusdeploy_lifecycle.Default.id

  auto_create_release = true

    versioning_strategy {
      donor_package {
        deployment_action = "Package"
        package_reference = ""
      }
    }
}

terraform apply works once, and then I get the error message ['Package' could not be deleted because it is used as part of the release versioning strategy.] Removing the versioning_strategy block does not fix the issue, maybe because the deployment_process updates fails first.