Skip to content

Commit 58d06a5

Browse files
authored
Properly handle the nil response on read in raft_snapshot_agent_config resource (#1360)
- Ensure that a nil response on read for raft_snapshot_agent_config removes the resource from the state.
1 parent 1070235 commit 58d06a5

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
BUGS:
33
* `resource/identity_group`: Report an error upon duplicate resource creation failure. Document group name caveats. ([#1352](https://github.com/hashicorp/terraform-provider-vault/pull/1352))
44
* `resource/pki_secret_backend_root_sign_intermediate`: Fix panic when reading `ca_chain` from Vault ([#1357](https://github.com/hashicorp/terraform-provider-vault/issues/1357)
5+
* `resource/raft_snapshot_agent_config`: Properly handle nil response on read ([#1360](https://github.com/hashicorp/terraform-provider-vault/pull/1360))
56

67
## 3.3.0 (February 17, 2022)
78
FEATURES:

vault/resource_raft_snapshot_agent_config.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import (
1111
"github.com/hashicorp/vault/api"
1212
)
1313

14-
var snapshotAutoPath = "sys/storage/raft/snapshot-auto/config/%s"
15-
var allowedStorageTypes = []string{"local", "azure-blob", "aws-s3", "google-gcs"}
14+
var (
15+
snapshotAutoPath = "sys/storage/raft/snapshot-auto/config/%s"
16+
allowedStorageTypes = []string{"local", "azure-blob", "aws-s3", "google-gcs"}
17+
)
1618

1719
func raftSnapshotAgentConfigResource() *schema.Resource {
1820
fields := map[string]*schema.Schema{
@@ -196,7 +198,6 @@ func buildConfigFromResourceData(d *schema.ResourceData) (map[string]interface{}
196198
} else {
197199
return nil, errors.New("specified local storage without setting local_max_space")
198200
}
199-
200201
}
201202

202203
if storageType == "aws-s3" {
@@ -306,11 +307,12 @@ func readSnapshotAgentConfigResource(d *schema.ResourceData, meta interface{}) e
306307
log.Printf("[DEBUG] Reading %q", configPath)
307308

308309
resp, err := client.Logical().Read(configPath)
309-
if err != nil && util.Is404(err) {
310+
if resp == nil || (err != nil && util.Is404(err)) {
310311
log.Printf("[WARN] %q not found, removing from state", name)
311312
d.SetId("")
312313
return nil
313-
} else if err != nil {
314+
}
315+
if err != nil {
314316
return fmt.Errorf("error reading %q: %s", configPath, err)
315317
}
316318

0 commit comments

Comments
 (0)