Terraform providers for snowflake are not perfect, neither is Snowflake in this case, because it doesn’t allow data type change in most of cases. Solution is a kind of hack, and includes multiple steps:
1. Use get_ddl() function to easily retrieve create statement:
select get_ddl('table', 'RESPONSES');
2. Copy the result, paste into worksheet and IMMEDIATELY delete the “or replace” and change its name. Also adjust data type that needs to be changed.
create TABLE RESPONSES_tmp (ID NUMBER(38,0), col1 NUMBER(12,2));
3. If the table is used by a task it is time to stop it:
ALTER TASK raw_data.RESPONSES_FROM_RAW_DATA SUSPEND;
4. Copy data into new table:
insert into RESPONSES_tmp select * from RESPONSES;
5. Rename old table:
alter table RESPONSES rename to RESPONSES_old;
6. Rename new table:
alter table RESPONSES_tmp rename to RESPONSES;
7. Task can be resumed now:
alter task raw_data.NB_RESPONSES_FROM_RAW_DATA resume;
8. Time for terraform – in the snowflake_table resource just adjust column types and run. The plan should say, that column data type was changed outside of it, and no changes should be required.
9. Drop old table.
drop table RESPONSES_old;