From 4ba51c9951c24aed607ccb0a551f46eb5177303c Mon Sep 17 00:00:00 2001 From: Bec Callow Date: Mon, 9 Dec 2024 07:56:58 +1000 Subject: [PATCH 1/3] Use new client for project scheduled trigger to include specified space ID --- octopusdeploy/resource_project_scheduled_trigger.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/octopusdeploy/resource_project_scheduled_trigger.go b/octopusdeploy/resource_project_scheduled_trigger.go index 272758c11..bf673d6d4 100644 --- a/octopusdeploy/resource_project_scheduled_trigger.go +++ b/octopusdeploy/resource_project_scheduled_trigger.go @@ -4,6 +4,7 @@ import ( "context" "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client" "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/projects" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/triggers" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "log" @@ -23,8 +24,9 @@ func resourceProjectScheduledTrigger() *schema.Resource { func resourceProjectScheduledTriggerRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*client.Client) + spaceId := d.Get("space_id").(string) - scheduledTrigger, err := client.ProjectTriggers.GetByID(d.Id()) + scheduledTrigger, err := triggers.GetByID(client, spaceId, d.Id()) if scheduledTrigger == nil { d.SetId("") @@ -61,7 +63,7 @@ func resourceProjectScheduledTriggerCreate(ctx context.Context, d *schema.Resour return diag.FromErr(err) } - scheduledTrigger, err := client.ProjectTriggers.Add(expandedScheduledTrigger) + scheduledTrigger, err := triggers.Add(client, expandedScheduledTrigger) if err != nil { return diag.FromErr(err) @@ -97,7 +99,7 @@ func resourceProjectScheduledTriggerUpdate(ctx context.Context, d *schema.Resour return diag.FromErr(err) } - scheduledTrigger, err := client.ProjectTriggers.Update(expandedScheduledTrigger) + scheduledTrigger, err := triggers.Update(client, expandedScheduledTrigger) if err != nil { return diag.FromErr(err) } @@ -109,7 +111,9 @@ func resourceProjectScheduledTriggerUpdate(ctx context.Context, d *schema.Resour func resourceProjectScheduledTriggerDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*client.Client) - err := client.ProjectTriggers.DeleteByID(d.Id()) + spaceId := d.Get("space_id").(string) + err := triggers.DeleteById(client, spaceId, d.Id()) + if err != nil { return diag.FromErr(err) } From 8be69ab9cadb833d17eaa09c51f4513432773cb5 Mon Sep 17 00:00:00 2001 From: Bec Callow Date: Tue, 10 Dec 2024 08:28:10 +1000 Subject: [PATCH 2/3] Workaround to fetch space ID from the provider for imports --- octopusdeploy/resource_project_scheduled_trigger.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/octopusdeploy/resource_project_scheduled_trigger.go b/octopusdeploy/resource_project_scheduled_trigger.go index bf673d6d4..adb95cca1 100644 --- a/octopusdeploy/resource_project_scheduled_trigger.go +++ b/octopusdeploy/resource_project_scheduled_trigger.go @@ -5,6 +5,7 @@ import ( "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client" "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/projects" "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/triggers" + "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "log" @@ -25,6 +26,7 @@ func resourceProjectScheduledTrigger() *schema.Resource { func resourceProjectScheduledTriggerRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*client.Client) spaceId := d.Get("space_id").(string) + spaceId = util.Ternary(len(spaceId) > 0, spaceId, client.GetSpaceID()) scheduledTrigger, err := triggers.GetByID(client, spaceId, d.Id()) @@ -112,7 +114,7 @@ func resourceProjectScheduledTriggerUpdate(ctx context.Context, d *schema.Resour func resourceProjectScheduledTriggerDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*client.Client) spaceId := d.Get("space_id").(string) - err := triggers.DeleteById(client, spaceId, d.Id()) + err := triggers.DeleteByID(client, spaceId, d.Id()) if err != nil { return diag.FromErr(err) From 69559532b516145a19b7bf2ba80220d3c531a6a0 Mon Sep 17 00:00:00 2001 From: Bec Callow Date: Fri, 20 Dec 2024 08:24:02 +1000 Subject: [PATCH 3/3] Use latest version of go CLI --- go.mod | 2 +- go.sum | 1 + octopusdeploy/resource_project_scheduled_trigger.go | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f5a145f5f..cbfd298d0 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.22 toolchain go1.22.3 require ( - github.com/OctopusDeploy/go-octopusdeploy/v2 v2.63.1 + github.com/OctopusDeploy/go-octopusdeploy/v2 v2.64.0 github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20241206032352-dbc62b2d16cf github.com/google/uuid v1.6.0 github.com/hashicorp/go-cty v1.4.1-0.20200723130312-85980079f637 diff --git a/go.sum b/go.sum index 0a7a2e409..8017f47de 100644 --- a/go.sum +++ b/go.sum @@ -20,6 +20,7 @@ github.com/OctopusDeploy/go-octodiff v1.0.0 h1:U+ORg6azniwwYo+O44giOw6TiD5USk8S4 github.com/OctopusDeploy/go-octodiff v1.0.0/go.mod h1:Mze0+EkOWTgTmi8++fyUc6r0aLZT7qD9gX+31t8MmIU= github.com/OctopusDeploy/go-octopusdeploy/v2 v2.63.1 h1:ShfJ3VZqNblU5V0UnA/UNjQuUrgkljZdDp9Vxh8rhcI= github.com/OctopusDeploy/go-octopusdeploy/v2 v2.63.1/go.mod h1:ggvOXzMnq+w0pLg6C9zdjz6YBaHfO3B3tqmmB7JQdaw= +github.com/OctopusDeploy/go-octopusdeploy/v2 v2.64.0/go.mod h1:ggvOXzMnq+w0pLg6C9zdjz6YBaHfO3B3tqmmB7JQdaw= github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20241206032352-dbc62b2d16cf h1:wuUJ6DbSZEHE4a3SfSJIcoeTQCSI6lbQ+i46ibY14+Q= github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20241206032352-dbc62b2d16cf/go.mod h1:xVv8DvYhhwxtQUQQDfOYA6CY8KTkHXccxQ2RfRj6IJ0= github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg= diff --git a/octopusdeploy/resource_project_scheduled_trigger.go b/octopusdeploy/resource_project_scheduled_trigger.go index adb95cca1..d0e318964 100644 --- a/octopusdeploy/resource_project_scheduled_trigger.go +++ b/octopusdeploy/resource_project_scheduled_trigger.go @@ -28,7 +28,7 @@ func resourceProjectScheduledTriggerRead(ctx context.Context, d *schema.Resource spaceId := d.Get("space_id").(string) spaceId = util.Ternary(len(spaceId) > 0, spaceId, client.GetSpaceID()) - scheduledTrigger, err := triggers.GetByID(client, spaceId, d.Id()) + scheduledTrigger, err := triggers.GetById(client, spaceId, d.Id()) if scheduledTrigger == nil { d.SetId("") @@ -114,7 +114,7 @@ func resourceProjectScheduledTriggerUpdate(ctx context.Context, d *schema.Resour func resourceProjectScheduledTriggerDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*client.Client) spaceId := d.Get("space_id").(string) - err := triggers.DeleteByID(client, spaceId, d.Id()) + err := triggers.DeleteById(client, spaceId, d.Id()) if err != nil { return diag.FromErr(err)