fix: populate type from API during resource import#18
Conversation
Greptile SummaryThis PR fixes the
Confidence Score: 5/5The import fix is correctly scoped: both the null/unknown guard and the normalizeAPIColumnType function are only active when type has not been set, so normal read/plan/apply cycles are unaffected. The core logic correctly addresses the described problem without touching the read path for already-managed resources. The encrypt default is safe because the schema already declares Computed: true, Default: false. Only a minor style inconsistency was found in the new code. No files require special attention. Important Files Changed
Reviews (7): Last reviewed commit: "fix: add plan modifiers to ensure state ..." | Re-trigger Greptile |
Description
During resource import, the
typefield was not populated from the API response, leaving it empty in Terraform state. Sincetypehas aRequiresReplaceplan modifier, Terraform detected a diff and planned a destroy/recreate — even though the resource already existed with the correct type.We intentionally skip overwriting
typeduring normal reads to preserve the user's value. During import however,typehasn't been set yet, so we now conditionally populate it from the API when it is null or unknown.Column resource
Because the Appwrite API returns internal type names that differ from the schema in some cases, a
normalizeAPIColumnTypefunction maps them back to user-facing names:"double"→"float""linestring"→"line""string"+format:"email"→"email""string"+format:"enum"→"enum""string"+format:"url"→"url""string"+format:"ip"→"ip"Additionally:
encryptfield now defaults tofalsewhen the API doesn't return it (non-string types), preventing null/unknown state mismatches during import.defaultvalue handling no longer gates onDefaultStrbeing non-null, so default values are correctly populated during import for bool and numeric columns.Provider resource
Provider types (
sendgrid,smtp,twilio, etc.) match between API and schema, so no normalization is needed — the API value is used directly when type is null/unknown.Affected resources
appwrite_tablesdb_columnappwrite_messaging_providerType of Change
Checklist
make lintpassesmake testpassesmake docshas been run and changes committed