@@ -1893,9 +1893,9 @@ func TestContext2Plan_computedInFunction(t *testing.T) {
18931893 assertNoErrors (t , diags )
18941894
18951895 if p .ReadDataSourceCalled {
1896- t .Fatalf ("ReadDataSource was called on provider during plan; should not have been called" )
1896+ // there was no config change to read during plan
1897+ t .Fatalf ("ReadDataSource should not have been called" )
18971898 }
1898-
18991899}
19001900
19011901func TestContext2Plan_computedDataCountResource (t * testing.T ) {
@@ -1993,6 +1993,7 @@ func TestContext2Plan_dataResourceBecomesComputed(t *testing.T) {
19931993 DataSources : map [string ]* configschema.Block {
19941994 "aws_data_source" : {
19951995 Attributes : map [string ]* configschema.Attribute {
1996+ "id" : {Type : cty .String , Computed : true },
19961997 "foo" : {Type : cty .String , Optional : true },
19971998 },
19981999 },
@@ -4992,8 +4993,10 @@ func TestContext2Plan_createBeforeDestroy_depends_datasource(t *testing.T) {
49924993 }
49934994 }
49944995 p .ReadDataSourceFn = func (req providers.ReadDataSourceRequest ) providers.ReadDataSourceResponse {
4996+ cfg := req .Config .AsValueMap ()
4997+ cfg ["id" ] = cty .StringVal ("data_id" )
49954998 return providers.ReadDataSourceResponse {
4996- Diagnostics : tfdiags . Diagnostics ( nil ). Append ( fmt . Errorf ( "ReadDataSource called, but should not have been" ) ),
4999+ State : cty . ObjectVal ( cfg ),
49975000 }
49985001 }
49995002
@@ -5010,9 +5013,6 @@ func TestContext2Plan_createBeforeDestroy_depends_datasource(t *testing.T) {
50105013 // thus the plan call below is forced to produce a deferred read action.
50115014
50125015 plan , diags := ctx .Plan ()
5013- if p .ReadDataSourceCalled {
5014- t .Errorf ("ReadDataSource was called on the provider, but should not have been because we didn't refresh" )
5015- }
50165016 if diags .HasErrors () {
50175017 t .Fatalf ("unexpected errors: %s" , diags .Err ())
50185018 }
@@ -5042,38 +5042,30 @@ func TestContext2Plan_createBeforeDestroy_depends_datasource(t *testing.T) {
50425042 }
50435043 checkVals (t , objectVal (t , schema , map [string ]cty.Value {
50445044 "num" : cty .StringVal ("2" ),
5045- "computed" : cty .UnknownVal ( cty . String ),
5045+ "computed" : cty .StringVal ( "data_id" ),
50465046 }), ric .After )
50475047 case "aws_instance.foo[1]" :
50485048 if res .Action != plans .Create {
50495049 t .Fatalf ("resource %s should be created, got %s" , ric .Addr , ric .Action )
50505050 }
50515051 checkVals (t , objectVal (t , schema , map [string ]cty.Value {
50525052 "num" : cty .StringVal ("2" ),
5053- "computed" : cty .UnknownVal ( cty . String ),
5053+ "computed" : cty .StringVal ( "data_id" ),
50545054 }), ric .After )
50555055 case "data.aws_vpc.bar[0]" :
50565056 if res .Action != plans .Read {
50575057 t .Fatalf ("resource %s should be read, got %s" , ric .Addr , ric .Action )
50585058 }
50595059 checkVals (t , objectVal (t , schema , map [string ]cty.Value {
5060- // In a normal flow we would've read an exact value in
5061- // ReadDataSource, but because this test doesn't run
5062- // cty.Refresh we have no opportunity to do that lookup
5063- // and a deferred read is forced.
5064- "id" : cty .UnknownVal (cty .String ),
5060+ "id" : cty .StringVal ("data_id" ),
50655061 "foo" : cty .StringVal ("0" ),
50665062 }), ric .After )
50675063 case "data.aws_vpc.bar[1]" :
50685064 if res .Action != plans .Read {
50695065 t .Fatalf ("resource %s should be read, got %s" , ric .Addr , ric .Action )
50705066 }
50715067 checkVals (t , objectVal (t , schema , map [string ]cty.Value {
5072- // In a normal flow we would've read an exact value in
5073- // ReadDataSource, but because this test doesn't run
5074- // cty.Refresh we have no opportunity to do that lookup
5075- // and a deferred read is forced.
5076- "id" : cty .UnknownVal (cty .String ),
5068+ "id" : cty .StringVal ("data_id" ),
50775069 "foo" : cty .StringVal ("1" ),
50785070 }), ric .After )
50795071 default :
@@ -5513,11 +5505,18 @@ func TestContext2Plan_invalidOutput(t *testing.T) {
55135505data "aws_data_source" "name" {}
55145506
55155507output "out" {
5516- value = "${ data.aws_data_source.name.missing}"
5508+ value = data.aws_data_source.name.missing
55175509}` ,
55185510 })
55195511
55205512 p := testProvider ("aws" )
5513+ p .ReadDataSourceResponse = providers.ReadDataSourceResponse {
5514+ State : cty .ObjectVal (map [string ]cty.Value {
5515+ "id" : cty .StringVal ("data_id" ),
5516+ "foo" : cty .StringVal ("foo" ),
5517+ }),
5518+ }
5519+
55215520 ctx := testContext2 (t , & ContextOpts {
55225521 Config : m ,
55235522 Providers : map [addrs.Provider ]providers.Factory {
@@ -5558,6 +5557,13 @@ resource "aws_instance" "foo" {
55585557 })
55595558
55605559 p := testProvider ("aws" )
5560+ p .ReadDataSourceResponse = providers.ReadDataSourceResponse {
5561+ State : cty .ObjectVal (map [string ]cty.Value {
5562+ "id" : cty .StringVal ("data_id" ),
5563+ "foo" : cty .StringVal ("foo" ),
5564+ }),
5565+ }
5566+
55615567 ctx := testContext2 (t , & ContextOpts {
55625568 Config : m ,
55635569 Providers : map [addrs.Provider ]providers.Factory {
0 commit comments