XR004
The XR004 analyzer reports Set()
calls that receive a complex value type, but do not perform error checking. This error checking is to prevent issues where the code is not able to properly set the Terraform state for drift detection. Addition details are available in the Extending Terraform documentation.
Flagged Code
d.Set("example", []interface{}{})
d.Set("example", map[string]interface{}{})
d.Set("example", schema.NewSet(/* ... */))
Passing Code
if err := d.Set("example", []interface{}{}); err != nil {
return fmt.Errorf("error setting example: %s", err)
}
if err := d.Set("example", map[string]interface{}{}); err != nil {
return fmt.Errorf("error setting example: %s", err)
}
if err := d.Set("example", schema.NewSet(/* ... */)); err != nil {
return fmt.Errorf("error setting example: %s", err)
}
Ignoring Reports
Singular reports can be ignored by adding the a //lintignore:XR004
Go code comment at the end of the offending line or on the line immediately proceding, e.g.
//lintignore:XR004
d.Set("example", []interface{}{})