Skip to content

Commit

Permalink
Ensure response data is set for CustomResourceEmulator (#1825)
Browse files Browse the repository at this point in the history
The response data (`Data` property) of CFN Custom Resources is optional
(see [AWS
docs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-responses.html)).
This needs to be handled accordingly in the pulumi resource.
  • Loading branch information
flostadler authored Nov 14, 2024
1 parent 4cd3523 commit 4872ad6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions provider/pkg/resources/cfn_custom_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,5 +678,10 @@ func sanitizeCustomResourceResponse(event *cfn.Event, response *cfn.Response) *c
response.PhysicalResourceID = event.RequestID
}

// ensure Data is not nil
if response.Data == nil {
response.Data = map[string]interface{}{}
}

return response
}
25 changes: 23 additions & 2 deletions provider/pkg/resources/cfn_custom_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ func TestCfnCustomResource_Create(t *testing.T) {
},
},
},
{
name: "CustomResource without response data",
customResourceData: nil,
customResourceInputs: map[string]interface{}{
"key1": "value1",
},
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -329,9 +336,14 @@ func TestCfnCustomResource_Create(t *testing.T) {
require.NoError(t, err)

expectedID := physicalResourceID
expectedCustomResourceData := tt.customResourceData
if expectedCustomResourceData == nil {
expectedCustomResourceData = map[string]interface{}{}
}

expectedState := CfnCustomResourceState{
PhysicalResourceID: physicalResourceID,
Data: tt.customResourceData,
Data: expectedCustomResourceData,
StackID: stackID,
ServiceToken: serviceToken,
Bucket: bucketName,
Expand Down Expand Up @@ -611,6 +623,10 @@ func TestCfnCustomResource_Update(t *testing.T) {
timeout: 10 * time.Minute,
newCustomResourceData: map[string]interface{}{"new": "value"},
},
{
name: "CustomResource without response data",
newCustomResourceData: nil,
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -733,9 +749,14 @@ func TestCfnCustomResource_Update(t *testing.T) {

require.NoError(t, err)

expectedCustomResourceData := tt.newCustomResourceData
if expectedCustomResourceData == nil {
expectedCustomResourceData = map[string]interface{}{}
}

expectedState := CfnCustomResourceState{
PhysicalResourceID: physicalResourceID,
Data: tt.newCustomResourceData,
Data: expectedCustomResourceData,
StackID: stackID,
ServiceToken: serviceToken,
Bucket: bucketName,
Expand Down

0 comments on commit 4872ad6

Please sign in to comment.