Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config.Resource.RemoveSingletonListConversion #411

Merged
merged 6 commits into from
Jun 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Export config.TraverseSchemas
Signed-off-by: Alper Rifat Ulucinar <[email protected]>
ulucinar committed May 30, 2024

Verified

This commit was signed with the committer’s verified signature.
ulucinar Alper Rifat Ulucinar
commit 526529269697bc0d69d3796ca47e59cd8b06c070
2 changes: 1 addition & 1 deletion pkg/config/provider.go
Original file line number Diff line number Diff line change
@@ -373,7 +373,7 @@ func NewProvider(schema []byte, prefix string, modulePath string, metadata []byt
p.Resources[name].useTerraformPluginFrameworkClient = isPluginFrameworkResource
// traverse the Terraform resource schema to initialize the upjet Resource
// configurations
if err := traverseSchemas(name, terraformResource, p.Resources[name], p.schemaTraversers...); err != nil {
if err := TraverseSchemas(name, terraformResource, p.Resources[name], p.schemaTraversers...); err != nil {
panic(errors.Wrap(err, "failed to execute the Terraform schema traverser chain"))
}
}
6 changes: 5 additions & 1 deletion pkg/config/schema_conversions.go
Original file line number Diff line number Diff line change
@@ -17,7 +17,11 @@ type ResourceSetter interface {
SetResource(r *Resource)
}

func traverseSchemas(tfName string, tfResource *schema.Resource, r *Resource, visitors ...traverser.SchemaTraverser) error {
// TraverseSchemas visits the specified schema belonging to the Terraform
// resource with the given name and given upjet resource configuration using
// the specified visitors. If any visitors report an error, traversal is
// stopped and the error is reported to the caller.
func TraverseSchemas(tfName string, tfResource *schema.Resource, r *Resource, visitors ...traverser.SchemaTraverser) error {
// set the upjet Resource configuration as context for the visitors that
// satisfy the ResourceSetter interface.
for _, v := range visitors {
2 changes: 1 addition & 1 deletion pkg/config/schema_conversions_test.go
Original file line number Diff line number Diff line change
@@ -155,7 +155,7 @@ func TestSingletonListEmbedder(t *testing.T) {
t.Run(n, func(t *testing.T) {
e := &SingletonListEmbedder{}
r := DefaultResource(tt.args.name, tt.args.resource, nil, nil)
err := traverseSchemas(tt.args.name, tt.args.resource, r, e)
err := TraverseSchemas(tt.args.name, tt.args.resource, r, e)
if diff := cmp.Diff(tt.want.err, err, test.EquateErrors()); diff != "" {
t.Fatalf("\n%s\ntraverseSchemas(name, schema, ...): -wantErr, +gotErr:\n%s", tt.reason, diff)
}