Skip to content

Commit

Permalink
use api for deploy delete
Browse files Browse the repository at this point in the history
  • Loading branch information
DrFaust92 committed Feb 10, 2024
1 parent 0518324 commit 4f00007
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions bitbucket/resource_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,20 @@ func resourceDeploymentUpdate(ctx context.Context, d *schema.ResourceData, m int
}

func resourceDeploymentDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := m.(Clients).httpClient
_, err := client.Delete(fmt.Sprintf("2.0/repositories/%s/environments/%s",
d.Get("repository").(string),
d.Get("uuid").(string),
))
return diag.FromErr(err)
c := m.(Clients).genClient
deployApi := c.ApiClient.DeploymentsApi

workspaceId, repoId, err := deploymentRepoId(d.Get("repository").(string))
if err != nil {
return diag.FromErr(err)
}

_, err = deployApi.DeleteEnvironmentForRepository(c.AuthContext, workspaceId, repoId, d.Get("uuid").(string))
if err := handleClientError(err); err != nil {
return diag.FromErr(err)
}

return nil
}

func expandRestrictions(conf []interface{}) Restrictions {
Expand Down Expand Up @@ -279,3 +287,13 @@ func deploymentId(id string) (string, string, error) {

return parts[0], parts[1], nil
}

func deploymentRepoId(id string) (string, string, error) {
parts := strings.Split(id, "/")

if len(parts) != 2 {
return "", "", fmt.Errorf("unexpected format of ID (%q), expected WORKSPACE-ID/REPO-ID", id)
}

return parts[0], parts[1], nil
}

0 comments on commit 4f00007

Please sign in to comment.