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

fix: remove stage from statefile if not found #1220

Merged
merged 2 commits into from
Sep 20, 2022
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
7 changes: 4 additions & 3 deletions pkg/resources/external_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"encoding/csv"
"fmt"
"log"
"strings"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/snowflake"
Expand Down Expand Up @@ -150,8 +151,8 @@ type externalTableID struct {
ExternalTableName string
}

//String() takes in a externalTableID object and returns a pipe-delimited string:
//DatabaseName|SchemaName|ExternalTableName
// String() takes in a externalTableID object and returns a pipe-delimited string:
// DatabaseName|SchemaName|ExternalTableName
func (si *externalTableID) String() (string, error) {
var buf bytes.Buffer
csvWriter := csv.NewWriter(&buf)
Expand Down Expand Up @@ -276,7 +277,7 @@ func ReadExternalTable(d *schema.ResourceData, meta interface{}) error {
externalTable, err := snowflake.ScanExternalTable(row)
if err != nil {
if err.Error() == snowflake.ErrNoRowInRS {
fmt.Println("Good !!")
log.Printf("[DEBUG] external table (%s) not found", d.Id())
d.SetId("")
return nil
} else {
Expand Down
12 changes: 10 additions & 2 deletions pkg/resources/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/snowflake"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/pkg/errors"
"github.com/snowflakedb/gosnowflake"
)

const (
Expand Down Expand Up @@ -241,8 +242,15 @@ func ReadStage(d *schema.ResourceData, meta interface{}) error {
d.SetId("")
return nil
}
if err != nil {
return err

if driverErr, ok := err.(*gosnowflake.SnowflakeError); ok {
// 002003 (02000): SQL compilation error:
// 'XXX' does not exist or not authorized.
if driverErr.Number == 2003 {
log.Printf("[DEBUG] stage (%s) not found", d.Id())
d.SetId("")
return nil
}
}

sq := snowflake.Stage(stage, dbName, schema).Show()
Expand Down