<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
Fixes https://github.com/pulumi/pulumi/issues/13981.
This regressed in https://github.com/pulumi/pulumi/pull/11803. I've
added tests to this PR to show both the value diffing and text diffing
for when the JSON/YAML string is different but the values are the same.
## Checklist
- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
- [x] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
This PR implements the new policy transforms feature, which allows
policy packs to not only issue warnings and errors in response to policy
violations, but actually fix them by rewriting resource property state.
This can be used, for instance, to auto-tag resources, remove Internet
access on the fly, or apply encryption to storage, among other use
cases.
Fixes https://github.com/pulumi/pulumi/issues/10312
When attempting to decode a string property value as JSON or YAML the
decoder would return a partial parse as valid. This resulted in strings
like "{} stuff" being reported as an empty JSON object, rather than the
literal string "{} stuff".
This also fixes the decoder to ignore whitespace around the value so for
example " [1, 2] " is now treated as a JSON array, not a string
literal.
Fixes https://github.com/pulumi/pulumi/issues/11990
There were a few places we were passing an already formatted string in
as the format argument for printf. This replaces those calls with
non-formatting print calls.
Switch this to "View in Browser" per discussion
which is closer to the old "View Live" message.
sdk/go/auto doesn't need an update because the regex there
is still using "View in Browser".
Add support for using Ctrl+O to open the current update in the browser
for backends that support permalinks.
The keybinding is advertised in the interactive display as part of the
message that displays the permalink:
```
Previewing update (dev)
View in Browser (Ctrl+O): https://<some-url>
Type Name Plan
+ pulumi:pulumi:Stack vpc-dev create
+ ├─ aws:ec2:Vpc vpc create
+ ├─ aws:ec2:SecurityGroup secgroup create
+ ├─ aws:ec2:SecurityGroupRule rule-2 create
+ ├─ aws:ec2:SecurityGroupRule rule-0 create
+ ├─ aws:ec2:SecurityGroupRule rule-1 create
+ └─ aws:ec2:SecurityGroupRule rule-3 create
```
In order to maintain backwards compatibility with older versions of the
Automation API, the message is not changed for non-interactive
scenarios.
- If the display is scrolled to the bottom, autoscroll it as new lines are
added to the output.
- Add support for scrolling the interactive display using page-down and
page-up. These keys scroll the display N lines at a time, where N is the
height of the terminal.
The number of Unicode code points in a string is not the same as the
number of user-visible characters (graphemes). When measuring colorized
strings, we want the latter rather than the former. Notably, these
changes fix some issues where the interactive display cut off before the
right edge of the terminal.
Replace direct interaction with the terminal with an abstraction. This
abstraction is tightly constrained to the capabilities needed for the
CLI's display. Using this abstraction allows for straightforward testing
of the interactive renderers.
Reuse the support for decoding JSON/YAML strings into objects to display
such values as objects during create, same, and delete operations (we
already do this for updates).
These changes also unexport a number of methods that should be internal
to the display package.
When displaying a diff between textual values, first try to decode the
old and new values as JSON and YAML. If both values decode successfully,
render the diff between the decoded values rather than the diff between
the text.
Fixes#5831.
Instead of simply rendering the old and new values for textual
properties, compute the diff between the old and new values and render
that. For single-line values, the diff is computed and rendered
character-wise, with simplification applied to avoid "small" diffs. For
multi-line values, the diff is computed and rendered linewise (as we
already to for textual assets).
Fixes#9136.
Instead of passing around a set of arguments that are mostly immutable,
collect the common parameters to most of our diff printing functions in
a struct and hang the various print methods off of that struct.