test: Add E2E test coverage for inspecting a plan file using the `terraform show` command (#38020)

pull/38030/head
Sarah French 5 months ago committed by GitHub
parent 13cccebef0
commit 193867f060
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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 <path-to-state-file>`
// > `terraform show <path-to-plan-file>` // TODO
// > `terraform show <path-to-plan-file>`
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 <path to plan file>
//// Show state: terraform show <path to plan file>
// 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:

@ -19,7 +19,3 @@ variable "name" {
resource "terraform_data" "my-data" {
input = "hello ${var.name}"
}
output "greeting" {
value = resource.terraform_data.my-data.output
}

@ -0,0 +1,3 @@
output "greeting" {
value = resource.terraform_data.my-data.output
}
Loading…
Cancel
Save