Skip to content

Commit c31bf17

Browse files
committed
Restore Partial
1 parent a51c479 commit c31bf17

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

helper/schema/resource_data.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type ResourceData struct {
3333
multiReader *MultiLevelFieldReader
3434
setWriter *MapFieldWriter
3535
newState *terraform.InstanceState
36+
partial bool
3637
once sync.Once
3738
isNew bool
3839

@@ -141,6 +142,21 @@ func (d *ResourceData) HasChange(key string) bool {
141142
return !reflect.DeepEqual(o, n)
142143
}
143144

145+
// Partial is a legacy function that was used for capturing state of specific
146+
// attributes if an update only partially worked. Enabling this flag without
147+
// setting any specific keys with the now removed SetPartial has a useful side
148+
// effect of preserving all of the resource's previous state. Although confusing,
149+
// it has been discovered that during an update when an error is returned, the
150+
// proposed config is set into state, even without any calls to d.Set.
151+
//
152+
// In practice this default behavior goes mostly unnoticed since Terraform
153+
// refreshes between operations by default. The state situation discussed is
154+
// subject to further investigation and potential change. Until then, this
155+
// function has been preserved for the specific usecase.
156+
func (d *ResourceData) Partial(on bool) {
157+
d.partial = on
158+
}
159+
144160
// Set sets the value for the given key.
145161
//
146162
// If the key is invalid or the value is not a correct type, an error
@@ -287,7 +303,9 @@ func (d *ResourceData) State() *terraform.InstanceState {
287303
rawMap := make(map[string]interface{})
288304
for k := range d.schema {
289305
source := getSourceSet
290-
306+
if d.partial {
307+
source = getSourceState
308+
}
291309
raw := d.get([]string{k}, source)
292310
if raw.Exists && !raw.Computed {
293311
rawMap[k] = raw.Value

0 commit comments

Comments
 (0)