Skip to content

Commit

Permalink
When a bucket that is in state no longer exists, warning is logged an…
Browse files Browse the repository at this point in the history
…d the bucket is removed from state. Prepare for 0.7.1 release
  • Loading branch information
mszumocki-reef committed Oct 14, 2021
1 parent 333d614 commit 04bdee1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.7.1] - 2021-10-14

### Changed
* When a bucket that is in state no longer exists, warning is logged and the bucket is removed from state

## [0.7.0] - 2021-09-24

### Fixed
Expand Down Expand Up @@ -83,7 +88,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
* Implementation of PoC (simple `b2_application_key` data source)

[Unreleased]: https://github.com/Backblaze/terraform-provider-b2/compare/v0.7.0...HEAD
[Unreleased]: https://github.com/Backblaze/terraform-provider-b2/compare/v0.7.1...HEAD
[0.7.1]: https://github.com/Backblaze/terraform-provider-b2/compare/v0.7.9...v0.7.1
[0.7.0]: https://github.com/Backblaze/terraform-provider-b2/compare/v0.6.1...v0.7.0
[0.6.1]: https://github.com/Backblaze/terraform-provider-b2/compare/v0.6.0...v0.6.1
[0.6.0]: https://github.com/Backblaze/terraform-provider-b2/compare/v0.5.0...v0.6.0
Expand Down
7 changes: 7 additions & 0 deletions b2/resource_b2_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package b2

import (
"context"
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -158,6 +159,12 @@ func resourceB2BucketRead(ctx context.Context, d *schema.ResourceData, meta inte
if err != nil {
return diag.FromErr(err)
}
if len(output) == 0 && !d.IsNewResource() {
// deleted bucket
log.Printf("[WARN] Bucket (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}

err = client.populate(name, op, output, d)
if err != nil {
Expand Down
7 changes: 5 additions & 2 deletions python-bindings/b2_terraform/provider_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
EncryptionMode,
EncryptionSetting,
)
from b2sdk.exception import BadRequest
from b2sdk.exception import BadRequest, NonExistentBucket

from b2_terraform.api_wrapper import B2ApiWrapper
from b2_terraform.arg_parser import ArgumentParser
Expand Down Expand Up @@ -239,7 +239,10 @@ def resource_create(
return self._postprocess(**bucket)

def resource_read(self, *, bucket_id, **kwargs):
bucket = self.api.get_bucket_by_id(bucket_id)
try:
bucket = self.api.get_bucket_by_id(bucket_id)
except NonExistentBucket: # return empty dict if bucket does not exist, handled in resource_b2.bucket.go
return {}
return self._postprocess(**bucket.as_dict())

def resource_update(
Expand Down

0 comments on commit 04bdee1

Please sign in to comment.