Merge pull request #35512 from hashicorp/TF-18555

stacks: add fields required to display plan
pull/31863/merge
Daniel Schmidt 2 years ago committed by GitHub
commit 429ccbb88e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

File diff suppressed because it is too large Load Diff

@ -882,8 +882,10 @@ message PlannedChange {
repeated AttributePath replace_paths = 11;
// TODO: Everything else we need for feature-parity with the
// existing JSON plan export format.
string resource_name = 12;
DynamicValue index = 13;
string module_addr = 14;
string action_reason = 15;
message Moved {
ResourceInstanceInStackAddr prev_addr = 1;
@ -891,6 +893,7 @@ message PlannedChange {
message Imported {
string import_id = 1;
bool unknown = 2;
string generated_config = 3;
}
}
// Note: this is only for output values from the topmost

@ -9,12 +9,14 @@ import (
"github.com/hashicorp/go-version"
"github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/msgpack"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
"github.com/hashicorp/terraform/internal/addrs"
"github.com/hashicorp/terraform/internal/collections"
"github.com/hashicorp/terraform/internal/configs/configschema"
"github.com/hashicorp/terraform/internal/lang/marks"
"github.com/hashicorp/terraform/internal/plans"
"github.com/hashicorp/terraform/internal/plans/planfile"
"github.com/hashicorp/terraform/internal/plans/planproto"
@ -390,13 +392,27 @@ func (pc *PlannedChangeResourceInstancePlanned) ChangeDescription() (*terraform1
}
}
var index *terraform1.DynamicValue
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
}
}
return &terraform1.PlannedChange_ChangeDescription{
Description: &terraform1.PlannedChange_ChangeDescription_ResourceInstancePlanned{
ResourceInstancePlanned: &terraform1.PlannedChange_ResourceInstance{
Addr: terraform1.NewResourceInstanceObjectInStackAddr(rioAddr),
ResourceName: pc.ChangeSrc.Addr.Resource.Resource.Name,
Index: index,
ModuleAddr: pc.ChangeSrc.Addr.Module.String(),
ResourceMode: stackutils.ResourceModeForProto(pc.ChangeSrc.Addr.Resource.Resource.Mode),
ResourceType: pc.ChangeSrc.Addr.Resource.Resource.Type,
ProviderAddr: pc.ChangeSrc.ProviderAddr.Provider.String(),
ActionReason: pc.ChangeSrc.ActionReason.String(),
Actions: protoChangeTypes,
Values: &terraform1.DynamicValueChange{
@ -418,6 +434,35 @@ func (pc *PlannedChangeResourceInstancePlanned) ChangeDescription() (*terraform1
}
func DynamicValueToTerraform1(val cty.Value, ty cty.Type) (*terraform1.DynamicValue, error) {
unmarkedVal, markPaths := val.UnmarkDeepWithPaths()
sensitivePaths, withOtherMarks := marks.PathsWithMark(markPaths, marks.Sensitive)
if len(withOtherMarks) != 0 {
return nil, withOtherMarks[0].Path.NewErrorf(
"can't serialize value marked with %#v (this is a bug in Terraform)",
withOtherMarks[0].Marks,
)
}
rawVal, err := msgpack.Marshal(unmarkedVal, ty)
if err != nil {
return nil, err
}
ret := &terraform1.DynamicValue{
Msgpack: rawVal,
}
if len(markPaths) == 0 {
return ret, nil
}
ret.Sensitive = make([]*terraform1.AttributePath, 0, len(markPaths))
for _, path := range sensitivePaths {
ret.Sensitive = append(ret.Sensitive, terraform1.NewAttributePath(path))
}
return ret, nil
}
// PlannedChangeProto implements PlannedChange.
func (pc *PlannedChangeResourceInstancePlanned) PlannedChangeProto() (*terraform1.PlannedChange, error) {
pric, err := pc.PlanResourceInstanceChangePlannedProto()

@ -291,6 +291,12 @@ func TestPlannedChangeAsProto(t *testing.T) {
ResourceType: "thingy",
ProviderAddr: "example.com/thingers/thingy",
Actions: []terraform1.ChangeType{terraform1.ChangeType_CREATE},
ActionReason: "ResourceInstanceChangeNoReason",
Index: &terraform1.DynamicValue{
Msgpack: []byte{'\x01'}, // 1
},
ModuleAddr: `module.pizza["chicken"]`,
ResourceName: "wotsit",
Values: &terraform1.DynamicValueChange{
Old: &terraform1.DynamicValue{
Msgpack: []byte{'\xc0'}, // null
@ -387,6 +393,12 @@ func TestPlannedChangeAsProto(t *testing.T) {
ResourceType: "thingy",
ProviderAddr: "example.com/thingers/thingy",
Actions: []terraform1.ChangeType{terraform1.ChangeType_CREATE},
ActionReason: "ResourceInstanceChangeNoReason",
Index: &terraform1.DynamicValue{
Msgpack: []byte{'\x01'}, // 1
},
ModuleAddr: `module.pizza["chicken"]`,
ResourceName: "wotsit",
Values: &terraform1.DynamicValueChange{
Old: &terraform1.DynamicValue{
Msgpack: []byte{'\xc0'}, // null
@ -490,6 +502,12 @@ func TestPlannedChangeAsProto(t *testing.T) {
ResourceType: "thingy",
ProviderAddr: "example.com/thingers/thingy",
Actions: []terraform1.ChangeType{terraform1.ChangeType_DELETE, terraform1.ChangeType_CREATE},
ActionReason: "ResourceInstanceChangeNoReason",
Index: &terraform1.DynamicValue{
Msgpack: []byte{'\x01'}, // 1
},
ModuleAddr: `module.pizza["chicken"]`,
ResourceName: "wotsit",
Values: &terraform1.DynamicValueChange{
Old: &terraform1.DynamicValue{
Msgpack: []byte("\x81\xa3foo\xa3bar"),
@ -594,6 +612,12 @@ func TestPlannedChangeAsProto(t *testing.T) {
ResourceType: "thingy",
ProviderAddr: "example.com/thingers/thingy",
Actions: []terraform1.ChangeType{terraform1.ChangeType_NOOP},
ActionReason: "ResourceInstanceChangeNoReason",
Index: &terraform1.DynamicValue{
Msgpack: []byte{'\x01'}, // 1
},
ModuleAddr: `module.pizza["chicken"]`,
ResourceName: "wotsit",
Values: &terraform1.DynamicValueChange{
Old: &terraform1.DynamicValue{
Msgpack: []byte{'\x80'}, // zero-length mapping
@ -693,6 +717,12 @@ func TestPlannedChangeAsProto(t *testing.T) {
ResourceType: "thingy",
ProviderAddr: "example.com/thingers/thingy",
Actions: []terraform1.ChangeType{terraform1.ChangeType_NOOP},
ActionReason: "ResourceInstanceChangeNoReason",
Index: &terraform1.DynamicValue{
Msgpack: []byte{'\x01'}, // 1
},
ModuleAddr: `module.pizza["chicken"]`,
ResourceName: "wotsit",
Values: &terraform1.DynamicValueChange{
Old: &terraform1.DynamicValue{
Msgpack: []byte{'\x80'}, // zero-length mapping

Loading…
Cancel
Save