Skip to content

Commit

Permalink
Renaming bitbucket_repository fails with 404 (not found) error
Browse files Browse the repository at this point in the history
  • Loading branch information
Barry Hart committed May 15, 2024
1 parent 3c7b99e commit 177e314
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions bitbucket/resource_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,19 @@ func resourceRepositoryUpdate(ctx context.Context, d *schema.ResourceData, m int
}
}

// Check if the "owner" or "name" properties have changed. If so:
// 1. Update the resource ID used by Terraform to track the resource
// 2. Update the workspace and repoSlug variables used to make API calls
if d.HasChange("owner") || d.HasChange("name") {
_, newWorkspace := d.GetChange("owner")
_, newRepoSlug := d.GetChange("name")
workspace = newWorkspace.(string)
repoSlug = newRepoSlug.(string)
newId := fmt.Sprintf("%s/%s", workspace, repoSlug)
log.Printf("[DEBUG] repo owner/name has changed; setting new resource ID: %s", newId)
d.SetId(newId)
}

if d.HasChange("pipelines_enabled") {
// nolint:staticcheck
if v, ok := d.GetOkExists("pipelines_enabled"); ok {
Expand Down Expand Up @@ -315,6 +328,16 @@ func resourceRepositoryRead(ctx context.Context, d *schema.ResourceData, m inter
diag.FromErr(err)
}

// Check if the "owner" or "name" properties have changed. If so, update the
// the workspace and repoSlug variables used to make API calls.
if d.HasChange("owner") || d.HasChange("name") {
_, newWorkspace := d.GetChange("owner")
_, newRepoSlug := d.GetChange("name")
workspace = newWorkspace.(string)
repoSlug = newRepoSlug.(string)
log.Printf("[DEBUG] repo owner/name has changed to %s/%s", workspace, repoSlug)
}

if repoSlug == "" {
repoSlug = d.Get("name").(string)
}
Expand Down

0 comments on commit 177e314

Please sign in to comment.