Skip to content

Commit

Permalink
Return error for non-existent resources when using terraformless expo…
Browse files Browse the repository at this point in the history
…rt (#560)

* tfclient import raise error if resource read returns nil

* remove nonsense change
  • Loading branch information
magodo authored Sep 4, 2024
1 parent 4f99968 commit ee37f13
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/meta/base_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,15 @@ func (meta *baseMeta) importItem_notf(ctx context.Context, item *ImportItem, imp
return
}

// Ensure the state is not null
if readResp.NewState.IsNull() {
meta.Logger().Error("Cannot import an non-existent resource", "tf_addr", item.TFAddr)
meta.tc.Trace(telemetry.Error, fmt.Sprintf("Cannot import an non-existent resource: %s", item.AzureResourceID.TypeString()))
item.ImportError = fmt.Errorf("Cannot import non-existent remote object")
item.Imported = false
return
}

meta.Logger().Debug("Finish importing a resource", "tf_id", item.TFResourceId, "tf_addr", addr)
item.State = readResp.NewState
item.ImportError = nil
Expand Down

0 comments on commit ee37f13

Please sign in to comment.