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

provider/logentries: Refresh from state when resources not found #13810

Merged
merged 1 commit into from
Apr 20, 2017
Merged
Show file tree
Hide file tree
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
24 changes: 16 additions & 8 deletions builtin/providers/logentries/resource_logentries_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package logentries

import (
"fmt"
"log"
"strconv"
"strings"

"github.com/hashicorp/terraform/helper/schema"
logentries "github.com/logentries/le_goclient"
"strconv"
)

func resourceLogentriesLog() *schema.Resource {
Expand All @@ -16,25 +19,25 @@ func resourceLogentriesLog() *schema.Resource {
Delete: resourceLogentriesLogDelete,

Schema: map[string]*schema.Schema{
"token": &schema.Schema{
"token": {
Type: schema.TypeString,
Computed: true,
ForceNew: true,
},
"logset_id": &schema.Schema{
"logset_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"name": &schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"filename": &schema.Schema{
"filename": {
Type: schema.TypeString,
Optional: true,
},
"retention_period": &schema.Schema{
"retention_period": {
Type: schema.TypeString,
Optional: true,
Default: "ACCOUNT_DEFAULT",
Expand All @@ -47,7 +50,7 @@ func resourceLogentriesLog() *schema.Resource {
return
},
},
"source": &schema.Schema{
"source": {
Type: schema.TypeString,
Optional: true,
Default: "token",
Expand All @@ -60,7 +63,7 @@ func resourceLogentriesLog() *schema.Resource {
return
},
},
"type": &schema.Schema{
"type": {
Type: schema.TypeString,
Default: "",
Optional: true,
Expand Down Expand Up @@ -100,6 +103,11 @@ func resourceLogentriesLogRead(d *schema.ResourceData, meta interface{}) error {
Key: d.Id(),
})
if err != nil {
if strings.Contains(err.Error(), "not found") {
log.Printf("Logentries Log Not Found - Refreshing from State")
d.SetId("")
return nil
}
return err
}

Expand Down
10 changes: 9 additions & 1 deletion builtin/providers/logentries/resource_logentries_logset.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package logentries

import (
"log"
"strings"

"github.com/hashicorp/terraform/helper/schema"
"github.com/logentries/le_goclient"
logentries "github.com/logentries/le_goclient"
)

func resourceLogentriesLogSet() *schema.Resource {
Expand Down Expand Up @@ -49,6 +52,11 @@ func resourceLogentriesLogSetRead(d *schema.ResourceData, meta interface{}) erro
Key: d.Id(),
})
if err != nil {
if strings.Contains(err.Error(), "No such log set") {
log.Printf("Logentries LogSet Not Found - Refreshing from State")
d.SetId("")
return nil
}
return err
}

Expand Down