From f9dfa98533c51e766b0cc60fe0c94c882f2d9516 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 3 May 2019 16:23:32 -0400 Subject: [PATCH] test to make sure a data source is planned The data source here needs to be re-read during apply, because its config is changing. --- builtin/providers/test/data_source_test.go | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/builtin/providers/test/data_source_test.go b/builtin/providers/test/data_source_test.go index 6e809cabc..c0a1ae57c 100644 --- a/builtin/providers/test/data_source_test.go +++ b/builtin/providers/test/data_source_test.go @@ -239,3 +239,53 @@ data "test_data_source" "two" { }, }) } + +func TestDataSource_planUpdate(t *testing.T) { + resource.UnitTest(t, resource.TestCase{ + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: strings.TrimSpace(` +resource "test_resource" "a" { + required = "first" + required_map = { + key = "1" + } + optional_force_new = "first" +} + +data "test_data_source" "a" { + input = "${test_resource.a.computed_from_required}" +} + +output "out" { + value = "${data.test_data_source.a.output}" +} + `), + }, + { + Config: strings.TrimSpace(` +resource "test_resource" "a" { + required = "second" + required_map = { + key = "1" + } + optional_force_new = "second" +} + +data "test_data_source" "a" { + input = "${test_resource.a.computed_from_required}" +} + +output "out" { + value = "${data.test_data_source.a.output}" +} + `), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.test_data_source.a", "output", "second"), + resource.TestCheckOutput("out", "second"), + ), + }, + }, + }) +}