Skip to content

Commit

Permalink
feat: spaceID support runbooks
Browse files Browse the repository at this point in the history
  • Loading branch information
domenicsim1 committed Oct 18, 2023
1 parent ca4c8bc commit fb52c29
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
10 changes: 5 additions & 5 deletions octopusdeploy/resource_runbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func resourceRunbookCreate(ctx context.Context, d *schema.ResourceData, m interf
tflog.Info(ctx, fmt.Sprintf("creating runbook (%s)", runbook.Name))

client := m.(*client.Client)
createdRunbook, err := client.Runbooks.Add(runbook)
createdRunbook, err := runbooks.Add(client, runbook)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -49,7 +49,7 @@ func resourceRunbookDelete(ctx context.Context, d *schema.ResourceData, m interf
tflog.Info(ctx, fmt.Sprintf("deleting runbook (%s)", d.Id()))

client := m.(*client.Client)
if err := client.Runbooks.DeleteByID(d.Id()); err != nil {
if err := runbooks.DeleteByID(client, d.Get("space_id").(string), d.Id()); err != nil {
return diag.FromErr(err)
}

Expand All @@ -62,7 +62,7 @@ func resourceRunbookRead(ctx context.Context, d *schema.ResourceData, m interfac
tflog.Info(ctx, fmt.Sprintf("reading runbook (%s)", d.Id()))

client := m.(*client.Client)
runbook, err := client.Runbooks.GetByID(d.Id())
runbook, err := runbooks.GetByID(client, d.Get("space_id").(string), d.Id())
if err != nil {
return errors.ProcessApiError(ctx, d, err, "runbook")
}
Expand All @@ -83,14 +83,14 @@ func resourceRunbookUpdate(ctx context.Context, d *schema.ResourceData, m interf
var updatedRunbook *runbooks.Runbook
var err error

runbookLinks, err := client.Runbooks.GetByID(d.Id())
runbookLinks, err := runbooks.GetByID(client, d.Get("space_id").(string), d.Id())
if err != nil {
return diag.FromErr(err)
}

runbook.Links = runbookLinks.Links

updatedRunbook, err = client.Runbooks.Update(runbook)
updatedRunbook, err = runbooks.Update(client, runbook)
if err != nil {
return diag.FromErr(err)
}
Expand Down
24 changes: 14 additions & 10 deletions octopusdeploy/resource_runbook_process.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/runbookprocess"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/runbooks"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -61,19 +62,19 @@ func resourceRunbookProcessCreate(ctx context.Context, d *schema.ResourceData, m

log.Printf("[INFO] creating runbook process: %#v", runbookProcess)

runbook, err := client.Runbooks.GetByID(runbookProcess.RunbookID)
runbook, err := runbooks.GetByID(client, d.Get("space_id").(string), runbookProcess.RunbookID)
if err != nil {
return diag.FromErr(err)
}

var current *runbooks.RunbookProcess
current, err = client.RunbookProcesses.GetByID(runbook.RunbookProcessID)
var current *runbookprocess.RunbookProcess
current, err = runbookprocess.GetByID(client, d.Get("space_id").(string), runbook.RunbookProcessID)

runbookProcess.ID = current.ID
runbookProcess.Links = current.Links
runbookProcess.Version = current.Version

createdRunbookProcess, err := client.RunbookProcesses.Update(runbookProcess)
createdRunbookProcess, err := runbookprocess.Update(client, runbookProcess)

if err != nil {
return diag.FromErr(err)
Expand All @@ -96,19 +97,22 @@ func resourceRunbookProcessDelete(ctx context.Context, d *schema.ResourceData, m

// "Deleting" a runbook process just means to clear it out
client := m.(*client.Client)
current, err := client.RunbookProcesses.GetByID(d.Id())
current, err := runbookprocess.GetByID(client, d.Get("space_id").(string), d.Id())

if err != nil {
return diag.FromErr(err)
}

runbookProcess := &runbooks.RunbookProcess{
runbookProcess := &runbookprocess.RunbookProcess{
Version: current.Version,
}
runbookProcess.Links = current.Links
runbookProcess.ID = d.Id()
if v, ok := d.GetOk("space_id"); ok {
runbookProcess.SpaceID = v.(string)
}

_, err = client.RunbookProcesses.Update(runbookProcess)
_, err = runbookprocess.Update(client, runbookProcess)

if err != nil {
return diag.FromErr(err)
Expand All @@ -123,7 +127,7 @@ func resourceRunbookProcessRead(ctx context.Context, d *schema.ResourceData, m i
log.Printf("[INFO] reading runbook process (%s)", d.Id())

client := m.(*client.Client)
runbookProcess, err := client.RunbookProcesses.GetByID(d.Id())
runbookProcess, err := runbookprocess.GetByID(client, d.Get("space_id").(string), d.Id())

if err != nil {
return errors.ProcessApiError(ctx, d, err, "runbook_process")
Expand All @@ -142,7 +146,7 @@ func resourceRunbookProcessUpdate(ctx context.Context, d *schema.ResourceData, m

client := m.(*client.Client)
runbookProcess := expandRunbookProcess(ctx, d, client)
current, err := client.RunbookProcesses.GetByID(d.Id())
current, err := runbookprocess.GetByID(client, runbookProcess.SpaceID, d.Id())

if err != nil {
return diag.FromErr(err)
Expand All @@ -151,7 +155,7 @@ func resourceRunbookProcessUpdate(ctx context.Context, d *schema.ResourceData, m
runbookProcess.Links = current.Links
runbookProcess.Version = current.Version

updatedRunbookProcess, err := client.RunbookProcesses.Update(runbookProcess)
updatedRunbookProcess, err := runbookprocess.Update(client, runbookProcess)

if err != nil {
return diag.FromErr(err)
Expand Down
8 changes: 1 addition & 7 deletions octopusdeploy/schema_runbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,7 @@ func getRunbookSchema() map[string]*schema.Schema {
Computed: true,
Type: schema.TypeString,
},
"space_id": {
Computed: true,
Description: "The space ID associated with this runbook.",
Optional: true,
Type: schema.TypeString,
ValidateDiagFunc: validation.ToDiagFunc(validation.StringIsNotWhiteSpace),
},
"space_id": getSpaceIDSchema(),
"multi_tenancy_mode": getTenantedDeploymentSchema(),
"connectivity_policy": {
Computed: true,
Expand Down
8 changes: 4 additions & 4 deletions octopusdeploy/schema_runbook_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"context"
"fmt"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/runbooks"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/runbookprocess"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func expandRunbookProcess(ctx context.Context, d *schema.ResourceData, client *client.Client) *runbooks.RunbookProcess {
runbookProcess := runbooks.NewRunbookProcess()
func expandRunbookProcess(ctx context.Context, d *schema.ResourceData, client *client.Client) *runbookprocess.RunbookProcess {
runbookProcess := runbookprocess.NewRunbookProcess()
runbookProcess.ID = d.Id()

if v, ok := d.GetOk("project_id"); ok {
Expand Down Expand Up @@ -46,7 +46,7 @@ func expandRunbookProcess(ctx context.Context, d *schema.ResourceData, client *c
return runbookProcess
}

func setRunbookProcess(ctx context.Context, d *schema.ResourceData, RunbookProcess *runbooks.RunbookProcess) error {
func setRunbookProcess(ctx context.Context, d *schema.ResourceData, RunbookProcess *runbookprocess.RunbookProcess) error {
d.Set("last_snapshot_id", RunbookProcess.LastSnapshotID)
d.Set("project_id", RunbookProcess.ProjectID)
d.Set("runbook_id", RunbookProcess.RunbookID)
Expand Down

0 comments on commit fb52c29

Please sign in to comment.