json plan: update resource index and import ids to support unknown values (#35518)

pull/37025/head
Liam Cervante 2 years ago committed by GitHub
parent 61a6e12863
commit 471bddf3ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -153,7 +153,7 @@ type Change struct {
// during planning as a string.
//
// If this is populated, then Importing should also be populated but this
// might change in the future. However, nNot all Importing changes will
// might change in the future. However, not all Importing changes will
// contain generated config.
GeneratedConfig string `json:"generated_config,omitempty"`
}
@ -163,6 +163,11 @@ type Importing struct {
// The original ID of this resource used to target it as part of planned
// import operation.
ID string `json:"id,omitempty"`
// Unknown indicates the ID was unknown at the time of planning. This
// would have led to the overall change being deferred, as such this should
// only be true when processing changes from the deferred changes list.
Unknown bool `json:"unknown,omitempty"`
}
type output struct {
@ -493,7 +498,11 @@ func marshalResourceChange(rc *plans.ResourceInstanceChangeSrc, schemas *terrafo
var importing *Importing
if rc.Importing != nil {
importing = &Importing{ID: rc.Importing.ID}
if rc.Importing.Unknown {
importing = &Importing{Unknown: true}
} else {
importing = &Importing{ID: rc.Importing.ID}
}
}
r.Change = Change{
@ -514,9 +523,14 @@ func marshalResourceChange(rc *plans.ResourceInstanceChangeSrc, schemas *terrafo
key := addr.Resource.Key
if key != nil {
value := key.Value()
if r.Index, err = ctyjson.Marshal(value, value.Type()); err != nil {
return r, err
if key == addrs.WildcardKey {
// The wildcard key should only be set for a deferred instance.
r.IndexUnknown = true
} else {
value := key.Value()
if r.Index, err = ctyjson.Marshal(value, value.Type()); err != nil {
return r, err
}
}
}

@ -73,6 +73,7 @@ type ResourceChange struct {
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
Index json.RawMessage `json:"index,omitempty"`
IndexUnknown bool `json:"index_unknown,omitempty"`
ProviderName string `json:"provider_name,omitempty"`
// "deposed", if set, indicates that this action applies to a "deposed"

File diff suppressed because it is too large Load Diff

@ -883,10 +883,15 @@ message PlannedChange {
repeated AttributePath replace_paths = 11;
string resource_name = 12;
DynamicValue index = 13;
Index index = 13;
string module_addr = 14;
string action_reason = 15;
message Index {
DynamicValue value = 1;
bool unknown = 2;
}
message Moved {
ResourceInstanceInStackAddr prev_addr = 1;
}

@ -392,13 +392,21 @@ func (pc *PlannedChangeResourceInstancePlanned) ChangeDescription() (*terraform1
}
}
var index *terraform1.DynamicValue
var index *terraform1.PlannedChange_ResourceInstance_Index
if pc.ChangeSrc.Addr.Resource.Key != nil {
var err error
key := pc.ChangeSrc.Addr.Resource.Key.Value()
index, err = DynamicValueToTerraform1(key, key.Type())
if err != nil {
return nil, err
key := pc.ChangeSrc.Addr.Resource.Key
if key == addrs.WildcardKey {
index = &terraform1.PlannedChange_ResourceInstance_Index{
Unknown: true,
}
} else {
value, err := DynamicValueToTerraform1(key.Value(), cty.DynamicPseudoType)
if err != nil {
return nil, err
}
index = &terraform1.PlannedChange_ResourceInstance_Index{
Value: value,
}
}
}

@ -292,8 +292,10 @@ func TestPlannedChangeAsProto(t *testing.T) {
ProviderAddr: "example.com/thingers/thingy",
Actions: []terraform1.ChangeType{terraform1.ChangeType_CREATE},
ActionReason: "ResourceInstanceChangeNoReason",
Index: &terraform1.DynamicValue{
Msgpack: []byte{'\x01'}, // 1
Index: &terraform1.PlannedChange_ResourceInstance_Index{
Value: &terraform1.DynamicValue{
Msgpack: []byte{0x92, 0xc4, 0x08, 0x22, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x01}, // 1
},
},
ModuleAddr: `module.pizza["chicken"]`,
ResourceName: "wotsit",
@ -394,8 +396,10 @@ func TestPlannedChangeAsProto(t *testing.T) {
ProviderAddr: "example.com/thingers/thingy",
Actions: []terraform1.ChangeType{terraform1.ChangeType_CREATE},
ActionReason: "ResourceInstanceChangeNoReason",
Index: &terraform1.DynamicValue{
Msgpack: []byte{'\x01'}, // 1
Index: &terraform1.PlannedChange_ResourceInstance_Index{
Value: &terraform1.DynamicValue{
Msgpack: []byte{0x92, 0xc4, 0x08, 0x22, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x01}, // 1
},
},
ModuleAddr: `module.pizza["chicken"]`,
ResourceName: "wotsit",
@ -503,8 +507,10 @@ func TestPlannedChangeAsProto(t *testing.T) {
ProviderAddr: "example.com/thingers/thingy",
Actions: []terraform1.ChangeType{terraform1.ChangeType_DELETE, terraform1.ChangeType_CREATE},
ActionReason: "ResourceInstanceChangeNoReason",
Index: &terraform1.DynamicValue{
Msgpack: []byte{'\x01'}, // 1
Index: &terraform1.PlannedChange_ResourceInstance_Index{
Value: &terraform1.DynamicValue{
Msgpack: []byte{0x92, 0xc4, 0x08, 0x22, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x01}, // 1
},
},
ModuleAddr: `module.pizza["chicken"]`,
ResourceName: "wotsit",
@ -613,8 +619,10 @@ func TestPlannedChangeAsProto(t *testing.T) {
ProviderAddr: "example.com/thingers/thingy",
Actions: []terraform1.ChangeType{terraform1.ChangeType_NOOP},
ActionReason: "ResourceInstanceChangeNoReason",
Index: &terraform1.DynamicValue{
Msgpack: []byte{'\x01'}, // 1
Index: &terraform1.PlannedChange_ResourceInstance_Index{
Value: &terraform1.DynamicValue{
Msgpack: []byte{0x92, 0xc4, 0x08, 0x22, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x01}, // 1
},
},
ModuleAddr: `module.pizza["chicken"]`,
ResourceName: "wotsit",
@ -718,8 +726,10 @@ func TestPlannedChangeAsProto(t *testing.T) {
ProviderAddr: "example.com/thingers/thingy",
Actions: []terraform1.ChangeType{terraform1.ChangeType_NOOP},
ActionReason: "ResourceInstanceChangeNoReason",
Index: &terraform1.DynamicValue{
Msgpack: []byte{'\x01'}, // 1
Index: &terraform1.PlannedChange_ResourceInstance_Index{
Value: &terraform1.DynamicValue{
Msgpack: []byte{0x92, 0xc4, 0x08, 0x22, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x01}, // 1
},
},
ModuleAddr: `module.pizza["chicken"]`,
ResourceName: "wotsit",

Loading…
Cancel
Save