From ca3ee2dbb9bf5df5c3af41f4329822d39ee64bc7 Mon Sep 17 00:00:00 2001 From: kevjt Date: Tue, 30 Apr 2024 14:51:31 +1000 Subject: [PATCH 01/14] make space_id optional --- octopusdeploy/schema_external_feed_create_release_trigger.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octopusdeploy/schema_external_feed_create_release_trigger.go b/octopusdeploy/schema_external_feed_create_release_trigger.go index d04f199ce..5c5a142f9 100644 --- a/octopusdeploy/schema_external_feed_create_release_trigger.go +++ b/octopusdeploy/schema_external_feed_create_release_trigger.go @@ -9,7 +9,7 @@ func getExternalFeedCreateReleaseTriggerSchema() map[string]*schema.Schema { return map[string]*schema.Schema{ "name": getNameSchema(true), "space_id": { - Required: true, + Optional: true, Description: "The space ID associated with the project to attach the trigger.", Type: schema.TypeString, ValidateDiagFunc: validation.ToDiagFunc(validation.StringIsNotWhiteSpace), From 29643f1bf0b07ef45baca00c92ed6ccdea7019cf Mon Sep 17 00:00:00 2001 From: kevjt Date: Tue, 30 Apr 2024 15:24:32 +1000 Subject: [PATCH 02/14] use slug --- ...ce_external_feed_create_release_trigger.go | 4 +- .../schema_deployment_action_slug_package.go | 51 ++++++++++++++++ ...ema_deployment_action_slug_package_test.go | 59 +++++++++++++++++++ ...ma_external_feed_create_release_trigger.go | 2 +- 4 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 octopusdeploy/schema_deployment_action_slug_package.go create mode 100644 octopusdeploy/schema_deployment_action_slug_package_test.go diff --git a/octopusdeploy/resource_external_feed_create_release_trigger.go b/octopusdeploy/resource_external_feed_create_release_trigger.go index 28e01c6a4..e04165005 100644 --- a/octopusdeploy/resource_external_feed_create_release_trigger.go +++ b/octopusdeploy/resource_external_feed_create_release_trigger.go @@ -37,7 +37,7 @@ func buildExternalFeedCreateReleaseTriggerResource(d *schema.ResourceData, clien } flattenedPackages := d.Get("package") - packages := expandDeploymentActionPackages(flattenedPackages) + packages := expandDeploymentActionSlugPackages(flattenedPackages) action := actions.NewCreateReleaseAction(channelId) filter := filters.NewFeedTriggerFilter(packages) @@ -95,7 +95,7 @@ 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)) return nil } diff --git a/octopusdeploy/schema_deployment_action_slug_package.go b/octopusdeploy/schema_deployment_action_slug_package.go new file mode 100644 index 000000000..65bae2e2e --- /dev/null +++ b/octopusdeploy/schema_deployment_action_slug_package.go @@ -0,0 +1,51 @@ +package octopusdeploy + +import ( + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/packages" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func expandDeploymentActionSlugPackages(values interface{}) []packages.DeploymentActionSlugPackage { + if values == nil { + return nil + } + + actionPackages := []packages.DeploymentActionSlugPackage{} + for _, v := range values.([]interface{}) { + flattenedMap := v.(map[string]interface{}) + actionPackages = append(actionPackages, packages.DeploymentActionSlugPackage{ + DeploymentActionSlug: flattenedMap["deployment_action_slug"].(string), + PackageReference: flattenedMap["package_reference"].(string), + }) + } + return actionPackages +} + +func flattenDeploymentActionSlugPackages(deploymentActionSlugPackages []packages.DeploymentActionSlugPackage) []interface{} { + if len(deploymentActionSlugPackages) == 0 { + return nil + } + + flattenedDeploymentActionSlugPackages := []interface{}{} + for _, v := range deploymentActionSlugPackages { + flattenedDeploymentActionSlugPackage := map[string]interface{}{ + "deployment_action_slug": v.DeploymentActionSlug, + "package_reference": v.PackageReference, + } + flattenedDeploymentActionSlugPackages = append(flattenedDeploymentActionSlugPackages, flattenedDeploymentActionSlugPackage) + } + return flattenedDeploymentActionSlugPackages +} + +func getDeploymentActionSlugPackageSchema() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "deployment_action_slug": { + Optional: true, + Type: schema.TypeString, + }, + "package_reference": { + Optional: true, + Type: schema.TypeString, + }, + } +} diff --git a/octopusdeploy/schema_deployment_action_slug_package_test.go b/octopusdeploy/schema_deployment_action_slug_package_test.go new file mode 100644 index 000000000..19df62af1 --- /dev/null +++ b/octopusdeploy/schema_deployment_action_slug_package_test.go @@ -0,0 +1,59 @@ +package octopusdeploy + +import ( + "testing" + + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/packages" + "github.com/stretchr/testify/require" +) + +func TestExpandDeploymentActionSlugPackages(t *testing.T) { + actual := expandDeploymentActionSlugPackages(nil) + require.Nil(t, actual) + + actual = expandDeploymentActionSlugPackages([]interface{}{}) + expected := []packages.DeploymentActionSlugPackage{} + require.Equal(t, expected, actual) + + flattened := []interface{}{ + map[string]interface{}{ + "deployment_action_slug": "", + "package_reference": "", + }, + map[string]interface{}{ + "deployment_action_slug": "test-deployment_action", + "package_reference": "test-package_reference", + }, + } + expected = []packages.DeploymentActionSlugPackage{ + {DeploymentActionSlug: "", PackageReference: ""}, + {DeploymentActionSlug: "test-deployment_action", PackageReference: "test-package_reference"}, + } + actual = expandDeploymentActionSlugPackages(flattened) + require.Equal(t, expected, actual) +} + +func TestFlattenDeploymentActionSlugPackages(t *testing.T) { + actual := flattenDeploymentActionSlugPackages(nil) + require.Nil(t, actual) + + actual = flattenDeploymentActionSlugPackages([]packages.DeploymentActionSlugPackage{}) + require.Nil(t, actual) + + expanded := []packages.DeploymentActionSlugPackage{{}, { + DeploymentActionSlug: "test-deployment_action", + PackageReference: "test-package_reference", + }} + actual = flattenDeploymentActionSlugPackages(expanded) + expected := []interface{}{ + map[string]interface{}{ + "deployment_action_slug": "", + "package_reference": "", + }, + map[string]interface{}{ + "deployment_action_slug": "test-deployment_action", + "package_reference": "test-package_reference", + }, + } + require.Equal(t, expected, actual) +} diff --git a/octopusdeploy/schema_external_feed_create_release_trigger.go b/octopusdeploy/schema_external_feed_create_release_trigger.go index 5c5a142f9..0ad8e1031 100644 --- a/octopusdeploy/schema_external_feed_create_release_trigger.go +++ b/octopusdeploy/schema_external_feed_create_release_trigger.go @@ -30,7 +30,7 @@ func getExternalFeedCreateReleaseTriggerSchema() map[string]*schema.Schema { Description: "List of package references that will cause the trigger to fire. The triggering condition is if any of the packages are updated.", Required: true, Type: schema.TypeList, - Elem: &schema.Resource{Schema: getDeploymentActionPackageSchema()}, + Elem: &schema.Resource{Schema: getDeploymentActionSlugPackageSchema()}, }, "is_disabled": { Description: "Disables the trigger from being run when set.", From 38d57fad800c85d762e0143d976d0b3b1a272f7e Mon Sep 17 00:00:00 2001 From: kevjt Date: Wed, 1 May 2024 15:47:17 +1000 Subject: [PATCH 03/14] update go mod --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index a2d773c0a..2ea550f2e 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/OctopusDeploy/terraform-provider-octopusdeploy go 1.21 require ( - github.com/OctopusDeploy/go-octopusdeploy/v2 v2.40.3 + github.com/OctopusDeploy/go-octopusdeploy/v2 v2.41.0 github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240409225949-b27d14ff2bcb github.com/google/uuid v1.6.0 github.com/gruntwork-io/terratest v0.41.11 diff --git a/go.sum b/go.sum index e65a0f128..a32f09ddf 100644 --- a/go.sum +++ b/go.sum @@ -68,8 +68,8 @@ 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/OctopusDeploy/go-octopusdeploy/v2 v2.41.0 h1:11fXSFfz0YQ9/e4KX7v7XW99z2+Q8qgyL9Z9E195YgM= +github.com/OctopusDeploy/go-octopusdeploy/v2 v2.41.0/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/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ= From 9eaf344c8ba7148746510b09376ea7906fdba44f Mon Sep 17 00:00:00 2001 From: kevjt Date: Wed, 1 May 2024 17:14:08 +1000 Subject: [PATCH 04/14] add primary_package schema to external feed triggers --- ...ce_external_feed_create_release_trigger.go | 6 ++ .../schema_deployment_action_slug_package.go | 55 ++++++++-- ...ema_deployment_action_slug_package_test.go | 100 ++++++++++++++++-- ...ma_external_feed_create_release_trigger.go | 10 +- 4 files changed, 154 insertions(+), 17 deletions(-) diff --git a/octopusdeploy/resource_external_feed_create_release_trigger.go b/octopusdeploy/resource_external_feed_create_release_trigger.go index e04165005..8d998d08e 100644 --- a/octopusdeploy/resource_external_feed_create_release_trigger.go +++ b/octopusdeploy/resource_external_feed_create_release_trigger.go @@ -39,6 +39,11 @@ func buildExternalFeedCreateReleaseTriggerResource(d *schema.ResourceData, clien flattenedPackages := d.Get("package") packages := expandDeploymentActionSlugPackages(flattenedPackages) + flattenedPrimaryPackages := d.Get("primary_package") + primaryPackages := expandDeploymentActionSlugPrimaryPackages(flattenedPrimaryPackages) + + packages = append(packages, primaryPackages...) + action := actions.NewCreateReleaseAction(channelId) filter := filters.NewFeedTriggerFilter(packages) @@ -96,6 +101,7 @@ func resourceExternalFeedCreateReleaseTriggerRead(ctx context.Context, d *schema d.Set("is_disabled", projectTrigger.IsDisabled) d.Set("channel_id", action.ChannelID) d.Set("package", flattenDeploymentActionSlugPackages(filter.Packages)) + d.Set("primary_package", flattenDeploymentActionSlugPrimaryPackages(filter.Packages)) return nil } diff --git a/octopusdeploy/schema_deployment_action_slug_package.go b/octopusdeploy/schema_deployment_action_slug_package.go index 65bae2e2e..9419b77a5 100644 --- a/octopusdeploy/schema_deployment_action_slug_package.go +++ b/octopusdeploy/schema_deployment_action_slug_package.go @@ -21,6 +21,21 @@ func expandDeploymentActionSlugPackages(values interface{}) []packages.Deploymen return actionPackages } +func expandDeploymentActionSlugPrimaryPackages(values interface{}) []packages.DeploymentActionSlugPackage { + if values == nil { + return nil + } + + actionPackages := []packages.DeploymentActionSlugPackage{} + for _, v := range values.([]interface{}) { + flattenedMap := v.(map[string]interface{}) + actionPackages = append(actionPackages, packages.DeploymentActionSlugPackage{ + DeploymentActionSlug: flattenedMap["deployment_action_slug"].(string), + }) + } + return actionPackages +} + func flattenDeploymentActionSlugPackages(deploymentActionSlugPackages []packages.DeploymentActionSlugPackage) []interface{} { if len(deploymentActionSlugPackages) == 0 { return nil @@ -28,11 +43,30 @@ func flattenDeploymentActionSlugPackages(deploymentActionSlugPackages []packages flattenedDeploymentActionSlugPackages := []interface{}{} for _, v := range deploymentActionSlugPackages { - flattenedDeploymentActionSlugPackage := map[string]interface{}{ - "deployment_action_slug": v.DeploymentActionSlug, - "package_reference": v.PackageReference, + if v.PackageReference != "" { + flattenedDeploymentActionSlugPackage := map[string]interface{}{ + "deployment_action_slug": v.DeploymentActionSlug, + "package_reference": v.PackageReference, + } + flattenedDeploymentActionSlugPackages = append(flattenedDeploymentActionSlugPackages, flattenedDeploymentActionSlugPackage) + } + } + return flattenedDeploymentActionSlugPackages +} + +func flattenDeploymentActionSlugPrimaryPackages(deploymentActionSlugPackages []packages.DeploymentActionSlugPackage) []interface{} { + if len(deploymentActionSlugPackages) == 0 { + return nil + } + + flattenedDeploymentActionSlugPackages := []interface{}{} + for _, v := range deploymentActionSlugPackages { + if v.PackageReference == "" { + flattenedDeploymentActionSlugPackage := map[string]interface{}{ + "deployment_action_slug": v.DeploymentActionSlug, + } + flattenedDeploymentActionSlugPackages = append(flattenedDeploymentActionSlugPackages, flattenedDeploymentActionSlugPackage) } - flattenedDeploymentActionSlugPackages = append(flattenedDeploymentActionSlugPackages, flattenedDeploymentActionSlugPackage) } return flattenedDeploymentActionSlugPackages } @@ -40,11 +74,20 @@ func flattenDeploymentActionSlugPackages(deploymentActionSlugPackages []packages func getDeploymentActionSlugPackageSchema() map[string]*schema.Schema { return map[string]*schema.Schema{ "deployment_action_slug": { - Optional: true, + Required: true, Type: schema.TypeString, }, "package_reference": { - Optional: true, + Required: true, + Type: schema.TypeString, + }, + } +} + +func getDeploymentActionSlugPrimaryPackageSchema() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "deployment_action_slug": { + Required: true, Type: schema.TypeString, }, } diff --git a/octopusdeploy/schema_deployment_action_slug_package_test.go b/octopusdeploy/schema_deployment_action_slug_package_test.go index 19df62af1..b8522c44f 100644 --- a/octopusdeploy/schema_deployment_action_slug_package_test.go +++ b/octopusdeploy/schema_deployment_action_slug_package_test.go @@ -33,6 +33,31 @@ func TestExpandDeploymentActionSlugPackages(t *testing.T) { require.Equal(t, expected, actual) } +func TestExpandDeploymentActionSlugPrimaryPackages(t *testing.T) { + actual := expandDeploymentActionSlugPrimaryPackages(nil) + require.Nil(t, actual) + + actual = expandDeploymentActionSlugPrimaryPackages([]interface{}{}) + expected := []packages.DeploymentActionSlugPackage{} + require.Equal(t, expected, actual) + + flattened := []interface{}{ + map[string]interface{}{ + "deployment_action_slug": "", + }, + map[string]interface{}{ + "deployment_action_slug": "test-deployment_action", + "package_reference": "should_be_ignored", + }, + } + expected = []packages.DeploymentActionSlugPackage{ + {DeploymentActionSlug: "", PackageReference: ""}, + {DeploymentActionSlug: "test-deployment_action", PackageReference: ""}, + } + actual = expandDeploymentActionSlugPrimaryPackages(flattened) + require.Equal(t, expected, actual) +} + func TestFlattenDeploymentActionSlugPackages(t *testing.T) { actual := flattenDeploymentActionSlugPackages(nil) require.Nil(t, actual) @@ -40,20 +65,77 @@ func TestFlattenDeploymentActionSlugPackages(t *testing.T) { actual = flattenDeploymentActionSlugPackages([]packages.DeploymentActionSlugPackage{}) require.Nil(t, actual) - expanded := []packages.DeploymentActionSlugPackage{{}, { - DeploymentActionSlug: "test-deployment_action", - PackageReference: "test-package_reference", - }} + expanded := []packages.DeploymentActionSlugPackage{ + { + DeploymentActionSlug: "action-one", + PackageReference: "", + }, + { + DeploymentActionSlug: "action-two", + PackageReference: "", + }, + } + actual = flattenDeploymentActionSlugPackages(expanded) + expected := []interface{}{} + require.Equal(t, expected, actual) + + expanded = getCommonExpandedPackages() actual = flattenDeploymentActionSlugPackages(expanded) - expected := []interface{}{ + expected = []interface{}{ map[string]interface{}{ - "deployment_action_slug": "", - "package_reference": "", + "deployment_action_slug": "action-one", + "package_reference": "some-package", + }, + } + require.Equal(t, expected, actual) + +} + +func TestFlattenDeploymentActionSlugPrimaryPackages(t *testing.T) { + actual := flattenDeploymentActionSlugPrimaryPackages(nil) + require.Nil(t, actual) + + actual = flattenDeploymentActionSlugPrimaryPackages([]packages.DeploymentActionSlugPackage{}) + require.Nil(t, actual) + + expanded := []packages.DeploymentActionSlugPackage{ + { + DeploymentActionSlug: "action-one", + PackageReference: "some-package", + }, + { + DeploymentActionSlug: "action-two", + PackageReference: "some-other-package", }, + } + actual = flattenDeploymentActionSlugPrimaryPackages(expanded) + expected := []interface{}{} + + expanded = getCommonExpandedPackages() + actual = flattenDeploymentActionSlugPrimaryPackages(expanded) + expected = []interface{}{ map[string]interface{}{ - "deployment_action_slug": "test-deployment_action", - "package_reference": "test-package_reference", + "deployment_action_slug": "action-two", + }, + map[string]interface{}{ + "deployment_action_slug": "action-three", }, } require.Equal(t, expected, actual) } + +func getCommonExpandedPackages() []packages.DeploymentActionSlugPackage { + return []packages.DeploymentActionSlugPackage{ + { + DeploymentActionSlug: "action-one", + PackageReference: "some-package", + }, + { + DeploymentActionSlug: "action-two", + PackageReference: "", + }, + { + DeploymentActionSlug: "action-three", + }, + } +} diff --git a/octopusdeploy/schema_external_feed_create_release_trigger.go b/octopusdeploy/schema_external_feed_create_release_trigger.go index 0ad8e1031..9fcd858b3 100644 --- a/octopusdeploy/schema_external_feed_create_release_trigger.go +++ b/octopusdeploy/schema_external_feed_create_release_trigger.go @@ -27,11 +27,17 @@ func getExternalFeedCreateReleaseTriggerSchema() map[string]*schema.Schema { ValidateDiagFunc: validation.ToDiagFunc(validation.StringIsNotWhiteSpace), }, "package": { - Description: "List of package references that will cause the trigger to fire. The triggering condition is if any of the packages are updated.", - Required: true, + Description: "List of package references that will cause the trigger to fire. Will trigger if any of the packages are updated.", + Optional: true, Type: schema.TypeList, Elem: &schema.Resource{Schema: getDeploymentActionSlugPackageSchema()}, }, + "primary_package": { + Description: "List of primary package references (primary with respect to its corresponding deployment action). Will trigger if any of the primary packages are updated.", + Optional: true, + Type: schema.TypeList, + Elem: &schema.Resource{Schema: getDeploymentActionSlugPrimaryPackageSchema()}, + }, "is_disabled": { Description: "Disables the trigger from being run when set.", Optional: true, From f71d98b6f870c8114da53f9dd721fa2283ffc0d9 Mon Sep 17 00:00:00 2001 From: kevjt Date: Thu, 2 May 2024 13:34:27 +1000 Subject: [PATCH 05/14] update integration test --- go.mod | 2 +- go.sum | 4 +- integration_test.go | 19 ++++- .../deployment_process.tf | 78 +++++++++++++++++++ .../feed.tf | 8 +- .../project.tf | 18 ++++- .../project_triggers.tf | 40 ++++++++-- 7 files changed, 154 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 2ea550f2e..8ab7940c8 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/OctopusDeploy/terraform-provider-octopusdeploy go 1.21 require ( - github.com/OctopusDeploy/go-octopusdeploy/v2 v2.41.0 + github.com/OctopusDeploy/go-octopusdeploy/v2 v2.41.1 github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240409225949-b27d14ff2bcb github.com/google/uuid v1.6.0 github.com/gruntwork-io/terratest v0.41.11 diff --git a/go.sum b/go.sum index a32f09ddf..5676603e5 100644 --- a/go.sum +++ b/go.sum @@ -68,8 +68,8 @@ 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.41.0 h1:11fXSFfz0YQ9/e4KX7v7XW99z2+Q8qgyL9Z9E195YgM= -github.com/OctopusDeploy/go-octopusdeploy/v2 v2.41.0/go.mod h1:GZmFu6LmN8Yg0tEoZx3ytk9FnaH+84cWm7u5TdWZC6E= +github.com/OctopusDeploy/go-octopusdeploy/v2 v2.41.1 h1:CpKfSXxI8HlwD6wOY4x2jpRHjQCZNssHZ5qr0HyB7PQ= +github.com/OctopusDeploy/go-octopusdeploy/v2 v2.41.1/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/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ= diff --git a/integration_test.go b/integration_test.go index 79808fcfb..f4b971683 100644 --- a/integration_test.go +++ b/integration_test.go @@ -3553,18 +3553,20 @@ func TestPackageFeedCreateReleaseTriggerResources(t *testing.T) { return err } - if len(project_triggers) != 2 { - t.Fatal("There must be exactly 2 project triggers") + if len(project_triggers) != 3 { + t.Fatal("There must be exactly 3 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 { @@ -3579,8 +3581,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) @@ -3590,6 +3597,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 }) } diff --git a/terraform/52-packagefeedcreatereleasetrigger/deployment_process.tf b/terraform/52-packagefeedcreatereleasetrigger/deployment_process.tf index 48b0aac30..be2e90124 100644 --- a/terraform/52-packagefeedcreatereleasetrigger/deployment_process.tf +++ b/terraform/52-packagefeedcreatereleasetrigger/deployment_process.tf @@ -65,4 +65,82 @@ resource "octopusdeploy_deployment_process" "example" { } } } + step { + condition = "Success" + name = "Helm one" + package_requirement = "LetOctopusDecide" + start_trigger = "StartAfterPrevious" + + action { + action_type = "Octopus.HelmChartUpgrade" + name = "Helm one" + condition = "Success" + run_on_server = true + is_disabled = false + can_be_used_for_project_versioning = true + is_required = false + worker_pool_id = "" + properties = { + "Octopus.Action.Helm.ClientVersion" = "V3" + "Octopus.Action.Helm.Namespace" = "dev" + "Octopus.Action.Package.DownloadOnTentacle" = "False" + "Octopus.Action.Helm.ResetValues" = "True" + } + environments = [] + excluded_environments = [] + channels = [] + tenant_tags = [] + + primary_package { + package_id = "redis" + acquisition_location = "Server" + feed_id = "${octopusdeploy_helm_feed.feed_helm_charts.id}" + properties = { SelectionMode = "immediate" } + } + + features = [] + } + + properties = {} + target_roles = ["k8s"] + } + step { + condition = "Success" + name = "Helm two" + package_requirement = "LetOctopusDecide" + start_trigger = "StartAfterPrevious" + + action { + action_type = "Octopus.HelmChartUpgrade" + name = "Helm two" + condition = "Success" + run_on_server = true + is_disabled = false + can_be_used_for_project_versioning = true + is_required = false + worker_pool_id = "" + properties = { + "Octopus.Action.Helm.ClientVersion" = "V3" + "Octopus.Action.Helm.Namespace" = "dev" + "Octopus.Action.Package.DownloadOnTentacle" = "False" + "Octopus.Action.Helm.ResetValues" = "True" + } + environments = [] + excluded_environments = [] + channels = [] + tenant_tags = [] + + primary_package { + package_id = "prometheus" + acquisition_location = "Server" + feed_id = "${octopusdeploy_helm_feed.feed_helm_charts.id}" + properties = { SelectionMode = "immediate" } + } + + features = [] + } + + properties = {} + target_roles = ["k8s"] + } } diff --git a/terraform/52-packagefeedcreatereleasetrigger/feed.tf b/terraform/52-packagefeedcreatereleasetrigger/feed.tf index bef8fdfeb..aae2d7f88 100644 --- a/terraform/52-packagefeedcreatereleasetrigger/feed.tf +++ b/terraform/52-packagefeedcreatereleasetrigger/feed.tf @@ -1,4 +1,10 @@ resource "octopusdeploy_docker_container_registry" "docker_feed" { feed_uri = "https://index.docker.io" name = "Test Docker Container Registry" -} \ No newline at end of file +} + +resource "octopusdeploy_helm_feed" "feed_helm_charts" { + name = "Test Helm Charts" + feed_uri = "https://charts.helm.sh/stable" + package_acquisition_location_options = ["ExecutionTarget", "NotAcquired"] +} diff --git a/terraform/52-packagefeedcreatereleasetrigger/project.tf b/terraform/52-packagefeedcreatereleasetrigger/project.tf index 494b9526c..3a62b322c 100644 --- a/terraform/52-packagefeedcreatereleasetrigger/project.tf +++ b/terraform/52-packagefeedcreatereleasetrigger/project.tf @@ -10,8 +10,22 @@ resource "octopusdeploy_project_group" "project_group_test" { description = "Test Description" } -resource "octopusdeploy_channel" "test_channel" { - name = "Test Channel" +resource "octopusdeploy_channel" "test_channel_1" { + name = "Test Channel 1" + project_id = "${octopusdeploy_project.deploy_frontend_project.id}" + space_id = var.octopus_space_id + lifecycle_id = data.octopusdeploy_lifecycles.lifecycle_default_lifecycle.lifecycles[0].id +} + +resource "octopusdeploy_channel" "test_channel_2" { + name = "Test Channel 2" + project_id = "${octopusdeploy_project.deploy_frontend_project.id}" + space_id = var.octopus_space_id + lifecycle_id = data.octopusdeploy_lifecycles.lifecycle_default_lifecycle.lifecycles[0].id +} + +resource "octopusdeploy_channel" "test_channel_3" { + name = "Test Channel 3" project_id = "${octopusdeploy_project.deploy_frontend_project.id}" space_id = var.octopus_space_id lifecycle_id = data.octopusdeploy_lifecycles.lifecycle_default_lifecycle.lifecycles[0].id diff --git a/terraform/52-packagefeedcreatereleasetrigger/project_triggers.tf b/terraform/52-packagefeedcreatereleasetrigger/project_triggers.tf index 50a98acb4..4bee6ec44 100644 --- a/terraform/52-packagefeedcreatereleasetrigger/project_triggers.tf +++ b/terraform/52-packagefeedcreatereleasetrigger/project_triggers.tf @@ -3,14 +3,18 @@ resource "octopusdeploy_external_feed_create_release_trigger" "external_feed_tri space_id = var.octopus_space_id project_id = "${octopusdeploy_project.deploy_frontend_project.id}" package { - deployment_action = octopusdeploy_deployment_process.example.step[0].run_script_action[0].name + deployment_action_slug = "hello-world-using-powershell-1" package_reference = "busybox" } package { - deployment_action = octopusdeploy_deployment_process.example.step[0].run_script_action[0].name + deployment_action_slug = "hello-world-using-powershell-1" package_reference = "nginx" } - channel_id = octopusdeploy_channel.test_channel.id + channel_id = octopusdeploy_channel.test_channel_1.id + + depends_on = [ + octopusdeploy_deployment_process.example + ] } resource "octopusdeploy_external_feed_create_release_trigger" "external_feed_trigger_2" { @@ -19,8 +23,34 @@ resource "octopusdeploy_external_feed_create_release_trigger" "external_feed_tri project_id = "${octopusdeploy_project.deploy_frontend_project.id}" is_disabled = true package { - deployment_action = octopusdeploy_deployment_process.example.step[1].run_script_action[0].name + deployment_action_slug = "hello-world-using-powershell-2" package_reference = "scratch" } - channel_id = octopusdeploy_channel.test_channel.id + channel_id = octopusdeploy_channel.test_channel_2.id + + depends_on = [ + octopusdeploy_deployment_process.example + ] +} + +resource "octopusdeploy_external_feed_create_release_trigger" "external_feed_trigger_3" { + name = "My third trigger" + space_id = var.octopus_space_id + project_id = "${octopusdeploy_project.deploy_frontend_project.id}" + is_disabled = false + package { + deployment_action_slug = "hello-world-using-powershell-1" + package_reference = "busybox" + } + primary_package { + deployment_action_slug = "helm-one" + } + primary_package { + deployment_action_slug = "helm-two" + } + channel_id = octopusdeploy_channel.test_channel_3.id + + depends_on = [ + octopusdeploy_deployment_process.example + ] } \ No newline at end of file From 837a8f81f6aab45de9027f8e0ca6556d899e31e6 Mon Sep 17 00:00:00 2001 From: kevjt Date: Thu, 2 May 2024 14:16:36 +1000 Subject: [PATCH 06/14] use latest version of Terraform Testing Framework that has the change to stop telemetry from being sent --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 8ab7940c8..04fdbbcb0 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( github.com/OctopusDeploy/go-octopusdeploy/v2 v2.41.1 - github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240409225949-b27d14ff2bcb + 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 diff --git a/go.sum b/go.sum index 5676603e5..558dc333d 100644 --- a/go.sum +++ b/go.sum @@ -70,8 +70,8 @@ github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7 github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYxPRqGcpAD9w= github.com/OctopusDeploy/go-octopusdeploy/v2 v2.41.1 h1:CpKfSXxI8HlwD6wOY4x2jpRHjQCZNssHZ5qr0HyB7PQ= github.com/OctopusDeploy/go-octopusdeploy/v2 v2.41.1/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/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= From 968597194ebaf60614dd8c3e6c2fc7a46f76f913 Mon Sep 17 00:00:00 2001 From: kevjt Date: Thu, 2 May 2024 15:35:56 +1000 Subject: [PATCH 07/14] update docs --- .../external_feed_create_release_trigger.md | 17 +++++++++++++---- docs/resources/variable.md | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/resources/external_feed_create_release_trigger.md b/docs/resources/external_feed_create_release_trigger.md index e6b02d6c1..b0ef39925 100644 --- a/docs/resources/external_feed_create_release_trigger.md +++ b/docs/resources/external_feed_create_release_trigger.md @@ -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 package references that will cause the trigger to fire. Will trigger if any of the packages are updated. (see [below for nested schema](#nestedblock--package)) +- `primary_package` (Block List) List of primary package references (primary with respect to its corresponding deployment action). Will trigger if any of the primary packages are updated. (see [below for nested schema](#nestedblock--primary_package)) +- `space_id` (String) The space ID associated with the project to attach the trigger. ### Read-Only @@ -49,11 +50,19 @@ resource "octopusdeploy_external_feed_create_release_trigger" "my_trigger" { ### Nested Schema for `package` -Optional: +Required: -- `deployment_action` (String) +- `deployment_action_slug` (String) - `package_reference` (String) + + +### Nested Schema for `primary_package` + +Required: + +- `deployment_action_slug` (String) + ## Import Import is supported using the following syntax: diff --git a/docs/resources/variable.md b/docs/resources/variable.md index 514743f1b..3404fc285 100644 --- a/docs/resources/variable.md +++ b/docs/resources/variable.md @@ -88,7 +88,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 From 3c99250295438a9f190574728bdac6607c1c87f6 Mon Sep 17 00:00:00 2001 From: kevjt Date: Fri, 3 May 2024 09:22:22 +1000 Subject: [PATCH 08/14] rerun build to update github status From feb6e5a00d73e4bfbc6c7a85d6d0571214c4240e Mon Sep 17 00:00:00 2001 From: Kevin Tchang <151479559+kevjt@users.noreply.github.com> Date: Fri, 3 May 2024 15:46:48 +1000 Subject: [PATCH 09/14] update description Co-authored-by: EddyMoulton --- octopusdeploy/schema_external_feed_create_release_trigger.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/octopusdeploy/schema_external_feed_create_release_trigger.go b/octopusdeploy/schema_external_feed_create_release_trigger.go index 9fcd858b3..cb304eb10 100644 --- a/octopusdeploy/schema_external_feed_create_release_trigger.go +++ b/octopusdeploy/schema_external_feed_create_release_trigger.go @@ -27,7 +27,8 @@ func getExternalFeedCreateReleaseTriggerSchema() map[string]*schema.Schema { ValidateDiagFunc: validation.ToDiagFunc(validation.StringIsNotWhiteSpace), }, "package": { - Description: "List of package references that will cause the trigger to fire. Will trigger if any of the packages are updated.", + Description: "List of referenced package that will cause the trigger to fire. New versions of any of the packages you select will trigger release creation. + ", Optional: true, Type: schema.TypeList, Elem: &schema.Resource{Schema: getDeploymentActionSlugPackageSchema()}, From 4689ecb7f506655315c30b95833c972db1273318 Mon Sep 17 00:00:00 2001 From: Kevin Tchang <151479559+kevjt@users.noreply.github.com> Date: Fri, 3 May 2024 15:47:01 +1000 Subject: [PATCH 10/14] update description Co-authored-by: EddyMoulton --- octopusdeploy/schema_external_feed_create_release_trigger.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octopusdeploy/schema_external_feed_create_release_trigger.go b/octopusdeploy/schema_external_feed_create_release_trigger.go index cb304eb10..634dde4d4 100644 --- a/octopusdeploy/schema_external_feed_create_release_trigger.go +++ b/octopusdeploy/schema_external_feed_create_release_trigger.go @@ -34,7 +34,7 @@ func getExternalFeedCreateReleaseTriggerSchema() map[string]*schema.Schema { Elem: &schema.Resource{Schema: getDeploymentActionSlugPackageSchema()}, }, "primary_package": { - Description: "List of primary package references (primary with respect to its corresponding deployment action). Will trigger if any of the primary packages are updated.", + Description: "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.", Optional: true, Type: schema.TypeList, Elem: &schema.Resource{Schema: getDeploymentActionSlugPrimaryPackageSchema()}, From 3f522721d23a1782638932ff5d9d595e4f8de170 Mon Sep 17 00:00:00 2001 From: kevjt Date: Fri, 3 May 2024 16:20:02 +1000 Subject: [PATCH 11/14] split tests into named functions --- integration_test.go | 4 -- ...ema_deployment_action_slug_package_test.go | 62 ++++++++++++------- ...ma_external_feed_create_release_trigger.go | 3 +- 3 files changed, 42 insertions(+), 27 deletions(-) diff --git a/integration_test.go b/integration_test.go index f4b971683..1b9765d1e 100644 --- a/integration_test.go +++ b/integration_test.go @@ -3553,10 +3553,6 @@ func TestPackageFeedCreateReleaseTriggerResources(t *testing.T) { return err } - if len(project_triggers) != 3 { - t.Fatal("There must be exactly 3 project triggers") - } - tr1Name := "My first trigger" tr2Name := "My second trigger" tr3Name := "My third trigger" diff --git a/octopusdeploy/schema_deployment_action_slug_package_test.go b/octopusdeploy/schema_deployment_action_slug_package_test.go index b8522c44f..37c26d145 100644 --- a/octopusdeploy/schema_deployment_action_slug_package_test.go +++ b/octopusdeploy/schema_deployment_action_slug_package_test.go @@ -7,14 +7,18 @@ import ( "github.com/stretchr/testify/require" ) -func TestExpandDeploymentActionSlugPackages(t *testing.T) { +func TestExpandDeploymentActionSlugPackages_NilExpandsToNil(t *testing.T) { actual := expandDeploymentActionSlugPackages(nil) require.Nil(t, actual) +} - actual = expandDeploymentActionSlugPackages([]interface{}{}) +func TestExpandDeploymentActionSlugPackages_EmptyExpandsToEmpty(t *testing.T) { + actual := expandDeploymentActionSlugPackages([]interface{}{}) expected := []packages.DeploymentActionSlugPackage{} require.Equal(t, expected, actual) +} +func TestExpandDeploymentActionSlugPackages_ArrayExpandsCorrectly(t *testing.T) { flattened := []interface{}{ map[string]interface{}{ "deployment_action_slug": "", @@ -25,22 +29,26 @@ func TestExpandDeploymentActionSlugPackages(t *testing.T) { "package_reference": "test-package_reference", }, } - expected = []packages.DeploymentActionSlugPackage{ + expected := []packages.DeploymentActionSlugPackage{ {DeploymentActionSlug: "", PackageReference: ""}, {DeploymentActionSlug: "test-deployment_action", PackageReference: "test-package_reference"}, } - actual = expandDeploymentActionSlugPackages(flattened) + actual := expandDeploymentActionSlugPackages(flattened) require.Equal(t, expected, actual) } -func TestExpandDeploymentActionSlugPrimaryPackages(t *testing.T) { +func TestExpandDeploymentActionSlugPrimaryPackages_NilExpandsToNil(t *testing.T) { actual := expandDeploymentActionSlugPrimaryPackages(nil) require.Nil(t, actual) +} - actual = expandDeploymentActionSlugPrimaryPackages([]interface{}{}) +func TestExpandDeploymentActionSlugPrimaryPackages_EmptyExpandsToEmpty(t *testing.T) { + actual := expandDeploymentActionSlugPrimaryPackages([]interface{}{}) expected := []packages.DeploymentActionSlugPackage{} require.Equal(t, expected, actual) +} +func TestExpandDeploymentActionSlugPrimaryPackages_ArrayExpandsCorrectly(t *testing.T) { flattened := []interface{}{ map[string]interface{}{ "deployment_action_slug": "", @@ -50,21 +58,25 @@ func TestExpandDeploymentActionSlugPrimaryPackages(t *testing.T) { "package_reference": "should_be_ignored", }, } - expected = []packages.DeploymentActionSlugPackage{ + expected := []packages.DeploymentActionSlugPackage{ {DeploymentActionSlug: "", PackageReference: ""}, {DeploymentActionSlug: "test-deployment_action", PackageReference: ""}, } - actual = expandDeploymentActionSlugPrimaryPackages(flattened) + actual := expandDeploymentActionSlugPrimaryPackages(flattened) require.Equal(t, expected, actual) } -func TestFlattenDeploymentActionSlugPackages(t *testing.T) { +func TestFlattenDeploymentActionSlugPackages_NilFlattensToNil(t *testing.T) { actual := flattenDeploymentActionSlugPackages(nil) require.Nil(t, actual) +} - actual = flattenDeploymentActionSlugPackages([]packages.DeploymentActionSlugPackage{}) +func TestFlattenDeploymentActionSlugPackages_EmptyFlattensToNil(t *testing.T) { + actual := flattenDeploymentActionSlugPackages([]packages.DeploymentActionSlugPackage{}) require.Nil(t, actual) +} +func TestFlattenDeploymentActionSlugPackages_IgnoresPrimaryPackages_NoPackagesAfterFlattening(t *testing.T) { expanded := []packages.DeploymentActionSlugPackage{ { DeploymentActionSlug: "action-one", @@ -75,29 +87,34 @@ func TestFlattenDeploymentActionSlugPackages(t *testing.T) { PackageReference: "", }, } - actual = flattenDeploymentActionSlugPackages(expanded) + actual := flattenDeploymentActionSlugPackages(expanded) expected := []interface{}{} require.Equal(t, expected, actual) +} - expanded = getCommonExpandedPackages() - actual = flattenDeploymentActionSlugPackages(expanded) - expected = []interface{}{ +func TestFlattenDeploymentActionSlugPackages_IgnoresPrimaryPackages_ArrayFlattensCorrectly(t *testing.T) { + expanded := getCommonExpandedPackages() + actual := flattenDeploymentActionSlugPackages(expanded) + expected := []interface{}{ map[string]interface{}{ "deployment_action_slug": "action-one", "package_reference": "some-package", }, } require.Equal(t, expected, actual) - } -func TestFlattenDeploymentActionSlugPrimaryPackages(t *testing.T) { +func TestFlattenDeploymentActionSlugPrimaryPackages_NilFlattensToNil(t *testing.T) { actual := flattenDeploymentActionSlugPrimaryPackages(nil) require.Nil(t, actual) +} - actual = flattenDeploymentActionSlugPrimaryPackages([]packages.DeploymentActionSlugPackage{}) +func TestFlattenDeploymentActionSlugPrimaryPackages_EmptyFlattensToNil(t *testing.T) { + actual := flattenDeploymentActionSlugPrimaryPackages([]packages.DeploymentActionSlugPackage{}) require.Nil(t, actual) +} +func TestFlattenDeploymentActionSlugPrimaryPackages_IgnoresPackages_NoPrimaryPackagesAfterFlattening(t *testing.T) { expanded := []packages.DeploymentActionSlugPackage{ { DeploymentActionSlug: "action-one", @@ -108,12 +125,15 @@ func TestFlattenDeploymentActionSlugPrimaryPackages(t *testing.T) { PackageReference: "some-other-package", }, } - actual = flattenDeploymentActionSlugPrimaryPackages(expanded) + actual := flattenDeploymentActionSlugPrimaryPackages(expanded) expected := []interface{}{} + require.Equal(t, expected, actual) +} - expanded = getCommonExpandedPackages() - actual = flattenDeploymentActionSlugPrimaryPackages(expanded) - expected = []interface{}{ +func TestFlattenDeploymentActionSlugPrimaryPackages_IgnoresPackages_ArrayFlattensCorrectly(t *testing.T) { + expanded := getCommonExpandedPackages() + actual := flattenDeploymentActionSlugPrimaryPackages(expanded) + expected := []interface{}{ map[string]interface{}{ "deployment_action_slug": "action-two", }, diff --git a/octopusdeploy/schema_external_feed_create_release_trigger.go b/octopusdeploy/schema_external_feed_create_release_trigger.go index 634dde4d4..8bf072325 100644 --- a/octopusdeploy/schema_external_feed_create_release_trigger.go +++ b/octopusdeploy/schema_external_feed_create_release_trigger.go @@ -27,8 +27,7 @@ func getExternalFeedCreateReleaseTriggerSchema() map[string]*schema.Schema { ValidateDiagFunc: validation.ToDiagFunc(validation.StringIsNotWhiteSpace), }, "package": { - Description: "List of referenced package that will cause the trigger to fire. New versions of any of the packages you select will trigger release creation. - ", + Description: "List of referenced packages that will cause the trigger to fire. New versions of any of the packages you select will trigger release creation.", Optional: true, Type: schema.TypeList, Elem: &schema.Resource{Schema: getDeploymentActionSlugPackageSchema()}, From 969ebf53d03baef5ce287c480c0ecc2c341af820 Mon Sep 17 00:00:00 2001 From: kevjt Date: Fri, 3 May 2024 16:29:29 +1000 Subject: [PATCH 12/14] add example for usernamepassword account variable usage --- docs/resources/variable.md | 8 ++++++++ examples/resources/octopusdeploy_variable/resource.tf | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/docs/resources/variable.md b/docs/resources/variable.md index 3404fc285..31c956c10 100644 --- a/docs/resources/variable.md +++ b/docs/resources/variable.md @@ -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" diff --git a/examples/resources/octopusdeploy_variable/resource.tf b/examples/resources/octopusdeploy_variable/resource.tf index 57e70fef7..693e90d20 100644 --- a/examples/resources/octopusdeploy_variable/resource.tf +++ b/examples/resources/octopusdeploy_variable/resource.tf @@ -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" From d3e0eb5b370d3ab8113ee2d649afdddb3f57029d Mon Sep 17 00:00:00 2001 From: kevjt Date: Mon, 6 May 2024 09:59:56 +1000 Subject: [PATCH 13/14] add computed property for deploymentaction slug --- docs/resources/deployment_process.md | 32 +++++++++++++++++ .../external_feed_create_release_trigger.md | 4 +-- docs/resources/runbook_process.md | 34 +++++++++++++++++-- go.mod | 2 +- go.sum | 4 +-- octopusdeploy/schema_deployment_action.go | 9 +++++ octopusdeploy/schema_utilities.go | 8 +++++ .../project_triggers.tf | 12 +++---- 8 files changed, 92 insertions(+), 13 deletions(-) diff --git a/docs/resources/deployment_process.md b/docs/resources/deployment_process.md index db150de2e..837a86f97 100644 --- a/docs/resources/deployment_process.md +++ b/docs/resources/deployment_process.md @@ -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. + ### Nested Schema for `step.action.action_template` @@ -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. + ### Nested Schema for `step.apply_terraform_template_action.advanced_options` @@ -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. + ### Nested Schema for `step.deploy_kubernetes_secret_action.action_template` @@ -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. + ### Nested Schema for `step.deploy_package_action.primary_package` @@ -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. + ### Nested Schema for `step.deploy_windows_service_action.primary_package` @@ -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. + ### Nested Schema for `step.manual_intervention_action.action_template` @@ -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. + ### Nested Schema for `step.run_kubectl_script_action.action_template` @@ -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. + ### Nested Schema for `step.run_script_action.action_template` diff --git a/docs/resources/external_feed_create_release_trigger.md b/docs/resources/external_feed_create_release_trigger.md index b0ef39925..e45666b70 100644 --- a/docs/resources/external_feed_create_release_trigger.md +++ b/docs/resources/external_feed_create_release_trigger.md @@ -39,8 +39,8 @@ resource "octopusdeploy_external_feed_create_release_trigger" "my_trigger" { ### Optional - `is_disabled` (Boolean) Disables the trigger from being run when set. -- `package` (Block List) List of package references that will cause the trigger to fire. Will trigger if any of the packages are updated. (see [below for nested schema](#nestedblock--package)) -- `primary_package` (Block List) List of primary package references (primary with respect to its corresponding deployment action). Will trigger if any of the primary packages are updated. (see [below for nested schema](#nestedblock--primary_package)) +- `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 diff --git a/docs/resources/runbook_process.md b/docs/resources/runbook_process.md index a49235552..01a940899 100644 --- a/docs/resources/runbook_process.md +++ b/docs/resources/runbook_process.md @@ -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. + ### Nested Schema for `step.action.action_template` @@ -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. + ### Nested Schema for `step.apply_terraform_template_action.advanced_options` @@ -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. + ### Nested Schema for `step.deploy_kubernetes_secret_action.action_template` @@ -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. + ### Nested Schema for `step.deploy_package_action.primary_package` @@ -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. + ### Nested Schema for `step.deploy_windows_service_action.primary_package` @@ -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. + ### Nested Schema for `step.manual_intervention_action.action_template` @@ -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. + ### Nested Schema for `step.run_kubectl_script_action.action_template` @@ -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. + ### Nested Schema for `step.run_script_action.action_template` @@ -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. - - diff --git a/go.mod b/go.mod index 04fdbbcb0..9d3587260 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/OctopusDeploy/terraform-provider-octopusdeploy go 1.21 require ( - github.com/OctopusDeploy/go-octopusdeploy/v2 v2.41.1 + 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 diff --git a/go.sum b/go.sum index 558dc333d..9e284d411 100644 --- a/go.sum +++ b/go.sum @@ -68,8 +68,8 @@ 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.41.1 h1:CpKfSXxI8HlwD6wOY4x2jpRHjQCZNssHZ5qr0HyB7PQ= -github.com/OctopusDeploy/go-octopusdeploy/v2 v2.41.1/go.mod h1:GZmFu6LmN8Yg0tEoZx3ytk9FnaH+84cWm7u5TdWZC6E= +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= diff --git a/octopusdeploy/schema_deployment_action.go b/octopusdeploy/schema_deployment_action.go index 33ccea1a5..efe4e32bb 100644 --- a/octopusdeploy/schema_deployment_action.go +++ b/octopusdeploy/schema_deployment_action.go @@ -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 } @@ -257,6 +261,7 @@ func getActionSchema() (*schema.Schema, *schema.Resource) { Optional: true, Default: -1, }, + "slug": getSlugSchema(), "tenant_tags": getTenantTagsSchema(), }, } @@ -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 { diff --git a/octopusdeploy/schema_utilities.go b/octopusdeploy/schema_utilities.go index 9950c656b..50294a90c 100644 --- a/octopusdeploy/schema_utilities.go +++ b/octopusdeploy/schema_utilities.go @@ -185,6 +185,14 @@ func getIDSchema() *schema.Schema { } } +func getSlugSchema() *schema.Schema { + return &schema.Schema{ + Computed: true, + Description: "The human-readable unique identifier for this resource.", + Type: schema.TypeString, + } +} + func getIsSensitiveSchema() *schema.Schema { return &schema.Schema{ Default: false, diff --git a/terraform/52-packagefeedcreatereleasetrigger/project_triggers.tf b/terraform/52-packagefeedcreatereleasetrigger/project_triggers.tf index 4bee6ec44..703d5e23d 100644 --- a/terraform/52-packagefeedcreatereleasetrigger/project_triggers.tf +++ b/terraform/52-packagefeedcreatereleasetrigger/project_triggers.tf @@ -3,11 +3,11 @@ resource "octopusdeploy_external_feed_create_release_trigger" "external_feed_tri space_id = var.octopus_space_id project_id = "${octopusdeploy_project.deploy_frontend_project.id}" package { - deployment_action_slug = "hello-world-using-powershell-1" + deployment_action_slug = octopusdeploy_deployment_process.example.step[0].run_script_action[0].slug package_reference = "busybox" } package { - deployment_action_slug = "hello-world-using-powershell-1" + deployment_action_slug = octopusdeploy_deployment_process.example.step[0].run_script_action[0].slug package_reference = "nginx" } channel_id = octopusdeploy_channel.test_channel_1.id @@ -23,7 +23,7 @@ resource "octopusdeploy_external_feed_create_release_trigger" "external_feed_tri project_id = "${octopusdeploy_project.deploy_frontend_project.id}" is_disabled = true package { - deployment_action_slug = "hello-world-using-powershell-2" + deployment_action_slug = octopusdeploy_deployment_process.example.step[1].run_script_action[0].slug package_reference = "scratch" } channel_id = octopusdeploy_channel.test_channel_2.id @@ -39,14 +39,14 @@ resource "octopusdeploy_external_feed_create_release_trigger" "external_feed_tri project_id = "${octopusdeploy_project.deploy_frontend_project.id}" is_disabled = false package { - deployment_action_slug = "hello-world-using-powershell-1" + deployment_action_slug = octopusdeploy_deployment_process.example.step[0].run_script_action[0].slug package_reference = "busybox" } primary_package { - deployment_action_slug = "helm-one" + deployment_action_slug = octopusdeploy_deployment_process.example.step[2].action[0].slug } primary_package { - deployment_action_slug = "helm-two" + deployment_action_slug = octopusdeploy_deployment_process.example.step[3].action[0].slug } channel_id = octopusdeploy_channel.test_channel_3.id From d5ece6c4e36409d53f84eae808c48fab1416d6cc Mon Sep 17 00:00:00 2001 From: kevjt Date: Mon, 6 May 2024 10:07:26 +1000 Subject: [PATCH 14/14] use for loop --- integration_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/integration_test.go b/integration_test.go index 1b9765d1e..4a3ba30e0 100644 --- a/integration_test.go +++ b/integration_test.go @@ -3565,8 +3565,10 @@ func TestPackageFeedCreateReleaseTriggerResources(t *testing.T) { 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 {