Recently I have noticed a few instances of TypeSet causing all resources in set to be destroyed and recreated when one item in the set has a difference. Is this intended behavior for TypeSet
? Also, is there another resource that should be used to avoid this type of behavior? More details an an example of this can be found in this github issue on terraform-plugin-sdk.
That’s not what’s happening:
-
These are not resources, they are blocks within a resource.
-
They’re not all being destroyed and recreated - it’s just every element which has any changes is being removed, and new ones are being added.
This is expected behaviour - it’s how sets work. Since identity within sets is entirely defined by the value of the nested object, any change will be rendered as deletion of the old object, and addition of a new one.
It is worth noting that this is only how Terraform displays the diff. Whether the provider actually implements the change that way, or not, is entirely up to the provider code.
If you wanted Terraform to understand that an old entry and a new entry were related, and should be shown as a change, you need to use a list or map type, instead of a set.
@maxb Thanks for the reply! I’ll try to update the to a TypeList
or TypeMap
then as part of the issue is the diff as well as only performing an update operation rather than recreating the policies.