From c3470b5650c90f661468afeb0e1a1e505a9e61b8 Mon Sep 17 00:00:00 2001 From: Chris Kim Date: Mon, 9 Oct 2023 09:01:42 +1300 Subject: [PATCH] feat: use new client for scriptmodules --- octopusdeploy/resource_script_module.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/octopusdeploy/resource_script_module.go b/octopusdeploy/resource_script_module.go index 24987a0f7..faf0f5232 100644 --- a/octopusdeploy/resource_script_module.go +++ b/octopusdeploy/resource_script_module.go @@ -5,6 +5,7 @@ import ( "log" "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/scriptmodules" "github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -28,7 +29,7 @@ func resourceScriptModuleCreate(ctx context.Context, d *schema.ResourceData, m i log.Printf("[INFO] creating script module: %#v", scriptModule) client := m.(*client.Client) - createdScriptModule, err := client.ScriptModules.Add(scriptModule) + createdScriptModule, err := scriptmodules.Add(client, scriptModule) if err != nil { return diag.FromErr(err) } @@ -46,8 +47,13 @@ func resourceScriptModuleCreate(ctx context.Context, d *schema.ResourceData, m i func resourceScriptModuleDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Printf("[INFO] deleting script module (%s)", d.Id()) + var spaceID string + if v, ok := d.GetOk("space_id"); ok { + spaceID = v.(string) + } + client := m.(*client.Client) - err := client.ScriptModules.DeleteByID(d.Id()) + err := scriptmodules.DeleteByID(client, spaceID, d.Id()) if err != nil { return diag.FromErr(err) } @@ -60,8 +66,14 @@ func resourceScriptModuleDelete(ctx context.Context, d *schema.ResourceData, m i func resourceScriptModuleRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Printf("[INFO] reading script module (%s)", d.Id()) + var spaceID string + if v, ok := d.GetOk("space_id"); ok { + spaceID = v.(string) + } + client := m.(*client.Client) - scriptModule, err := client.ScriptModules.GetByID(d.Id()) + + scriptModule, err := scriptmodules.GetByID(client, spaceID, d.Id()) if err != nil { return errors.ProcessApiError(ctx, d, err, "script module") } @@ -80,7 +92,7 @@ func resourceScriptModuleUpdate(ctx context.Context, d *schema.ResourceData, m i scriptModule := expandScriptModule(d) client := m.(*client.Client) - updatedScriptModule, err := client.ScriptModules.Update(scriptModule) + updatedScriptModule, err := scriptmodules.Update(client, scriptModule) if err != nil { return diag.FromErr(err) }