Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit c6da48f

Browse files
authored
feat: Use DeploymentActionSlugPackage for external feed triggers and 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
1 parent addbdd3 commit c6da48f

18 files changed

+543
-35
lines changed

docs/resources/deployment_process.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ Optional:
208208
- `worker_pool_id` (String) The worker pool associated with this deployment action.
209209
- `worker_pool_variable` (String) The worker pool variable associated with this deployment action.
210210

211+
Read-Only:
212+
213+
- `slug` (String) The human-readable unique identifier for this resource.
214+
211215
<a id="nestedblock--step--action--action_template"></a>
212216
### Nested Schema for `step.action.action_template`
213217

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

324+
Read-Only:
325+
326+
- `slug` (String) The human-readable unique identifier for this resource.
327+
320328
<a id="nestedblock--step--apply_terraform_template_action--advanced_options"></a>
321329
### Nested Schema for `step.apply_terraform_template_action.advanced_options`
322330

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

497+
Read-Only:
498+
499+
- `slug` (String) The human-readable unique identifier for this resource.
500+
489501
<a id="nestedblock--step--deploy_kubernetes_secret_action--action_template"></a>
490502
### Nested Schema for `step.deploy_kubernetes_secret_action.action_template`
491503

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

584+
Read-Only:
585+
586+
- `slug` (String) The human-readable unique identifier for this resource.
587+
572588
<a id="nestedblock--step--deploy_package_action--primary_package"></a>
573589
### Nested Schema for `step.deploy_package_action.primary_package`
574590

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

718+
Read-Only:
719+
720+
- `slug` (String) The human-readable unique identifier for this resource.
721+
702722
<a id="nestedblock--step--deploy_windows_service_action--primary_package"></a>
703723
### Nested Schema for `step.deploy_windows_service_action.primary_package`
704724

@@ -798,6 +818,10 @@ Optional:
798818
- `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
799819
- `tenant_tags` (List of String) A list of tenant tags associated with this resource.
800820

821+
Read-Only:
822+
823+
- `slug` (String) The human-readable unique identifier for this resource.
824+
801825
<a id="nestedblock--step--manual_intervention_action--action_template"></a>
802826
### Nested Schema for `step.manual_intervention_action.action_template`
803827

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

917+
Read-Only:
918+
919+
- `slug` (String) The human-readable unique identifier for this resource.
920+
893921
<a id="nestedblock--step--run_kubectl_script_action--action_template"></a>
894922
### Nested Schema for `step.run_kubectl_script_action.action_template`
895923

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

1029+
Read-Only:
1030+
1031+
- `slug` (String) The human-readable unique identifier for this resource.
1032+
10011033
<a id="nestedblock--step--run_script_action--action_template"></a>
10021034
### Nested Schema for `step.run_script_action.action_template`
10031035

docs/resources/external_feed_create_release_trigger.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ resource "octopusdeploy_external_feed_create_release_trigger" "my_trigger" {
3434

3535
- `channel_id` (String) The ID of the channel in which the release will be created if the action type is CreateRelease.
3636
- `name` (String) The name of this resource.
37-
- `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))
3837
- `project_id` (String) The ID of the project to attach the trigger.
39-
- `space_id` (String) The space ID associated with the project to attach the trigger.
4038

4139
### Optional
4240

4341
- `is_disabled` (Boolean) Disables the trigger from being run when set.
42+
- `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))
43+
- `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))
44+
- `space_id` (String) The space ID associated with the project to attach the trigger.
4445

4546
### Read-Only
4647

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

52-
Optional:
53+
Required:
5354

54-
- `deployment_action` (String)
55+
- `deployment_action_slug` (String)
5556
- `package_reference` (String)
5657

58+
59+
<a id="nestedblock--primary_package"></a>
60+
### Nested Schema for `primary_package`
61+
62+
Required:
63+
64+
- `deployment_action_slug` (String)
65+
5766
## Import
5867

5968
Import is supported using the following syntax:

docs/resources/runbook_process.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ Optional:
8686
- `worker_pool_id` (String) The worker pool associated with this deployment action.
8787
- `worker_pool_variable` (String) The worker pool variable associated with this deployment action.
8888

89+
Read-Only:
90+
91+
- `slug` (String) The human-readable unique identifier for this resource.
92+
8993
<a id="nestedblock--step--action--action_template"></a>
9094
### Nested Schema for `step.action.action_template`
9195

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

202+
Read-Only:
203+
204+
- `slug` (String) The human-readable unique identifier for this resource.
205+
198206
<a id="nestedblock--step--apply_terraform_template_action--advanced_options"></a>
199207
### Nested Schema for `step.apply_terraform_template_action.advanced_options`
200208

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

