Skip to content

Commit

Permalink
initial commit: handle missing resources
Browse files Browse the repository at this point in the history
  • Loading branch information
czembower committed Jan 9, 2024
1 parent 69776cc commit dea8119
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
14 changes: 7 additions & 7 deletions vault/resource_github_auth_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,6 @@ func githubAuthBackendRead(d *schema.ResourceData, meta interface{}) error {
path := "auth/" + d.Id()
configPath := path + "/config"

log.Printf("[DEBUG] Reading github auth mount from '%q'", path)
mount, err := authMountInfoGet(client, d.Id())
if err != nil {
return fmt.Errorf("error reading github auth mount from '%q': %w", path, err)
}
log.Printf("[INFO] Read github auth mount from '%q'", path)

log.Printf("[DEBUG] Reading github auth config from '%q'", configPath)
resp, err := client.Logical().Read(configPath)
if err != nil {
Expand All @@ -199,6 +192,13 @@ func githubAuthBackendRead(d *schema.ResourceData, meta interface{}) error {
return nil
}

log.Printf("[DEBUG] Reading github auth mount from '%q'", path)
mount, err := authMountInfoGet(client, d.Id())
if err != nil {
return fmt.Errorf("error reading github auth mount from '%q': %w", path, err)
}
log.Printf("[INFO] Read github auth mount from '%q'", path)

log.Printf("[DEBUG] Reading github auth tune from '%q/tune'", path)
rawTune, err := authMountTuneGet(client, path)
if err != nil {
Expand Down
13 changes: 11 additions & 2 deletions vault/resource_github_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package vault

import (
"fmt"
"log"
"strings"

Expand Down Expand Up @@ -101,10 +100,20 @@ func githubTeamRead(d *schema.ResourceData, meta interface{}) error {
return err
}

// If the auth method is not enabled, dt is nil
if dt == nil {
log.Printf("[WARN] Github team mapping from '%q' is null, removing from state", d.Id())
d.SetId("")
return nil
}

if v, ok := dt.Data["key"]; ok {
d.Set("team", v.(string))
} else {
return fmt.Errorf("github team information not found at path: '%v'", d.Id())
// If the method is enabled but the team is not mapped, the API responds 200 with an empty Data object
log.Printf("[WARN] Github team information from '%q' not found, removing from state", d.Id())
d.SetId("")
return nil
}

if v, ok := dt.Data["value"]; ok {
Expand Down
13 changes: 11 additions & 2 deletions vault/resource_github_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package vault

import (
"fmt"
"log"
"strings"

Expand Down Expand Up @@ -100,10 +99,20 @@ func githubUserRead(d *schema.ResourceData, meta interface{}) error {
return err
}

// If the auth method is not enabled, dt is nil
if dt == nil {
log.Printf("[WARN] Github user mapping from '%q' is null, removing from state", d.Id())
d.SetId("")
return nil
}

if v, ok := dt.Data["key"]; ok {
d.Set("user", v.(string))
} else {
return fmt.Errorf("github user information not found at path: '%v'", d.Id())
// If the method is enabled but the user is not mapped, the API responds 200 with an empty Data object
log.Printf("[WARN] Github user information from '%q' not found, removing from state", d.Id())
d.SetId("")
return nil
}

if v, ok := dt.Data["value"]; ok {
Expand Down

0 comments on commit dea8119

Please sign in to comment.