XR004

ResourcesExtra · tfsproutx

check for ResourceData.Set() calls that should implement error checking with complex values

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.

Examples

d.Set("example", []interface{}{})

d.Set("example", map[string]interface{}{})

d.Set("example", schema.NewSet(/* ... */))
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 a //lintignore:XR004 Go code comment at the end of the offending line or on the line immediately preceding, e.g.

//lintignore:XR004
d.Set("example", []interface{}{})

This page is generated from xpasses/XR004/README.md, which lives beside the analyzer.