|
|
|
|
@ -27,175 +27,6 @@ import (
|
|
|
|
|
"github.com/hashicorp/terraform/internal/terraform"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestRenderHuman_InvokeActionPlan(t *testing.T) {
|
|
|
|
|
color := &colorstring.Colorize{Colors: colorstring.DefaultColors, Disable: true}
|
|
|
|
|
streams, done := terminal.StreamsForTesting(t)
|
|
|
|
|
|
|
|
|
|
plan := Plan{
|
|
|
|
|
ActionInvocations: []jsonplan.ActionInvocation{
|
|
|
|
|
{
|
|
|
|
|
Address: "action.test_action.action",
|
|
|
|
|
Type: "test_action",
|
|
|
|
|
Name: "action",
|
|
|
|
|
ConfigValues: map[string]json.RawMessage{
|
|
|
|
|
"attr": []byte("\"one\""),
|
|
|
|
|
},
|
|
|
|
|
ConfigSensitive: nil,
|
|
|
|
|
ProviderName: "test",
|
|
|
|
|
InvokeActionTrigger: new(jsonplan.InvokeActionTrigger),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
ProviderSchemas: map[string]*jsonprovider.Provider{
|
|
|
|
|
"test": {
|
|
|
|
|
ActionSchemas: map[string]*jsonprovider.ActionSchema{
|
|
|
|
|
"test_action": {
|
|
|
|
|
ConfigSchema: &jsonprovider.Block{
|
|
|
|
|
Attributes: map[string]*jsonprovider.Attribute{
|
|
|
|
|
"attr": {
|
|
|
|
|
AttributeType: []byte("\"string\""),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Unlinked: new(jsonprovider.UnlinkedAction),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderer := Renderer{Colorize: color, Streams: streams}
|
|
|
|
|
plan.renderHuman(renderer, plans.RefreshOnlyMode)
|
|
|
|
|
|
|
|
|
|
want := `
|
|
|
|
|
Terraform will invoke the following action(s):
|
|
|
|
|
|
|
|
|
|
# action.test_action.action will be invoked
|
|
|
|
|
action "test_action" "action" {
|
|
|
|
|
config {
|
|
|
|
|
attr = "one"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
got := done(t).Stdout()
|
|
|
|
|
if diff := cmp.Diff(want, got); len(diff) > 0 {
|
|
|
|
|
t.Errorf("unexpected output\ngot:\n%s\nwant:\n%s\ndiff:\n%s", got, want, diff)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestRenderHuman_InvokeActionPlanWithRefresh(t *testing.T) {
|
|
|
|
|
color := &colorstring.Colorize{Colors: colorstring.DefaultColors, Disable: true}
|
|
|
|
|
streams, done := terminal.StreamsForTesting(t)
|
|
|
|
|
|
|
|
|
|
plan := Plan{
|
|
|
|
|
ActionInvocations: []jsonplan.ActionInvocation{
|
|
|
|
|
{
|
|
|
|
|
Address: "action.test_action.action",
|
|
|
|
|
Type: "test_action",
|
|
|
|
|
Name: "action",
|
|
|
|
|
ConfigValues: map[string]json.RawMessage{
|
|
|
|
|
"attr": []byte("\"one\""),
|
|
|
|
|
},
|
|
|
|
|
ConfigSensitive: nil,
|
|
|
|
|
ProviderName: "test",
|
|
|
|
|
InvokeActionTrigger: new(jsonplan.InvokeActionTrigger),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
ResourceDrift: []jsonplan.ResourceChange{
|
|
|
|
|
{
|
|
|
|
|
Address: "aws_instance.foo",
|
|
|
|
|
Mode: "managed",
|
|
|
|
|
Type: "aws_instance",
|
|
|
|
|
Name: "foo",
|
|
|
|
|
IndexUnknown: true,
|
|
|
|
|
ProviderName: "aws",
|
|
|
|
|
Change: jsonplan.Change{
|
|
|
|
|
Actions: []string{"update"},
|
|
|
|
|
Before: marshalJson(t, map[string]interface{}{
|
|
|
|
|
"id": "1D5F5E9E-F2E5-401B-9ED5-692A215AC67E",
|
|
|
|
|
"value": "Hello, World!",
|
|
|
|
|
}),
|
|
|
|
|
After: marshalJson(t, map[string]interface{}{
|
|
|
|
|
"id": "1D5F5E9E-F2E5-401B-9ED5-692A215AC67E",
|
|
|
|
|
"value": "Hello, World!",
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
ProviderSchemas: map[string]*jsonprovider.Provider{
|
|
|
|
|
"test": {
|
|
|
|
|
ActionSchemas: map[string]*jsonprovider.ActionSchema{
|
|
|
|
|
"test_action": {
|
|
|
|
|
ConfigSchema: &jsonprovider.Block{
|
|
|
|
|
Attributes: map[string]*jsonprovider.Attribute{
|
|
|
|
|
"attr": {
|
|
|
|
|
AttributeType: []byte("\"string\""),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Unlinked: new(jsonprovider.UnlinkedAction),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"aws": {
|
|
|
|
|
ResourceSchemas: map[string]*jsonprovider.Schema{
|
|
|
|
|
"aws_instance": {
|
|
|
|
|
Block: &jsonprovider.Block{
|
|
|
|
|
Attributes: map[string]*jsonprovider.Attribute{
|
|
|
|
|
"id": {
|
|
|
|
|
AttributeType: marshalJson(t, "string"),
|
|
|
|
|
},
|
|
|
|
|
"ami": {
|
|
|
|
|
AttributeType: marshalJson(t, "string"),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderer := Renderer{Colorize: color, Streams: streams}
|
|
|
|
|
plan.renderHuman(renderer, plans.RefreshOnlyMode)
|
|
|
|
|
|
|
|
|
|
want := `
|
|
|
|
|
Note: Objects have changed outside of Terraform
|
|
|
|
|
|
|
|
|
|
Terraform detected the following changes made outside of Terraform since the
|
|
|
|
|
last "terraform apply" which may have affected this plan:
|
|
|
|
|
|
|
|
|
|
# aws_instance.foo has changed
|
|
|
|
|
~ resource "aws_instance" "foo" {
|
|
|
|
|
id = "1D5F5E9E-F2E5-401B-9ED5-692A215AC67E"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This is a refresh-only plan, so Terraform will not take any actions to undo
|
|
|
|
|
these. If you were expecting these changes then you can apply this plan to
|
|
|
|
|
record the updated values in the Terraform state without changing any remote
|
|
|
|
|
objects.
|
|
|
|
|
|
|
|
|
|
─────────────────────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
Terraform will invoke the following action(s):
|
|
|
|
|
|
|
|
|
|
# action.test_action.action will be invoked
|
|
|
|
|
action "test_action" "action" {
|
|
|
|
|
config {
|
|
|
|
|
attr = "one"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
got := done(t).Stdout()
|
|
|
|
|
if diff := cmp.Diff(want, got); len(diff) > 0 {
|
|
|
|
|
t.Errorf("unexpected output\ngot:\n%s\nwant:\n%s\ndiff:\n%s", got, want, diff)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestRenderHuman_EmptyPlan(t *testing.T) {
|
|
|
|
|
color := &colorstring.Colorize{Colors: colorstring.DefaultColors, Disable: true}
|
|
|
|
|
streams, done := terminal.StreamsForTesting(t)
|
|
|
|
|
|