Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renaming bitbucket_repository fails with 404 (not found) error #206

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading