Skip to content

Commit

Permalink
feat: Use DeploymentActionSlugPackage for external feed triggers and …
Browse files Browse the repository at this point in the history
…add resource schema for primary package references (#634)

* make space_id optional

* send space_id in the fetch to get ProjectTriggers

* use slug instead of name for referencing deployment action packages

* add primary_package schema to external feed triggers

* use latest version of Terraform Testing Framework that has the change to stop telemetry from being sent

* update docs

* add computed property for deploymentaction slug
  • Loading branch information
kevjt committed May 6, 2024
1 parent addbdd3 commit c6da48f
Show file tree
Hide file tree
Showing 18 changed files with 543 additions and 35 deletions.
32 changes: 32 additions & 0 deletions docs/resources/deployment_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ Optional:
- `worker_pool_id` (String) The worker pool associated with this deployment action.
- `worker_pool_variable` (String) The worker pool variable associated with this deployment action.

Read-Only:

- `slug` (String) The human-readable unique identifier for this resource.

<a id="nestedblock--step--action--action_template"></a>
### Nested Schema for `step.action.action_template`

Expand Down Expand Up @@ -317,6 +321,10 @@ Optional:
- `worker_pool_id` (String) The worker pool associated with this deployment action.
- `worker_pool_variable` (String) The worker pool variable associated with this deployment action.

Read-Only:

- `slug` (String) The human-readable unique identifier for this resource.

<a id="nestedblock--step--apply_terraform_template_action--advanced_options"></a>
### Nested Schema for `step.apply_terraform_template_action.advanced_options`

Expand Down Expand Up @@ -486,6 +494,10 @@ Optional:
- `worker_pool_id` (String) The worker pool associated with this deployment action.
- `worker_pool_variable` (String) The worker pool variable associated with this deployment action.

Read-Only:

- `slug` (String) The human-readable unique identifier for this resource.

<a id="nestedblock--step--deploy_kubernetes_secret_action--action_template"></a>
### Nested Schema for `step.deploy_kubernetes_secret_action.action_template`

Expand Down Expand Up @@ -569,6 +581,10 @@ Optional:
- `tenant_tags` (List of String) A list of tenant tags associated with this resource.
- `windows_service` (Block Set, Max: 1) Deploy a windows service feature (see [below for nested schema](#nestedblock--step--deploy_package_action--windows_service))

Read-Only:

- `slug` (String) The human-readable unique identifier for this resource.

<a id="nestedblock--step--deploy_package_action--primary_package"></a>
### Nested Schema for `step.deploy_package_action.primary_package`

Expand Down Expand Up @@ -699,6 +715,10 @@ Optional:
- `start_mode` (String) When will the service start. Can be auto, delayed-auto, manual, unchanged or an expression
- `tenant_tags` (List of String) A list of tenant tags associated with this resource.

Read-Only:

- `slug` (String) The human-readable unique identifier for this resource.

<a id="nestedblock--step--deploy_windows_service_action--primary_package"></a>
### Nested Schema for `step.deploy_windows_service_action.primary_package`

Expand Down Expand Up @@ -798,6 +818,10 @@ Optional:
- `sort_order` (Number) Order used by terraform to ensure correct ordering of actions. This property must be either omitted from all actions, or provided on all actions
- `tenant_tags` (List of String) A list of tenant tags associated with this resource.

Read-Only:

- `slug` (String) The human-readable unique identifier for this resource.

<a id="nestedblock--step--manual_intervention_action--action_template"></a>
### Nested Schema for `step.manual_intervention_action.action_template`

Expand Down Expand Up @@ -890,6 +914,10 @@ Optional:
- `worker_pool_id` (String) The worker pool associated with this deployment action.
- `worker_pool_variable` (String) The worker pool variable associated with this deployment action.

Read-Only:

- `slug` (String) The human-readable unique identifier for this resource.

<a id="nestedblock--step--run_kubectl_script_action--action_template"></a>
### Nested Schema for `step.run_kubectl_script_action.action_template`

Expand Down Expand Up @@ -998,6 +1026,10 @@ Optional:
- `worker_pool_id` (String) The worker pool associated with this deployment action.
- `worker_pool_variable` (String) The worker pool variable associated with this deployment action.

Read-Only:

- `slug` (String) The human-readable unique identifier for this resource.

<a id="nestedblock--step--run_script_action--action_template"></a>
### Nested Schema for `step.run_script_action.action_template`

Expand Down
17 changes: 13 additions & 4 deletions docs/resources/external_feed_create_release_trigger.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ resource "octopusdeploy_external_feed_create_release_trigger" "my_trigger" {

- `channel_id` (String) The ID of the channel in which the release will be created if the action type is CreateRelease.
- `name` (String) The name of this resource.
- `package` (Block List, Min: 1) List of package references that will cause the trigger to fire. The triggering condition is if any of the packages are updated. (see [below for nested schema](#nestedblock--package))
- `project_id` (String) The ID of the project to attach the trigger.
- `space_id` (String) The space ID associated with the project to attach the trigger.

### Optional

- `is_disabled` (Boolean) Disables the trigger from being run when set.
- `package` (Block List) List of referenced packages that will cause the trigger to fire. New versions of any of the packages you select will trigger release creation. (see [below for nested schema](#nestedblock--package))
- `primary_package` (Block List) List of deployment actions for which the primary packages will cause the trigger to fire. New versions of any of the packages you select will trigger release creation. (see [below for nested schema](#nestedblock--primary_package))
- `space_id` (String) The space ID associated with the project to attach the trigger.

### Read-Only

Expand All @@ -49,11 +50,19 @@ resource "octopusdeploy_external_feed_create_release_trigger" "my_trigger" {
<a id="nestedblock--package"></a>
### Nested Schema for `package`

Optional:
Required:

- `deployment_action` (String)
- `deployment_action_slug` (String)
- `package_reference` (String)


<a id="nestedblock--primary_package"></a>
### Nested Schema for `primary_package`

Required:

- `deployment_action_slug` (String)

## Import

Import is supported using the following syntax:
Expand Down
34 changes: 32 additions & 2 deletions docs/resources/runbook_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ Optional:
- `worker_pool_id` (String) The worker pool associated with this deployment action.
- `worker_pool_variable` (String) The worker pool variable associated with this deployment action.

Read-Only:

- `slug` (String) The human-readable unique identifier for this resource.

<a id="nestedblock--step--action--action_template"></a>
### Nested Schema for `step.action.action_template`

Expand Down Expand Up @@ -195,6 +199,10 @@ Optional:
- `worker_pool_id` (String) The worker pool associated with this deployment action.
- `worker_pool_variable` (String) The worker pool variable associated with this deployment action.

Read-Only:

- `slug` (String) The human-readable unique identifier for this resource.

<a id="nestedblock--step--apply_terraform_template_action--advanced_options"></a>
### Nested Schema for `step.apply_terraform_template_action.advanced_options`

Expand Down Expand Up @@ -364,6 +372,10 @@ Optional:
- `worker_pool_id` (String) The worker pool associated with this deployment action.
- `worker_pool_variable` (String) The worker pool variable associated with this deployment action.

Read-Only:

- `slug` (String) The human-readable unique identifier for this resource.

<a id="nestedblock--step--deploy_kubernetes_secret_action--action_template"></a>
### Nested Schema for `step.deploy_kubernetes_secret_action.action_template`

Expand Down Expand Up @@ -447,6 +459,10 @@ Optional:
- `tenant_tags` (List of String) A list of tenant tags associated with this resource.
- `windows_service` (Block Set, Max: 1) Deploy a windows service feature (see [below for nested schema](#nestedblock--step--deploy_package_action--windows_service))

Read-Only:

- `slug` (String) The human-readable unique identifier for this resource.

<a id="nestedblock--step--deploy_package_action--primary_package"></a>
### Nested Schema for `step.deploy_package_action.primary_package`

Expand Down Expand Up @@ -577,6 +593,10 @@ Optional:
- `start_mode` (String) When will the service start. Can be auto, delayed-auto, manual, unchanged or an expression
- `tenant_tags` (List of String) A list of tenant tags associated with this resource.

Read-Only:

- `slug` (String) The human-readable unique identifier for this resource.

<a id="nestedblock--step--deploy_windows_service_action--primary_package"></a>
### Nested Schema for `step.deploy_windows_service_action.primary_package`

Expand Down Expand Up @@ -676,6 +696,10 @@ Optional:
- `sort_order` (Number) Order used by terraform to ensure correct ordering of actions. This property must be either omitted from all actions, or provided on all actions
- `tenant_tags` (List of String) A list of tenant tags associated with this resource.

Read-Only:

- `slug` (String) The human-readable unique identifier for this resource.

<a id="nestedblock--step--manual_intervention_action--action_template"></a>
### Nested Schema for `step.manual_intervention_action.action_template`

Expand Down Expand Up @@ -768,6 +792,10 @@ Optional:
- `worker_pool_id` (String) The worker pool associated with this deployment action.
- `worker_pool_variable` (String) The worker pool variable associated with this deployment action.

Read-Only:

- `slug` (String) The human-readable unique identifier for this resource.

<a id="nestedblock--step--run_kubectl_script_action--action_template"></a>
### Nested Schema for `step.run_kubectl_script_action.action_template`

Expand Down Expand Up @@ -876,6 +904,10 @@ Optional:
- `worker_pool_id` (String) The worker pool associated with this deployment action.
- `worker_pool_variable` (String) The worker pool variable associated with this deployment action.

Read-Only:

- `slug` (String) The human-readable unique identifier for this resource.

<a id="nestedblock--step--run_script_action--action_template"></a>
### Nested Schema for `step.run_script_action.action_template`

Expand Down Expand Up @@ -944,5 +976,3 @@ Optional:
- `id` (String) The unique ID for this resource.
- `name` (String) The name of this resource.
- `properties` (Map of String) A list of properties associated with this package.


10 changes: 9 additions & 1 deletion docs/resources/variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ resource "octopusdeploy_variable" "google_cloud_account_variable" {
value = "Accounts-123"
}
# Create a UsernamePassword account variable
resource "octopusdeploy_variable" "usernamepassword_account_variable" {
owner_id = "Projects-123"
type = "UsernamePasswordAccount"
name = "UsernamePasswordVariable"
value = octopusdeploy_username_password_account.account_user_pass.id
}
# create a Certificate variable
resource "octopusdeploy_variable" "certificate_variable" {
owner_id = "Projects-123"
Expand Down Expand Up @@ -88,7 +96,7 @@ resource "octopusdeploy_variable" "prompted_variable" {
### Required

- `name` (String) The name of this resource.
- `type` (String) The type of variable represented by this resource. Valid types are `AmazonWebServicesAccount`, `AzureAccount`, `GoogleCloudAccount`, `Certificate`, `Sensitive`, `String`, or `WorkerPool`.
- `type` (String) The type of variable represented by this resource. Valid types are `AmazonWebServicesAccount`, `AzureAccount`, `GoogleCloudAccount`, `UsernamePasswordAccount`, `Certificate`, `Sensitive`, `String`, or `WorkerPool`.

### Optional

Expand Down
8 changes: 8 additions & 0 deletions examples/resources/octopusdeploy_variable/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ resource "octopusdeploy_variable" "google_cloud_account_variable" {
value = "Accounts-123"
}

# Create a UsernamePassword account variable
resource "octopusdeploy_variable" "usernamepassword_account_variable" {
owner_id = "Projects-123"
type = "UsernamePasswordAccount"
name = "UsernamePasswordVariable"
value = octopusdeploy_username_password_account.account_user_pass.id
}

# create a Certificate variable
resource "octopusdeploy_variable" "certificate_variable" {
owner_id = "Projects-123"
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/OctopusDeploy/terraform-provider-octopusdeploy
go 1.21

require (
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.40.3
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240409225949-b27d14ff2bcb
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.42.0
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240502041300-f71244db277d
github.com/google/uuid v1.6.0
github.com/gruntwork-io/terratest v0.41.11
github.com/hashicorp/go-cty v1.4.1-0.20200723130312-85980079f637
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8=
github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYxPRqGcpAD9w=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.40.3 h1:Gi3tlcwFJPQe9mmdIV0NcScnHGvOcTFcoM67L+dx6gE=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.40.3/go.mod h1:GZmFu6LmN8Yg0tEoZx3ytk9FnaH+84cWm7u5TdWZC6E=
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240409225949-b27d14ff2bcb h1:4Lzs6TsvSZkahw99VlIDP5aAihQiJZPoCQKTw1A9el4=
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240409225949-b27d14ff2bcb/go.mod h1:Nyg+7cyTrSQ/lMIy5YY1UdJekRuoMWf4uHIPfaGmgTM=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.42.0 h1:LZ8qWUHrUhnG1TLT0c38o2/22T0JspvO1zK7Ha+eXgs=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.42.0/go.mod h1:GZmFu6LmN8Yg0tEoZx3ytk9FnaH+84cWm7u5TdWZC6E=
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240502041300-f71244db277d h1:E0Rm52/XBlVzdkHET/+Js1FVVgf5/0oRk1tNkI4jcyk=
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240502041300-f71244db277d/go.mod h1:Nyg+7cyTrSQ/lMIy5YY1UdJekRuoMWf4uHIPfaGmgTM=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk=
Expand Down
25 changes: 17 additions & 8 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3553,22 +3553,22 @@ func TestPackageFeedCreateReleaseTriggerResources(t *testing.T) {
return err
}

if len(project_triggers) != 2 {
t.Fatal("There must be exactly 2 project triggers")
}

tr1Name := "My first trigger"
tr2Name := "My second trigger"
tr3Name := "My third trigger"

tr1Index := stdslices.IndexFunc(project_triggers, func(t *triggers.ProjectTrigger) bool { return t.Name == tr1Name })
tr2Index := stdslices.IndexFunc(project_triggers, func(t *triggers.ProjectTrigger) bool { return t.Name == tr2Name })
tr3Index := stdslices.IndexFunc(project_triggers, func(t *triggers.ProjectTrigger) bool { return t.Name == tr3Name })

if tr1Index == -1 || tr2Index == -1 {
t.Fatalf("Unable to find both triggers. Expecting there to be \"%s\" and \"%s\".", tr1Name, tr2Name)
if tr1Index == -1 || tr2Index == -1 || tr3Index == -1 {
t.Fatalf("Unable to find all triggers. Expecting there to be \"%s\", \"%s\", and \"%s\".", tr1Name, tr2Name, tr3Name)
}

if project_triggers[0].Filter.GetFilterType() != filters.FeedFilter || project_triggers[1].Filter.GetFilterType() != filters.FeedFilter {
t.Fatal("The project triggers must all be of \"FeedFilter\" type")
for _, triggerIndex := range []int{tr1Index, tr2Index, tr3Index} {
if project_triggers[triggerIndex].Filter.GetFilterType() != filters.FeedFilter {
t.Fatal("The project triggers must all be of \"FeedFilter\" type")
}
}

if project_triggers[tr1Index].IsDisabled {
Expand All @@ -3579,8 +3579,13 @@ func TestPackageFeedCreateReleaseTriggerResources(t *testing.T) {
t.Fatalf("The trigger \"%s\" should be disabled", tr2Name)
}

if project_triggers[tr3Index].IsDisabled {
t.Fatalf("The trigger \"%s\" should not be disabled", tr3Name)
}

tr1Filter := project_triggers[tr1Index].Filter.(*filters.FeedTriggerFilter)
tr2Filter := project_triggers[tr2Index].Filter.(*filters.FeedTriggerFilter)
tr3Filter := project_triggers[tr3Index].Filter.(*filters.FeedTriggerFilter)

if len(tr1Filter.Packages) != 2 {
t.Fatalf("The trigger \"%s\" should have 2 package references", tr1Name)
Expand All @@ -3590,6 +3595,10 @@ func TestPackageFeedCreateReleaseTriggerResources(t *testing.T) {
t.Fatalf("The trigger \"%s\" should have 1 package reference", tr2Name)
}

if len(tr3Filter.Packages) != 3 {
t.Fatalf("The trigger \"%s\" should have 3 package reference", tr3Name)
}

return nil
})
}
Expand Down
10 changes: 8 additions & 2 deletions octopusdeploy/resource_external_feed_create_release_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ func buildExternalFeedCreateReleaseTriggerResource(d *schema.ResourceData, clien
}

flattenedPackages := d.Get("package")
packages := expandDeploymentActionPackages(flattenedPackages)
packages := expandDeploymentActionSlugPackages(flattenedPackages)

flattenedPrimaryPackages := d.Get("primary_package")
primaryPackages := expandDeploymentActionSlugPrimaryPackages(flattenedPrimaryPackages)

packages = append(packages, primaryPackages...)

action := actions.NewCreateReleaseAction(channelId)
filter := filters.NewFeedTriggerFilter(packages)
Expand Down Expand Up @@ -95,7 +100,8 @@ func resourceExternalFeedCreateReleaseTriggerRead(ctx context.Context, d *schema
d.Set("project_id", projectTrigger.ProjectID)
d.Set("is_disabled", projectTrigger.IsDisabled)
d.Set("channel_id", action.ChannelID)
d.Set("package", flattenDeploymentActionPackages(filter.Packages))
d.Set("package", flattenDeploymentActionSlugPackages(filter.Packages))
d.Set("primary_package", flattenDeploymentActionSlugPrimaryPackages(filter.Packages))

return nil
}
Expand Down
9 changes: 9 additions & 0 deletions octopusdeploy/schema_deployment_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func flattenAction(action *deployments.DeploymentAction) map[string]interface{}
flattenedAction["name"] = action.Name
}

if len(action.Slug) > 0 {
flattenedAction["slug"] = action.Slug
}

if len(action.Notes) > 0 {
flattenedAction["notes"] = action.Notes
}
Expand Down Expand Up @@ -257,6 +261,7 @@ func getActionSchema() (*schema.Schema, *schema.Resource) {
Optional: true,
Default: -1,
},
"slug": getSlugSchema(),
"tenant_tags": getTenantTagsSchema(),
},
}
Expand Down Expand Up @@ -448,6 +453,10 @@ func expandAction(flattenedAction map[string]interface{}) *deployments.Deploymen
action.Properties["Octopus.Action.RunOnServer"] = core.NewPropertyValue(cases.Title(language.Und, cases.NoLower).String(strconv.FormatBool(runOnServer)), false)
}

if v, ok := flattenedAction["slug"]; ok {
action.Slug = v.(string)
}

if v, ok := flattenedAction["action_template"]; ok {
templateList := v.(*schema.Set).List()
if len(templateList) > 0 {
Expand Down

0 comments on commit c6da48f

Please sign in to comment.