Skip to content

Commit 6534798

Browse files
authored
Fix convertExamplesInObjectSpec to avoid in-place modification (#3108)
Due to an unfortunate interaction, pulumi/pulumi-aws on commit 7c14e422b23f9fbb34e37e381adb9d9ee4da49b4 started generating `{convertExamples:123}` markers into the schema. These markers are an artifact of convert_cli.go implementation and should not leak. The root cause is subtle, with type reuse introduced in pulumi-aws, convertExamplesInObjectSpec gets to repeatedly traverse the same in-memory location, which causes cliConverter.StartConvertingExamples() to call itself: docs = StartConvertingExamples(StartConvertingExamples(docs, p), p) Which breaks the assumptions, as it now assumes `{convertExamples:%d}` is an HCL snippet. The simple fix here is to avoid self-modifying the schema during convertExamplesInObjectSpec. This is the expected behavior with the signature: ``` func (g *Generator) convertExamplesInObjectSpec(path examplePath, spec pschema.ObjectTypeSpec) pschema.ObjectTypeSpec { ``` If later this changes to in-place traversal for efficiency, the signature should also change to not return ObjectTypeSpec.
1 parent d347579 commit 6534798

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

pkg/tfgen/generate_schema.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,9 +1114,12 @@ func (g *Generator) convertExamplesInObjectSpec(
11141114
path examplePath, spec pschema.ObjectTypeSpec,
11151115
) pschema.ObjectTypeSpec {
11161116
spec.Description = g.convertExamples(spec.Description, path)
1117+
1118+
newProperties := map[string]pschema.PropertySpec{}
11171119
for name, prop := range spec.Properties {
1118-
spec.Properties[name] = g.convertExamplesInPropertySpec(path.Property(name), prop)
1120+
newProperties[name] = g.convertExamplesInPropertySpec(path.Property(name), prop)
11191121
}
1122+
spec.Properties = newProperties
11201123
return spec
11211124
}
11221125

0 commit comments

Comments
 (0)