terraform-provider-bigip icon indicating copy to clipboard operation
terraform-provider-bigip copied to clipboard

Exists functions are modifying the Resource Data when they shouldn't

Open dannyk81 opened this issue 6 years ago • 0 comments

I've noticed that in several places where the Exists method is implemented, it is modifying the resource data under certain conditions (e.g. when the resource is not found).

Examples:

https://github.com/terraform-providers/terraform-provider-bigip/blob/3736641c61a3b5969a988fe1aabdf73dbb6a58a8/bigip/resource_bigip_ltm_monitor.go#L201-L205

https://github.com/terraform-providers/terraform-provider-bigip/blob/3736641c61a3b5969a988fe1aabdf73dbb6a58a8/bigip/resource_bigip_ltm_irule.go#L92-L96

https://github.com/terraform-providers/terraform-provider-bigip/blob/3736641c61a3b5969a988fe1aabdf73dbb6a58a8/bigip/resource_bigip_ltm_virtual_server.go#L311-L313

It is my understanding that Exists should not modify the resource data as indicated in the documentation, using SetId("") should be reserved to Read and Delete methods:

    // Exists is a function that is called to check if a resource still
    // exists. If this returns false, then this will affect the diff
    // accordingly. If this function isn't set, it will not be called. It
    // is highly recommended to set it. The *ResourceData passed to Exists
    // should _not_ be modified.

reference: https://godoc.org/github.com/hashicorp/terraform/helper/schema#Resource

dannyk81 avatar Oct 01 '18 20:10 dannyk81