375+
Read-Only:
376+
377+
- `slug` (String) The human-readable unique identifier for this resource.
378+
367379
<a id="nestedblock--step--deploy_kubernetes_secret_action--action_template"></a>
368380
### Nested Schema for `step.deploy_kubernetes_secret_action.action_template`
369381

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

462+
Read-Only:
463+
464+
- `slug` (String) The human-readable unique identifier for this resource.
465+
450466
<a id="nestedblock--step--deploy_package_action--primary_package"></a>
451467
### Nested Schema for `step.deploy_package_action.primary_package`
452468

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

596+
Read-Only:
597+
598+
- `slug` (String) The human-readable unique identifier for this resource.
599+
580600
<a id="nestedblock--step--deploy_windows_service_action--primary_package"></a>
581601
### Nested Schema for `step.deploy_windows_service_action.primary_package`
582602

@@ -676,6 +696,10 @@ Optional:
676696
- `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
677697
- `tenant_tags` (List of String) A list of tenant tags associated with this resource.
678698

699+
Read-Only:
700+
701+
- `slug` (String) The human-readable unique identifier for this resource.
702+
679703
<a id="nestedblock--step--manual_intervention_action--action_template"></a>
680704
### Nested Schema for `step.manual_intervention_action.action_template`
681705

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

795+
Read-Only:
796+
797+
- `slug` (String) The human-readable unique identifier for this resource.
798+
771799
<a id="nestedblock--step--run_kubectl_script_action--action_template"></a>
772800
### Nested Schema for `step.run_kubectl_script_action.action_template`
773801

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

907+
Read-Only:
908+
909+
- `slug` (String) The human-readable unique identifier for this resource.
910+
879911
<a id="nestedblock--step--run_script_action--action_template"></a>
880912
### Nested Schema for `step.run_script_action.action_template`
881913

@@ -944,5 +976,3 @@ Optional:
944976
- `id` (String) The unique ID for this resource.
945977
- `name` (String) The name of this resource.
946978
- `properties` (Map of String) A list of properties associated with this package.
947-
948-

docs/resources/variable.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ resource "octopusdeploy_variable" "google_cloud_account_variable" {
3636
value = "Accounts-123"
3737
}
3838
39+
# Create a UsernamePassword account variable
40+
resource "octopusdeploy_variable" "usernamepassword_account_variable" {
41+
owner_id = "Projects-123"
42+
type = "UsernamePasswordAccount"
43+
name = "UsernamePasswordVariable"
44+
value = octopusdeploy_username_password_account.account_user_pass.id
45+
}
46+
3947
# create a Certificate variable
4048
resource "octopusdeploy_variable" "certificate_variable" {
4149
owner_id = "Projects-123"
@@ -88,7 +96,7 @@ resource "octopusdeploy_variable" "prompted_variable" {
8896
### Required
8997

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

93101
### Optional
94102

examples/resources/octopusdeploy_variable/resource.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ resource "octopusdeploy_variable" "google_cloud_account_variable" {
2222
value = "Accounts-123"
2323
}
2424

25+
# Create a UsernamePassword account variable
26+
resource "octopusdeploy_variable" "usernamepassword_account_variable" {
27+
owner_id = "Projects-123"
28+
type = "UsernamePasswordAccount"
29+
name = "UsernamePasswordVariable"
30+
value = octopusdeploy_username_password_account.account_user_pass.id
31+
}
32+
2533
# create a Certificate variable
2634
resource "octopusdeploy_variable" "certificate_variable" {
2735
owner_id = "Projects-123"

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module github.com/OctopusDeploy/terraform-provider-octopusdeploy
33
go 1.21
44

55
require (
6-
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.40.3
7-
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240409225949-b27d14ff2bcb
6+
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.42.0
7+
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240502041300-f71244db277d
88
github.com/google/uuid v1.6.0
99
github.com/gruntwork-io/terratest v0.41.11
1010
github.com/hashicorp/go-cty v1.4.1-0.20200723130312-85980079f637

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
6868
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
6969
github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8=
7070
github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYxPRqGcpAD9w=
71-
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.40.3 h1:Gi3tlcwFJPQe9mmdIV0NcScnHGvOcTFcoM67L+dx6gE=
72-
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.40.3/go.mod h1:GZmFu6LmN8Yg0tEoZx3ytk9FnaH+84cWm7u5TdWZC6E=
73-
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240409225949-b27d14ff2bcb h1:4Lzs6TsvSZkahw99VlIDP5aAihQiJZPoCQKTw1A9el4=
74-
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240409225949-b27d14ff2bcb/go.mod h1:Nyg+7cyTrSQ/lMIy5YY1UdJekRuoMWf4uHIPfaGmgTM=
71+
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.42.0 h1:LZ8qWUHrUhnG1TLT0c38o2/22T0JspvO1zK7Ha+eXgs=
72+
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.42.0/go.mod h1:GZmFu6LmN8Yg0tEoZx3ytk9FnaH+84cWm7u5TdWZC6E=
73+
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240502041300-f71244db277d h1:E0Rm52/XBlVzdkHET/+Js1FVVgf5/0oRk1tNkI4jcyk=
74+
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240502041300-f71244db277d/go.mod h1:Nyg+7cyTrSQ/lMIy5YY1UdJekRuoMWf4uHIPfaGmgTM=
7575
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ=
7676
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
7777
github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk=

integration_test.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3553,22 +3553,22 @@ func TestPackageFeedCreateReleaseTriggerResources(t *testing.T) {
35533553
return err
35543554
}
35553555

3556-
if len(project_triggers) != 2 {
3557-
t.Fatal("There must be exactly 2 project triggers")
3558-
}
3559-
35603556
tr1Name := "My first trigger"
35613557
tr2Name := "My second trigger"
3558+
tr3Name := "My third trigger"
35623559

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

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

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

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

3582+
if project_triggers[tr3Index].IsDisabled {
3583+
t.Fatalf("The trigger \"%s\" should not be disabled", tr3Name)
3584+
}
3585+
35823586
tr1Filter := project_triggers[tr1Index].Filter.(*filters.FeedTriggerFilter)
35833587
tr2Filter := project_triggers[tr2Index].Filter.(*filters.FeedTriggerFilter)
3588+
tr3Filter := project_triggers[tr3Index].Filter.(*filters.FeedTriggerFilter)
35843589

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

3598+
if len(tr3Filter.Packages) != 3 {
3599+
t.Fatalf("The trigger \"%s\" should have 3 package reference", tr3Name)
3600+
}
3601+
35933602
return nil
35943603
})
35953604
}

octopusdeploy/resource_external_feed_create_release_trigger.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ func buildExternalFeedCreateReleaseTriggerResource(d *schema.ResourceData, clien
3737
}
3838

3939
flattenedPackages := d.Get("package")
40-
packages := expandDeploymentActionPackages(flattenedPackages)
40+
packages := expandDeploymentActionSlugPackages(flattenedPackages)
41+
42+
flattenedPrimaryPackages := d.Get("primary_package")
43+
primaryPackages := expandDeploymentActionSlugPrimaryPackages(flattenedPrimaryPackages)
44+
45+
packages = append(packages, primaryPackages...)
4146

4247
action := actions.NewCreateReleaseAction(channelId)
4348
filter := filters.NewFeedTriggerFilter(packages)
@@ -95,7 +100,8 @@ func resourceExternalFeedCreateReleaseTriggerRead(ctx context.Context, d *schema
95100
d.Set("project_id", projectTrigger.ProjectID)
96101
d.Set("is_disabled", projectTrigger.IsDisabled)
97102
d.Set("channel_id", action.ChannelID)
98-
d.Set("package", flattenDeploymentActionPackages(filter.Packages))
103+
d.Set("package", flattenDeploymentActionSlugPackages(filter.Packages))
104+
d.Set("primary_package", flattenDeploymentActionSlugPrimaryPackages(filter.Packages))
99105

100106
return nil
101107
}

octopusdeploy/schema_deployment_action.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ func flattenAction(action *deployments.DeploymentAction) map[string]interface{}
7878
flattenedAction["name"] = action.Name
7979
}
8080

81+
if len(action.Slug) > 0 {
82+
flattenedAction["slug"] = action.Slug
83+
}
84+
8185
if len(action.Notes) > 0 {
8286
flattenedAction["notes"] = action.Notes
8387
}
@@ -257,6 +261,7 @@ func getActionSchema() (*schema.Schema, *schema.Resource) {
257261
Optional: true,
258262
Default: -1,
259263
},
264+
"slug": getSlugSchema(),
260265
"tenant_tags": getTenantTagsSchema(),
261266
},
262267
}
@@ -448,6 +453,10 @@ func expandAction(flattenedAction map[string]interface{}) *deployments.Deploymen
448453
action.Properties["Octopus.Action.RunOnServer"] = core.NewPropertyValue(cases.Title(language.Und, cases.NoLower).String(strconv.FormatBool(runOnServer)), false)
449454
}
450455

456+
if v, ok := flattenedAction["slug"]; ok {
457+
action.Slug = v.(string)
458+
}
459+
451460
if v, ok := flattenedAction["action_template"]; ok {
452461
templateList := v.(*schema.Set).List()
453462
if len(templateList) > 0 {

0 commit comments

Comments
 (0)