Skip to content

Commit

Permalink
return correct element types for latebound resources (#664)
Browse files Browse the repository at this point in the history
We currently return a pointer to the interface for latebound resources
from their ElementType methods. However pulumi expects pointers to the
concrete type here, so it can create it and assign values to the created
object. Fix that.

In particular this can happen when calling `fn::secret` on a created
resource. Currently that will panic because the internals get confused
by this wrong `ElementType`. I'm not sure it makes all that much sense
to even call `fn::secret` on this, but we shouldn't panic either.

Fixes pulumi/pulumi#17530. I'm not sure this
completely fixes it as I've managed to produce a slightly different
panic, but not the same one. For lack of better ideas I'm gonna claim
this fixes it for now, and we can revisit if we get any more panic
reports with a pulumi version with this fix included.
  • Loading branch information
tgummerer authored Oct 15, 2024
1 parent 43dbcc8 commit ca55909
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Bug Fixes-664.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
component: runtime
kind: Bug Fixes
body: Fix potential panic when using fn::secret on a resource
time: 2024-10-14T17:31:02.140545881+02:00
custom:
PR: "664"
7 changes: 4 additions & 3 deletions pkg/pulumiyaml/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ func (st *lateboundCustomResourceState) ProviderResource() *pulumi.ProviderResou
}

func (*lateboundCustomResourceState) ElementType() reflect.Type {
return reflect.TypeOf((*lateboundResource)(nil)).Elem()
return reflect.TypeOf((**lateboundCustomResourceState)(nil)).Elem()
}

func (st *lateboundCustomResourceState) GetRawOutputs() pulumi.Output {
Expand Down Expand Up @@ -625,7 +625,7 @@ func (st *lateboundProviderResourceState) ProviderResource() *pulumi.ProviderRes
}

func (*lateboundProviderResourceState) ElementType() reflect.Type {
return reflect.TypeOf((*lateboundResource)(nil)).Elem()
return reflect.TypeOf((**lateboundProviderResourceState)(nil)).Elem()
}

func (st *lateboundProviderResourceState) GetRawOutputs() pulumi.Output {
Expand Down Expand Up @@ -866,7 +866,8 @@ func (r *Runner) Evaluate(ctx *pulumi.Context) syntax.Diagnostics {
return r.Run(programEvaluator{
evalContext: eCtx,
pulumiCtx: ctx,
packageRefs: packageRefs})
packageRefs: packageRefs,
})
}

func getConfNodesFromMap(project string, configPropertyMap resource.PropertyMap) []configNode {
Expand Down
7 changes: 7 additions & 0 deletions pkg/tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,10 @@ func TestResourceOrderingWithDefaultProvider(t *testing.T) {
SkipEmptyPreviewUpdate: true,
})
}

//nolint:paralleltest // uses parallel programtest
func TestResourceSecret(t *testing.T) {
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dir: filepath.Join("testdata", "resource-secret"),
})
}
15 changes: 15 additions & 0 deletions pkg/tests/testdata/resource-secret/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: resource-secret
runtime:
name: yaml
resources:
randomPassword:
type: random:RandomPassword
properties:
length: 16
lower: true
upper: true
numeric: true
special: true
outputs:
superSecret:
fn::secret: ${randomPassword}

0 comments on commit ca55909

Please sign in to comment.