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

How do you target the Default channel of a project?

Open ArturDorochowicz opened this issue 2 years ago • 2 comments
trafficstars

Describe the bug There may be some tf-fu that I'm missing, but how do you target the Default channel of a project?

Creating a project automatically creates a default channel called "Default". As far as I understand it will have the lifecycle inherited from the project, so we can control that property at the project level with lifecycle_id. But what about other properties, e.g. description or rules?

Steps to reproduce

Let's say I want to set something as simple as description on the Default channel:

resource "octopusdeploy_project" "test" {
  name = "Test Project"
 
  project_group_id = octopusdeploy_project_group.test.id
  lifecycle_id = octopusdeploy_lifecycle.test.id
}
 
resource "octopusdeploy_project_group" "test" {
  name = "Test Project Group"
}
 
resource "octopusdeploy_lifecycle" "test" {
  name = "Test Lifecycle"
}

# --> this will cause failure; how to make it work?
resource "octopusdeploy_channel" "default" {
  name = "Default"
  description = "custom description"
  project_id = octopusdeploy_project.test.id
}

Applying this fails with A channel with this name already exists for this project. Please choose a different name.

$>  terraform apply -auto-approve
 
[...]
 
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following    
symbols:
  + create
 
Terraform will perform the following actions:
 
  # octopusdeploy_channel.default will be created
  + resource "octopusdeploy_channel" "default" {
      + description = "custom description"
      + id          = (known after apply)
      + name        = "Default"
      + project_id  = (known after apply)
      + space_id    = (known after apply)
      + tenant_tags = (known after apply)
    }
 
  # octopusdeploy_lifecycle.test will be created
  + resource "octopusdeploy_lifecycle" "test" {
      + id       = (known after apply)
      + name     = "Test Lifecycle"
      + space_id = (known after apply)
 
      + phase {
          + automatic_deployment_targets          = (known after apply)
          + id                                    = (known after apply)
          + is_optional_phase                     = (known after apply)
          + minimum_environments_before_promotion = (known after apply)
          + name                                  = (known after apply)
          + optional_deployment_targets           = (known after apply)
 
          + release_retention_policy {
              + quantity_to_keep    = (known after apply)
              + should_keep_forever = (known after apply)
              + unit                = (known after apply)
            }
 
          + tentacle_retention_policy {
              + quantity_to_keep    = (known after apply)
              + should_keep_forever = (known after apply)
              + unit                = (known after apply)
            }
        }
 
      + release_retention_policy {
          + quantity_to_keep    = (known after apply)
          + should_keep_forever = (known after apply)
          + unit                = (known after apply)
        }
 
      + tentacle_retention_policy {
          + quantity_to_keep    = (known after apply)
          + should_keep_forever = (known after apply)
          + unit                = (known after apply)
        }
    }
 
  # octopusdeploy_project.test will be created
  + resource "octopusdeploy_project" "test" {
      + auto_create_release                  = (known after apply)
      + auto_deploy_release_overrides        = (known after apply)
      + cloned_from_project_id               = (known after apply)
      + default_guided_failure_mode          = (known after apply)
      + default_to_skip_if_already_installed = (known after apply)
      + deployment_changes_template          = (known after apply)
      + deployment_process_id                = (known after apply)
      + description                          = (known after apply)
      + id                                   = (known after apply)
      + included_library_variable_sets       = (known after apply)
      + is_disabled                          = (known after apply)
      + is_discrete_channel_release          = (known after apply)
      + is_version_controlled                = (known after apply)
      + lifecycle_id                         = (known after apply)
      + name                                 = "Test Project"
      + project_group_id                     = (known after apply)
      + release_notes_template               = (known after apply)
      + slug                                 = (known after apply)
      + space_id                             = (known after apply)
      + tenanted_deployment_participation    = (known after apply)
      + variable_set_id                      = (known after apply)
 
      + connectivity_policy {
          + allow_deployments_to_no_targets = (known after apply)
          + exclude_unhealthy_targets       = (known after apply)
          + skip_machine_behavior           = (known after apply)
          + target_roles                    = (known after apply)
        }
 
      + release_creation_strategy {
          + channel_id                       = (known after apply)
          + release_creation_package_step_id = (known after apply)
 
          + release_creation_package {
              + deployment_action = (known after apply)
              + package_reference = (known after apply)
            }
        }
 
      + versioning_strategy {
          + donor_package_step_id = (known after apply)
          + template              = (known after apply)
 
          + donor_package {
              + deployment_action = (known after apply)
              + package_reference = (known after apply)
            }
        }
    }
 
  # octopusdeploy_project_group.test will be created
  + resource "octopusdeploy_project_group" "test" {
      + description         = (known after apply)
      + id                  = (known after apply)
      + name                = "Test Project Group"
      + retention_policy_id = (known after apply)
      + space_id            = (known after apply)
    }
 
