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

Add Built-in trigger #846

Merged
merged 4 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions docs/resources/built_in_trigger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "octopusdeploy_built_in_trigger Resource - terraform-provider-octopusdeploy"
subcategory: ""
description: |-
This resource manages automatic release trigger based on new version of referenced package.
---

# octopusdeploy_built_in_trigger (Resource)

This resource manages automatic release trigger based on new version of referenced package.

## Example Usage

```terraform
resource "octopusdeploy_project_group" "example" {
name = "Example"
description = "Example Group"
}

resource "octopusdeploy_project" "example" {
name = "Example"
lifecycle_id = "Lifecycles-101"
project_group_id = octopusdeploy_project_group.example.id
default_guided_failure_mode = "EnvironmentDefault"
default_to_skip_if_already_installed = false
description = "Project with Built-In Trigger"
discrete_channel_release = false
is_disabled = false
is_discrete_channel_release = false
is_version_controlled = false
tenanted_deployment_participation = "Untenanted"
included_library_variable_sets = []

connectivity_policy {
allow_deployments_to_no_targets = false
exclude_unhealthy_targets = false
skip_machine_behavior = "SkipUnavailableMachines"
}
}

resource "octopusdeploy_channel" "example" {
name = "Example Channel"
project_id = octopusdeploy_project.example.id
lifecycle_id = "Lifecycles-101"
}

data "octopusdeploy_feeds" "built_in" {
feed_type = "BuiltIn"
ids = null
partial_name = ""
skip = 0
take = 1
}

resource "octopusdeploy_deployment_process" "example" {
project_id = octopusdeploy_project.example.id
step {
condition = "Success"
name = "Step One"
package_requirement = "LetOctopusDecide"
start_trigger = "StartAfterPrevious"
run_script_action {
condition = "Success"
is_disabled = false
is_required = true
name = "Action One"
script_body = <<-EOT
$ExtractedPath = $OctopusParameters["Octopus.Action.Package[my.package].ExtractedPath"]
Write-Host $ExtractedPath
EOT
run_on_server = true

package {
name = "my.package"
package_id = "my.package"
feed_id = data.octopusdeploy_feeds.built_in.feeds[0].id
acquisition_location = "Server"
extract_during_deployment = true
}
}
}
}

resource "octopusdeploy_built_in_trigger" "example" {
project_id = octopusdeploy_project.example.id
channel_id = octopusdeploy_channel.example.id

release_creation_package = {
deployment_action = "Action One"
package_reference = "my.package"
}

depends_on = [
octopusdeploy_project.example,
octopusdeploy_channel.example,
octopusdeploy_deployment_process.example
]
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `channel_id` (String) The ID of the channel in which triggered release will be created.
- `project_id` (String) The ID of the project the trigger will be attached to.
- `release_creation_package` (Attributes) Combination of deployment action and package references. (see [below for nested schema](#nestedatt--release_creation_package))

### Optional

- `release_creation_package_step_id` (String) The package step ID trigger will be listening.
- `space_id` (String) Space ID of the associated project.

<a id="nestedatt--release_creation_package"></a>
### Nested Schema for `release_creation_package`

Optional:

- `deployment_action` (String) Deployment action.
- `package_reference` (String) Package reference.


84 changes: 84 additions & 0 deletions examples/resources/octopusdeploy_built_in_trigger/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
resource "octopusdeploy_project_group" "example" {
name = "Example"
description = "Example Group"
}

resource "octopusdeploy_project" "example" {
name = "Example"
lifecycle_id = "Lifecycles-101"
project_group_id = octopusdeploy_project_group.example.id
default_guided_failure_mode = "EnvironmentDefault"
default_to_skip_if_already_installed = false
description = "Project with Built-In Trigger"
discrete_channel_release = false
is_disabled = false
is_discrete_channel_release = false
is_version_controlled = false
tenanted_deployment_participation = "Untenanted"
included_library_variable_sets = []

connectivity_policy {
allow_deployments_to_no_targets = false
exclude_unhealthy_targets = false
skip_machine_behavior = "SkipUnavailableMachines"
}
}

resource "octopusdeploy_channel" "example" {
name = "Example Channel"
project_id = octopusdeploy_project.example.id
lifecycle_id = "Lifecycles-101"
}

data "octopusdeploy_feeds" "built_in" {
feed_type = "BuiltIn"
ids = null
partial_name = ""
skip = 0
take = 1
}

resource "octopusdeploy_deployment_process" "example" {
project_id = octopusdeploy_project.example.id
step {
condition = "Success"
name = "Step One"
package_requirement = "LetOctopusDecide"
start_trigger = "StartAfterPrevious"
run_script_action {
condition = "Success"
is_disabled = false
is_required = true
name = "Action One"
script_body = <<-EOT
$ExtractedPath = $OctopusParameters["Octopus.Action.Package[my.package].ExtractedPath"]
Write-Host $ExtractedPath
EOT
run_on_server = true

package {
name = "my.package"
package_id = "my.package"
feed_id = data.octopusdeploy_feeds.built_in.feeds[0].id
acquisition_location = "Server"
extract_during_deployment = true
}
}
}
}

resource "octopusdeploy_built_in_trigger" "example" {
project_id = octopusdeploy_project.example.id
channel_id = octopusdeploy_channel.example.id

release_creation_package = {
deployment_action = "Action One"
package_reference = "my.package"
}

depends_on = [
octopusdeploy_project.example,
octopusdeploy_channel.example,
octopusdeploy_deployment_process.example
]
}
4 changes: 4 additions & 0 deletions octopusdeploy/schema_package_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ func expandPackageReference(tfPkg map[string]interface{}) *packages.PackageRefer
Properties: map[string]string{},
}

if id, ok := tfPkg["id"]; ok {
pkg.ID = id.(string)
}

Copy link
Contributor Author

@denys-octopus denys-octopus Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without that ☝️ , updating of deployment process resource would fail, because new id will be generated every time when updating deployment process and because old id is referenced by built-in trigger deployment process will prevent to replace it.

if v, ok := tfPkg["extract_during_deployment"]; ok {
pkg.Properties["Extract"] = cases.Title(language.Und, cases.NoLower).String(strconv.FormatBool(v.(bool)))
}
Expand Down
1 change: 1 addition & 0 deletions octopusdeploy_framework/framework_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func (p *octopusDeployFrameworkProvider) Resources(ctx context.Context) []func()
NewGenericOidcResource,
NewDeploymentFreezeTenantResource,
NewGitTriggerResource,
NewBuiltInTriggerResource,
}
}

Expand Down
Loading
Loading