-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc88992
commit ccd2b2a
Showing
37 changed files
with
471 additions
and
64 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
internal/backend/local/testdata/plan-outputs-changed/submodule/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
output "foo" { | ||
value = "bar" | ||
} | ||
|
||
variable "foo" { | ||
ephemeral = true | ||
type = string | ||
default = "eph-val" | ||
} | ||
|
||
output "existing_eph" { | ||
ephemeral = true | ||
value = var.foo | ||
} | ||
|
||
output "new_ephemeral" { | ||
ephemeral = true | ||
value = var.foo | ||
} |
49 changes: 49 additions & 0 deletions
49
internal/command/jsonformat/computed/renderers/ephemeral.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package renderers | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/internal/command/jsonformat/computed" | ||
"github.com/hashicorp/terraform/internal/plans" | ||
) | ||
|
||
var _ computed.DiffRenderer = (*ephemeralRenderer)(nil) | ||
|
||
func Ephemeral(action plans.Action, beforeEphemeral, afterEphemeral bool) computed.DiffRenderer { | ||
return &ephemeralRenderer{ | ||
planAction: action, | ||
beforeEphemeral: beforeEphemeral, | ||
afterEphemeral: afterEphemeral, | ||
} | ||
} | ||
|
||
type ephemeralRenderer struct { | ||
planAction plans.Action | ||
beforeEphemeral bool | ||
afterEphemeral bool | ||
} | ||
|
||
func (renderer ephemeralRenderer) RenderHuman(diff computed.Diff, indent int, opts computed.RenderHumanOpts) string { | ||
return fmt.Sprintf("(ephemeral value)%s%s", nullSuffix(diff.Action, opts), forcesReplacement(diff.Replace, opts)) | ||
} | ||
|
||
func (renderer ephemeralRenderer) WarningsHuman(diff computed.Diff, indent int, opts computed.RenderHumanOpts) []string { | ||
if (renderer.beforeEphemeral == renderer.afterEphemeral) || renderer.planAction == plans.Create || renderer.planAction == plans.Delete { | ||
// Only display warnings for ephemeral values if they are changing from | ||
// being ephemeral or to being ephemeral and if they are not being | ||
// destroyed or created. | ||
return []string{} | ||
} | ||
|
||
var warning string | ||
if renderer.beforeEphemeral { | ||
warning = opts.Colorize.Color(fmt.Sprintf(" # [yellow]Warning[reset]: this attribute value will no longer be marked as ephemeral\n%s # after applying this change.", formatIndent(indent))) | ||
} else { | ||
warning = opts.Colorize.Color(fmt.Sprintf(" # [yellow]Warning[reset]: this attribute value will be marked as ephemeral and will not\n%s # display in UI output after applying this change.", formatIndent(indent))) | ||
} | ||
|
||
if renderer.planAction == plans.NoOp { | ||
return []string{fmt.Sprintf("%s The value is unchanged.", warning)} | ||
} | ||
return []string{warning} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package differ | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/internal/command/jsonformat/computed" | ||
"github.com/hashicorp/terraform/internal/command/jsonformat/computed/renderers" | ||
"github.com/hashicorp/terraform/internal/command/jsonformat/structured" | ||
) | ||
|
||
type CreateEphemeralRenderer func(computed.Diff, bool, bool) computed.DiffRenderer | ||
|
||
func checkForEphemeralType(change structured.Change) (computed.Diff, bool) { | ||
if !change.IsBeforeEphemeral() && !change.IsAfterEphemeral() { | ||
return computed.Diff{}, false | ||
} | ||
|
||
return computed.NewDiff(renderers.Ephemeral(change.PlanAction, change.IsBeforeEphemeral(), change.IsAfterEphemeral()), change.CalculateAction(), change.ReplacePaths.Matches()), true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package structured | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/internal/command/jsonformat/computed" | ||
"github.com/hashicorp/terraform/internal/plans" | ||
) | ||
|
||
type ProcessEphemeralInner func(change Change) computed.Diff | ||
type CreateEphemeralDiff func(inner computed.Diff, beforeEphemeral, afterEphemeral bool, action plans.Action) computed.Diff | ||
|
||
func (change Change) CheckForEphemeral(processInner ProcessEphemeralInner, createDiff CreateEphemeralDiff) (computed.Diff, bool) { | ||
if !change.IsBeforeEphemeral() && !change.IsAfterEphemeral() { | ||
return computed.Diff{}, false | ||
} | ||
|
||
value := Change{ | ||
BeforeExplicit: change.BeforeExplicit, | ||
AfterExplicit: change.AfterExplicit, | ||
Before: change.Before, | ||
After: change.After, | ||
Unknown: change.Unknown, | ||
BeforeSensitive: change.BeforeSensitive, | ||
AfterSensitive: change.AfterSensitive, | ||
BeforeEphemeral: change.BeforeEphemeral, | ||
AfterEphemeral: change.AfterEphemeral, | ||
ReplacePaths: change.ReplacePaths, | ||
RelevantAttributes: change.RelevantAttributes, | ||
} | ||
|
||
// TODO: this turns create into update | ||
inner := processInner(value) | ||
|
||
return createDiff(inner, change.IsBeforeEphemeral(), change.IsAfterEphemeral(), inner.Action), true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.