Skip to content

Commit f669f79

Browse files
authored
Add conformance test for using a provider in a component (#23904)
Towards fixing #23896. Get a conformance test added to check that a component can declare and use a provider resource. This needed `pcl.MapProvidersAsResources` called when generating component programs to fix up the type tokens.
1 parent f26934b commit f669f79

49 files changed

Lines changed: 492 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
component: codegen
2+
kind: fix
3+
body: Correctly generate provider resources declared inside PCL components for Node.js, Python and Go
4+
time: 2026-07-13T00:00:00+00:00

‎pkg/codegen/go/gen_program.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ func GenerateProgramWithOptions(program *pcl.Program, opts GenerateProgramOption
550550

551551
componentFilename := filepath.Base(componentDir)
552552
componentName := component.DeclarationName()
553+
pcl.MapProvidersAsResources(component.Program)
553554
componentGenerator, err := newGenerator(component.Program, opts)
554555
componentGenerator.isComponent = true
555556
for _, n := range component.Program.Nodes {

‎pkg/codegen/nodejs/gen_program.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ func GenerateProgramWithOptions(program *pcl.Program, opts ProgramOptions) (map[
198198
for componentDir, component := range program.CollectComponents() {
199199
componentFilename := filepath.Base(componentDir)
200200
componentName := component.DeclarationName()
201+
pcl.MapProvidersAsResources(component.Program)
201202
componentGenerator := &generator{
202203
program: component.Program,
203204
isComponent: true,

‎pkg/codegen/python/gen_program.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func GenerateProgram(program *pcl.Program) (map[string][]byte, hcl.Diagnostics,
109109
for componentDir, component := range program.CollectComponents() {
110110
componentFilename := strings.ReplaceAll(filepath.Base(componentDir), "-", "_")
111111
componentName := component.DeclarationName()
112+
pcl.MapProvidersAsResources(component.Program)
112113
componentGenerator, err := newGenerator(component.Program)
113114
if err != nil {
114115
return files, componentGenerator.diagnostics, err
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2026, Pulumi Corporation.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package tests
16+
17+
import (
18+
"github.com/pulumi/pulumi/pkg/v3/resource/plugin"
19+
"github.com/pulumi/pulumi/pkg/v3/testing/pulumi-test-language/providers"
20+
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
21+
"github.com/stretchr/testify/assert"
22+
"github.com/stretchr/testify/require"
23+
)
24+
25+
func init() {
26+
// Regression test for https://github.com/pulumi/pulumi/issues/23896: a ComponentResource authored inside a
27+
// component provider must be able to instantiate and use a provider resource from within its constructor.
28+
LanguageTests["l3-component-provider"] = LanguageTest{
29+
Providers: []func() plugin.Provider{
30+
func() plugin.Provider { return &providers.ConfigProvider{} },
31+
},
32+
Runs: []TestRun{
33+
{
34+
Assert: func(l *L, res AssertArgs) {
35+
err := res.Err
36+
snap := res.Snap
37+
changes := res.Changes
38+
39+
RequireStackResource(l, err, changes)
40+
41+
// stack, component, explicit provider, config resource
42+
require.Len(l, snap.Resources, 4, "expected 4 resources in snapshot")
43+
44+
RequireSingleResource(l, snap.Resources, "pulumi:pulumi:Stack")
45+
46+
component := RequireSingleResource(l, snap.Resources, "components:index:ProviderComponent")
47+
assert.Equal(l, "myComponent", component.URN.Name())
48+
49+
provider := RequireSingleResource(l, snap.Resources, "pulumi:providers:config")
50+
assert.Equal(l, component.URN, provider.Parent,
51+
"expected explicit provider to be parented to the component")
52+
53+
configRes := RequireSingleResource(l, snap.Resources, "config:index:Resource")
54+
assert.Equal(l, component.URN, configRes.Parent,
55+
"expected config resource to be parented to the component")
56+
assert.Equal(l, string(provider.URN)+"::"+string(provider.ID), configRes.Provider,
57+
"expected config resource to use the explicit provider")
58+
59+
want := resource.NewPropertyMapFromMap(map[string]any{"text": "hello"})
60+
assert.Equal(l, want, configRes.Inputs, "expected inputs to be %v", want)
61+
wantOut := resource.NewPropertyMapFromMap(map[string]any{"text": ": hello"})
62+
assert.Equal(l, wantOut, configRes.Outputs, "expected outputs to be %v", wantOut)
63+
},
64+
},
65+
},
66+
}
67+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
component "myComponent" "./providerComponent" {
2+
text = "hello"
3+
}
4+
5+
output "result" {
6+
value = myComponent.result
7+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
config text string {}
2+
3+
resource "prov" "pulumi:providers:config" {
4+
name = "my config"
5+
}
6+
7+
resource "res" "config:index:Resource" {
8+
options {
9+
provider = prov
10+
}
11+
text = text
12+
}
13+
14+
output "result" {
15+
value = res.text
16+
}

‎sdk/go/pulumi-language-go/language_test.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ var expectedFailures = map[string]string{
134134

135135
"l3-component-config-primitives": "does not compile; missing necessary casts for pulumi inputs",
136136
"l3-component-config-objects": "does not compile; missing necessary casts for pulumi inputs",
137-
"l2-resource-primitive-conversions": "primitive conversions accepted by PCL bind, but not lowered correctly by SDK generators", //nolint:lll
138-
"l3-component-primitive-conversions": "primitive conversions accepted by PCL bind, but not lowered correctly by SDK generators", //nolint:lll
137+
"l3-component-provider": "does not compile; missing necessary casts for pulumi inputs and untyped component outputs", //nolint:lll
138+
"l2-resource-primitive-conversions": "primitive conversions accepted by PCL bind, but not lowered correctly by SDK generators", //nolint:lll
139+
"l3-component-primitive-conversions": "primitive conversions accepted by PCL bind, but not lowered correctly by SDK generators", //nolint:lll
139140

140141
"l3-range-list-ref": "fails with syntax errors: undefined: err",
141142
"l3-range-map-ref": "fails with syntax errors: mapResource.K1 undefined (type []*nestedobject.Target has no field or method K1)", //nolint:lll
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/bin/
2+
/node_modules/
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name: l3-component-provider
2+
runtime: bun

0 commit comments

Comments
 (0)