This fixes a bug found while working on another internal issue. This bug
is reproduced in the first commit which adds tests, clearly showing the
behavior of the incoherent rendering. The second commit makes the change
and updates the tests.
Fixes#17028
Fixes all outputs being printed adjacent without context, as seen in the
linked issue and the first commit:
```
--outputs:--
readme: "line 1\nline2\nline3\nline4"
--outputs:--
arn : "arn:aws:iam::616138583583:role/eks-role-24b1266"
assumeRolePolicy : (json) {
Statement: [
[0]: {
Action : "sts:AssumeRole"
Effect : "Allow"
Principal: {
Service: "eks.amazonaws.com"
}
Sid : ""
}
]
Version : "2008-10-17"
}
createDate : "2022-02-09T23:14:50Z"
id : "eks-role-24b1266"
inlinePolicies : [
[0]: {
name : ""
policy: ""
}
]
managedPolicyArns : [
[0]: "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy"
[1]: "arn:aws:iam::aws:policy/AmazonEKSServicePolicy"
]
uniqueId : "AROAY65FYVYPWXZQUXMBX"
--outputs:--
id : "eks-role-24b1266-20220209231452499500000001"
--outputs:--
id : "eks-role-24b1266-20220209231452597100000002"
--outputs:--
```
<!---
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. -->
<!---
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. -->
Small refactor I noticed while writing a test with engine events. We
always had to call `NewEvent` with the tag and payload value for an
event and these _had_ to match up else the engine panics. But we can
just pass the payload and type switch to work out the tag. Means one
less parameter to pass to `NewEvent` and pretty much no chance of it
going wrong. To ensure there's really no chance I've added a generic
union type so you can only pass payload types to this method now.
Cancel had to be handled separately because it doesn't have a payload
type, it's just nil.
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.
This change causes only mandatory policy violations to skip the summary
display causing the resources changed and duration details to not be
printed.
Policy Violations are categorized as `mandatory`, `disabled`, and
`advisory`. We were treating all 3 as policy violations to skip
displaying the update summary. Now we only use `mandatory`.
Per team discussion, switching to gofumpt.
[gofumpt][1] is an alternative, stricter alternative to gofmt.
It addresses other stylistic concerns that gofmt doesn't yet cover.
[1]: https://github.com/mvdan/gofumpt
See the full list of [Added rules][2], but it includes:
- Dropping empty lines around function bodies
- Dropping unnecessary variable grouping when there's only one variable
- Ensuring an empty line between multi-line functions
- simplification (`-s` in gofmt) is always enabled
- Ensuring multi-line function signatures end with
`) {` on a separate line.
[2]: https://github.com/mvdan/gofumpt#Added-rules
gofumpt is stricter, but there's no lock-in.
All gofumpt output is valid gofmt output,
so if we decide we don't like it, it's easy to switch back
without any code changes.
gofumpt support is built into the tooling we use for development
so this won't change development workflows.
- golangci-lint includes a gofumpt check (enabled in this PR)
- gopls, the LSP for Go, includes a gofumpt option
(see [installation instrutions][3])
[3]: https://github.com/mvdan/gofumpt#installation
This change was generated by running:
```bash
gofumpt -w $(rg --files -g '*.go' | rg -v testdata | rg -v compilation_error)
```
The following files were manually tweaked afterwards:
- pkg/cmd/pulumi/stack_change_secrets_provider.go:
one of the lines overflowed and had comments in an inconvenient place
- pkg/cmd/pulumi/destroy.go:
`var x T = y` where `T` wasn't necessary
- pkg/cmd/pulumi/policy_new.go:
long line because of error message
- pkg/backend/snapshot_test.go:
long line trying to assign three variables in the same assignment
I have included mention of gofumpt in the CONTRIBUTING.md.
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.
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.