Plan: 4 to add, 0 to change, 0 to destroy.
octopusdeploy_project_group.test: Creating...
octopusdeploy_lifecycle.test: Creating...
octopusdeploy_project_group.test: Creation complete after 0s [id=ProjectGroups-47]
octopusdeploy_lifecycle.test: Creation complete after 0s [id=Lifecycles-47]
octopusdeploy_project.test: Creating...
octopusdeploy_project.test: Creation complete after 1s [id=Projects-51]
octopusdeploy_channel.default: Creating...
╷
│ Error: octopus deploy api returned an error on endpoint /api/Spaces-22/channels - [A channel with this name already exists for this
project. Please choose a different name.]
│
│   with octopusdeploy_channel.default,
│   on test.tf line 16, in resource "octopusdeploy_channel" "default":
│   16: resource "octopusdeploy_channel" "default" {
│
╵

Expected behavior Have a way to modify the Default channel.

Logs and other supporting information Add the output of running tf plan or tf apply along with any errors in the Octopus Server logs.

Environment and versions:

  • OS: Windows
  • Octopus Server Version: 2022.4.8474
  • Terraform Version: 1.3.9
  • Octopus Terraform Provider Version: 0.10.5

Additional context Add any other context about the problem here.

ArturDorochowicz avatar Mar 13 '23 10:03 ArturDorochowicz

I don't think we provide a way to modify the Default Lifecycle or Channel right now - there might be some magic you could do with imports and such, but it feels yuck.

Agreed that this is a gap, and it's particularly annoying that we force you to specify a lifecycle explicitly, rather than allowing lifecycle_id to be optional, and defaulting to the default lifecycle/channel if not provided.

mjhilton avatar Sep 10 '24 05:09 mjhilton

Not sure how we would address this given the way that those defaults are handled "in the background" in the UI. Might need a bit more thinking.

mjhilton avatar Sep 10 '24 05:09 mjhilton

This has been fixed with v0.42.0 of the provider. You can now request Channel by project id using the channel data source. This will allow you to find the default channel after the project is created, you will need to ensure you use the depends_on metatag to ensure execution order.

If you believe this is still an issue please reopen it in the new repo.

On 1 June 2025, the Octopus Deploy Terraform Provider was promoted from a Labs project to a fully-supported, first-class Octopus Deploy integration.

As part of this promotion, we released v1.0 of the provider, and migrated the codebase from the OctopusDeployLabs GitHub organization to the OctopusDeploy organization. The provider also moved in the Hashicorp Terraform Registry.

New Repository: https://github.com/OctopusDeploy/ New Provider Registry Page: https://registry.terraform.io/providers/OctopusDeploy/octopusdeploy/latest/docs Migration Guide: https://registry.terraform.io/providers/OctopusDeploy/octopusdeploy/1.0.0/docs/guides/moving-from-octopus-deploy-labs-namespace We are no longer accepting contributions or issues in this repo, and we plan to archive it.

Please head over to the new repository for continued support, updates and contributions.

domenicsim1 avatar Jun 04 '25 03:06 domenicsim1