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

Update Terraform state for NOT_FOUND (1/n) #149

Merged
merged 1 commit into from
Aug 29, 2024
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
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
Loading