terraform-plugin-sdk icon indicating copy to clipboard operation
terraform-plugin-sdk copied to clipboard

GetOkExists broken with schema.TypeSet

Open craigdbarber opened this issue 7 years ago • 1 comments

GetOkExists seems to have some cases which it returns a false positive, specifically when dealing with properties within a nested object with the type: schema.TypeSet.

In the example below within the nested object "backend", the only property which is explicitly set is "max_connections_per_instance", however schema.ResourceData.GetOkExists() is returning true on all the other properties within the nested object's schema: https://github.com/terraform-providers/terraform-provider-google/blob/96b17536b9f6152ca9b421a665c5ac56bc673280/google/resource_compute_backend_service.go#L67

This is causing breaking behavior when fields which weren't set by the user are being sent across to the wire inappropriately, causing the backend API to return an error in some use cases. We're currently having to work around this issue by implementing client side logic which proactively filters out these properties in such use cases and diff suppressing these properties from TF state. This is problematic as it obfuscates scenarios wherein users are incorrectly setting these values, but aren't being informed of their incorrect configs due to the client side filtering.

Terraform Version

0.11.7

Terraform Configuration Files

resource "google_compute_backend_service" "testservice" {                                                     
  name        = "```"                                                                                     
  description = "Hello World 1234"                                                                       
  port_name   = "http"                                                                                   
  protocol    = "TCP"                                                                                    
                                                                                                         
  backend {                                                                                              
    group = "${google_compute_instance_group_manager.foobar.instance_group}"                             
    max_connections_per_instance = 20                                                                    
  }                                                                                                      
                                                                                                         
  health_checks = ["${google_compute_health_check.default.self_link}"]                                   
} 

Debug Output

Crash Output

Expected Behavior

Actual Behavior

Steps to Reproduce

Additional Context

References

craigdbarber avatar Aug 22 '18 23:08 craigdbarber

Seems like Get() will return the map with all fields set (the absent field will be filled with default value of its type)

magodo avatar Feb 20 '20 12:02 magodo