@@ -276,7 +276,7 @@ func TestPrimary_stateStore_outputCmd(t *testing.T) {
276276// Tests using the `terraform show` command in combination with pluggable state storage
277277// > `terraform show`
278278// > `terraform show <path-to-state-file>`
279- // > `terraform show <path-to-plan-file>` // TODO
279+ // > `terraform show <path-to-plan-file>`
280280func TestPrimary_stateStore_showCmd (t * testing.T ) {
281281
282282 if ! canRunGoBuild {
@@ -353,7 +353,44 @@ greeting = "hello world"
353353 t .Errorf ("wrong result, diff:\n %s" , diff )
354354 }
355355
356- // TODO(SarahFrench/radeksimko): Show plan file: terraform show <path to plan file>
356+ //// Show state: terraform show <path to plan file>
357+
358+ // 1. Create a plan file via plan command
359+ newOutput := `output "replacement" {
360+ value = resource.terraform_data.my-data.output
361+ }`
362+ if err := os .WriteFile (filepath .Join (tf .WorkDir (), "outputs.tf" ), []byte (newOutput ), 0644 ); err != nil {
363+ t .Fatalf ("err: %s" , err )
364+ }
365+
366+ planFile := "tfplan"
367+ stdout , stderr , err = tf .Run ("plan" , fmt .Sprintf ("-out=%s" , planFile ), "-no-color" )
368+ if err != nil {
369+ t .Fatalf ("unexpected error: %s\n stderr:\n %s" , err , stderr )
370+ }
371+ expectedMsg = "Changes to Outputs"
372+ if ! strings .Contains (stdout , expectedMsg ) {
373+ t .Errorf ("wrong result, expected the plan command to create a plan file but that hasn't happened, got:\n %s" ,
374+ stdout ,
375+ )
376+ }
377+
378+ // 2. Inspect plan file
379+ stdout , stderr , err = tf .Run ("show" , planFile , "-no-color" )
380+ if err != nil {
381+ t .Fatalf ("unexpected error: %s\n stderr:\n %s" , err , stderr )
382+ }
383+ expectedMsg = `
384+ Changes to Outputs:
385+ - greeting = "hello world" -> null
386+ + replacement = "hello world"
387+
388+ You can apply this plan to save these new output values to the Terraform
389+ state, without changing any real infrastructure.
390+ `
391+ if diff := cmp .Diff (stdout , expectedMsg ); diff != "" {
392+ t .Errorf ("wrong result, diff:\n %s" , diff )
393+ }
357394}
358395
359396// Tests using the `terraform provider` subcommands in combination with pluggable state storage:
0 commit comments