From 9f433fd13153752faae1df08b7d83d8e8bea5b9e Mon Sep 17 00:00:00 2001 From: VenelinMartinov Date: Tue, 19 Nov 2024 13:16:11 +0000 Subject: [PATCH] Refactor providerbuilder Resource to apply defaults in NewResource (#2630) This PR is a refactor of the test utilities in PF for creating Resources. We now have a `NewResource` function to create `pb.Resource` which fills in reasonable defaults which were previously handled in `NewProvider`. This in turn will allow us to use `pb.Resource` as an argument in `Diff` cross-tests. The concrete use case I am after with this is for `Diff` cross-tests for Computed properties, which require a custom Create and Update function. --- pkg/pf/tests/diff_list_test.go | 7 ++- pkg/pf/tests/diff_map_test.go | 6 ++- pkg/pf/tests/diff_object_test.go | 11 +++- pkg/pf/tests/diff_set_test.go | 6 ++- pkg/pf/tests/diff_test.go | 19 ++++--- pkg/pf/tests/dynamic_types_test.go | 8 +-- pkg/pf/tests/extract_inputs_test.go | 4 +- .../tests/internal/cross-tests/configure.go | 8 +-- pkg/pf/tests/internal/cross-tests/diff.go | 10 ++-- pkg/pf/tests/internal/pftfcheck/pftf_test.go | 8 +-- .../providerbuilder/build_provider.go | 31 ----------- .../providerbuilder/build_resource.go | 51 +++++++++++++++++++ pkg/pf/tests/muxwith_test.go | 4 +- pkg/pf/tests/provider_check_test.go | 10 ++-- .../provider_nested_custom_types_test.go | 12 +++-- pkg/pf/tests/provider_read_test.go | 4 +- pkg/pf/tests/schema_and_program_test.go | 25 ++++----- pkg/pf/tests/schemas.go | 1 + pkg/pf/tests/tfgen_test.go | 4 +- 19 files changed, 138 insertions(+), 91 deletions(-) diff --git a/pkg/pf/tests/diff_list_test.go b/pkg/pf/tests/diff_list_test.go index b5de36c91..cfb9d3396 100644 --- a/pkg/pf/tests/diff_list_test.go +++ b/pkg/pf/tests/diff_list_test.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hexops/autogold/v2" crosstests "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/cross-tests" + pb "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/providerbuilder" "github.com/zclconf/go-cty/cty" ) @@ -217,8 +218,12 @@ func TestDetailedDiffList(t *testing.T) { initialValue := schemaValueMakerPair.valueMaker(scenario.initialValue) changeValue := schemaValueMakerPair.valueMaker(scenario.changeValue) + res := pb.NewResource(pb.NewResourceArgs{ + ResourceSchema: schemaValueMakerPair.schema, + }) + diff := crosstests.Diff( - t, schemaValueMakerPair.schema, map[string]cty.Value{"key": initialValue}, map[string]cty.Value{"key": changeValue}) + t, res, map[string]cty.Value{"key": initialValue}, map[string]cty.Value{"key": changeValue}) autogold.ExpectFile(t, testOutput{ initialValue: scenario.initialValue, diff --git a/pkg/pf/tests/diff_map_test.go b/pkg/pf/tests/diff_map_test.go index 6638e7502..56a38579b 100644 --- a/pkg/pf/tests/diff_map_test.go +++ b/pkg/pf/tests/diff_map_test.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hexops/autogold/v2" crosstests "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/cross-tests" + pb "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/providerbuilder" "github.com/zclconf/go-cty/cty" ) @@ -171,8 +172,11 @@ func TestDetailedDiffMap(t *testing.T) { t.Parallel() initialValue := schemaValueMakerPair.valueMaker(scenario.initialValue) changeValue := schemaValueMakerPair.valueMaker(scenario.changeValue) + res := pb.NewResource(pb.NewResourceArgs{ + ResourceSchema: schemaValueMakerPair.schema, + }) - diff := crosstests.Diff(t, schemaValueMakerPair.schema, map[string]cty.Value{"key": initialValue}, map[string]cty.Value{"key": changeValue}) + diff := crosstests.Diff(t, res, map[string]cty.Value{"key": initialValue}, map[string]cty.Value{"key": changeValue}) autogold.ExpectFile(t, testOutput{ initialValue: scenario.initialValue, diff --git a/pkg/pf/tests/diff_object_test.go b/pkg/pf/tests/diff_object_test.go index 92a97a0be..9ef66dae2 100644 --- a/pkg/pf/tests/diff_object_test.go +++ b/pkg/pf/tests/diff_object_test.go @@ -15,6 +15,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hexops/autogold/v2" crosstests "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/cross-tests" + pb "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/providerbuilder" "github.com/zclconf/go-cty/cty" ) @@ -331,7 +332,10 @@ func TestDetailedDiffObject(t *testing.T) { t.Parallel() initialValue := map[string]cty.Value{"key": makeValue(scenario.initialValue)} changeValue := map[string]cty.Value{"key": makeValue(scenario.changeValue)} - diff := crosstests.Diff(t, schema.schema, initialValue, changeValue) + res := pb.NewResource(pb.NewResourceArgs{ + ResourceSchema: schema.schema, + }) + diff := crosstests.Diff(t, res, initialValue, changeValue) autogold.ExpectFile(t, testOutput{ initialValue: scenario.initialValue, changeValue: scenario.changeValue, @@ -347,7 +351,10 @@ func TestDetailedDiffObject(t *testing.T) { t.Parallel() initialValue := map[string]cty.Value{"key": makeValue(scenario.initialValue)} changeValue := map[string]cty.Value{"key": makeValue(scenario.changeValue)} - diff := crosstests.Diff(t, schema.schema, initialValue, changeValue) + res := pb.NewResource(pb.NewResourceArgs{ + ResourceSchema: schema.schema, + }) + diff := crosstests.Diff(t, res, initialValue, changeValue) autogold.ExpectFile(t, testOutput{ initialValue: scenario.initialValue, changeValue: scenario.changeValue, diff --git a/pkg/pf/tests/diff_set_test.go b/pkg/pf/tests/diff_set_test.go index a35f164db..3d77bbc6e 100644 --- a/pkg/pf/tests/diff_set_test.go +++ b/pkg/pf/tests/diff_set_test.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hexops/autogold/v2" crosstests "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/cross-tests" + pb "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/providerbuilder" "github.com/zclconf/go-cty/cty" ) @@ -225,7 +226,10 @@ func TestDetailedDiffSet(t *testing.T) { initialValue := schemaValueMakerPair.valueMaker(scenario.initialValue) changeValue := schemaValueMakerPair.valueMaker(scenario.changeValue) - diff := crosstests.Diff(t, schemaValueMakerPair.schema, map[string]cty.Value{"key": initialValue}, map[string]cty.Value{"key": changeValue}) + res := pb.NewResource(pb.NewResourceArgs{ + ResourceSchema: schemaValueMakerPair.schema, + }) + diff := crosstests.Diff(t, res, map[string]cty.Value{"key": initialValue}, map[string]cty.Value{"key": changeValue}) autogold.ExpectFile(t, testOutput{ initialValue: scenario.initialValue, diff --git a/pkg/pf/tests/diff_test.go b/pkg/pf/tests/diff_test.go index df4b83272..085a4258e 100644 --- a/pkg/pf/tests/diff_test.go +++ b/pkg/pf/tests/diff_test.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hexops/autogold/v2" crosstests "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/cross-tests" + pb "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/providerbuilder" "github.com/zclconf/go-cty/cty" ) @@ -25,7 +26,10 @@ func TestSimpleNoDiff(t *testing.T) { }, } - res := crosstests.Diff(t, sch, + res := pb.NewResource(pb.NewResourceArgs{ + ResourceSchema: sch, + }) + diff := crosstests.Diff(t, res, map[string]cty.Value{"key": cty.StringVal("value")}, map[string]cty.Value{"key": cty.StringVal("value1")}, ) @@ -45,7 +49,7 @@ Terraform will perform the following actions: Plan: 0 to add, 1 to change, 0 to destroy. -`).Equal(t, res.TFOut) +`).Equal(t, diff.TFOut) autogold.Expect(`Previewing update (test): pulumi:pulumi:Stack: (same) [urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test] @@ -56,7 +60,7 @@ Plan: 0 to add, 1 to change, 0 to destroy. Resources: ~ 1 to update 1 unchanged -`).Equal(t, res.PulumiOut) +`).Equal(t, diff.PulumiOut) } type stringDefault string @@ -186,13 +190,16 @@ func TestDetailedDiffStringAttribute(t *testing.T) { initialValue := makeValue(scenario.initialValue) changeValue := makeValue(scenario.changeValue) - res := crosstests.Diff(t, schema.schema, map[string]cty.Value{"key": initialValue}, map[string]cty.Value{"key": changeValue}) + res := pb.NewResource(pb.NewResourceArgs{ + ResourceSchema: schema.schema, + }) + diff := crosstests.Diff(t, res, map[string]cty.Value{"key": initialValue}, map[string]cty.Value{"key": changeValue}) autogold.ExpectFile(t, testOutput{ initialValue: scenario.initialValue, changeValue: scenario.changeValue, - tfOut: res.TFOut, - pulumiOut: res.PulumiOut, + tfOut: diff.TFOut, + pulumiOut: diff.PulumiOut, }) }) } diff --git a/pkg/pf/tests/dynamic_types_test.go b/pkg/pf/tests/dynamic_types_test.go index 9b85f588c..0d8ebcccd 100644 --- a/pkg/pf/tests/dynamic_types_test.go +++ b/pkg/pf/tests/dynamic_types_test.go @@ -231,7 +231,7 @@ func TestCreateResourceWithDynamicAttribute(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { t.Parallel() - r := pb.Resource{ + r := pb.NewResource(pb.NewResourceArgs{ Name: "r", CreateFunc: func( ctx context.Context, @@ -266,10 +266,10 @@ func TestCreateResourceWithDynamicAttribute(t *testing.T) { }, }, }, - } + }) // Define an aux resource to produce unknown values for testing. - r0 := pb.Resource{ + r0 := pb.NewResource(pb.NewResourceArgs{ Name: "r0", CreateFunc: func( ctx context.Context, @@ -298,7 +298,7 @@ func TestCreateResourceWithDynamicAttribute(t *testing.T) { }, }, }, - } + }) p := pb.NewProvider(pb.NewProviderArgs{ AllResources: []pb.Resource{r, r0}, diff --git a/pkg/pf/tests/extract_inputs_test.go b/pkg/pf/tests/extract_inputs_test.go index 1a7dd8350..12e4dd215 100644 --- a/pkg/pf/tests/extract_inputs_test.go +++ b/pkg/pf/tests/extract_inputs_test.go @@ -904,10 +904,10 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { t.Run(tc.name, func(t *testing.T) { prov := pb.NewProvider(pb.NewProviderArgs{ AllResources: []pb.Resource{ - { + pb.NewResource(pb.NewResourceArgs{ Name: "test", ResourceSchema: tc.resSchema, - }, + }), }, }) diff --git a/pkg/pf/tests/internal/cross-tests/configure.go b/pkg/pf/tests/internal/cross-tests/configure.go index 5b61417b0..0dc135e5b 100644 --- a/pkg/pf/tests/internal/cross-tests/configure.go +++ b/pkg/pf/tests/internal/cross-tests/configure.go @@ -100,9 +100,11 @@ func Configure(t T, schema pschema.Schema, tfConfig map[string]cty.Value, option ConfigureFunc: func(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { *config = req.Config }, - AllResources: []pb.Resource{{ - Name: "res", - }}, + AllResources: []pb.Resource{ + pb.NewResource(pb.NewResourceArgs{ + Name: "res", + }), + }, }) } diff --git a/pkg/pf/tests/internal/cross-tests/diff.go b/pkg/pf/tests/internal/cross-tests/diff.go index e4cf0595b..519e15323 100644 --- a/pkg/pf/tests/internal/cross-tests/diff.go +++ b/pkg/pf/tests/internal/cross-tests/diff.go @@ -17,7 +17,6 @@ package crosstests import ( "bytes" - rschema "github.com/hashicorp/terraform-plugin-framework/resource/schema" crosstests "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/tests/cross-tests" crosstestsimpl "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/tests/cross-tests/impl" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/tests/cross-tests/impl/hclwrite" @@ -50,7 +49,7 @@ func yamlResource(t T, properties resource.PropertyMap) map[string]any { // when computed by Terraform and Pulumi. // // Diff should be safe to run in parallel. -func Diff(t T, schema rschema.Schema, tfConfig1, tfConfig2 map[string]cty.Value, options ...DiffOption) crosstestsimpl.DiffResult { +func Diff(t T, res pb.Resource, tfConfig1, tfConfig2 map[string]cty.Value, options ...DiffOption) crosstestsimpl.DiffResult { skipUnlessLinux(t) var opts diffOpts @@ -59,10 +58,7 @@ func Diff(t T, schema rschema.Schema, tfConfig1, tfConfig2 map[string]cty.Value, } prov := pb.NewProvider(pb.NewProviderArgs{ - AllResources: []pb.Resource{{ - Name: "test", - ResourceSchema: schema, - }}, + AllResources: []pb.Resource{res}, }) shimProvider := tfbridge.ShimProvider(prov) @@ -70,7 +66,7 @@ func Diff(t T, schema rschema.Schema, tfConfig1, tfConfig2 map[string]cty.Value, // Run the TF part var hcl1 bytes.Buffer - sch := hclSchemaPFResource(schema) + sch := hclSchemaPFResource(res.ResourceSchema) err := hclwrite.WriteResource(&hcl1, sch, "testprovider_test", "res", tfConfig1, hclwrite.WithCreateBeforeDestroy(true)) require.NoError(t, err) diff --git a/pkg/pf/tests/internal/pftfcheck/pftf_test.go b/pkg/pf/tests/internal/pftfcheck/pftf_test.go index 0aa03af97..fbe545163 100644 --- a/pkg/pf/tests/internal/pftfcheck/pftf_test.go +++ b/pkg/pf/tests/internal/pftfcheck/pftf_test.go @@ -14,14 +14,14 @@ func TestBasic(t *testing.T) { t.Parallel() prov := pb.NewProvider(pb.NewProviderArgs{ AllResources: []pb.Resource{ - { + pb.NewResource(pb.NewResourceArgs{ Name: "res", ResourceSchema: rschema.Schema{ Attributes: map[string]rschema.Attribute{ "s": rschema.StringAttribute{Optional: true}, }, }, - }, + }), }, }) @@ -48,7 +48,7 @@ func TestDefaults(t *testing.T) { t.Parallel() prov := pb.NewProvider(pb.NewProviderArgs{ AllResources: []pb.Resource{ - { + pb.NewResource(pb.NewResourceArgs{ Name: "res", ResourceSchema: rschema.Schema{ Attributes: map[string]rschema.Attribute{ @@ -59,7 +59,7 @@ func TestDefaults(t *testing.T) { }, }, }, - }, + }), }, }) diff --git a/pkg/pf/tests/internal/providerbuilder/build_provider.go b/pkg/pf/tests/internal/providerbuilder/build_provider.go index d3ffcb42b..4f8c72907 100644 --- a/pkg/pf/tests/internal/providerbuilder/build_provider.go +++ b/pkg/pf/tests/internal/providerbuilder/build_provider.go @@ -18,14 +18,10 @@ import ( "github.com/hashicorp/terraform-plugin-framework/datasource" dschema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" - "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/provider/schema" "github.com/hashicorp/terraform-plugin-framework/providerserver" "github.com/hashicorp/terraform-plugin-framework/resource" - rschema "github.com/hashicorp/terraform-plugin-framework/resource/schema" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-go/tfprotov6" ) @@ -114,33 +110,6 @@ func NewProvider(params NewProviderArgs) *Provider { prov.Version = "0.0.1" } - for i := range prov.AllResources { - r := &prov.AllResources[i] - if r.ResourceSchema.Attributes == nil { - r.ResourceSchema.Attributes = map[string]rschema.Attribute{} - } - - if r.ResourceSchema.Attributes["id"] == nil { - r.ResourceSchema.Attributes["id"] = rschema.StringAttribute{ - Computed: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), - }, - } - } - if r.CreateFunc == nil { - r.CreateFunc = func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - resp.State = tfsdk.State(req.Plan) - resp.State.SetAttribute(ctx, path.Root("id"), "test-id") - } - } - if r.UpdateFunc == nil { - r.UpdateFunc = func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - resp.State = tfsdk.State(req.Plan) - } - } - } - for i := range prov.AllDataSources { d := &prov.AllDataSources[i] if d.DataSourceSchema.Attributes == nil { diff --git a/pkg/pf/tests/internal/providerbuilder/build_resource.go b/pkg/pf/tests/internal/providerbuilder/build_resource.go index df8f83584..c2e118b35 100644 --- a/pkg/pf/tests/internal/providerbuilder/build_resource.go +++ b/pkg/pf/tests/internal/providerbuilder/build_resource.go @@ -17,10 +17,61 @@ package providerbuilder import ( "context" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" ) +type NewResourceArgs struct { + // Name is the name of the resource. Defaults to "test". + Name string + ResourceSchema schema.Schema + + CreateFunc func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) + ReadFunc func(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) + UpdateFunc func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) + DeleteFunc func(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) + ImportStateFunc func(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) +} + +// NewResource creates a new Resource with the given parameters, filling reasonable defaults. +func NewResource(args NewResourceArgs) Resource { + if args.Name == "" { + args.Name = "test" + } + + if args.ResourceSchema.Attributes == nil { + args.ResourceSchema.Attributes = map[string]schema.Attribute{} + } + + if args.ResourceSchema.Attributes["id"] == nil { + args.ResourceSchema.Attributes["id"] = schema.StringAttribute{ + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + } + } + + if args.CreateFunc == nil { + args.CreateFunc = func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + resp.State = tfsdk.State(req.Plan) + resp.State.SetAttribute(ctx, path.Root("id"), "test-id") + } + } + if args.UpdateFunc == nil { + args.UpdateFunc = func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + resp.State = tfsdk.State(req.Plan) + } + } + + return Resource(args) +} + +// Resource is a utility type that helps define PF resources. Prefer creating via NewResource. type Resource struct { Name string ResourceSchema schema.Schema diff --git a/pkg/pf/tests/muxwith_test.go b/pkg/pf/tests/muxwith_test.go index 01b523b62..ad6dde61e 100644 --- a/pkg/pf/tests/muxwith_test.go +++ b/pkg/pf/tests/muxwith_test.go @@ -30,7 +30,7 @@ func TestNewMuxProvider(t *testing.T) { t.Parallel() createCallCount := 0 - r := pb.Resource{ + r := pb.NewResource(pb.NewResourceArgs{ Name: "r", CreateFunc: func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { t.Logf("CREATE called: %v", req.Plan.Raw.String()) @@ -45,7 +45,7 @@ func TestNewMuxProvider(t *testing.T) { }, }, }, - } + }) p := pb.NewProvider(pb.NewProviderArgs{ AllResources: []pb.Resource{r}, diff --git a/pkg/pf/tests/provider_check_test.go b/pkg/pf/tests/provider_check_test.go index 8b2b24ec5..a768b9826 100644 --- a/pkg/pf/tests/provider_check_test.go +++ b/pkg/pf/tests/provider_check_test.go @@ -319,10 +319,12 @@ func TestCheck(t *testing.T) { }, }, }, - AllResources: []providerbuilder.Resource{{ - Name: "res", - ResourceSchema: tc.schema, - }}, + AllResources: []providerbuilder.Resource{ + pb.NewResource(pb.NewResourceArgs{ + Name: "res", + ResourceSchema: tc.schema, + }), + }, }) res := tfbridge0.ResourceInfo{ Tok: "testprovider:index/res:Res", diff --git a/pkg/pf/tests/provider_nested_custom_types_test.go b/pkg/pf/tests/provider_nested_custom_types_test.go index 753c9e366..f35b96e34 100644 --- a/pkg/pf/tests/provider_nested_custom_types_test.go +++ b/pkg/pf/tests/provider_nested_custom_types_test.go @@ -27,9 +27,10 @@ func TestNestedCustomTypeEncoding(t *testing.T) { testProvider := pb.NewProvider(pb.NewProviderArgs{ // This resource is modified from AWS Bedrockagent. - AllResources: []providerbuilder.Resource{{ - Name: "bedrockagent", - ResourceSchema: schema.Schema{ + AllResources: []providerbuilder.Resource{ + pb.NewResource(pb.NewResourceArgs{ + Name: "bedrockagent", + ResourceSchema: schema.Schema{ Attributes: map[string]schema.Attribute{ "prompt_override_configuration": schema.ListAttribute{ // proto5 Optional+Computed nested block. CustomType: NewListNestedObjectTypeOf[promptOverrideConfigurationModel](context.Background()), @@ -46,8 +47,9 @@ func TestNestedCustomTypeEncoding(t *testing.T) { }, }, }, - }, - }}, + }, + }), + }, }) res := tfbridge0.ResourceInfo{ Tok: "testprovider:index/bedrockagent:Bedrockagent", diff --git a/pkg/pf/tests/provider_read_test.go b/pkg/pf/tests/provider_read_test.go index 51a298613..a99d80c24 100644 --- a/pkg/pf/tests/provider_read_test.go +++ b/pkg/pf/tests/provider_read_test.go @@ -344,7 +344,7 @@ func TestRefreshMissingResources(t *testing.T) { // See https://github.com/pulumi/pulumi-terraform-bridge/issues/1919 func TestRefreshResourceNotFound(t *testing.T) { t.Parallel() - r := pb.Resource{ + r := pb.NewResource(pb.NewResourceArgs{ Name: "resource", ResourceSchema: fwsch.Schema{ Attributes: map[string]fwsch.Attribute{ @@ -358,7 +358,7 @@ func TestRefreshResourceNotFound(t *testing.T) { // Indicate that it was no found and should be removed from state. resp.State.RemoveResource(ctx) }, - } + }) p := pb.NewProvider(pb.NewProviderArgs{ TypeName: "my", diff --git a/pkg/pf/tests/schema_and_program_test.go b/pkg/pf/tests/schema_and_program_test.go index 019debab5..f43b9dcad 100644 --- a/pkg/pf/tests/schema_and_program_test.go +++ b/pkg/pf/tests/schema_and_program_test.go @@ -33,14 +33,13 @@ func TestBasic(t *testing.T) { provBuilder := providerbuilder.NewProvider( providerbuilder.NewProviderArgs{ AllResources: []providerbuilder.Resource{ - { - Name: "test", + providerbuilder.NewResource(providerbuilder.NewResourceArgs{ ResourceSchema: rschema.Schema{ Attributes: map[string]rschema.Attribute{ "s": rschema.StringAttribute{Optional: true}, }, }, - }, + }), }, }) @@ -66,8 +65,7 @@ func TestComputedSetNoDiffWhenElementRemoved(t *testing.T) { // Regression test for [pulumi/pulumi-terraform-bridge#2192] provBuilder := pb.NewProvider(pb.NewProviderArgs{ AllResources: []providerbuilder.Resource{ - { - Name: "test", + providerbuilder.NewResource(providerbuilder.NewResourceArgs{ ResourceSchema: rschema.Schema{ Attributes: map[string]rschema.Attribute{ "vlan_names": rschema.SetNestedAttribute{ @@ -99,7 +97,7 @@ func TestComputedSetNoDiffWhenElementRemoved(t *testing.T) { }, }, }, - }, + }), }, }) @@ -238,8 +236,7 @@ func TestIDAttribute(t *testing.T) { Version: "0.0.1", ProviderSchema: pschema.Schema{}, AllResources: []providerbuilder.Resource{ - { - Name: "test", + providerbuilder.NewResource(providerbuilder.NewResourceArgs{ ResourceSchema: rschema.Schema{ Attributes: map[string]rschema.Attribute{ "id": tc.attribute, @@ -252,7 +249,7 @@ func TestIDAttribute(t *testing.T) { resp.State.SetAttribute(ctx, path.Root("id"), "test-id") resp.State.SetAttribute(ctx, path.Root("x"), "x-id") }, - }, + }), }, } @@ -314,8 +311,7 @@ func TestDefaults(t *testing.T) { t.Parallel() provBuilder := pb.NewProvider(pb.NewProviderArgs{ AllResources: []providerbuilder.Resource{ - { - Name: "test", + providerbuilder.NewResource(providerbuilder.NewResourceArgs{ ResourceSchema: rschema.Schema{ Attributes: map[string]rschema.Attribute{ "other_prop": rschema.StringAttribute{ @@ -328,7 +324,7 @@ func TestDefaults(t *testing.T) { }, }, }, - }, + }), }, }) @@ -375,8 +371,7 @@ func TestPlanModifiers(t *testing.T) { t.Parallel() provBuilder := pb.NewProvider(pb.NewProviderArgs{ AllResources: []providerbuilder.Resource{ - { - Name: "test", + providerbuilder.NewResource(providerbuilder.NewResourceArgs{ ResourceSchema: rschema.Schema{ Attributes: map[string]rschema.Attribute{ "other_prop": rschema.StringAttribute{ @@ -391,7 +386,7 @@ func TestPlanModifiers(t *testing.T) { }, }, }, - }, + }), }, }) diff --git a/pkg/pf/tests/schemas.go b/pkg/pf/tests/schemas.go index 3f15d13c6..bad241e89 100644 --- a/pkg/pf/tests/schemas.go +++ b/pkg/pf/tests/schemas.go @@ -36,6 +36,7 @@ func genMetadata(t *testing.T, info tfbridge0.ProviderInfo) (tfpf.ProviderMetada generated, err := tfgen.GenerateSchema(context.Background(), tfgen.GenerateSchemaOptions{ ProviderInfo: info, DiagnosticsSink: testSink(t), + XInMemoryDocs: true, }) if err != nil { return tfpf.ProviderMetadata{}, err diff --git a/pkg/pf/tests/tfgen_test.go b/pkg/pf/tests/tfgen_test.go index e57e38b58..db6fb20f4 100644 --- a/pkg/pf/tests/tfgen_test.go +++ b/pkg/pf/tests/tfgen_test.go @@ -44,7 +44,9 @@ func TestRenameResourceWithAliasInAugmentedProvider(t *testing.T) { pfProvider := pb.NewProvider(pb.NewProviderArgs{ TypeName: providerID, AllResources: []providerbuilder.Resource{ - {Name: resourceID}, + pb.NewResource(pb.NewResourceArgs{ + Name: resourceID, + }), }, }) legacyToken := tokens.Type(fmt.Sprintf("my:%s:Resource", resModule))