diff --git a/pkg/tests/flake.lock b/pkg/tests/flake.lock new file mode 100644 index 000000000..fa703dce7 --- /dev/null +++ b/pkg/tests/flake.lock @@ -0,0 +1,83 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1751984180, + "narHash": "sha256-LwWRsENAZJKUdD3SpLluwDmdXY9F45ZEgCb0X+xgOL0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9807714d6944a957c2e036f84b0ff8caf9930bc0", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pulumi-flake": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1731998715, + "narHash": "sha256-OZi2H2uDhcg4bP8pbtDIYQ8ziN6UpyO3/ewdPGklaOE=", + "owner": "nyobe", + "repo": "pulumi-flake", + "rev": "a4677c00e2be5ed39b38a2c0a0cdd702de515a77", + "type": "github" + }, + "original": { + "owner": "nyobe", + "ref": "v3.139.0", + "repo": "pulumi-flake", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "pulumi-flake": "pulumi-flake" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/pkg/tests/flake.nix b/pkg/tests/flake.nix new file mode 100644 index 000000000..7544f6871 --- /dev/null +++ b/pkg/tests/flake.nix @@ -0,0 +1,38 @@ +# Build a Nix flake that defines a development environment. +# Use this flake as an input: +# +# https://github.com/nyobe/pulumi-flake/tree/v3.146.0 + + + +# Here's a Nix flake that defines a development environment using the pulumi-flake as an input: + + +{ + description = "Development environment with Pulumi"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + pulumi-flake = { + url = "github:nyobe/pulumi-flake/v3.139.0"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, flake-utils, pulumi-flake }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + pulumi = pulumi-flake.packages.${system}; + in + { + devShells.default = pkgs.mkShell { + buildInputs = [ + pulumi.default + pkgs.go + pkgs.git + ]; + }; + }); +} diff --git a/pkg/tests/regress_vsphere_824_test.go b/pkg/tests/regress_vsphere_824_test.go new file mode 100644 index 000000000..c6cc7d49f --- /dev/null +++ b/pkg/tests/regress_vsphere_824_test.go @@ -0,0 +1,141 @@ +package tests + +import ( + "bytes" + "context" + "encoding/json" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/tests/pulcheck" + "github.com/pulumi/pulumi/sdk/v3/go/auto/debug" + "github.com/pulumi/pulumi/sdk/v3/go/auto/optup" +) + +// The test is set up to reproduce https://github.com/pulumi/pulumi-vsphere/issues/824 +func Test_RegressVSphere824(t *testing.T) { + t.Parallel() + + subResourceSchema := map[string]*schema.Schema{ + "label": { + Type: schema.TypeString, + Required: true, + }, + "datastore_id": { + Type: schema.TypeString, + Optional: true, + }, + } + + res := &schema.Resource{ + Schema: map[string]*schema.Schema{ + "disk": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Description: "A specification for a virtual disk device on this virtual machine.", + MaxItems: 60, + Elem: &schema.Resource{Schema: subResourceSchema}, + }, + }, + } + + tfp := &schema.Provider{ + ResourcesMap: map[string]*schema.Resource{"prov_test": res}, + } + + bridgedProvider := pulcheck.BridgedProvider(t, "prov", tfp) + + program1 := ` +name: test +runtime: yaml +resources: + mainRes: + type: prov:index:Test + properties: + disks: + - label: label1 + datastoreId: ds1 + - label: label2 + datastoreId: ds2 + options: + ignoreChanges: + - "disks[*].datastoreId" +` + pt := pulcheck.PulCheck(t, bridgedProvider, program1) + + out := pt.Up(t) + t.Logf("# update 1: %v", out.StdErr+out.StdOut) + + d := pt.ExportStack(t) + text, err := json.MarshalIndent(d, "", " ") + require.NoError(t, err) + t.Logf("STATE: %s", text) + + program2 := ` +name: test +runtime: yaml +resources: + mainRes: + type: prov:index:Test + properties: + disks: + - label: label1 + datastoreId: ds1 + - label: label2 + datastoreId: ds2 + - label: label3 + datastoreId: ds3 + options: + ignoreChanges: + - "disks[*].datastoreId" +` + + pp := func(j json.RawMessage) string { + var buf bytes.Buffer + err := json.Indent(&buf, j, "", " ") + if err != nil { + return string(j) + } + return buf.String() + } + + for _, e := range pt.GrpcLog(t).Entries { + t.Logf("%q:\n%s\n=> %s", e.Method, pp(e.Request), pp(e.Response)) + } + + err = os.WriteFile(filepath.Join(pt.WorkingDir(), "Pulumi.yaml"), []byte(program2), 0655) + require.NoError(t, err) + + pt.ClearGrpcLog(t) + + var debugOpts debug.LoggingOptions + + // To enable debug logging in this test, un-comment: + // logLevel := uint(13) + // debugOpts = debug.LoggingOptions{ + // LogLevel: &logLevel, + // LogToStdErr: true, + // FlowToPlugins: true, + // Debug: true, + // } + + out2, err := pt.CurrentStack().Up(context.Background(), + optup.DebugLogging(debugOpts), + ) + + t.Logf("GRPC entries: %d", len(pt.GrpcLog(t).Entries)) + + for _, e := range pt.GrpcLog(t).Entries { + t.Logf("%q:\n%s\n=> %s", e.Method, pp(e.Request), pp(e.Response)) + } + + t.Logf("# update 2: %v", out2.StdErr+out2.StdOut) + + t.Logf("PULUMI VERSION %v", pt.CurrentStack().Workspace().PulumiCommand().Version()) + require.NoError(t, err) +}