add terraform_data e2e test

This commit is contained in:
James Bardin 2022-09-07 17:29:01 -04:00
parent 3b73ed3348
commit 58e15c7f0e
2 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,55 @@
package e2etest
import (
"path/filepath"
"strings"
"testing"
"github.com/hashicorp/terraform/internal/addrs"
"github.com/hashicorp/terraform/internal/e2e"
)
func TestTerraformProviderData(t *testing.T) {
fixturePath := filepath.Join("testdata", "terraform-managed-data")
tf := e2e.NewBinary(t, terraformBin, fixturePath)
_, stderr, err := tf.Run("init", "-input=false")
if err != nil {
t.Fatalf("unexpected init error: %s\nstderr:\n%s", err, stderr)
}
stdout, stderr, err := tf.Run("plan", "-out=tfplan", "-input=false")
if err != nil {
t.Fatalf("unexpected plan error: %s\nstderr:\n%s", err, stderr)
}
if !strings.Contains(stdout, "4 to add, 0 to change, 0 to destroy") {
t.Errorf("incorrect plan tally; want 4 to add:\n%s", stdout)
}
stdout, stderr, err = tf.Run("apply", "-input=false", "tfplan")
if err != nil {
t.Fatalf("unexpected apply error: %s\nstderr:\n%s", err, stderr)
}
if !strings.Contains(stdout, "Resources: 4 added, 0 changed, 0 destroyed") {
t.Errorf("incorrect apply tally; want 4 added:\n%s", stdout)
}
state, err := tf.LocalState()
if err != nil {
t.Fatalf("failed to read state file: %s", err)
}
// we'll check the final output to validate the resources
d := state.Module(addrs.RootModuleInstance).OutputValues["d"].Value
input := d.GetAttr("input")
output := d.GetAttr("output")
if input.IsNull() {
t.Fatal("missing input from resource d")
}
if !input.RawEquals(output) {
t.Fatalf("input %#v does not equal output %#v\n", input, output)
}
}

View File

@ -0,0 +1,18 @@
resource "terraform_data" "a" {
}
resource "terraform_data" "b" {
input = terraform_data.a.id
}
resource "terraform_data" "c" {
trigger = terraform_data.b
}
resource "terraform_data" "d" {
input = [ terraform_data.b, terraform_data.c ]
}
output "d" {
value = terraform_data.d
}