From 4f9aabc7ea64a4ab9c77ac592fa13b3e449553c9 Mon Sep 17 00:00:00 2001 From: Ian Wahbe Date: Fri, 25 Oct 2024 23:37:41 +0200 Subject: [PATCH] Support parameterization at the gRPC level (#281) This PR adds basic support for provider parameterization. --- examples/assets/go.mod | 4 +- examples/assets/go.sum | 8 +-- examples/credentials/go.mod | 4 +- examples/credentials/go.sum | 8 +-- examples/dna-store/go.mod | 4 +- examples/dna-store/go.sum | 8 +-- examples/file/go.mod | 4 +- examples/file/go.sum | 8 +-- examples/random-login/go.mod | 4 +- examples/random-login/go.sum | 8 +-- examples/str/go.mod | 4 +- examples/str/go.sum | 8 +-- go.mod | 4 +- go.sum | 8 +-- infer/tests/go.mod | 4 +- infer/tests/go.sum | 8 +-- provider.go | 95 +++++++++++++++++++++++++++++ tests/go.mod | 4 +- tests/go.sum | 8 +-- tests/parameterize_test.go | 115 +++++++++++++++++++++++++++++++++++ 20 files changed, 264 insertions(+), 54 deletions(-) create mode 100644 tests/parameterize_test.go diff --git a/examples/assets/go.mod b/examples/assets/go.mod index aefe467..3039312 100644 --- a/examples/assets/go.mod +++ b/examples/assets/go.mod @@ -62,8 +62,8 @@ require ( github.com/pkg/term v1.1.0 // indirect github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 // indirect github.com/pulumi/esc v0.10.0 // indirect - github.com/pulumi/pulumi/pkg/v3 v3.134.0 // indirect - github.com/pulumi/pulumi/sdk/v3 v3.134.0 // indirect + github.com/pulumi/pulumi/pkg/v3 v3.137.0 // indirect + github.com/pulumi/pulumi/sdk/v3 v3.137.0 // indirect github.com/rivo/uniseg v0.4.4 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect diff --git a/examples/assets/go.sum b/examples/assets/go.sum index 7b72f23..48781c7 100644 --- a/examples/assets/go.sum +++ b/examples/assets/go.sum @@ -160,10 +160,10 @@ github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 h1:vkHw5I/plNdTr435 github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231/go.mod h1:murToZ2N9hNJzewjHBgfFdXhZKjY3z5cYC1VXk+lbFE= github.com/pulumi/esc v0.10.0 h1:jzBKzkLVW0mePeanDRfqSQoCJ5yrkux0jIwAkUxpRKE= github.com/pulumi/esc v0.10.0/go.mod h1:2Bfa+FWj/xl8CKqRTWbWgDX0SOD4opdQgvYSURTGK2c= -github.com/pulumi/pulumi/pkg/v3 v3.134.0 h1:EaUwz7GMv38SlKqRt+KfzMh9+sYyAZQJvXeBpQfE1ZI= -github.com/pulumi/pulumi/pkg/v3 v3.134.0/go.mod h1:zYNlBVHCvl3r+43iEwQX11BfEC+Dln7UOX8rvwuf1Co= -github.com/pulumi/pulumi/sdk/v3 v3.134.0 h1:jnkRmtB/2Swkdj6b6CdtbDlCVLZTPCqINi8slnN7I/I= -github.com/pulumi/pulumi/sdk/v3 v3.134.0/go.mod h1:J5kQEX8v87aeUhk6NdQXnjCo1DbiOnOiL3Sf2DuDda8= +github.com/pulumi/pulumi/pkg/v3 v3.137.0 h1:/KPFQQaB5W0/GhVxSTGnEzv3ZW5uieGN5Q2q+Lsr+Zw= +github.com/pulumi/pulumi/pkg/v3 v3.137.0/go.mod h1:ZQXJUTysDwq/mtilutRBKguH6DI+3b2WgNcOrs0whJ0= +github.com/pulumi/pulumi/sdk/v3 v3.137.0 h1:bxhYpOY7Z4xt+VmezEpHuhjpOekkaMqOjzxFg/1OhCw= +github.com/pulumi/pulumi/sdk/v3 v3.137.0/go.mod h1:PvKsX88co8XuwuPdzolMvew5lZV+4JmZfkeSjj7A6dI= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= diff --git a/examples/credentials/go.mod b/examples/credentials/go.mod index 115c157..8ce7e83 100644 --- a/examples/credentials/go.mod +++ b/examples/credentials/go.mod @@ -6,7 +6,7 @@ go 1.22 require ( github.com/pulumi/pulumi-go-provider v0.0.0-00010101000000-000000000000 - github.com/pulumi/pulumi/sdk/v3 v3.134.0 + github.com/pulumi/pulumi/sdk/v3 v3.137.0 ) require ( @@ -65,7 +65,7 @@ require ( github.com/pkg/term v1.1.0 // indirect github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 // indirect github.com/pulumi/esc v0.10.0 // indirect - github.com/pulumi/pulumi/pkg/v3 v3.134.0 // indirect + github.com/pulumi/pulumi/pkg/v3 v3.137.0 // indirect github.com/rivo/uniseg v0.4.4 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect diff --git a/examples/credentials/go.sum b/examples/credentials/go.sum index f027000..2df198f 100644 --- a/examples/credentials/go.sum +++ b/examples/credentials/go.sum @@ -160,10 +160,10 @@ github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 h1:vkHw5I/plNdTr435 github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231/go.mod h1:murToZ2N9hNJzewjHBgfFdXhZKjY3z5cYC1VXk+lbFE= github.com/pulumi/esc v0.10.0 h1:jzBKzkLVW0mePeanDRfqSQoCJ5yrkux0jIwAkUxpRKE= github.com/pulumi/esc v0.10.0/go.mod h1:2Bfa+FWj/xl8CKqRTWbWgDX0SOD4opdQgvYSURTGK2c= -github.com/pulumi/pulumi/pkg/v3 v3.134.0 h1:EaUwz7GMv38SlKqRt+KfzMh9+sYyAZQJvXeBpQfE1ZI= -github.com/pulumi/pulumi/pkg/v3 v3.134.0/go.mod h1:zYNlBVHCvl3r+43iEwQX11BfEC+Dln7UOX8rvwuf1Co= -github.com/pulumi/pulumi/sdk/v3 v3.134.0 h1:jnkRmtB/2Swkdj6b6CdtbDlCVLZTPCqINi8slnN7I/I= -github.com/pulumi/pulumi/sdk/v3 v3.134.0/go.mod h1:J5kQEX8v87aeUhk6NdQXnjCo1DbiOnOiL3Sf2DuDda8= +github.com/pulumi/pulumi/pkg/v3 v3.137.0 h1:/KPFQQaB5W0/GhVxSTGnEzv3ZW5uieGN5Q2q+Lsr+Zw= +github.com/pulumi/pulumi/pkg/v3 v3.137.0/go.mod h1:ZQXJUTysDwq/mtilutRBKguH6DI+3b2WgNcOrs0whJ0= +github.com/pulumi/pulumi/sdk/v3 v3.137.0 h1:bxhYpOY7Z4xt+VmezEpHuhjpOekkaMqOjzxFg/1OhCw= +github.com/pulumi/pulumi/sdk/v3 v3.137.0/go.mod h1:PvKsX88co8XuwuPdzolMvew5lZV+4JmZfkeSjj7A6dI= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= diff --git a/examples/dna-store/go.mod b/examples/dna-store/go.mod index bbdd4e6..4bf20b3 100644 --- a/examples/dna-store/go.mod +++ b/examples/dna-store/go.mod @@ -62,8 +62,8 @@ require ( github.com/pkg/term v1.1.0 // indirect github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 // indirect github.com/pulumi/esc v0.10.0 // indirect - github.com/pulumi/pulumi/pkg/v3 v3.134.0 // indirect - github.com/pulumi/pulumi/sdk/v3 v3.134.0 // indirect + github.com/pulumi/pulumi/pkg/v3 v3.137.0 // indirect + github.com/pulumi/pulumi/sdk/v3 v3.137.0 // indirect github.com/rivo/uniseg v0.4.4 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect diff --git a/examples/dna-store/go.sum b/examples/dna-store/go.sum index 7b72f23..48781c7 100644 --- a/examples/dna-store/go.sum +++ b/examples/dna-store/go.sum @@ -160,10 +160,10 @@ github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 h1:vkHw5I/plNdTr435 github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231/go.mod h1:murToZ2N9hNJzewjHBgfFdXhZKjY3z5cYC1VXk+lbFE= github.com/pulumi/esc v0.10.0 h1:jzBKzkLVW0mePeanDRfqSQoCJ5yrkux0jIwAkUxpRKE= github.com/pulumi/esc v0.10.0/go.mod h1:2Bfa+FWj/xl8CKqRTWbWgDX0SOD4opdQgvYSURTGK2c= -github.com/pulumi/pulumi/pkg/v3 v3.134.0 h1:EaUwz7GMv38SlKqRt+KfzMh9+sYyAZQJvXeBpQfE1ZI= -github.com/pulumi/pulumi/pkg/v3 v3.134.0/go.mod h1:zYNlBVHCvl3r+43iEwQX11BfEC+Dln7UOX8rvwuf1Co= -github.com/pulumi/pulumi/sdk/v3 v3.134.0 h1:jnkRmtB/2Swkdj6b6CdtbDlCVLZTPCqINi8slnN7I/I= -github.com/pulumi/pulumi/sdk/v3 v3.134.0/go.mod h1:J5kQEX8v87aeUhk6NdQXnjCo1DbiOnOiL3Sf2DuDda8= +github.com/pulumi/pulumi/pkg/v3 v3.137.0 h1:/KPFQQaB5W0/GhVxSTGnEzv3ZW5uieGN5Q2q+Lsr+Zw= +github.com/pulumi/pulumi/pkg/v3 v3.137.0/go.mod h1:ZQXJUTysDwq/mtilutRBKguH6DI+3b2WgNcOrs0whJ0= +github.com/pulumi/pulumi/sdk/v3 v3.137.0 h1:bxhYpOY7Z4xt+VmezEpHuhjpOekkaMqOjzxFg/1OhCw= +github.com/pulumi/pulumi/sdk/v3 v3.137.0/go.mod h1:PvKsX88co8XuwuPdzolMvew5lZV+4JmZfkeSjj7A6dI= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= diff --git a/examples/file/go.mod b/examples/file/go.mod index 483eed0..8fa0347 100644 --- a/examples/file/go.mod +++ b/examples/file/go.mod @@ -6,7 +6,7 @@ go 1.22 require ( github.com/pulumi/pulumi-go-provider v0.0.0-00010101000000-000000000000 - github.com/pulumi/pulumi/sdk/v3 v3.134.0 + github.com/pulumi/pulumi/sdk/v3 v3.137.0 ) require ( @@ -65,7 +65,7 @@ require ( github.com/pkg/term v1.1.0 // indirect github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 // indirect github.com/pulumi/esc v0.10.0 // indirect - github.com/pulumi/pulumi/pkg/v3 v3.134.0 // indirect + github.com/pulumi/pulumi/pkg/v3 v3.137.0 // indirect github.com/rivo/uniseg v0.4.4 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect diff --git a/examples/file/go.sum b/examples/file/go.sum index f027000..2df198f 100644 --- a/examples/file/go.sum +++ b/examples/file/go.sum @@ -160,10 +160,10 @@ github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 h1:vkHw5I/plNdTr435 github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231/go.mod h1:murToZ2N9hNJzewjHBgfFdXhZKjY3z5cYC1VXk+lbFE= github.com/pulumi/esc v0.10.0 h1:jzBKzkLVW0mePeanDRfqSQoCJ5yrkux0jIwAkUxpRKE= github.com/pulumi/esc v0.10.0/go.mod h1:2Bfa+FWj/xl8CKqRTWbWgDX0SOD4opdQgvYSURTGK2c= -github.com/pulumi/pulumi/pkg/v3 v3.134.0 h1:EaUwz7GMv38SlKqRt+KfzMh9+sYyAZQJvXeBpQfE1ZI= -github.com/pulumi/pulumi/pkg/v3 v3.134.0/go.mod h1:zYNlBVHCvl3r+43iEwQX11BfEC+Dln7UOX8rvwuf1Co= -github.com/pulumi/pulumi/sdk/v3 v3.134.0 h1:jnkRmtB/2Swkdj6b6CdtbDlCVLZTPCqINi8slnN7I/I= -github.com/pulumi/pulumi/sdk/v3 v3.134.0/go.mod h1:J5kQEX8v87aeUhk6NdQXnjCo1DbiOnOiL3Sf2DuDda8= +github.com/pulumi/pulumi/pkg/v3 v3.137.0 h1:/KPFQQaB5W0/GhVxSTGnEzv3ZW5uieGN5Q2q+Lsr+Zw= +github.com/pulumi/pulumi/pkg/v3 v3.137.0/go.mod h1:ZQXJUTysDwq/mtilutRBKguH6DI+3b2WgNcOrs0whJ0= +github.com/pulumi/pulumi/sdk/v3 v3.137.0 h1:bxhYpOY7Z4xt+VmezEpHuhjpOekkaMqOjzxFg/1OhCw= +github.com/pulumi/pulumi/sdk/v3 v3.137.0/go.mod h1:PvKsX88co8XuwuPdzolMvew5lZV+4JmZfkeSjj7A6dI= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= diff --git a/examples/random-login/go.mod b/examples/random-login/go.mod index 152f590..120dd38 100644 --- a/examples/random-login/go.mod +++ b/examples/random-login/go.mod @@ -8,7 +8,7 @@ require ( github.com/blang/semver v3.5.1+incompatible github.com/pulumi/pulumi-go-provider v0.0.0-00010101000000-000000000000 github.com/pulumi/pulumi-random/sdk/v4 v4.8.0 - github.com/pulumi/pulumi/sdk/v3 v3.134.0 + github.com/pulumi/pulumi/sdk/v3 v3.137.0 github.com/stretchr/testify v1.9.0 ) @@ -69,7 +69,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 // indirect github.com/pulumi/esc v0.10.0 // indirect - github.com/pulumi/pulumi/pkg/v3 v3.134.0 // indirect + github.com/pulumi/pulumi/pkg/v3 v3.137.0 // indirect github.com/rivo/uniseg v0.4.4 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect diff --git a/examples/random-login/go.sum b/examples/random-login/go.sum index fc08928..56763e6 100644 --- a/examples/random-login/go.sum +++ b/examples/random-login/go.sum @@ -162,10 +162,10 @@ github.com/pulumi/esc v0.10.0 h1:jzBKzkLVW0mePeanDRfqSQoCJ5yrkux0jIwAkUxpRKE= github.com/pulumi/esc v0.10.0/go.mod h1:2Bfa+FWj/xl8CKqRTWbWgDX0SOD4opdQgvYSURTGK2c= github.com/pulumi/pulumi-random/sdk/v4 v4.8.0 h1:zaSdfNqcaRqKld2jTB+YZIN7O4BsQ2m/AEFx7qNZJUY= github.com/pulumi/pulumi-random/sdk/v4 v4.8.0/go.mod h1:czSwj+jZnn/VWovMpTLUs/RL/ZS4PFHRdmlXrkvHqeI= -github.com/pulumi/pulumi/pkg/v3 v3.134.0 h1:EaUwz7GMv38SlKqRt+KfzMh9+sYyAZQJvXeBpQfE1ZI= -github.com/pulumi/pulumi/pkg/v3 v3.134.0/go.mod h1:zYNlBVHCvl3r+43iEwQX11BfEC+Dln7UOX8rvwuf1Co= -github.com/pulumi/pulumi/sdk/v3 v3.134.0 h1:jnkRmtB/2Swkdj6b6CdtbDlCVLZTPCqINi8slnN7I/I= -github.com/pulumi/pulumi/sdk/v3 v3.134.0/go.mod h1:J5kQEX8v87aeUhk6NdQXnjCo1DbiOnOiL3Sf2DuDda8= +github.com/pulumi/pulumi/pkg/v3 v3.137.0 h1:/KPFQQaB5W0/GhVxSTGnEzv3ZW5uieGN5Q2q+Lsr+Zw= +github.com/pulumi/pulumi/pkg/v3 v3.137.0/go.mod h1:ZQXJUTysDwq/mtilutRBKguH6DI+3b2WgNcOrs0whJ0= +github.com/pulumi/pulumi/sdk/v3 v3.137.0 h1:bxhYpOY7Z4xt+VmezEpHuhjpOekkaMqOjzxFg/1OhCw= +github.com/pulumi/pulumi/sdk/v3 v3.137.0/go.mod h1:PvKsX88co8XuwuPdzolMvew5lZV+4JmZfkeSjj7A6dI= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= diff --git a/examples/str/go.mod b/examples/str/go.mod index 5d61ce9..79834b8 100644 --- a/examples/str/go.mod +++ b/examples/str/go.mod @@ -7,7 +7,7 @@ replace github.com/pulumi/pulumi-go-provider => ../.. require ( github.com/blang/semver v3.5.1+incompatible github.com/pulumi/pulumi-go-provider v0.0.0-00010101000000-000000000000 - github.com/pulumi/pulumi/sdk/v3 v3.134.0 + github.com/pulumi/pulumi/sdk/v3 v3.137.0 github.com/stretchr/testify v1.9.0 ) @@ -68,7 +68,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 // indirect github.com/pulumi/esc v0.10.0 // indirect - github.com/pulumi/pulumi/pkg/v3 v3.134.0 // indirect + github.com/pulumi/pulumi/pkg/v3 v3.137.0 // indirect github.com/rivo/uniseg v0.4.4 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect diff --git a/examples/str/go.sum b/examples/str/go.sum index 78de183..c33aaf8 100644 --- a/examples/str/go.sum +++ b/examples/str/go.sum @@ -160,10 +160,10 @@ github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 h1:vkHw5I/plNdTr435 github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231/go.mod h1:murToZ2N9hNJzewjHBgfFdXhZKjY3z5cYC1VXk+lbFE= github.com/pulumi/esc v0.10.0 h1:jzBKzkLVW0mePeanDRfqSQoCJ5yrkux0jIwAkUxpRKE= github.com/pulumi/esc v0.10.0/go.mod h1:2Bfa+FWj/xl8CKqRTWbWgDX0SOD4opdQgvYSURTGK2c= -github.com/pulumi/pulumi/pkg/v3 v3.134.0 h1:EaUwz7GMv38SlKqRt+KfzMh9+sYyAZQJvXeBpQfE1ZI= -github.com/pulumi/pulumi/pkg/v3 v3.134.0/go.mod h1:zYNlBVHCvl3r+43iEwQX11BfEC+Dln7UOX8rvwuf1Co= -github.com/pulumi/pulumi/sdk/v3 v3.134.0 h1:jnkRmtB/2Swkdj6b6CdtbDlCVLZTPCqINi8slnN7I/I= -github.com/pulumi/pulumi/sdk/v3 v3.134.0/go.mod h1:J5kQEX8v87aeUhk6NdQXnjCo1DbiOnOiL3Sf2DuDda8= +github.com/pulumi/pulumi/pkg/v3 v3.137.0 h1:/KPFQQaB5W0/GhVxSTGnEzv3ZW5uieGN5Q2q+Lsr+Zw= +github.com/pulumi/pulumi/pkg/v3 v3.137.0/go.mod h1:ZQXJUTysDwq/mtilutRBKguH6DI+3b2WgNcOrs0whJ0= +github.com/pulumi/pulumi/sdk/v3 v3.137.0 h1:bxhYpOY7Z4xt+VmezEpHuhjpOekkaMqOjzxFg/1OhCw= +github.com/pulumi/pulumi/sdk/v3 v3.137.0/go.mod h1:PvKsX88co8XuwuPdzolMvew5lZV+4JmZfkeSjj7A6dI= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= diff --git a/go.mod b/go.mod index 8e6ad69..c3295f6 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,8 @@ go 1.22 require ( github.com/blang/semver v3.5.1+incompatible github.com/mitchellh/mapstructure v1.5.0 - github.com/pulumi/pulumi/pkg/v3 v3.134.0 - github.com/pulumi/pulumi/sdk/v3 v3.134.0 + github.com/pulumi/pulumi/pkg/v3 v3.137.0 + github.com/pulumi/pulumi/sdk/v3 v3.137.0 google.golang.org/grpc v1.63.2 google.golang.org/protobuf v1.33.0 pgregory.net/rapid v1.1.0 diff --git a/go.sum b/go.sum index bf3d48e..e402eac 100644 --- a/go.sum +++ b/go.sum @@ -160,10 +160,10 @@ github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 h1:vkHw5I/plNdTr435 github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231/go.mod h1:murToZ2N9hNJzewjHBgfFdXhZKjY3z5cYC1VXk+lbFE= github.com/pulumi/esc v0.10.0 h1:jzBKzkLVW0mePeanDRfqSQoCJ5yrkux0jIwAkUxpRKE= github.com/pulumi/esc v0.10.0/go.mod h1:2Bfa+FWj/xl8CKqRTWbWgDX0SOD4opdQgvYSURTGK2c= -github.com/pulumi/pulumi/pkg/v3 v3.134.0 h1:EaUwz7GMv38SlKqRt+KfzMh9+sYyAZQJvXeBpQfE1ZI= -github.com/pulumi/pulumi/pkg/v3 v3.134.0/go.mod h1:zYNlBVHCvl3r+43iEwQX11BfEC+Dln7UOX8rvwuf1Co= -github.com/pulumi/pulumi/sdk/v3 v3.134.0 h1:jnkRmtB/2Swkdj6b6CdtbDlCVLZTPCqINi8slnN7I/I= -github.com/pulumi/pulumi/sdk/v3 v3.134.0/go.mod h1:J5kQEX8v87aeUhk6NdQXnjCo1DbiOnOiL3Sf2DuDda8= +github.com/pulumi/pulumi/pkg/v3 v3.137.0 h1:/KPFQQaB5W0/GhVxSTGnEzv3ZW5uieGN5Q2q+Lsr+Zw= +github.com/pulumi/pulumi/pkg/v3 v3.137.0/go.mod h1:ZQXJUTysDwq/mtilutRBKguH6DI+3b2WgNcOrs0whJ0= +github.com/pulumi/pulumi/sdk/v3 v3.137.0 h1:bxhYpOY7Z4xt+VmezEpHuhjpOekkaMqOjzxFg/1OhCw= +github.com/pulumi/pulumi/sdk/v3 v3.137.0/go.mod h1:PvKsX88co8XuwuPdzolMvew5lZV+4JmZfkeSjj7A6dI= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= diff --git a/infer/tests/go.mod b/infer/tests/go.mod index 09e5270..5128ee6 100644 --- a/infer/tests/go.mod +++ b/infer/tests/go.mod @@ -7,8 +7,8 @@ replace github.com/pulumi/pulumi-go-provider => ../.. require ( github.com/blang/semver v3.5.1+incompatible github.com/pulumi/pulumi-go-provider v0.10.1 - github.com/pulumi/pulumi/pkg/v3 v3.134.0 - github.com/pulumi/pulumi/sdk/v3 v3.134.0 + github.com/pulumi/pulumi/pkg/v3 v3.137.0 + github.com/pulumi/pulumi/sdk/v3 v3.137.0 github.com/stretchr/testify v1.9.0 ) diff --git a/infer/tests/go.sum b/infer/tests/go.sum index 78de183..c33aaf8 100644 --- a/infer/tests/go.sum +++ b/infer/tests/go.sum @@ -160,10 +160,10 @@ github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 h1:vkHw5I/plNdTr435 github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231/go.mod h1:murToZ2N9hNJzewjHBgfFdXhZKjY3z5cYC1VXk+lbFE= github.com/pulumi/esc v0.10.0 h1:jzBKzkLVW0mePeanDRfqSQoCJ5yrkux0jIwAkUxpRKE= github.com/pulumi/esc v0.10.0/go.mod h1:2Bfa+FWj/xl8CKqRTWbWgDX0SOD4opdQgvYSURTGK2c= -github.com/pulumi/pulumi/pkg/v3 v3.134.0 h1:EaUwz7GMv38SlKqRt+KfzMh9+sYyAZQJvXeBpQfE1ZI= -github.com/pulumi/pulumi/pkg/v3 v3.134.0/go.mod h1:zYNlBVHCvl3r+43iEwQX11BfEC+Dln7UOX8rvwuf1Co= -github.com/pulumi/pulumi/sdk/v3 v3.134.0 h1:jnkRmtB/2Swkdj6b6CdtbDlCVLZTPCqINi8slnN7I/I= -github.com/pulumi/pulumi/sdk/v3 v3.134.0/go.mod h1:J5kQEX8v87aeUhk6NdQXnjCo1DbiOnOiL3Sf2DuDda8= +github.com/pulumi/pulumi/pkg/v3 v3.137.0 h1:/KPFQQaB5W0/GhVxSTGnEzv3ZW5uieGN5Q2q+Lsr+Zw= +github.com/pulumi/pulumi/pkg/v3 v3.137.0/go.mod h1:ZQXJUTysDwq/mtilutRBKguH6DI+3b2WgNcOrs0whJ0= +github.com/pulumi/pulumi/sdk/v3 v3.137.0 h1:bxhYpOY7Z4xt+VmezEpHuhjpOekkaMqOjzxFg/1OhCw= +github.com/pulumi/pulumi/sdk/v3 v3.137.0/go.mod h1:PvKsX88co8XuwuPdzolMvew5lZV+4JmZfkeSjj7A6dI= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= diff --git a/provider.go b/provider.go index 08cbaed..6336729 100644 --- a/provider.go +++ b/provider.go @@ -26,6 +26,7 @@ import ( "io" "os" + "github.com/blang/semver" "github.com/hashicorp/go-multierror" "github.com/pulumi/pulumi/pkg/v3/codegen/schema" pprovider "github.com/pulumi/pulumi/pkg/v3/resource/provider" @@ -315,6 +316,20 @@ type Provider struct { // GetSchema fetches the schema for this resource provider. GetSchema func(context.Context, GetSchemaRequest) (GetSchemaResponse, error) + + // Parameterize sets up the provider as a replacement parameterized provider. + // + // If a SDK was generated with parameters, then Parameterize should be called once before + // [Provider.CheckConfig], [Provider.DiffConfig] or [Provider.Configure]. + // + // Parameterize can be called in 2 configurations: with [ParameterizeRequest.Args] specified or with + // [ParameterizeRequest.Value] specified. Parameterize should leave the provider in the same state + // regardless of which variant was used. + // + // For more through documentation on Parameterize, see + // https://pulumi-developer-docs.readthedocs.io/latest/docs/architecture/providers.html#parameterized-providers. + Parameterize func(context.Context, ParameterizeRequest) (ParameterizeResponse, error) + // Cancel signals the provider to gracefully shut down and abort any ongoing resource operations. // Operations aborted in this way will return an error (e.g., `Update` and `Create` will either return a // creation error or an initialization error). Since Cancel is advisory and non-blocking, it is up @@ -380,6 +395,13 @@ func (d Provider) WithDefaults() Provider { return nyi("Cancel") } } + + if d.Parameterize == nil { + d.Parameterize = func(context.Context, ParameterizeRequest) (ParameterizeResponse, error) { + return ParameterizeResponse{}, nyi("Parameterize") + } + } + if d.CheckConfig == nil { d.CheckConfig = func(context.Context, CheckRequest) (CheckResponse, error) { return CheckResponse{}, nyi("CheckConfig") @@ -1091,6 +1113,79 @@ func (p *provider) Cancel(ctx context.Context, _ *emptypb.Empty) (*emptypb.Empty } +type ( + // ParameterizeRequest configures the provider as parameterized. + // + // Parameterize can be called in 2 configurations: with Args non-nil or with Value non-nil. Exactly + // one of Args or Value will be non-nil. Parameterize should leave the provider in the same state + // regardless of which variant was used. + ParameterizeRequest struct { + // Args indicates that the provider has been configured from the CLI. + Args *ParameterizeRequestArgs + // Value re-parameterizes an existing provider. + Value *ParameterizeRequestValue + } + + ParameterizeRequestArgs struct { + // Args is the un-processed CLI args for the parameterization. + // + // For example: + // + // pulumi package add my-provider arg1 arg2 + // ^^^^ ^^^^ + // + // Then ParameterizeRequestArgs{Args:[]string{"arg1", "arg2"}} will be sent. + Args []string + } + + // ParameterizeRequestValue represents a re-parameterization from an already generated parameterized + // SDK. + // + // Name and Version will match what was in the ParameterizeResponse that generated the SDK. Value will + // match what was in the schema returned during SDK generation. + ParameterizeRequestValue struct { + Name string + Version semver.Version + Value []byte + } + + ParameterizeResponse struct { + Name string + Version semver.Version + } +) + +func (p *provider) Parameterize(ctx context.Context, req *rpc.ParameterizeRequest) (*rpc.ParameterizeResponse, error) { + var parsedRequest ParameterizeRequest + + switch params := req.Parameters.(type) { + case *rpc.ParameterizeRequest_Args: + parsedRequest.Args = &ParameterizeRequestArgs{ + Args: params.Args.GetArgs(), + } + case *rpc.ParameterizeRequest_Value: + version, err := semver.Parse(params.Value.Version) + if err != nil { + return nil, rpcerror.Wrapf(codes.InvalidArgument, err, "invalid version %q", params.Value.Version) + } + parsedRequest.Value = &ParameterizeRequestValue{ + Name: params.Value.Name, + Version: version, + Value: params.Value.Value, + } + } + + resp, err := p.client.Parameterize(p.ctx(ctx, ""), parsedRequest) + if err != nil { + return nil, err + } + + return &rpc.ParameterizeResponse{ + Name: resp.Name, + Version: resp.Version.String(), + }, nil +} + func (p *provider) GetPluginInfo(context.Context, *emptypb.Empty) (*rpc.PluginInfo, error) { return &rpc.PluginInfo{ Version: p.version, diff --git a/tests/go.mod b/tests/go.mod index 64dac07..f6059ee 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -9,8 +9,8 @@ require ( github.com/pulumi/providertest v0.0.12 github.com/pulumi/pulumi-go-provider v0.0.0-00010101000000-000000000000 github.com/pulumi/pulumi-random/sdk/v4 v4.16.3 - github.com/pulumi/pulumi/pkg/v3 v3.134.0 - github.com/pulumi/pulumi/sdk/v3 v3.134.0 + github.com/pulumi/pulumi/pkg/v3 v3.137.0 + github.com/pulumi/pulumi/sdk/v3 v3.137.0 github.com/stretchr/testify v1.9.0 google.golang.org/protobuf v1.33.0 ) diff --git a/tests/go.sum b/tests/go.sum index 88ee303..896195f 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -348,10 +348,10 @@ github.com/pulumi/providertest v0.0.12 h1:UjcFQHHs4AGJyJqxhvC2q8yVQ7Li+UyCyP95HZ github.com/pulumi/providertest v0.0.12/go.mod h1:REAoaN+hGOtdWJGirfWYqcSjCejlbGfzyVTUuemJTuE= github.com/pulumi/pulumi-random/sdk/v4 v4.16.3 h1:nlN42MRSIuDh5Pc5nLq4b0lwZaX2ZUAW67Nw+OlNOig= github.com/pulumi/pulumi-random/sdk/v4 v4.16.3/go.mod h1:yRfWJSLEAVZvkwgXajr3S9OmFkAZTxfO44Ef2HfixXQ= -github.com/pulumi/pulumi/pkg/v3 v3.134.0 h1:EaUwz7GMv38SlKqRt+KfzMh9+sYyAZQJvXeBpQfE1ZI= -github.com/pulumi/pulumi/pkg/v3 v3.134.0/go.mod h1:zYNlBVHCvl3r+43iEwQX11BfEC+Dln7UOX8rvwuf1Co= -github.com/pulumi/pulumi/sdk/v3 v3.134.0 h1:jnkRmtB/2Swkdj6b6CdtbDlCVLZTPCqINi8slnN7I/I= -github.com/pulumi/pulumi/sdk/v3 v3.134.0/go.mod h1:J5kQEX8v87aeUhk6NdQXnjCo1DbiOnOiL3Sf2DuDda8= +github.com/pulumi/pulumi/pkg/v3 v3.137.0 h1:/KPFQQaB5W0/GhVxSTGnEzv3ZW5uieGN5Q2q+Lsr+Zw= +github.com/pulumi/pulumi/pkg/v3 v3.137.0/go.mod h1:ZQXJUTysDwq/mtilutRBKguH6DI+3b2WgNcOrs0whJ0= +github.com/pulumi/pulumi/sdk/v3 v3.137.0 h1:bxhYpOY7Z4xt+VmezEpHuhjpOekkaMqOjzxFg/1OhCw= +github.com/pulumi/pulumi/sdk/v3 v3.137.0/go.mod h1:PvKsX88co8XuwuPdzolMvew5lZV+4JmZfkeSjj7A6dI= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= diff --git a/tests/parameterize_test.go b/tests/parameterize_test.go new file mode 100644 index 0000000..bf3b6d8 --- /dev/null +++ b/tests/parameterize_test.go @@ -0,0 +1,115 @@ +// Copyright 2024, Pulumi Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package tests + +import ( + "context" + "testing" + + "github.com/blang/semver" + p "github.com/pulumi/pulumi-go-provider" + pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestParameterize(t *testing.T) { + t.Parallel() + + type args struct { + input *pulumirpc.ParameterizeRequest + expectedInput p.ParameterizeRequest + inputError string + output p.ParameterizeResponse + expectedOutput *pulumirpc.ParameterizeResponse + } + + run := func(args args) func(t *testing.T) { + return func(t *testing.T) { + t.Parallel() + server, err := p.RawServer("test", "0.0.0-dev", p.Provider{ + Parameterize: func(_ context.Context, req p.ParameterizeRequest) (p.ParameterizeResponse, error) { + assert.Equal(t, args.expectedInput, req) + return args.output, nil + }, + })(nil) + require.NoError(t, err) + + resp, err := server.Parameterize(context.Background(), args.input) + if args.inputError == "" { + require.NoError(t, err) + assert.Equal(t, args.expectedOutput, resp) + } else { + assert.ErrorContains(t, err, args.inputError) + } + } + } + + t.Run("cli args", run(args{ + input: &pulumirpc.ParameterizeRequest{ + Parameters: &pulumirpc.ParameterizeRequest_Args{ + Args: &pulumirpc.ParameterizeRequest_ParametersArgs{ + Args: []string{"arg1", "arg2"}, + }, + }, + }, + expectedInput: p.ParameterizeRequest{Args: &p.ParameterizeRequestArgs{ + Args: []string{"arg1", "arg2"}, + }}, output: p.ParameterizeResponse{ + Name: "my-name", + Version: semver.MustParse("1.2.3"), + }, expectedOutput: &pulumirpc.ParameterizeResponse{ + Name: "my-name", + Version: "1.2.3", + }, + })) + + t.Run("re-parameterization", run(args{ + input: &pulumirpc.ParameterizeRequest{ + Parameters: &pulumirpc.ParameterizeRequest_Value{ + Value: &pulumirpc.ParameterizeRequest_ParametersValue{ + Name: "my-name", + Version: "1.2.3", + Value: []byte("byte-slice"), + }, + }, + }, + expectedInput: p.ParameterizeRequest{Value: &p.ParameterizeRequestValue{ + Name: "my-name", + Version: semver.MustParse("1.2.3"), + Value: []byte("byte-slice"), + }}, + output: p.ParameterizeResponse{ + Name: "my-name", + Version: semver.MustParse("1.2.3"), + }, expectedOutput: &pulumirpc.ParameterizeResponse{ + Name: "my-name", + Version: "1.2.3", + }, + })) + + t.Run("err-invalid-version", run(args{ + input: &pulumirpc.ParameterizeRequest{ + Parameters: &pulumirpc.ParameterizeRequest_Value{ + Value: &pulumirpc.ParameterizeRequest_ParametersValue{ + Name: "my-name", + Version: "not-a-version", + Value: []byte("byte-slice"), + }, + }, + }, + inputError: `invalid version "not-a-version"`, + })) +}