diff --git a/internal/command/e2etest/pluggable_state_store_test.go b/internal/command/e2etest/pluggable_state_store_test.go index 5540904b42..70799fc3cb 100644 --- a/internal/command/e2etest/pluggable_state_store_test.go +++ b/internal/command/e2etest/pluggable_state_store_test.go @@ -276,7 +276,7 @@ func TestPrimary_stateStore_outputCmd(t *testing.T) { // Tests using the `terraform show` command in combination with pluggable state storage // > `terraform show` // > `terraform show ` -// > `terraform show ` // TODO +// > `terraform show ` func TestPrimary_stateStore_showCmd(t *testing.T) { if !canRunGoBuild { @@ -353,7 +353,44 @@ greeting = "hello world" t.Errorf("wrong result, diff:\n%s", diff) } - // TODO(SarahFrench/radeksimko): Show plan file: terraform show + //// Show state: terraform show + + // 1. Create a plan file via plan command + newOutput := `output "replacement" { + value = resource.terraform_data.my-data.output +}` + if err := os.WriteFile(filepath.Join(tf.WorkDir(), "outputs.tf"), []byte(newOutput), 0644); err != nil { + t.Fatalf("err: %s", err) + } + + planFile := "tfplan" + stdout, stderr, err = tf.Run("plan", fmt.Sprintf("-out=%s", planFile), "-no-color") + if err != nil { + t.Fatalf("unexpected error: %s\nstderr:\n%s", err, stderr) + } + expectedMsg = "Changes to Outputs" + if !strings.Contains(stdout, expectedMsg) { + t.Errorf("wrong result, expected the plan command to create a plan file but that hasn't happened, got:\n%s", + stdout, + ) + } + + // 2. Inspect plan file + stdout, stderr, err = tf.Run("show", planFile, "-no-color") + if err != nil { + t.Fatalf("unexpected error: %s\nstderr:\n%s", err, stderr) + } + expectedMsg = ` +Changes to Outputs: + - greeting = "hello world" -> null + + replacement = "hello world" + +You can apply this plan to save these new output values to the Terraform +state, without changing any real infrastructure. +` + if diff := cmp.Diff(stdout, expectedMsg); diff != "" { + t.Errorf("wrong result, diff:\n%s", diff) + } } // Tests using the `terraform provider` subcommands in combination with pluggable state storage: diff --git a/internal/command/e2etest/testdata/initialized-directory-with-state-store-fs/main.tf b/internal/command/e2etest/testdata/initialized-directory-with-state-store-fs/main.tf index d2c773a6fc..f20f555669 100644 --- a/internal/command/e2etest/testdata/initialized-directory-with-state-store-fs/main.tf +++ b/internal/command/e2etest/testdata/initialized-directory-with-state-store-fs/main.tf @@ -19,7 +19,3 @@ variable "name" { resource "terraform_data" "my-data" { input = "hello ${var.name}" } - -output "greeting" { - value = resource.terraform_data.my-data.output -} diff --git a/internal/command/e2etest/testdata/initialized-directory-with-state-store-fs/outputs.tf b/internal/command/e2etest/testdata/initialized-directory-with-state-store-fs/outputs.tf new file mode 100644 index 0000000000..b650136fa1 --- /dev/null +++ b/internal/command/e2etest/testdata/initialized-directory-with-state-store-fs/outputs.tf @@ -0,0 +1,3 @@ +output "greeting" { + value = resource.terraform_data.my-data.output +}