From 399b71599c6149470eae630a2d18bbf6eb165736 Mon Sep 17 00:00:00 2001 From: Matthew Casperson Date: Fri, 20 Oct 2023 12:47:28 +1000 Subject: [PATCH] Fixes https://github.com/OctopusDeployLabs/terraform-provider-octopusdeploy/issues/556 --- octopusdeploy/resource_deployment_process.go | 13 +++++++++++-- octopusdeploy/schema_deployment_process.go | 6 +++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/octopusdeploy/resource_deployment_process.go b/octopusdeploy/resource_deployment_process.go index ba00159f5..3dcb1ea64 100644 --- a/octopusdeploy/resource_deployment_process.go +++ b/octopusdeploy/resource_deployment_process.go @@ -57,7 +57,11 @@ func getDeploymentProcessSchema() map[string]*schema.Schema { func resourceDeploymentProcessCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*client.Client) - deploymentProcess := expandDeploymentProcess(ctx, d, client) + deploymentProcess, err := expandDeploymentProcess(ctx, d, client) + + if err != nil { + return diag.FromErr(err) + } log.Printf("[INFO] creating deployment process: %#v", deploymentProcess) @@ -195,7 +199,12 @@ func resourceDeploymentProcessUpdate(ctx context.Context, d *schema.ResourceData log.Printf("[INFO] updating deployment process (%s)", d.Id()) client := m.(*client.Client) - deploymentProcess := expandDeploymentProcess(ctx, d, client) + deploymentProcess, err := expandDeploymentProcess(ctx, d, client) + + if err != nil { + return diag.FromErr(err) + } + current, err := client.DeploymentProcesses.GetByID(d.Id()) if err != nil { r, _ := regexp.Compile(`Projects-\d+`) diff --git a/octopusdeploy/schema_deployment_process.go b/octopusdeploy/schema_deployment_process.go index 48d0308f5..9e547032c 100644 --- a/octopusdeploy/schema_deployment_process.go +++ b/octopusdeploy/schema_deployment_process.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func expandDeploymentProcess(ctx context.Context, d *schema.ResourceData, client *client.Client) *deployments.DeploymentProcess { +func expandDeploymentProcess(ctx context.Context, d *schema.ResourceData, client *client.Client) (*deployments.DeploymentProcess, error) { projectID := d.Get("project_id").(string) deploymentProcess := deployments.NewDeploymentProcess(projectID) deploymentProcess.ID = d.Id() @@ -20,7 +20,7 @@ func expandDeploymentProcess(ctx context.Context, d *schema.ResourceData, client } else { project, err := client.Projects.GetByID(projectID) if err != nil { - return nil + return nil, err } if project.PersistenceSettings != nil && project.PersistenceSettings.Type() == projects.PersistenceSettingsTypeVersionControlled { @@ -48,7 +48,7 @@ func expandDeploymentProcess(ctx context.Context, d *schema.ResourceData, client } } - return deploymentProcess + return deploymentProcess, nil } func setDeploymentProcess(ctx context.Context, d *schema.ResourceData, deploymentProcess *deployments.DeploymentProcess) error {