Skip to content

GetOk() evaluates bool values of false as !exists #1496

@drewmullen

Description

@drewmullen

SDK version

2.37.0

Relevant provider source code

func (d *ResourceData) GetOk(key string) (interface{}, bool) {
r := d.getRaw(key, getSourceSet)
exists := r.Exists && !r.Computed
if exists {
// If it exists, we also want to verify it is not the zero-value.
value := r.Value
zero := r.Schema.Type.Zero()
if eq, ok := value.(Equal); ok {
exists = !eq.Equal(zero)
} else {
exists = !reflect.DeepEqual(value, zero)
}
}
return r.Value, exists
}

Terraform Configuration Files

resource "tfe_workspace" "foobar" {
...
  auto_apply            = false
}

Debug Output

Expected Behavior

GetOk should return false, true meaning the value of auto_apply is false and true it exists in HCL code

Actual Behavior

because GetOk determines that the zero value of a interface-bool is false, exists = !reflect.DeepEqual(value, zero) sets exists to false and GetOk returns false,false

Workaround

Current workaround is to use GetOkExists for bool values. Which has been deprecated

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions