If you add a partition_index block to an existing aws_glue_catalog_table resource, rather than detecting that this can be an update in place and calling the CreatePartitionIndex API, the terraform provider instead destroys the table and recreates it. It does this even if the table is not empty, resulting in data loss.
Can the provider be updated to avoid this bad scenario? Even though the “correct” solution would be to instead add an aws_glue_partition_index resource, this is not necessarily obvious – the aws_glue_catalog_table don’t mention that you should do this rather than adding a partition_index directly to the aws_glue_catalog_table. Instead of happily going ahead and destroying a non-empty table, perhaps the provider could check if it’s empty and fail the apply if it’s not (and suggest the use of the aws_glue_partition_index resource as an alternative for a non-empty table). This would be much better behavior than destroying data.
...
07:22:35 - Installed hashicorp/aws v4.4.0 (signed by HashiCorp)
...
07:23:01 # aws_glue_catalog_table.cust_date_small must be replaced
07:23:01 -/+ resource "aws_glue_catalog_table" "cust_date_small" {
...
07:23:01 + partition_index { # forces replacement
07:23:01 + index_name = "customer_id_date_index"
07:23:01 + index_status = (known after apply)
07:23:01 + keys = [
07:23:01 + "customer_id",
07:23:01 + "date",
07:23:01 ]
07:23:01 }
...
Full trace log is attached.
aws_glue_catalog_table-log.txt (85.8 KB)