NS1 returns the answers in a record in the same order as it is sorted on the UI meaning a new or deleted answer anywhere in the list will mix up any subsequent answer because Terraform refers these by index in the list.
Suggested fix
Therefore, logically the correct schema should be TypeSet and not TypeList:
± git diff
diff --git a/ns1/resource_record.go b/ns1/resource_record.go
index 371d15d..9edd154 100644
--- a/ns1/resource_record.go
+++ b/ns1/resource_record.go
@@ -117,7 +117,7 @@ It is suggested to migrate to a regular "answers" block. Using Terraform 0.12+,
}`,
},
"answers": {
- Type: schema.TypeList,
+ Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
The two downsides of this change would be:
- In place update will not work anymore. If an answer item is not found it will be deleted and a new (updated one) will be added instead. Is NS1 transactional in these updates? If not, there could be a race condition if TTL is just expired on client when an answer is deleted but the new one is not yet added and the lookup might fail.
- Any references to answer items by index will be broken.
Why not sorting?
Sorting will not work even with created at timestamp because answers can be deleted and any record that was created after the deleted record will break again.
ps.: The apply is actually doing the right thing so the issue is only critical for plan and therefore any automatic pipeline testing.
NS1 returns the answers in a record in the same order as it is sorted on the UI meaning a new or deleted answer anywhere in the list will mix up any subsequent answer because Terraform refers these by index in the list.
Suggested fix
Therefore, logically the correct schema should be
TypeSetand notTypeList:The two downsides of this change would be:
Why not sorting?
Sorting will not work even with created at timestamp because answers can be deleted and any record that was created after the deleted record will break again.
ps.: The apply is actually doing the right thing so the issue is only critical for plan and therefore any automatic pipeline testing.