mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
command/format: indicate in diff when adding an attribute forces replacement
This commit is contained in:
parent
e893bae5da
commit
0f1f504c22
@ -253,6 +253,9 @@ func (p *blockBodyDiffPrinter) writeAttrDiff(name string, attrS *configschema.At
|
||||
switch {
|
||||
case showJustNew:
|
||||
p.writeValue(new, action, indent+2)
|
||||
if p.pathForcesNewResource(path) {
|
||||
p.buf.WriteString(p.color.Color(forcesNewResourceCaption))
|
||||
}
|
||||
default:
|
||||
// We show new even if it is null to emphasize the fact
|
||||
// that it is being unset, since otherwise it is easy to
|
||||
|
@ -327,6 +327,62 @@ new line
|
||||
~ ami = "ami-BEFORE" -> "ami-AFTER" # forces replacement
|
||||
~ id = "i-02ae66f368e8518a9" -> (known after apply)
|
||||
}
|
||||
`,
|
||||
},
|
||||
"force replacement with empty before value": {
|
||||
Action: plans.DeleteThenCreate,
|
||||
Mode: addrs.ManagedResourceMode,
|
||||
Before: cty.ObjectVal(map[string]cty.Value{
|
||||
"name": cty.StringVal("name"),
|
||||
"forced": cty.NullVal(cty.String),
|
||||
}),
|
||||
After: cty.ObjectVal(map[string]cty.Value{
|
||||
"name": cty.StringVal("name"),
|
||||
"forced": cty.StringVal("example"),
|
||||
}),
|
||||
Schema: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"name": {Type: cty.String, Optional: true},
|
||||
"forced": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
RequiredReplace: cty.NewPathSet(cty.Path{
|
||||
cty.GetAttrStep{Name: "forced"},
|
||||
}),
|
||||
Tainted: false,
|
||||
ExpectedOutput: ` # test_instance.example must be replaced
|
||||
-/+ resource "test_instance" "example" {
|
||||
+ forced = "example" # forces replacement
|
||||
name = "name"
|
||||
}
|
||||
`,
|
||||
},
|
||||
"force replacement with empty before value legacy": {
|
||||
Action: plans.DeleteThenCreate,
|
||||
Mode: addrs.ManagedResourceMode,
|
||||
Before: cty.ObjectVal(map[string]cty.Value{
|
||||
"name": cty.StringVal("name"),
|
||||
"forced": cty.StringVal(""),
|
||||
}),
|
||||
After: cty.ObjectVal(map[string]cty.Value{
|
||||
"name": cty.StringVal("name"),
|
||||
"forced": cty.StringVal("example"),
|
||||
}),
|
||||
Schema: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"name": {Type: cty.String, Optional: true},
|
||||
"forced": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
RequiredReplace: cty.NewPathSet(cty.Path{
|
||||
cty.GetAttrStep{Name: "forced"},
|
||||
}),
|
||||
Tainted: false,
|
||||
ExpectedOutput: ` # test_instance.example must be replaced
|
||||
-/+ resource "test_instance" "example" {
|
||||
+ forced = "example" # forces replacement
|
||||
name = "name"
|
||||
}
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user