From fb52c29b8710b6f1d043bedf6e30168a2a624b04 Mon Sep 17 00:00:00 2001 From: Domenic Simone Date: Thu, 19 Oct 2023 09:14:06 +1100 Subject: [PATCH] feat: spaceID support runbooks --- octopusdeploy/resource_runbook.go | 10 +++++----- octopusdeploy/resource_runbook_process.go | 24 +++++++++++++---------- octopusdeploy/schema_runbook.go | 8 +------- octopusdeploy/schema_runbook_process.go | 8 ++++---- 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/octopusdeploy/resource_runbook.go b/octopusdeploy/resource_runbook.go index 8316c07b0..7497a1a04 100644 --- a/octopusdeploy/resource_runbook.go +++ b/octopusdeploy/resource_runbook.go @@ -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) } @@ -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) } @@ -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") } @@ -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) } diff --git a/octopusdeploy/resource_runbook_process.go b/octopusdeploy/resource_runbook_process.go index 7c2c3e217..96e135174 100644 --- a/octopusdeploy/resource_runbook_process.go +++ b/octopusdeploy/resource_runbook_process.go @@ -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" @@ -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) @@ -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) @@ -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") @@ -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) @@ -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) diff --git a/octopusdeploy/schema_runbook.go b/octopusdeploy/schema_runbook.go index 38d83b457..47ffebba4 100644 --- a/octopusdeploy/schema_runbook.go +++ b/octopusdeploy/schema_runbook.go @@ -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, diff --git a/octopusdeploy/schema_runbook_process.go b/octopusdeploy/schema_runbook_process.go index 1dd0ee43a..a0488e879 100644 --- a/octopusdeploy/schema_runbook_process.go +++ b/octopusdeploy/schema_runbook_process.go @@ -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 { @@ -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)