diff --git a/go.mod b/go.mod index 7e9e42700..f88d20978 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/OctopusDeploy/terraform-provider-octopusdeploy go 1.20 require ( - github.com/OctopusDeploy/go-octopusdeploy/v2 v2.35.0 + github.com/OctopusDeploy/go-octopusdeploy/v2 v2.36.1 github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20230705105638-f5ef7c07973b github.com/google/uuid v1.3.0 github.com/gruntwork-io/terratest v0.41.11 diff --git a/go.sum b/go.sum index 5e6f8e909..950e0d5f5 100644 --- a/go.sum +++ b/go.sum @@ -63,8 +63,8 @@ github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugX github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg= github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE= github.com/Microsoft/hcsshim v0.9.7 h1:mKNHW/Xvv1aFH87Jb6ERDzXTJTLPlmzfZ28VBFD/bfg= -github.com/OctopusDeploy/go-octopusdeploy/v2 v2.35.0 h1:R12IQ98Iisju3ytFBnht0nEvWhBj42pnWeeoKdumesc= -github.com/OctopusDeploy/go-octopusdeploy/v2 v2.35.0/go.mod h1:GZmFu6LmN8Yg0tEoZx3ytk9FnaH+84cWm7u5TdWZC6E= +github.com/OctopusDeploy/go-octopusdeploy/v2 v2.36.1 h1:irRBBh+rSCMqR0YDaUdfBnpl9UAU7tI8zD0j8xt2C8U= +github.com/OctopusDeploy/go-octopusdeploy/v2 v2.36.1/go.mod h1:GZmFu6LmN8Yg0tEoZx3ytk9FnaH+84cWm7u5TdWZC6E= github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20230705105638-f5ef7c07973b h1:XOBPcVHeDUYIpcag0yI8IYKiBL+5LLL8suysvlavQwI= github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20230705105638-f5ef7c07973b/go.mod h1:E0hYVpZd61fXhzTozkxjiWEy+/yTRxAnr2SIE7k8ZSM= github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ= diff --git a/octopusdeploy/resource_deployment_process.go b/octopusdeploy/resource_deployment_process.go index 6212e42f1..407eb4d48 100644 --- a/octopusdeploy/resource_deployment_process.go +++ b/octopusdeploy/resource_deployment_process.go @@ -63,21 +63,23 @@ func resourceDeploymentProcessCreate(ctx context.Context, d *schema.ResourceData return diag.FromErr(err) } + spaceID := d.Get("space_id").(string) + log.Printf("[INFO] creating deployment process: %#v", deploymentProcess) - project, err := client.Projects.GetByID(deploymentProcess.ProjectID) + project, err := projects.GetByID(client, spaceID, deploymentProcess.ProjectID) if err != nil { return diag.FromErr(err) } var current *deployments.DeploymentProcess if project.PersistenceSettings != nil && project.PersistenceSettings.Type() == projects.PersistenceSettingsTypeVersionControlled { - current, err = client.DeploymentProcesses.Get(project, deploymentProcess.Branch) + current, err = deployments.GetDeploymentProcessByGitRef(client, spaceID, project, deploymentProcess.Branch) if err != nil { return diag.FromErr(err) } } else { - current, err = client.DeploymentProcesses.GetByID(project.DeploymentProcessID) + current, err = deployments.GetDeploymentProcessByID(client, spaceID, project.DeploymentProcessID) if err != nil { return diag.FromErr(err) } @@ -87,7 +89,7 @@ func resourceDeploymentProcessCreate(ctx context.Context, d *schema.ResourceData deploymentProcess.Links = current.Links deploymentProcess.Version = current.Version - createdDeploymentProcess, err := client.DeploymentProcesses.Update(deploymentProcess) + createdDeploymentProcess, err := deployments.UpdateDeploymentProcess(client, deploymentProcess) if err != nil { return diag.FromErr(err) } @@ -109,9 +111,10 @@ func resourceDeploymentProcessCreate(ctx context.Context, d *schema.ResourceData func resourceDeploymentProcessDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Printf("[INFO] deleting deployment process (%s)", d.Id()) + spaceID := d.Get("space_id").(string) client := m.(*client.Client) - current, err := client.DeploymentProcesses.GetByID(d.Id()) + current, err := deployments.GetDeploymentProcessByID(client, spaceID, d.Id()) if err == nil { deploymentProcess := &deployments.DeploymentProcess{ Steps: []*deployments.DeploymentStep{}, @@ -120,7 +123,7 @@ func resourceDeploymentProcessDelete(ctx context.Context, d *schema.ResourceData deploymentProcess.Links = current.Links deploymentProcess.ID = d.Id() - _, err = client.DeploymentProcesses.Update(deploymentProcess) + _, err = deployments.UpdateDeploymentProcess(client, deploymentProcess) if err != nil { return diag.FromErr(err) } @@ -133,13 +136,13 @@ func resourceDeploymentProcessDelete(ctx context.Context, d *schema.ResourceData r, _ := regexp.Compile(`Projects-\d+`) projectID := r.FindString(d.Id()) - project, err := client.Projects.GetByID(projectID) + project, err := projects.GetByID(client, spaceID, projectID) if err != nil { return diag.FromErr(err) } gitRef := getGitRef(d) - current, err = client.DeploymentProcesses.Get(project, gitRef) + current, err = deployments.GetDeploymentProcessByGitRef(client, spaceID, project, gitRef) if err != nil { return diag.FromErr(err) } @@ -150,7 +153,7 @@ func resourceDeploymentProcessDelete(ctx context.Context, d *schema.ResourceData deploymentProcess.Links = current.Links deploymentProcess.ID = d.Id() - _, err = client.DeploymentProcesses.Update(deploymentProcess) + _, err = deployments.UpdateDeploymentProcess(client, deploymentProcess) if err != nil { return diag.FromErr(err) } @@ -164,7 +167,9 @@ func resourceDeploymentProcessRead(ctx context.Context, d *schema.ResourceData, log.Printf("[INFO] reading deployment process (%s)", d.Id()) client := m.(*client.Client) - deploymentProcess, err := client.DeploymentProcesses.GetByID(d.Id()) + spaceID := d.Get("space_id").(string) + + deploymentProcess, err := deployments.GetDeploymentProcessByID(client, spaceID, d.Id()) if err == nil { if err := setDeploymentProcess(ctx, d, deploymentProcess); err != nil { return diag.FromErr(err) @@ -177,13 +182,13 @@ func resourceDeploymentProcessRead(ctx context.Context, d *schema.ResourceData, r, _ := regexp.Compile(`Projects-\d+`) projectID := r.FindString(d.Id()) - project, err := client.Projects.GetByID(projectID) + project, err := projects.GetByID(client, spaceID, projectID) if err != nil { return errors.ProcessApiError(ctx, d, err, "project") } gitRef := getGitRef(d) - deploymentProcess, err = client.DeploymentProcesses.Get(project, gitRef) + deploymentProcess, err = deployments.GetDeploymentProcessByGitRef(client, spaceID, project, gitRef) if err == nil { if err := setDeploymentProcess(ctx, d, deploymentProcess); err != nil { return diag.FromErr(err) @@ -206,12 +211,12 @@ func resourceDeploymentProcessUpdate(ctx context.Context, d *schema.ResourceData return diag.FromErr(err) } - current, err := client.DeploymentProcesses.GetByID(d.Id()) + current, err := deployments.GetDeploymentProcessByID(client, deploymentProcess.SpaceID, d.Id()) if err != nil { r, _ := regexp.Compile(`Projects-\d+`) projectID := r.FindString(d.Id()) - project, err := client.Projects.GetByID(projectID) + project, err := projects.GetByID(client, deploymentProcess.SpaceID, projectID) if err != nil { return diag.FromErr(err) } @@ -226,7 +231,7 @@ func resourceDeploymentProcessUpdate(ctx context.Context, d *schema.ResourceData d.SetId(deploymentProcess.ID) } - current, err = client.DeploymentProcesses.Get(project, deploymentProcess.Branch) + current, err = deployments.GetDeploymentProcessByGitRef(client, deploymentProcess.SpaceID, project, deploymentProcess.Branch) if err != nil { return diag.FromErr(err) @@ -236,7 +241,7 @@ func resourceDeploymentProcessUpdate(ctx context.Context, d *schema.ResourceData deploymentProcess.Links = current.Links deploymentProcess.Version = current.Version - updatedDeploymentProcess, err := client.DeploymentProcesses.Update(deploymentProcess) + updatedDeploymentProcess, err := deployments.UpdateDeploymentProcess(client, deploymentProcess) if err != nil { return diag.FromErr(err) } diff --git a/octopusdeploy/schema_deployment_process.go b/octopusdeploy/schema_deployment_process.go index 9e547032c..2d413afc8 100644 --- a/octopusdeploy/schema_deployment_process.go +++ b/octopusdeploy/schema_deployment_process.go @@ -12,13 +12,14 @@ import ( func expandDeploymentProcess(ctx context.Context, d *schema.ResourceData, client *client.Client) (*deployments.DeploymentProcess, error) { projectID := d.Get("project_id").(string) + spaceID := d.Get("space_id").(string) deploymentProcess := deployments.NewDeploymentProcess(projectID) deploymentProcess.ID = d.Id() if v, ok := d.GetOk("branch"); ok { deploymentProcess.Branch = v.(string) } else { - project, err := client.Projects.GetByID(projectID) + project, err := projects.GetByID(client, spaceID, projectID) if err != nil { return nil, err }