From 0f0bbaaba7d26e4d617bce8fb030aafae1e7c406 Mon Sep 17 00:00:00 2001 From: Yasmany Cubela Medina Date: Thu, 30 Apr 2026 14:40:24 -0500 Subject: [PATCH] fix: skip synthetic TF state when resource has no external ID When a managed resource has no external-name (tfID is empty), upjet was creating a synthetic TF state with all parameters but no ID. This caused TF Plugin Framework providers to fail on Refresh (Read requires ID) before Create could be attempted. Skip synthetic state creation entirely when tfID is empty. This leaves the state file empty, causing Refresh to return Exists=false and properly triggering the Create flow for new resources. Signed-off-by: Yasmany Cubela Medina --- pkg/terraform/files.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/terraform/files.go b/pkg/terraform/files.go index beee5c54..ac82098a 100644 --- a/pkg/terraform/files.go +++ b/pkg/terraform/files.go @@ -242,7 +242,10 @@ func (fp *FileProducer) EnsureTFState(_ context.Context, tfID string) error { // // This is especially useful for resources whose deletion are scheduled for // a long period of time, where if we fill the ID, the queries would actually // succeed, i.e. GCP KMS KeyRing. - if !empty || meta.WasDeleted(fp.Resource) { + // Skip synthetic state creation when: state already exists, resource is + // being deleted, or there is no external identifier yet (new resource). + // Without an ID, Refresh would fail on providers that require it for Read. + if !empty || meta.WasDeleted(fp.Resource) || tfID == "" { return nil } base := make(map[string]any)