diff --git a/pkg/config/provider.go b/pkg/config/provider.go index 9ae89ecb..1bb66c42 100644 --- a/pkg/config/provider.go +++ b/pkg/config/provider.go @@ -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")) } } diff --git a/pkg/config/schema_conversions.go b/pkg/config/schema_conversions.go index 3258a409..47aa94af 100644 --- a/pkg/config/schema_conversions.go +++ b/pkg/config/schema_conversions.go @@ -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 { diff --git a/pkg/config/schema_conversions_test.go b/pkg/config/schema_conversions_test.go index 1cd93c43..698ca2c9 100644 --- a/pkg/config/schema_conversions_test.go +++ b/pkg/config/schema_conversions_test.go @@ -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) }