Skip to content

Commit

Permalink
Merge pull request #589 from OctopusDeployLabs/feat/deploymentprocess…
Browse files Browse the repository at this point in the history
…-spaceid

feat: support space_id for deployment process
  • Loading branch information
mik-ky authored Dec 15, 2023
2 parents 7621985 + c963663 commit 68f2a84
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
37 changes: 21 additions & 16 deletions octopusdeploy/resource_deployment_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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{},
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
}
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion octopusdeploy/schema_deployment_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 68f2a84

Please sign in to comment.