Skip to content

Commit

Permalink
feat: use new client for scriptmodules
Browse files Browse the repository at this point in the history
  • Loading branch information
mik-ky committed Oct 8, 2023
1 parent e4435ef commit c3470b5
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions octopusdeploy/resource_script_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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")
}
Expand All @@ -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)
}
Expand Down

0 comments on commit c3470b5

Please sign in to comment.