Skip to content

Commit

Permalink
Update Terraform state for NOT_FOUND (1/n)
Browse files Browse the repository at this point in the history
Updated the following resources to properly handle NOT_FOUND responses
from the upstream:
- `dataset_outbound_share`
- `datastream`
- `filedrop`
- `monitor`
- `monitor_action`
- `rbac_group`
- `rbac_group_member`
- `rbac_statement`
- `snowflake_outbound_share`
  • Loading branch information
obs-gh-maxhahn committed Aug 29, 2024
1 parent df24060 commit 2292225
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 1 deletion.
4 changes: 4 additions & 0 deletions client/meta/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ var AllMonitorV2HttpTypes = []MonitorV2HttpType{
MonitorV2HttpTypePut,
}

const (
ErrNotFound = "NOT_FOUND"
)

type resultStatusResponse interface {
GetResultStatus() ResultStatus
}
Expand Down
4 changes: 4 additions & 0 deletions observe/resource_dataset_outbound_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ func resourceDatasetOutboundShareRead(ctx context.Context, d *schema.ResourceDat

datasetShare, err := client.GetDatasetOutboundShare(ctx, d.Id())
if err != nil {
if gql.HasErrorCode(err, gql.ErrNotFound) {
d.SetId("")
return nil
}
return append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "Failed to read dataset outbound share",
Expand Down
4 changes: 4 additions & 0 deletions observe/resource_datastream.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ func resourceDatastreamRead(ctx context.Context, data *schema.ResourceData, meta
client := meta.(*observe.Client)
result, err := client.GetDatastream(ctx, data.Id())
if err != nil {
if gql.HasErrorCode(err, gql.ErrNotFound) {
data.SetId("")
return nil
}
return append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: fmt.Sprintf("failed to retrieve datastream [id=%s]", data.Id()),
Expand Down
4 changes: 4 additions & 0 deletions observe/resource_filedrop.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ func resourceFiledropRead(ctx context.Context, data *schema.ResourceData, meta i

filedrop, err := client.GetFiledrop(ctx, data.Id())
if err != nil {
if gql.HasErrorCode(err, gql.ErrNotFound) {
data.SetId("")
return nil
}
return diag.Errorf("failed to read filedrop: %s", err.Error())
}

Expand Down
4 changes: 4 additions & 0 deletions observe/resource_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,10 @@ func resourceMonitorRead(ctx context.Context, data *schema.ResourceData, meta in

monitor, err := client.GetMonitor(ctx, data.Id())
if err != nil {
if gql.HasErrorCode(err, gql.ErrNotFound) {
data.SetId("")
return nil
}
return diag.Errorf("failed to read monitor: %s", err.Error())
}

Expand Down
4 changes: 4 additions & 0 deletions observe/resource_monitor_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ func resourceMonitorActionRead(ctx context.Context, data *schema.ResourceData, m

monitorActionPtr, err := client.GetMonitorAction(ctx, data.Id())
if err != nil {
if gql.HasErrorCode(err, gql.ErrNotFound) {
data.SetId("")
return nil
}
return diag.Errorf("failed to read monitor action: %s", err.Error())
}
monitorAction := *monitorActionPtr
Expand Down
2 changes: 1 addition & 1 deletion observe/resource_monitor_action_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func resourceMonitorActionAttachmentRead(ctx context.Context, data *schema.Resou

monitorActionAttachmentPtr, err := client.GetMonitorActionAttachment(ctx, data.Id())
if err != nil {
if gql.HasErrorCode(err, "NOT_FOUND") {
if gql.HasErrorCode(err, gql.ErrNotFound) {
data.SetId("")
return nil
}
Expand Down
4 changes: 4 additions & 0 deletions observe/resource_rbac_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func resourceRbacGroupRead(ctx context.Context, data *schema.ResourceData, meta

group, err := client.GetRbacGroup(ctx, data.Id())
if err != nil {
if gql.HasErrorCode(err, gql.ErrNotFound) {
data.SetId("")
return nil
}
return diag.Errorf("failed to read rbacgroup: %s", err.Error())
}
return rbacGroupToResourceData(group, data)
Expand Down
4 changes: 4 additions & 0 deletions observe/resource_rbac_group_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ func resourceRbacGroupmemberRead(ctx context.Context, data *schema.ResourceData,

group, err := client.GetRbacGroupmember(ctx, data.Id())
if err != nil {
if gql.HasErrorCode(err, gql.ErrNotFound) {
data.SetId("")
return nil
}
return diag.Errorf("failed to read rbacgroupmember: %s", err.Error())
}
return rbacGroupmemberToResourceData(group, data)
Expand Down
4 changes: 4 additions & 0 deletions observe/resource_rbac_statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ func resourceRbacStatementRead(ctx context.Context, data *schema.ResourceData, m

stmt, err := client.GetRbacStatement(ctx, data.Id())
if err != nil {
if gql.HasErrorCode(err, gql.ErrNotFound) {
data.SetId("")
return nil
}
return diag.Errorf("failed to read rbacstatement: %s", err.Error())
}
return rbacStatementToResourceData(stmt, data)
Expand Down
4 changes: 4 additions & 0 deletions observe/resource_snowflake_outbound_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ func resourceSnowflakeOutboundShareRead(ctx context.Context, d *schema.ResourceD

share, err := client.GetSnowflakeOutboundShare(ctx, d.Id())
if err != nil {
if gql.HasErrorCode(err, gql.ErrNotFound) {
d.SetId("")
return nil
}
return diag.FromErr(err)
}

Expand Down

0 comments on commit 2292225

Please sign in to comment.