diff --git a/dynamic/info.go b/dynamic/info.go index 2d2e5d739..435ad2535 100644 --- a/dynamic/info.go +++ b/dynamic/info.go @@ -27,11 +27,12 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/dynamic/version" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/proto" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/tokens" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" ) -func providerInfo(ctx context.Context, p run.Provider, value parameterize.Value) (tfbridge.ProviderInfo, error) { +func providerInfo(ctx context.Context, p run.Provider, value parameterize.Value) (info.Provider, error) { provider := proto.New(ctx, p) providerName := p.Name() @@ -39,7 +40,7 @@ func providerInfo(ctx context.Context, p run.Provider, value parameterize.Value) providerName = value.ProviderName } - prov := tfbridge.ProviderInfo{ + prov := info.Provider{ P: provider, Name: providerName, Version: p.Version(), @@ -50,20 +51,20 @@ func providerInfo(ctx context.Context, p run.Provider, value parameterize.Value) Path: "", Data: tfbridge.ProviderMetadata(nil), }, - Python: &tfbridge.PythonInfo{ + Python: &info.Python{ PyProject: struct{ Enabled bool }{true}, RespectSchemaVersion: true, }, - JavaScript: &tfbridge.JavaScriptInfo{ + JavaScript: &info.JavaScript{ LiftSingleValueMethodReturns: true, RespectSchemaVersion: true, }, - CSharp: &tfbridge.CSharpInfo{ + CSharp: &info.CSharp{ LiftSingleValueMethodReturns: true, RespectSchemaVersion: true, }, - Java: &tfbridge.JavaInfo{ /* Java does not have a RespectSchemaVersion flag */ }, - Golang: &tfbridge.GolangInfo{ + Java: &info.Java{ /* Java does not have a RespectSchemaVersion flag */ }, + Golang: &info.Golang{ ImportBasePath: path.Join( "github.com/pulumi/pulumi-terraform-provider/sdks/go", providerName, diff --git a/internal/logging/logging.go b/internal/logging/logging.go index 0a8a3e19c..edee5659f 100644 --- a/internal/logging/logging.go +++ b/internal/logging/logging.go @@ -254,21 +254,21 @@ var _ io.Writer = &logSinkWriter{} func (w *logSinkWriter) Write(p []byte) (n int, err error) { n = len(p) if w.sink == nil { - return + return n, err } raw := strings.TrimSuffix(string(p), "\n") level, raw := parseLevelFromRawString(raw) if level < w.desiredLevel { - return + return n, err } urn, raw := parseUrnFromRawString(raw) severity := logLevelToSeverity(level) err = w.sink.Log(w.ctx, severity, urn, raw) - return + return n, err } func parseTfLogEnvVar() hclog.Level { diff --git a/internal/testing/schemas.go b/internal/testing/schemas.go index 5aa5a7725..15678ecdc 100644 --- a/internal/testing/schemas.go +++ b/internal/testing/schemas.go @@ -33,7 +33,7 @@ func AssertEqualsJSONFile[T any]( unmarshalT := func(r io.Reader) (s T, err error) { err = json.NewDecoder(r).Decode(&s) - return + return s, err } readTFromFile := func(file string) (T, error) { diff --git a/internal/testprovider_invalid_schema/resources.go b/internal/testprovider_invalid_schema/resources.go index b5aa25f92..bf1103c63 100644 --- a/internal/testprovider_invalid_schema/resources.go +++ b/internal/testprovider_invalid_schema/resources.go @@ -18,19 +18,20 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/resource" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" sdkv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) -func ProviderInfo() tfbridge.ProviderInfo { - prov := tfbridge.ProviderInfo{ +func ProviderInfo() info.Provider { + prov := info.Provider{ P: sdkv2.NewProvider(Provider()), Name: "tpinvschema", PreConfigureCallback: func(vars resource.PropertyMap, config shim.ResourceConfig) error { return nil }, - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "invalid_res": { Tok: tfbridge.MakeResource("tpinvschema", "index", "invalid_res"), }, diff --git a/internal/testprovider_sdkv2/resources.go b/internal/testprovider_sdkv2/resources.go index f2d61c92c..5af7f9916 100644 --- a/internal/testprovider_sdkv2/resources.go +++ b/internal/testprovider_sdkv2/resources.go @@ -17,13 +17,13 @@ package tpsdkv2 import ( "github.com/pulumi/pulumi/sdk/v3/go/common/resource" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" sdkv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) -func ProviderInfo() tfbridge.ProviderInfo { - return tfbridge.ProviderInfo{ +func ProviderInfo() info.Provider { + return info.Provider{ P: sdkv2.NewProvider(Provider()), Name: "tpsdkv2", diff --git a/pkg/convert/convert.go b/pkg/convert/convert.go index b43b5bc9b..5e9c7e242 100644 --- a/pkg/convert/convert.go +++ b/pkg/convert/convert.go @@ -27,6 +27,7 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/resource" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" "github.com/pulumi/pulumi-terraform-bridge/v3/unstable/propertyvalue" ) @@ -54,9 +55,9 @@ type Encoder interface { // Schema information that is needed to construct Encoder or Decoder instances. type ObjectSchema struct { - SchemaMap shim.SchemaMap // required - SchemaInfos map[string]*tfbridge.SchemaInfo // optional - Object *tftypes.Object // optional, if not given will be inferred from SchemaMap + SchemaMap shim.SchemaMap // required + SchemaInfos map[string]*info.Schema // optional + Object *tftypes.Object // optional, if not given will be inferred from SchemaMap } func (os ObjectSchema) objectType() tftypes.Object { diff --git a/pkg/convert/encoding.go b/pkg/convert/encoding.go index 5da1f7b8a..d7bc7fea9 100644 --- a/pkg/convert/encoding.go +++ b/pkg/convert/encoding.go @@ -18,18 +18,18 @@ import ( "github.com/hashicorp/terraform-plugin-go/tftypes" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" ) type encoding struct { SchemaOnlyProvider shim.Provider - ProviderInfo *tfbridge.ProviderInfo // only SchemaInfo for fields is required + ProviderInfo *info.Provider // only SchemaInfo for fields is required } var _ Encoding = (*encoding)(nil) -func NewEncoding(schemaOnlyProvider shim.Provider, providerInfo *tfbridge.ProviderInfo) Encoding { +func NewEncoding(schemaOnlyProvider shim.Provider, providerInfo *info.Provider) Encoding { return &encoding{ SchemaOnlyProvider: schemaOnlyProvider, ProviderInfo: providerInfo, @@ -38,7 +38,7 @@ func NewEncoding(schemaOnlyProvider shim.Provider, providerInfo *tfbridge.Provid func (e *encoding) NewConfigEncoder(configType tftypes.Object) (Encoder, error) { schema := e.SchemaOnlyProvider.Schema() - var schemaInfos map[string]*tfbridge.SchemaInfo + var schemaInfos map[string]*info.Schema if e.ProviderInfo != nil { schemaInfos = e.ProviderInfo.Config } diff --git a/pkg/convert/encoding_test.go b/pkg/convert/encoding_test.go index c986e3446..19dc78f4d 100644 --- a/pkg/convert/encoding_test.go +++ b/pkg/convert/encoding_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/schema" ) @@ -37,7 +37,7 @@ func TestResourceDecoder(t *testing.T) { type testCase struct { testName string schema *schema.SchemaMap - info *tfbridge.ProviderInfo + info *info.Provider typ tftypes.Object val tftypes.Value expect autogold.Value @@ -188,7 +188,7 @@ func TestResourceEncoder(t *testing.T) { type testCase struct { testName string schema *schema.SchemaMap - info *tfbridge.ProviderInfo + info *info.Provider typ tftypes.Object val resource.PropertyMap expect autogold.Value @@ -254,7 +254,7 @@ func TestDataSourceDecoder(t *testing.T) { type testCase struct { testName string schema *schema.SchemaMap - info *tfbridge.ProviderInfo + info *info.Provider typ tftypes.Object val tftypes.Value expect autogold.Value @@ -306,10 +306,10 @@ func TestDataSourceDecoder(t *testing.T) { Optional: true, }).Shim(), }, - info: &tfbridge.ProviderInfo{ - DataSources: map[string]*tfbridge.DataSourceInfo{ + info: &info.Provider{ + DataSources: map[string]*info.DataSource{ myDataSource: { - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "foo": { Name: "renamedFoo", }, @@ -357,7 +357,7 @@ func TestDataSourceEncoder(t *testing.T) { type testCase struct { testName string schema *schema.SchemaMap - info *tfbridge.ProviderInfo + info *info.Provider typ tftypes.Object val resource.PropertyMap expect autogold.Value @@ -415,7 +415,7 @@ func TestConfigEncoder(t *testing.T) { type testCase struct { testName string schema *schema.SchemaMap - info *tfbridge.ProviderInfo + info *info.Provider typ tftypes.Object val resource.PropertyMap expect autogold.Value diff --git a/pkg/convert/flattened_test.go b/pkg/convert/flattened_test.go index d7239642e..36404f363 100644 --- a/pkg/convert/flattened_test.go +++ b/pkg/convert/flattened_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" shimschema "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/schema" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/walk" @@ -177,7 +177,7 @@ func maxItemsOneCollectionPropContext(propName string, collectionType shim.Value Optional: true, }).Shim(), }).Shim(), - schemaInfo: &tfbridge.SchemaInfo{ + schemaInfo: &info.Schema{ MaxItemsOne: &yes, }, } diff --git a/pkg/convert/schema_context.go b/pkg/convert/schema_context.go index ed5c093e4..d9ea26c09 100644 --- a/pkg/convert/schema_context.go +++ b/pkg/convert/schema_context.go @@ -23,19 +23,20 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" + shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/walk" ) type schemaMapContext struct { schemaPath walk.SchemaPath schemaMap shim.SchemaMap - schemaInfos map[string]*tfbridge.SchemaInfo + schemaInfos map[string]*info.Schema } var _ localPropertyNames = &schemaMapContext{} -func newSchemaMapContext(schemaMap shim.SchemaMap, schemaInfos map[string]*tfbridge.SchemaInfo) *schemaMapContext { +func newSchemaMapContext(schemaMap shim.SchemaMap, schemaInfos map[string]*info.Schema) *schemaMapContext { return &schemaMapContext{ schemaPath: walk.NewSchemaPath(), schemaMap: schemaMap, @@ -46,12 +47,12 @@ func newSchemaMapContext(schemaMap shim.SchemaMap, schemaInfos map[string]*tfbri func newResourceSchemaMapContext( resource string, schemaOnlyProvider shim.Provider, - providerInfo *tfbridge.ProviderInfo, + providerInfo *info.Provider, ) *schemaMapContext { r := schemaOnlyProvider.ResourcesMap().Get(resource) contract.Assertf(r != nil, "no resource %q found in ResourceMap", resource) sm := r.Schema() - var fields map[string]*tfbridge.SchemaInfo + var fields map[string]*info.Schema if providerInfo != nil { fields = providerInfo.Resources[resource].GetFields() } @@ -61,12 +62,12 @@ func newResourceSchemaMapContext( func newDataSourceSchemaMapContext( dataSource string, schemaOnlyProvider shim.Provider, - providerInfo *tfbridge.ProviderInfo, + providerInfo *info.Provider, ) *schemaMapContext { r := schemaOnlyProvider.DataSourcesMap().Get(dataSource) contract.Assertf(r != nil, "no data source %q found in DataSourcesMap", dataSource) sm := r.Schema() - var fields map[string]*tfbridge.SchemaInfo + var fields map[string]*info.Schema if providerInfo != nil { fields = providerInfo.DataSources[dataSource].GetFields() } @@ -99,7 +100,7 @@ func (sc *schemaMapContext) GetAttr(tfname terraformPropertyName) (*schemaPropCo type schemaPropContext struct { schemaPath walk.SchemaPath schema shim.Schema - schemaInfo *tfbridge.SchemaInfo + schemaInfo *info.Schema } func (pc *schemaPropContext) Secret() bool { @@ -149,7 +150,7 @@ func (pc *schemaPropContext) Object() (*schemaMapContext, error) { if pc.schema != nil { switch elem := pc.schema.Elem().(type) { case shim.Resource: - var fields map[string]*tfbridge.SchemaInfo + var fields map[string]*info.Schema if pc.schemaInfo != nil { fields = pc.schemaInfo.Fields } diff --git a/pkg/convert/secret_test.go b/pkg/convert/secret_test.go index 4829d4cbb..ab511b97e 100644 --- a/pkg/convert/secret_test.go +++ b/pkg/convert/secret_test.go @@ -24,6 +24,7 @@ import ( "github.com/stretchr/testify/require" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/schema" ) @@ -33,7 +34,7 @@ func TestSecretDecoderInjectsSchemaSecrets(t *testing.T) { type testCase struct { name string schemaMap schema.SchemaMap - schemaInfos map[string]*tfbridge.SchemaInfo + schemaInfos map[string]*info.Schema val tftypes.Value expect autogold.Value } @@ -66,7 +67,7 @@ func TestSecretDecoderInjectsSchemaSecrets(t *testing.T) { Type: shim.TypeString, }).Shim(), }, - schemaInfos: map[string]*tfbridge.SchemaInfo{ + schemaInfos: map[string]*info.Schema{ "secret_value": { Type: "string", Secret: tfbridge.True(), @@ -93,7 +94,7 @@ func TestSecretDecoderInjectsSchemaSecrets(t *testing.T) { Sensitive: true, }).Shim(), }, - schemaInfos: map[string]*tfbridge.SchemaInfo{ + schemaInfos: map[string]*info.Schema{ "secret_value": { Type: "string", Secret: tfbridge.False(), diff --git a/pkg/internal/tests/pulcheck/pulcheck.go b/pkg/internal/tests/pulcheck/pulcheck.go index 2c01deb2a..406cd0ddb 100644 --- a/pkg/internal/tests/pulcheck/pulcheck.go +++ b/pkg/internal/tests/pulcheck/pulcheck.go @@ -137,7 +137,7 @@ func WithValidProvider(t T, tfp *schema.Provider) *schema.Provider { } func ProviderServerFromInfo( - ctx context.Context, providerInfo tfbridge.ProviderInfo, + ctx context.Context, providerInfo info.Provider, ) (pulumirpc.ResourceProviderServer, error) { sink := pulumidiag.DefaultSink(io.Discard, io.Discard, pulumidiag.FormatOptions{ Color: colors.Never, @@ -158,7 +158,7 @@ func ProviderServerFromInfo( } // This is an experimental API. -func StartPulumiProvider(ctx context.Context, providerInfo tfbridge.ProviderInfo) (*rpcutil.ServeHandle, error) { +func StartPulumiProvider(ctx context.Context, providerInfo info.Provider) (*rpcutil.ServeHandle, error) { prov, err := ProviderServerFromInfo(ctx, providerInfo) if err != nil { return nil, fmt.Errorf("ProviderServerFromInfo failed: %w", err) @@ -231,7 +231,7 @@ func BridgedProvider(t T, providerName string, tfp *schema.Provider, opts ...Bri shimv2.WithPlanStateEdit(options.StateEdit), ) - provider := tfbridge.ProviderInfo{ + provider := info.Provider{ P: shimProvider, Name: providerName, Version: "0.0.1", diff --git a/pkg/pf/internal/check/check_test.go b/pkg/pf/internal/check/check_test.go index b11e24287..a48561e38 100644 --- a/pkg/pf/internal/check/check_test.go +++ b/pkg/pf/internal/check/check_test.go @@ -32,6 +32,7 @@ import ( pfbridge "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/tokens" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" sdkv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" @@ -97,7 +98,7 @@ func TestIsInputProperty(t *testing.T) { func TestMissingIDProperty(t *testing.T) { t.Parallel() - stderr, err := test(t, tfbridge.ProviderInfo{ + stderr, err := test(t, info.Provider{ P: pfbridge.ShimProvider(testProvider{missingID: true}), }) @@ -107,9 +108,9 @@ func TestMissingIDProperty(t *testing.T) { func TestMissingIDWithOverride(t *testing.T) { t.Parallel() - stderr, err := test(t, tfbridge.ProviderInfo{ + stderr, err := test(t, info.Provider{ P: pfbridge.ShimProvider(testProvider{missingID: true}), - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "test_res": {ComputeID: func(context.Context, property.PropertyMap) (property.ID, error) { panic("ComputeID") }}, @@ -122,7 +123,7 @@ func TestMissingIDWithOverride(t *testing.T) { func TestMissingIDUnmapped(t *testing.T) { t.Parallel() - stderr, err := test(t, tfbridge.ProviderInfo{ + stderr, err := test(t, info.Provider{ P: pfbridge.ShimProvider(testProvider{missingID: true}), IgnoreMappings: []string{"test_res"}, }) @@ -133,7 +134,7 @@ func TestMissingIDUnmapped(t *testing.T) { func TestSensitiveID(t *testing.T) { t.Parallel() - stderr, err := test(t, tfbridge.ProviderInfo{ + stderr, err := test(t, info.Provider{ P: pfbridge.ShimProvider(testProvider{sensitiveID: true}), }) @@ -145,10 +146,10 @@ func TestSensitiveID(t *testing.T) { func TestSensitiveIDWithOverride(t *testing.T) { t.Parallel() t.Run("false", func(t *testing.T) { - stderr, err := test(t, tfbridge.ProviderInfo{ + stderr, err := test(t, info.Provider{ P: pfbridge.ShimProvider(testProvider{sensitiveID: true}), - Resources: map[string]*tfbridge.ResourceInfo{ - "test_res": {Fields: map[string]*tfbridge.SchemaInfo{ + Resources: map[string]*info.Resource{ + "test_res": {Fields: map[string]*info.Schema{ "id": {Secret: tfbridge.False()}, }}, }, @@ -157,10 +158,10 @@ func TestSensitiveIDWithOverride(t *testing.T) { assert.NoError(t, err) }) t.Run("true (no-op)", func(t *testing.T) { - stderr, err := test(t, tfbridge.ProviderInfo{ + stderr, err := test(t, info.Provider{ P: pfbridge.ShimProvider(testProvider{sensitiveID: true}), - Resources: map[string]*tfbridge.ResourceInfo{ - "test_res": {Fields: map[string]*tfbridge.SchemaInfo{ + Resources: map[string]*info.Resource{ + "test_res": {Fields: map[string]*info.Schema{ "id": {Secret: tfbridge.True()}, }}, }, @@ -190,7 +191,7 @@ func TestInvalidInputID(t *testing.T) { t.Run(tc.name+" no overrides", func(t *testing.T) { provider := pfbridge.ShimProvider(testProvider{withID: &tc.idSchema}) idSchema := provider.ResourcesMap().Get("test_res").Schema().Get("id") - stderr, err := test(t, tfbridge.ProviderInfo{ + stderr, err := test(t, info.Provider{ P: provider, }) if isInputProperty(idSchema) { @@ -207,10 +208,10 @@ func TestInvalidInputID(t *testing.T) { // "id" is a required output property so if we remap "id" -> "otherId" now we // don't have an "id" output. We must create one by using `ComputeID` t.Run(tc.name+" overrides with Name and missing ComputeID", func(t *testing.T) { - stderr, err := test(t, tfbridge.ProviderInfo{ + stderr, err := test(t, info.Provider{ P: pfbridge.ShimProvider(testProvider{withID: &tc.idSchema}), - Resources: map[string]*tfbridge.ResourceInfo{ - "test_res": {Fields: map[string]*tfbridge.SchemaInfo{ + Resources: map[string]*info.Resource{ + "test_res": {Fields: map[string]*info.Schema{ "id": {Name: "otherId"}, }}, }, @@ -226,10 +227,10 @@ func TestInvalidInputID(t *testing.T) { t.Run(tc.name+" overrides with ComputeID and missing Name", func(t *testing.T) { provider := pfbridge.ShimProvider(testProvider{withID: &tc.idSchema}) idSchema := provider.ResourcesMap().Get("test_res").Schema().Get("id") - stderr, err := test(t, tfbridge.ProviderInfo{ + stderr, err := test(t, info.Provider{ P: provider, - Resources: map[string]*tfbridge.ResourceInfo{ - "test_res": {Fields: map[string]*tfbridge.SchemaInfo{ + Resources: map[string]*info.Resource{ + "test_res": {Fields: map[string]*info.Schema{ "id": {}, }, ComputeID: func(ctx context.Context, state property.PropertyMap) (property.ID, error) { panic("ComputeID") @@ -248,10 +249,10 @@ func TestInvalidInputID(t *testing.T) { }) // While remapping "id" may not make sense for an output property, it is still valid t.Run(tc.name+"no error (with override)", func(t *testing.T) { - stderr, err := test(t, tfbridge.ProviderInfo{ + stderr, err := test(t, info.Provider{ P: pfbridge.ShimProvider(testProvider{withID: &tc.idSchema}), - Resources: map[string]*tfbridge.ResourceInfo{ - "test_res": {Fields: map[string]*tfbridge.SchemaInfo{ + Resources: map[string]*info.Resource{ + "test_res": {Fields: map[string]*info.Schema{ "id": {Name: "otherId"}, }, ComputeID: func(ctx context.Context, state property.PropertyMap) (property.ID, error) { panic("ComputeID") @@ -266,11 +267,11 @@ func TestInvalidInputID(t *testing.T) { func TestMuxedProvider(t *testing.T) { t.Parallel() - stderr, err := test(t, tfbridge.ProviderInfo{ + stderr, err := test(t, info.Provider{ P: pfbridge.MuxShimWithPF(context.Background(), sdkv2.NewProvider(testSDKv2Provider()), testProvider{missingID: true}), - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "test_res": {ComputeID: func(context.Context, property.PropertyMap) (property.ID, error) { panic("ComputeID") }}, @@ -281,16 +282,16 @@ func TestMuxedProvider(t *testing.T) { assert.NoError(t, err) } -func test(t *testing.T, info tfbridge.ProviderInfo) (string, error) { +func test(t *testing.T, providerInfo info.Provider) (string, error) { var stdout, stderr bytes.Buffer sink := diag.DefaultSink(&stdout, &stderr, diag.FormatOptions{ Color: colors.Never, }) - info.MustComputeTokens(tokens.SingleModule(info.GetResourcePrefix(), - "index", tokens.MakeStandard(info.GetResourcePrefix()))) + providerInfo.MustComputeTokens(tokens.SingleModule(providerInfo.GetResourcePrefix(), + "index", tokens.MakeStandard(providerInfo.GetResourcePrefix()))) - err := Provider(sink, info) + err := Provider(sink, providerInfo) // We should not write diags to stdout assert.Empty(t, stdout.String()) diff --git a/pkg/pf/internal/check/checks.go b/pkg/pf/internal/check/checks.go index a456df491..2a8c099d0 100644 --- a/pkg/pf/internal/check/checks.go +++ b/pkg/pf/internal/check/checks.go @@ -22,6 +22,7 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/muxer" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" ) @@ -29,7 +30,7 @@ import ( // // This function should be called in the generate step, but before schema generation (so // as to error as soon as possible). -func Provider(sink diag.Sink, info tfbridge.ProviderInfo) error { +func Provider(sink diag.Sink, info info.Provider) error { // If info.P is not muxed, we assume that all resources are PF based resources and // that all datasources are PF based datasources. isPFResource := func(string) bool { return true } @@ -45,12 +46,12 @@ func Provider(sink diag.Sink, info tfbridge.ProviderInfo) error { ) } -func checkIDProperties(sink diag.Sink, info tfbridge.ProviderInfo, isPFResource func(tfToken string) bool) error { +func checkIDProperties(sink diag.Sink, providerInfo info.Provider, isPFResource func(tfToken string) bool) error { numErrors := 0 - info.P.ResourcesMap().Range(func(rname string, resource shim.Resource) bool { + providerInfo.P.ResourcesMap().Range(func(rname string, resource shim.Resource) bool { // Unmapped resources are not available, so they don't need to be correct. - if v, ok := info.Resources[rname]; !ok || v.Tok == "" { + if v, ok := providerInfo.Resources[rname]; !ok || v.Tok == "" { return true } @@ -59,10 +60,10 @@ func checkIDProperties(sink diag.Sink, info tfbridge.ProviderInfo, isPFResource if !isPFResource(rname) { return true } - if resourceHasComputeID(info, rname) { + if resourceHasComputeID(providerInfo, rname) { return true } - err := resourceHasRegularID(rname, resource, info.Resources[rname]) + err := resourceHasRegularID(rname, resource, providerInfo.Resources[rname]) if err == nil { return true } @@ -71,13 +72,13 @@ func checkIDProperties(sink diag.Sink, info tfbridge.ProviderInfo, isPFResource // added a ComputeID override, then fallback to using MissingID. var missing errMissingIDAttribute if errors.As(err, &missing) { - if info.Resources == nil { - info.Resources = map[string]*tfbridge.ResourceInfo{} + if providerInfo.Resources == nil { + providerInfo.Resources = map[string]*info.Resource{} } - resInfo := info.Resources[rname] + resInfo := providerInfo.Resources[rname] if resInfo == nil { - resInfo = &tfbridge.ResourceInfo{} - info.Resources[rname] = resInfo + resInfo = &info.Resource{} + providerInfo.Resources[rname] = resInfo } if resInfo.ComputeID == nil { resInfo.ComputeID = tfbridge.MissingIDComputeID() @@ -168,36 +169,36 @@ func isInputProperty(schema shim.Schema) bool { return true } -func resourceHasRegularID(rname string, resource shim.Resource, resourceInfo *tfbridge.ResourceInfo) error { +func resourceHasRegularID(rname string, resource shim.Resource, resourceInfo *info.Resource) error { idSchema, gotID := resource.Schema().GetOk("id") if !gotID { return errMissingIDAttribute{} } - var info tfbridge.SchemaInfo + var idSchemaInfo info.Schema if resourceInfo != nil { if id := resourceInfo.Fields["id"]; id != nil { - info = *id + idSchemaInfo = *id } } isInput := isInputProperty(idSchema) - if info.Name != "" && resourceInfo.ComputeID == nil { + if idSchemaInfo.Name != "" && resourceInfo.ComputeID == nil { // if Name is provided then ComputeID must be provided regardless of whether // "id" is an input or a computed property return errMissingComputeID{} } - if isInput && (info.Name == "" || resourceInfo.ComputeID == nil) { + if isInput && (idSchemaInfo.Name == "" || resourceInfo.ComputeID == nil) { return errInvalidRequiredID{} } // If the user over-rode the type to be a string, don't reject. - if idSchema.Type() != shim.TypeString && info.Type != "string" { + if idSchema.Type() != shim.TypeString && idSchemaInfo.Type != "string" { actual := idSchema.Type().String() - if info.Type != "" { - actual = string(info.Type) + if idSchemaInfo.Type != "" { + actual = string(idSchemaInfo.Type) } return errWrongIDType{actualType: actual} } - if idSchema.Sensitive() && (info.Secret == nil || *info.Secret) { + if idSchema.Sensitive() && (idSchemaInfo.Secret == nil || *idSchemaInfo.Secret) { return errSensitiveID{rname} } return nil @@ -205,13 +206,13 @@ func resourceHasRegularID(rname string, resource shim.Resource, resourceInfo *tf // resourceHasComputeID returns true if the resource does not have an "id" field, but // does have a "ComputeID" func -func resourceHasComputeID(info tfbridge.ProviderInfo, resname string) bool { - if info.Resources == nil { +func resourceHasComputeID(providerInfo info.Provider, resname string) bool { + if providerInfo.Resources == nil { return false } - if info, ok := info.Resources[resname]; ok { - if _, ok := info.Fields["id"]; !ok && info.ComputeID != nil { + if resInfo, ok := providerInfo.Resources[resname]; ok { + if _, ok := resInfo.Fields["id"]; !ok && resInfo.ComputeID != nil { return true } } diff --git a/pkg/pf/internal/check/not_supported.go b/pkg/pf/internal/check/not_supported.go index c1a585f49..09f85b816 100644 --- a/pkg/pf/internal/check/not_supported.go +++ b/pkg/pf/internal/check/not_supported.go @@ -23,12 +23,12 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/muxer" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) // Check if the user has customiezed ProviderInfo asking for features that are not yet supported for Plugin Framework // based providers, emit warnings in this case. -func notSupported(sink diag.Sink, prov tfbridge.ProviderInfo, isPFResource, isPFDataSource func(string) bool) error { +func notSupported(sink diag.Sink, prov info.Provider, isPFResource, isPFDataSource func(string) bool) error { if sink == nil { sink = diag.DefaultSink(os.Stdout, os.Stderr, diag.FormatOptions{ Color: colors.Always, @@ -97,23 +97,23 @@ func (u *notSupportedUtil) assertIsZero(path string, shouldBeZero interface{}) { path, shouldBeZero) } -func (u *notSupportedUtil) fields(path string, f map[string]*tfbridge.SchemaInfo) { +func (u *notSupportedUtil) fields(path string, f map[string]*info.Schema) { for k, v := range f { u.schema(path+".Fields."+k, v) } } -func (u *notSupportedUtil) datasource(path string, ds *tfbridge.DataSourceInfo) { +func (u *notSupportedUtil) datasource(path string, ds *info.DataSource) { u.fields(path, ds.Fields) } -func (u *notSupportedUtil) resource(path string, res *tfbridge.ResourceInfo) { +func (u *notSupportedUtil) resource(path string, res *info.Resource) { u.fields(path, res.Fields) u.assertIsZero(path+".UniqueNameFields", res.UniqueNameFields) u.assertIsZero(path+".Docs", res.Docs) } -func (u *notSupportedUtil) schema(path string, schema *tfbridge.SchemaInfo) { +func (u *notSupportedUtil) schema(path string, schema *info.Schema) { if schema.Type != "string" { u.assertIsZero(path+".Type", schema.Type) } diff --git a/pkg/pf/internal/defaults/defaults.go b/pkg/pf/internal/defaults/defaults.go index 628e928ed..e5488a7b8 100644 --- a/pkg/pf/internal/defaults/defaults.go +++ b/pkg/pf/internal/defaults/defaults.go @@ -25,6 +25,7 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" "github.com/pulumi/pulumi-terraform-bridge/v3/unstable/propertyvalue" ) @@ -37,11 +38,11 @@ type ApplyDefaultInfoValuesArgs struct { SchemaMap shim.SchemaMap // Toplevel SchemaInfo configuration matching TopSchemaMap. - SchemaInfos map[string]*tfbridge.SchemaInfo + SchemaInfos map[string]*info.Schema // Note that URN need not be specified for Invoke or Configure processing. Do not set PropertyPath as this // module will set it based on recursive traversal. - ComputeDefaultOptions tfbridge.ComputeDefaultOptions + ComputeDefaultOptions info.ComputeDefaultOptions // Optional. If known, these are the provider-level configuration values, to support DefaultInfo.Config. ProviderConfig resource.PropertyMap @@ -75,9 +76,9 @@ func ApplyDefaultInfoValues(ctx context.Context, args ApplyDefaultInfoValuesArgs func getDefaultValue( ctx context.Context, property resource.PropertyKey, - cdOptions tfbridge.ComputeDefaultOptions, + cdOptions info.ComputeDefaultOptions, fieldSchema shim.Schema, - defaultInfo *tfbridge.DefaultInfo, + defaultInfo *info.Default, providerConfig resource.PropertyMap, ) (resource.PropertyValue, bool) { na := resource.NewNullProperty() @@ -149,7 +150,7 @@ func getDefaultValue( map[string]any{"property": string(property)}) return recoverDefaultValue(raw), true } else if defaultInfo.From != nil { - raw, err := defaultInfo.From(&tfbridge.PulumiResource{ + raw, err := defaultInfo.From(&info.PulumiResource{ URN: cdOptions.URN, Properties: cdOptions.Properties, Seed: cdOptions.Seed, @@ -211,15 +212,15 @@ func recoverDefaultValue(defaultValue any) resource.PropertyValue { type defaultsTransform struct { topSchemaMap shim.SchemaMap - topFieldInfos map[string]*tfbridge.SchemaInfo // optional - computeDefaultOptions tfbridge.ComputeDefaultOptions + topFieldInfos map[string]*info.Schema // optional + computeDefaultOptions info.ComputeDefaultOptions providerConfig resource.PropertyMap // optional } // Returns matching object schema for a context determined by the PropertyPath, if any. func (du *defaultsTransform) lookupSchemaByContext( path resource.PropertyPath, -) (shim.SchemaMap, map[string]*tfbridge.SchemaInfo, bool) { +) (shim.SchemaMap, map[string]*info.Schema, bool) { if len(path) == 0 { return du.topSchemaMap, du.topFieldInfos, true } @@ -229,7 +230,7 @@ func (du *defaultsTransform) lookupSchemaByContext( return nil, nil, false } - schema, info, err := tfbridge.LookupSchemas(schemaPath, du.topSchemaMap, du.topFieldInfos) + schema, schemaInfo, err := tfbridge.LookupSchemas(schemaPath, du.topSchemaMap, du.topFieldInfos) if err != nil { return nil, nil, false } @@ -241,11 +242,11 @@ func (du *defaultsTransform) lookupSchemaByContext( objectSchema := encodedObjectSchema.Schema() - var fields map[string]*tfbridge.SchemaInfo - if info == nil || info.Fields == nil { - fields = map[string]*tfbridge.SchemaInfo{} + var fields map[string]*info.Schema + if schemaInfo == nil || schemaInfo.Fields == nil { + fields = map[string]*info.Schema{} } else { - fields = info.Fields + fields = schemaInfo.Fields } return objectSchema, fields, true diff --git a/pkg/pf/internal/defaults/defaults_test.go b/pkg/pf/internal/defaults/defaults_test.go index b95ce46eb..541943b24 100644 --- a/pkg/pf/internal/defaults/defaults_test.go +++ b/pkg/pf/internal/defaults/defaults_test.go @@ -22,7 +22,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/schema" @@ -53,29 +52,29 @@ func TestApplyDefaultInfoValues(t *testing.T) { type testCase struct { name string env map[string]string - computeDefaultOptions tfbridge.ComputeDefaultOptions + computeDefaultOptions info.ComputeDefaultOptions props resource.PropertyMap expected resource.PropertyMap - fieldInfos map[string]*tfbridge.SchemaInfo + fieldInfos map[string]*info.Schema providerConfig resource.PropertyMap } - testFrom := func(res *tfbridge.PulumiResource) (interface{}, error) { + testFrom := func(res *info.PulumiResource) (interface{}, error) { n := res.URN.Name() + "-" a := []rune("12345") unique, err := resource.NewUniqueName(res.Seed, n, 3, 12, a) return resource.NewStringProperty(unique), err } - testFromAutoname := func(res *tfbridge.PulumiResource) (interface{}, error) { + testFromAutoname := func(res *info.PulumiResource) (interface{}, error) { return resource.NewStringProperty(res.Autonaming.ProposedName), nil } testComputeDefaults := func( t *testing.T, expectPriorValue resource.PropertyValue, - ) func(context.Context, tfbridge.ComputeDefaultOptions) (interface{}, error) { - return func(_ context.Context, opts tfbridge.ComputeDefaultOptions) (interface{}, error) { + ) func(context.Context, info.ComputeDefaultOptions) (interface{}, error) { + return func(_ context.Context, opts info.ComputeDefaultOptions) (interface{}, error) { require.Equal(t, expectPriorValue, opts.PriorValue) n := opts.URN.Name() + "-" a := []rune("12345") @@ -87,9 +86,9 @@ func TestApplyDefaultInfoValues(t *testing.T) { testCases := []testCase{ { name: "simple top-level string", - fieldInfos: map[string]*tfbridge.SchemaInfo{ + fieldInfos: map[string]*info.Schema{ "string_prop": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ Value: "defaultValue", }, }, @@ -100,11 +99,11 @@ func TestApplyDefaultInfoValues(t *testing.T) { }, { name: "nested string", - fieldInfos: map[string]*tfbridge.SchemaInfo{ + fieldInfos: map[string]*info.Schema{ "object_prop": { - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "y_prop": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ Value: "Y", }, }, @@ -125,11 +124,11 @@ func TestApplyDefaultInfoValues(t *testing.T) { }, { name: "nested string does not create object", - fieldInfos: map[string]*tfbridge.SchemaInfo{ + fieldInfos: map[string]*info.Schema{ "object_prop": { - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "y_prop": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ Value: "Y", }, }, @@ -141,9 +140,9 @@ func TestApplyDefaultInfoValues(t *testing.T) { }, { name: "string prop can be set from environment", - fieldInfos: map[string]*tfbridge.SchemaInfo{ + fieldInfos: map[string]*info.Schema{ "string_prop": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ EnvVars: []string{"FOO", "BAR"}, }, }, @@ -157,9 +156,9 @@ func TestApplyDefaultInfoValues(t *testing.T) { }, { name: "int prop can be set from environment", - fieldInfos: map[string]*tfbridge.SchemaInfo{ + fieldInfos: map[string]*info.Schema{ "int_prop": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ EnvVars: []string{"FOO", "BAR"}, }, }, @@ -173,9 +172,9 @@ func TestApplyDefaultInfoValues(t *testing.T) { }, { name: "float prop can be set from environment", - fieldInfos: map[string]*tfbridge.SchemaInfo{ + fieldInfos: map[string]*info.Schema{ "float_prop": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ EnvVars: []string{"FOO", "BAR"}, }, }, @@ -189,9 +188,9 @@ func TestApplyDefaultInfoValues(t *testing.T) { }, { name: "bool prop can be set from environment", - fieldInfos: map[string]*tfbridge.SchemaInfo{ + fieldInfos: map[string]*info.Schema{ "bool_prop": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ EnvVars: []string{"FOO", "BAR"}, }, }, @@ -205,15 +204,15 @@ func TestApplyDefaultInfoValues(t *testing.T) { }, { name: "ComputeDefaults function can compute defaults", - fieldInfos: map[string]*tfbridge.SchemaInfo{ + fieldInfos: map[string]*info.Schema{ "string_prop": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ ComputeDefault: testComputeDefaults(t, resource.NewStringProperty("oldString")), }, }, }, - computeDefaultOptions: tfbridge.ComputeDefaultOptions{ + computeDefaultOptions: info.ComputeDefaultOptions{ URN: "urn:pulumi:test::test::pkgA:index:t1::n1", Properties: resource.PropertyMap{}, Seed: []byte(`123`), @@ -227,14 +226,14 @@ func TestApplyDefaultInfoValues(t *testing.T) { }, { name: "From function can compute defaults", - fieldInfos: map[string]*tfbridge.SchemaInfo{ + fieldInfos: map[string]*info.Schema{ "string_prop": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ From: testFrom, }, }, }, - computeDefaultOptions: tfbridge.ComputeDefaultOptions{ + computeDefaultOptions: info.ComputeDefaultOptions{ URN: "urn:pulumi:test::test::pkgA:index:t1::n1", Properties: resource.PropertyMap{}, Seed: []byte(`123`), @@ -245,14 +244,14 @@ func TestApplyDefaultInfoValues(t *testing.T) { }, { name: "From function can compute defaults with autoname", - fieldInfos: map[string]*tfbridge.SchemaInfo{ + fieldInfos: map[string]*info.Schema{ "string_prop": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ From: testFromAutoname, }, }, }, - computeDefaultOptions: tfbridge.ComputeDefaultOptions{ + computeDefaultOptions: info.ComputeDefaultOptions{ URN: "urn:pulumi:test::test::pkgA:index:t1::n1", Properties: resource.PropertyMap{}, Seed: []byte(`123`), @@ -267,11 +266,11 @@ func TestApplyDefaultInfoValues(t *testing.T) { }, { name: "ComputeDefaults function can compute nested defaults", - fieldInfos: map[string]*tfbridge.SchemaInfo{ + fieldInfos: map[string]*info.Schema{ "object_prop": { - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "y_prop": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ ComputeDefault: testComputeDefaults(t, resource.NewStringProperty("oldY")), }, @@ -284,7 +283,7 @@ func TestApplyDefaultInfoValues(t *testing.T) { "xProp": resource.NewStringProperty("X"), }), }, - computeDefaultOptions: tfbridge.ComputeDefaultOptions{ + computeDefaultOptions: info.ComputeDefaultOptions{ URN: "urn:pulumi:test::test::pkgA:index:t1::n1", Properties: resource.PropertyMap{}, Seed: []byte(`123`), @@ -304,11 +303,11 @@ func TestApplyDefaultInfoValues(t *testing.T) { }, { name: "From function can compute nested defaults", - fieldInfos: map[string]*tfbridge.SchemaInfo{ + fieldInfos: map[string]*info.Schema{ "object_prop": { - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "y_prop": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ From: testFrom, }, }, @@ -320,7 +319,7 @@ func TestApplyDefaultInfoValues(t *testing.T) { "xProp": resource.NewStringProperty("X"), }), }, - computeDefaultOptions: tfbridge.ComputeDefaultOptions{ + computeDefaultOptions: info.ComputeDefaultOptions{ URN: "urn:pulumi:test::test::pkgA:index:t1::n1", Properties: resource.PropertyMap{}, Seed: []byte(`123`), @@ -334,9 +333,9 @@ func TestApplyDefaultInfoValues(t *testing.T) { }, { name: "Defaults can be copied from provider configuration", - fieldInfos: map[string]*tfbridge.SchemaInfo{ + fieldInfos: map[string]*info.Schema{ "string_prop": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ Config: "providerStringProp", }, }, @@ -350,9 +349,9 @@ func TestApplyDefaultInfoValues(t *testing.T) { }, { name: "Empty env var is not a numeric zero", - fieldInfos: map[string]*tfbridge.SchemaInfo{ + fieldInfos: map[string]*info.Schema{ "int_prop": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ EnvVars: []string{"INT_PROP"}, }, }, diff --git a/pkg/pf/internal/muxer/muxer.go b/pkg/pf/internal/muxer/muxer.go index fb237fd34..792a714ec 100644 --- a/pkg/pf/internal/muxer/muxer.go +++ b/pkg/pf/internal/muxer/muxer.go @@ -26,7 +26,7 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/schemashim" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/x/muxer" ) @@ -147,7 +147,7 @@ func newProviderShim(provider shim.Provider) ProviderShim { // // For alias based mappings to work correctly at runtime, it is necessary to call // `ResolveDispatch` before running the provider. -func (m *ProviderShim) ResolveDispatch(info *tfbridge.ProviderInfo) (muxer.DispatchTable, error) { +func (m *ProviderShim) ResolveDispatch(info *info.Provider) (muxer.DispatchTable, error) { var dispatch muxer.DispatchTable dispatch.Resources = map[string]int{} dispatch.Functions = map[string]int{} diff --git a/pkg/pf/internal/providerbuilder/build_provider.go b/pkg/pf/internal/providerbuilder/build_provider.go index a4b423403..7632326d6 100644 --- a/pkg/pf/internal/providerbuilder/build_provider.go +++ b/pkg/pf/internal/providerbuilder/build_provider.go @@ -27,6 +27,7 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge" tfbridge0 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/tokens" ) @@ -85,10 +86,10 @@ func (impl *Provider) GRPCProvider() tfprotov6.ProviderServer { return providerserver.NewProtocol6(impl)() } -func (impl *Provider) ToProviderInfo() tfbridge0.ProviderInfo { +func (impl *Provider) ToProviderInfo() info.Provider { shimProvider := tfbridge.ShimProvider(impl) - provider := tfbridge0.ProviderInfo{ + provider := info.Provider{ P: shimProvider, Name: impl.TypeName, Version: "0.0.1", diff --git a/pkg/pf/tests/autonaming_test.go b/pkg/pf/tests/autonaming_test.go index 5d8118a12..680e640d9 100644 --- a/pkg/pf/tests/autonaming_test.go +++ b/pkg/pf/tests/autonaming_test.go @@ -10,6 +10,7 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/providerbuilder" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/pulcheck" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) func TestPFAutonaming(t *testing.T) { @@ -28,9 +29,9 @@ func TestPFAutonaming(t *testing.T) { }) prov := provBuilder.ToProviderInfo() - prov.Resources["testprovider_test"] = &tfbridge.ResourceInfo{ + prov.Resources["testprovider_test"] = &info.Resource{ Tok: "testprovider:index:Test", - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "name": tfbridge.AutoName("name", 50, "-"), }, } diff --git a/pkg/pf/tests/internal/testprovider/assert_provider.go b/pkg/pf/tests/internal/testprovider/assert_provider.go index f531a5cf8..1d51dfffa 100644 --- a/pkg/pf/tests/internal/testprovider/assert_provider.go +++ b/pkg/pf/tests/internal/testprovider/assert_provider.go @@ -29,10 +29,11 @@ import ( tfpf "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) -func AssertProvider(f AssertFn) tfbridge.ProviderInfo { - info := tfbridge.ProviderInfo{ +func AssertProvider(f AssertFn) info.Provider { + providerInfo := info.Provider{ Name: "assert", P: tfpf.ShimProvider(&assertProvider{f}), Description: "A Pulumi package to test pulumi-terraform-bridge Plugin Framework support.", @@ -43,18 +44,18 @@ func AssertProvider(f AssertFn) tfbridge.ProviderInfo { Version: "0.0.1", UpstreamRepoPath: ".", - Config: map[string]*tfbridge.SchemaInfo{}, + Config: map[string]*info.Schema{}, - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "assert_echo": {Tok: "assert:index/echo:Echo"}, }, MetadataInfo: tfbridge.NewProviderMetadata(testBridgeMetadata), } - info.SetAutonaming(255, "-") + providerInfo.SetAutonaming(255, "-") - return info + return providerInfo } type AssertFn = func(config tfsdk.Config, old *tfsdk.State, new *tfsdk.State) diff --git a/pkg/pf/tests/internal/testprovider/random.go b/pkg/pf/tests/internal/testprovider/random.go index c427ac3fe..4e758a0fa 100644 --- a/pkg/pf/tests/internal/testprovider/random.go +++ b/pkg/pf/tests/internal/testprovider/random.go @@ -30,6 +30,7 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/testprovider/sdkv2randomprovider" tfpf "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" sdkv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) @@ -41,7 +42,7 @@ var muxedRandomProviderBridgeMetadata []byte // Adapts Random provider to tfbridge for testing tfbridge against a // realistic provider. -func RandomProvider() tfbridge.ProviderInfo { +func RandomProvider() info.Provider { randomPkg := "random" randomMod := "index" @@ -80,7 +81,7 @@ func RandomProvider() tfbridge.ProviderInfo { return resource.ID(b.StringValue()), nil } - return tfbridge.ProviderInfo{ + return info.Provider{ Name: "random", P: tfpf.ShimProvider(randomshim.NewProvider()), Description: "A Pulumi package to safely use randomness in Pulumi programs.", @@ -89,7 +90,7 @@ func RandomProvider() tfbridge.ProviderInfo { Homepage: "https://pulumi.io", Repository: "https://github.com/pulumi/pulumi-random", Version: "4.8.2", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "random_id": {Tok: randomResource(randomMod, "RandomId")}, "random_password": {Tok: randomResource(randomMod, "RandomPassword")}, "random_pet": {Tok: randomResource(randomMod, "RandomPet")}, @@ -102,7 +103,7 @@ func RandomProvider() tfbridge.ProviderInfo { ComputeID: computeRandomBytesID, }, }, - JavaScript: &tfbridge.JavaScriptInfo{ + JavaScript: &info.JavaScript{ Dependencies: map[string]string{ "@pulumi/pulumi": "^3.0.0", }, @@ -110,12 +111,12 @@ func RandomProvider() tfbridge.ProviderInfo { "@types/node": "^10.0.0", // so we can access strongly typed node definitions. }, }, - Python: &tfbridge.PythonInfo{ + Python: &info.Python{ Requires: map[string]string{ "pulumi": ">=3.0.0,<4.0.0", }, }, - Golang: &tfbridge.GolangInfo{ + Golang: &info.Golang{ ImportBasePath: filepath.Join( fmt.Sprintf("github.com/pulumi/pulumi-%[1]s/sdk/", randomPkg), tfbridge.GetModuleMajorVersion("0.0.1"), @@ -124,7 +125,7 @@ func RandomProvider() tfbridge.ProviderInfo { ), GenerateResourceContainerTypes: true, }, - CSharp: &tfbridge.CSharpInfo{ + CSharp: &info.CSharp{ PackageReferences: map[string]string{ "Pulumi": "3.*", }, @@ -137,11 +138,11 @@ func RandomProvider() tfbridge.ProviderInfo { } } -func MuxedRandomProvider() tfbridge.ProviderInfo { +func MuxedRandomProvider() info.Provider { return MuxedRandomProviderWithSdkProvider(sdkv2randomprovider.New()) } -func MuxedRandomProviderWithSdkProvider(sdk2provider *sdk2schema.Provider) tfbridge.ProviderInfo { +func MuxedRandomProviderWithSdkProvider(sdk2provider *sdk2schema.Provider) info.Provider { randomPkg := "muxedrandom" randomMod := "index" @@ -164,7 +165,7 @@ func MuxedRandomProviderWithSdkProvider(sdk2provider *sdk2schema.Provider) tfbri pf := RandomProvider() - info := tfbridge.ProviderInfo{ + providerInfo := info.Provider{ Name: "muxedrandom", Description: "A Pulumi package to safely use randomness in Pulumi programs.", Keywords: []string{"pulumi", "random"}, @@ -175,7 +176,7 @@ func MuxedRandomProviderWithSdkProvider(sdk2provider *sdk2schema.Provider) tfbri P: tfpf.MuxShimWithPF(context.Background(), sdkv2.NewProvider(sdk2provider), randomshim.NewProvider()), - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ // "random_human_number": {Tok: randomResource("RandomHumanNumber")}, }, MetadataInfo: tfbridge.NewProviderMetadata(muxedRandomProviderBridgeMetadata), @@ -183,12 +184,12 @@ func MuxedRandomProviderWithSdkProvider(sdk2provider *sdk2schema.Provider) tfbri for tf, r := range pf.Resources { r.Tok = tokens.Type("muxedrandom:" + strings.TrimPrefix(string(r.Tok), "random:")) - info.Resources[tf] = r + providerInfo.Resources[tf] = r } - info.RenameResourceWithAlias("random_human_number", + providerInfo.RenameResourceWithAlias("random_human_number", randomResource("MyNumber"), randomResource("RandomHumanNumber"), "index", "index", nil) - return info + return providerInfo } diff --git a/pkg/pf/tests/internal/testprovider/testbridge.go b/pkg/pf/tests/internal/testprovider/testbridge.go index 037725d1d..cc30c2fea 100644 --- a/pkg/pf/tests/internal/testprovider/testbridge.go +++ b/pkg/pf/tests/internal/testprovider/testbridge.go @@ -30,6 +30,7 @@ import ( tfpf "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) //go:embed cmd/pulumi-resource-testbridge/bridge-metadata.json @@ -37,8 +38,8 @@ var testBridgeMetadata []byte // Synthetic provider is specifically constructed to test various // features of tfbridge and is the core of pulumi-resource-testbridge. -func SyntheticTestBridgeProvider() tfbridge.ProviderInfo { - info := tfbridge.ProviderInfo{ +func SyntheticTestBridgeProvider() info.Provider { + providerInfo := info.Provider{ Name: "testbridge", P: tfpf.ShimProvider(&syntheticProvider{}), Description: "A Pulumi package to test pulumi-terraform-bridge Plugin Framework support.", @@ -49,32 +50,32 @@ func SyntheticTestBridgeProvider() tfbridge.ProviderInfo { Version: "0.0.1", UpstreamRepoPath: ".", // Setting UpstreamRepoPath prevents the "could not find docs" warning. - Config: map[string]*tfbridge.SchemaInfo{ + Config: map[string]*info.Schema{ "string_defaultinfo_config_prop": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ Value: "DEFAULT", }, }, "skip_metadata_api_check": { Type: "boolean", - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ Value: true, }, }, }, - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "testbridge_testres": {Tok: "testbridge:index/testres:Testres"}, "testbridge_testnest": { Tok: "testbridge:index/testnest:Testnest", - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "rules": { - Elem: &tfbridge.SchemaInfo{ - Fields: map[string]*tfbridge.SchemaInfo{ + Elem: &info.Schema{ + Fields: map[string]*info.Schema{ "action_parameters": { MaxItemsOne: tfbridge.True(), - Elem: &tfbridge.SchemaInfo{ - Fields: map[string]*tfbridge.SchemaInfo{ + Elem: &info.Schema{ + Fields: map[string]*info.Schema{ "phases": {MaxItemsOne: tfbridge.True()}, }, }, @@ -92,9 +93,9 @@ func SyntheticTestBridgeProvider() tfbridge.ProviderInfo { "testbridge_test_default_info_res": { Tok: "testbridge:index/testres:TestDefaultInfoRes", - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "str": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ Value: "DEFAULT", }, }, @@ -105,21 +106,21 @@ func SyntheticTestBridgeProvider() tfbridge.ProviderInfo { "testbridge_autoname_res": {Tok: "testbridge:index/testres:AutoNameRes"}, "testbridge_int_id_res": { Tok: "testbridge:index/intID:IntID", - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "id": {Type: "string"}, }, }, "testbridge_vlan_names_res": {Tok: "testbridge:index/testres:VlanNamesRes"}, }, - DataSources: map[string]*tfbridge.DataSourceInfo{ + DataSources: map[string]*info.DataSource{ "testbridge_echo": {Tok: "testbridge:index/echo:Echo"}, "testbridge_test_defaultinfo": { Tok: "testbridge:index/testres:TestDefaultInfoDataSource", - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "input": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ Value: "DEFAULT", }, }, @@ -132,9 +133,9 @@ func SyntheticTestBridgeProvider() tfbridge.ProviderInfo { MetadataInfo: tfbridge.NewProviderMetadata(testBridgeMetadata), } - info.SetAutonaming(255, "-") + providerInfo.SetAutonaming(255, "-") - return info + return providerInfo } type syntheticProvider struct{} diff --git a/pkg/pf/tests/internal/testprovider/tls.go b/pkg/pf/tests/internal/testprovider/tls.go index 21328d5b0..39ad7ae3e 100644 --- a/pkg/pf/tests/internal/testprovider/tls.go +++ b/pkg/pf/tests/internal/testprovider/tls.go @@ -25,13 +25,14 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/tlsshim" tfpf "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) //go:embed cmd/pulumi-resource-tls/bridge-metadata.json var tlsProviderBridgeMetadata []byte // Adapts tls provider to tfbridge for testing tfbridge against another realistic provider. -func TLSProvider() tfbridge.ProviderInfo { +func TLSProvider() info.Provider { tlsPkg := "tls" tlsMod := "index" tlsVersion := "4.0.4" @@ -54,7 +55,7 @@ func TLSProvider() tfbridge.ProviderInfo { return tlsType(mod+"/"+fn, res) } - return tfbridge.ProviderInfo{ + return info.Provider{ Name: "tls", P: tfpf.ShimProvider(tlsshim.NewProvider()), Description: "A Pulumi package to create TLS resources in Pulumi programs.", @@ -62,17 +63,17 @@ func TLSProvider() tfbridge.ProviderInfo { License: "Apache-2.0", Homepage: "https://pulumi.io", Repository: "https://github.com/pulumi/pulumi-tls", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "tls_cert_request": {Tok: tlsResource(tlsMod, "CertRequest")}, "tls_locally_signed_cert": {Tok: tlsResource(tlsMod, "LocallySignedCert")}, "tls_private_key": {Tok: tlsResource(tlsMod, "PrivateKey")}, "tls_self_signed_cert": {Tok: tlsResource(tlsMod, "SelfSignedCert")}, }, - DataSources: map[string]*tfbridge.DataSourceInfo{ + DataSources: map[string]*info.DataSource{ "tls_public_key": {Tok: tlsDataSource(tlsMod, "getPublicKey")}, "tls_certificate": {Tok: tlsDataSource(tlsMod, "getCertificate")}, }, - JavaScript: &tfbridge.JavaScriptInfo{ + JavaScript: &info.JavaScript{ Dependencies: map[string]string{ "@pulumi/pulumi": "^3.0.0", }, @@ -80,12 +81,12 @@ func TLSProvider() tfbridge.ProviderInfo { "@types/node": "^10.0.0", // so we can access strongly typed node definitions. }, }, - Python: &tfbridge.PythonInfo{ + Python: &info.Python{ Requires: map[string]string{ "pulumi": ">=3.0.0,<4.0.0", }, }, - Golang: &tfbridge.GolangInfo{ + Golang: &info.Golang{ ImportBasePath: filepath.Join( fmt.Sprintf("github.com/pulumi/pulumi-%[1]s/sdk/", tlsPkg), tfbridge.GetModuleMajorVersion(tlsVersion), @@ -94,7 +95,7 @@ func TLSProvider() tfbridge.ProviderInfo { ), GenerateResourceContainerTypes: true, }, - CSharp: &tfbridge.CSharpInfo{ + CSharp: &info.CSharp{ PackageReferences: map[string]string{ "Pulumi": "3.*", }, diff --git a/pkg/pf/tests/prestateupgradehook_test.go b/pkg/pf/tests/prestateupgradehook_test.go index 1003734b9..81b2d4ca3 100644 --- a/pkg/pf/tests/prestateupgradehook_test.go +++ b/pkg/pf/tests/prestateupgradehook_test.go @@ -22,13 +22,13 @@ import ( "github.com/stretchr/testify/require" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/testprovider" - tfbridge "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) func TestPreStateUpgradeHook(t *testing.T) { t.Parallel() - info := testprovider.RandomProvider() - info.Resources["random_string"].PreStateUpgradeHook = func(args tfbridge.PreStateUpgradeHookArgs) (int64, resource.PropertyMap, error) { + providerInfo := testprovider.RandomProvider() + providerInfo.Resources["random_string"].PreStateUpgradeHook = func(args info.PreStateUpgradeHookArgs) (int64, resource.PropertyMap, error) { // Assume that if prior state is missing a schema version marker, it really is a corrupt state at version 2. if args.PriorStateSchemaVersion == 0 { return 2, args.PriorState, nil @@ -37,7 +37,7 @@ func TestPreStateUpgradeHook(t *testing.T) { return args.PriorStateSchemaVersion, args.PriorState, nil } - server, err := newProviderServer(t, info) + server, err := newProviderServer(t, providerInfo) require.NoError(t, err) testutils.Replay(t, server, ` { diff --git a/pkg/pf/tests/provider_check_test.go b/pkg/pf/tests/provider_check_test.go index b756f0fa3..73032eb86 100644 --- a/pkg/pf/tests/provider_check_test.go +++ b/pkg/pf/tests/provider_check_test.go @@ -32,6 +32,7 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/testprovider" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge" tfbridge0 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) func TestPFCheck(t *testing.T) { @@ -42,9 +43,9 @@ func TestPFCheck(t *testing.T) { replay string replayMulti string - callback tfbridge0.PreCheckCallback + callback info.PreCheckCallback - customizeResource func(*tfbridge0.ResourceInfo) + customizeResource func(*info.Resource) } testCases := []testCase{ @@ -276,12 +277,12 @@ func TestPFCheck(t *testing.T) { "s": schema.StringAttribute{Optional: true}, }, }, - customizeResource: func(info *tfbridge0.ResourceInfo) { - info.Fields["s"] = &tfbridge0.SchemaInfo{ - Default: &tfbridge0.DefaultInfo{ + customizeResource: func(resourceInfo *info.Resource) { + resourceInfo.Fields["s"] = &info.Schema{ + Default: &info.Default{ ComputeDefault: func( _ context.Context, - opts tfbridge0.ComputeDefaultOptions, + opts info.ComputeDefaultOptions, ) (any, error) { return opts.PriorState["s"].StringValue(), nil }, @@ -309,8 +310,6 @@ func TestPFCheck(t *testing.T) { } for _, tc := range testCases { - tc := tc - t.Run(tc.name, func(t *testing.T) { testProvider := pb.NewProvider(pb.NewProviderArgs{ ProviderSchema: prschema.Schema{ @@ -327,27 +326,27 @@ func TestPFCheck(t *testing.T) { }), }, }) - res := tfbridge0.ResourceInfo{ + res := info.Resource{ Tok: "testprovider:index/res:Res", - Docs: &tfbridge0.DocInfo{ + Docs: &info.Doc{ Markdown: []byte("OK"), }, PreCheckCallback: tc.callback, - Fields: map[string]*tfbridge0.SchemaInfo{}, + Fields: map[string]*info.Schema{}, } if tc.customizeResource != nil { tc.customizeResource(&res) } - info := tfbridge0.ProviderInfo{ + providerInfo := info.Provider{ Name: "testprovider", P: tfbridge.ShimProvider(testProvider), Version: "0.0.1", MetadataInfo: &tfbridge0.MetadataInfo{}, - Resources: map[string]*tfbridge0.ResourceInfo{ + Resources: map[string]*info.Resource{ "testprovider_res": &res, }, } - s, err := newProviderServer(t, info) + s, err := newProviderServer(t, providerInfo) require.NoError(t, err) if tc.replay != "" { testutils.Replay(t, s, tc.replay) diff --git a/pkg/pf/tests/provider_checkconfig_test.go b/pkg/pf/tests/provider_checkconfig_test.go index d8f89b3fe..3a2132919 100644 --- a/pkg/pf/tests/provider_checkconfig_test.go +++ b/pkg/pf/tests/provider_checkconfig_test.go @@ -481,7 +481,7 @@ func TestPFPreConfigureCallback(t *testing.T) { }, } callCounter := 0 - s := makeProviderServer(t, schema, func(info *tfbridge0.ProviderInfo) { + s := makeProviderServer(t, schema, func(info *info.Provider) { info.PreConfigureCallback = func(vars resource.PropertyMap, config shim.ResourceConfig) error { require.Equal(t, "bar", vars["configValue"].StringValue()) require.Truef(t, config.IsSet("configValue"), "configValue should be set") @@ -520,7 +520,7 @@ func TestPFPreConfigureCallback(t *testing.T) { }, } callCounter := 0 - s := makeProviderServer(t, schema, func(info *tfbridge0.ProviderInfo) { + s := makeProviderServer(t, schema, func(info *info.Provider) { info.PreConfigureCallbackWithLogger = func( ctx context.Context, host *hostclient.HostClient, @@ -563,7 +563,7 @@ func TestPFPreConfigureCallback(t *testing.T) { }, }, } - s := makeProviderServer(t, schema, func(info *tfbridge0.ProviderInfo) { + s := makeProviderServer(t, schema, func(info *info.Provider) { info.PreConfigureCallback = func(vars resource.PropertyMap, config shim.ResourceConfig) error { vars["configValue"] = resource.NewStringProperty("updated") return nil @@ -605,7 +605,7 @@ func TestPFPreConfigureCallback(t *testing.T) { }, }, } - s := makeProviderServer(t, schema, func(info *tfbridge0.ProviderInfo) { + s := makeProviderServer(t, schema, func(info *info.Provider) { info.PreConfigureCallbackWithLogger = m }) testutils.Replay(t, s, ` @@ -649,7 +649,7 @@ func TestPFPreConfigureCallback(t *testing.T) { }, }, } - s := makeProviderServer(t, schema, func(info *tfbridge0.ProviderInfo) { + s := makeProviderServer(t, schema, func(info *info.Provider) { info.PreConfigureCallbackWithLogger = m }) testutils.Replay(t, s, ` @@ -682,7 +682,7 @@ func TestPFPreConfigureCallback(t *testing.T) { return errors.New("Err") } schema := schema.Schema{} - s := makeProviderServer(t, schema, func(info *tfbridge0.ProviderInfo) { + s := makeProviderServer(t, schema, func(info *info.Provider) { info.PreConfigureCallbackWithLogger = m }) testutils.Replay(t, s, ` @@ -715,7 +715,7 @@ func TestPFPreConfigureCallback(t *testing.T) { } } schema := schema.Schema{} - s := makeProviderServer(t, schema, func(info *tfbridge0.ProviderInfo) { + s := makeProviderServer(t, schema, func(info *info.Provider) { info.PreConfigureCallbackWithLogger = m }) testutils.Replay(t, s, ` @@ -756,7 +756,7 @@ func TestPFPreConfigureCallback(t *testing.T) { } } schema := schema.Schema{} - s := makeProviderServer(t, schema, func(info *tfbridge0.ProviderInfo) { + s := makeProviderServer(t, schema, func(info *info.Provider) { info.PreConfigureCallbackWithLogger = m }) testutils.Replay(t, s, ` @@ -787,22 +787,22 @@ func TestPFPreConfigureCallback(t *testing.T) { func makeProviderServer( t *testing.T, schema schema.Schema, - customize ...func(*tfbridge0.ProviderInfo), + customize ...func(*info.Provider), ) pulumirpc.ResourceProviderServer { testProvider := pb.NewProvider(pb.NewProviderArgs{ ProviderSchema: schema, }) - info := tfbridge0.ProviderInfo{ + providerInfo := info.Provider{ Name: "testprovider", Version: "0.0.1", MetadataInfo: &tfbridge0.MetadataInfo{}, P: tfbridge.ShimProvider(testProvider), } for _, c := range customize { - c(&info) + c(&providerInfo) } - server, err := newProviderServer(t, info) + server, err := newProviderServer(t, providerInfo) require.NoError(t, err) return server } diff --git a/pkg/pf/tests/provider_configure_test.go b/pkg/pf/tests/provider_configure_test.go index 0b9c2ddd8..595ce0a0c 100644 --- a/pkg/pf/tests/provider_configure_test.go +++ b/pkg/pf/tests/provider_configure_test.go @@ -30,7 +30,6 @@ import ( crosstests "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/cross-tests" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/testprovider" tfpf "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) @@ -551,8 +550,8 @@ func TestPFConfigureErrorReplacement(t *testing.T) { providerInfo := testprovider.SyntheticTestBridgeProvider() providerInfo.P = tfpf.ShimProvider(prov) - providerInfo.Config["config_property"] = &tfbridge.SchemaInfo{Name: "configProperty"} - providerInfo.Config["config"] = &tfbridge.SchemaInfo{Name: "CONFIG!"} + providerInfo.Config["config_property"] = &info.Schema{Name: "configProperty"} + providerInfo.Config["config"] = &info.Schema{Name: "CONFIG!"} server, err := newProviderServer(t, providerInfo) require.NoError(t, err) @@ -580,8 +579,8 @@ func TestPFConfigureErrorReplacement(t *testing.T) { providerInfo := testprovider.SyntheticTestBridgeProvider() providerInfo.P = tfpf.ShimProvider(prov) - providerInfo.Config["config_property"] = &tfbridge.SchemaInfo{Name: "configProperty"} - providerInfo.Config["config"] = &tfbridge.SchemaInfo{Name: "CONFIG!"} + providerInfo.Config["config_property"] = &info.Schema{Name: "configProperty"} + providerInfo.Config["config"] = &info.Schema{Name: "CONFIG!"} server, err := newProviderServer(t, providerInfo) require.NoError(t, err) diff --git a/pkg/pf/tests/provider_get_mapping_test.go b/pkg/pf/tests/provider_get_mapping_test.go index 306dd5767..ccb5013e3 100644 --- a/pkg/pf/tests/provider_get_mapping_test.go +++ b/pkg/pf/tests/provider_get_mapping_test.go @@ -26,13 +26,13 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/testprovider" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge" - tfbridge0 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) func TestPFGetMapping(t *testing.T) { t.Parallel() ctx := context.Background() - info := testprovider.RandomProvider() + providerInfo := testprovider.RandomProvider() var p plugin.Provider @@ -40,9 +40,9 @@ func TestPFGetMapping(t *testing.T) { // This generates the schema on the fly but shells out to go mod download and // generates spurious warnings; for separating into separate sub-test. var err error - gen, err := genMetadata(t, info) + gen, err := genMetadata(t, providerInfo) assert.NoError(t, err) - p, err = tfbridge.NewProvider(ctx, info, gen) + p, err = tfbridge.NewProvider(ctx, providerInfo, gen) assert.NoError(t, err) }) @@ -75,14 +75,14 @@ func TestPFGetMapping(t *testing.T) { assert.Equal(t, "random", m.Provider) - var info tfbridge0.MarshallableProviderInfo - err = json.Unmarshal(m.Data, &info) + var mappingInfo info.MarshallableProvider + err = json.Unmarshal(m.Data, &mappingInfo) assert.NoError(t, err) - assert.Equal(t, "random", info.Name) - assert.Contains(t, info.Resources, "random_integer") + assert.Equal(t, "random", mappingInfo.Name) + assert.Contains(t, mappingInfo.Resources, "random_integer") assert.Equal(t, "random:index/randomInteger:RandomInteger", - string(info.Resources["random_integer"].Tok)) + string(mappingInfo.Resources["random_integer"].Tok)) } } } @@ -91,9 +91,9 @@ func TestMuxedGetMapping(t *testing.T) { t.Parallel() ctx := context.Background() - info := testprovider.MuxedRandomProvider() + providerInfo := testprovider.MuxedRandomProvider() - server, err := tfbridge.MakeMuxedServer(ctx, "muxedrandom", info, genSDKSchema(t, info))(nil) + server, err := tfbridge.MakeMuxedServer(ctx, "muxedrandom", providerInfo, genSDKSchema(t, providerInfo))(nil) require.NoError(t, err) req := func(key, provider string) (context.Context, *pulumirpc.GetMappingRequest) { @@ -125,20 +125,20 @@ func TestMuxedGetMapping(t *testing.T) { assert.Equal(t, "muxedrandom", resp.Provider) - var info tfbridge0.MarshallableProviderInfo - err = json.Unmarshal(resp.Data, &info) + var mappingInfo info.MarshallableProvider + err = json.Unmarshal(resp.Data, &mappingInfo) assert.NoError(t, err) - assert.Equal(t, "muxedrandom", info.Name) - assert.Contains(t, info.Resources, "random_integer") - assert.Contains(t, info.Resources, "random_human_number") + assert.Equal(t, "muxedrandom", mappingInfo.Name) + assert.Contains(t, mappingInfo.Resources, "random_integer") + assert.Contains(t, mappingInfo.Resources, "random_human_number") // A PF based resource assert.Equal(t, "muxedrandom:index/randomInteger:RandomInteger", - string(info.Resources["random_integer"].Tok)) + string(mappingInfo.Resources["random_integer"].Tok)) // An SDK bases resource assert.Equal(t, "muxedrandom:index/randomHumanNumber:RandomHumanNumber", - string(info.Resources["random_human_number"].Tok)) + string(mappingInfo.Resources["random_human_number"].Tok)) } } } diff --git a/pkg/pf/tests/provider_nested_custom_types_test.go b/pkg/pf/tests/provider_nested_custom_types_test.go index eef59e7f5..99e4601d0 100644 --- a/pkg/pf/tests/provider_nested_custom_types_test.go +++ b/pkg/pf/tests/provider_nested_custom_types_test.go @@ -20,6 +20,7 @@ import ( pb "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/providerbuilder" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge" tfbridge0 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) func TestNestedCustomTypeEncoding(t *testing.T) { @@ -51,26 +52,26 @@ func TestNestedCustomTypeEncoding(t *testing.T) { }), }, }) - res := tfbridge0.ResourceInfo{ + res := info.Resource{ Tok: "testprovider:index/bedrockagent:Bedrockagent", - Docs: &tfbridge0.DocInfo{ + Docs: &info.Doc{ Markdown: []byte("OK"), }, - Fields: map[string]*tfbridge0.SchemaInfo{}, + Fields: map[string]*info.Schema{}, } - info := tfbridge0.ProviderInfo{ + providerInfo := info.Provider{ Name: "testprovider", P: tfbridge.ShimProvider(testProvider), Version: "0.0.1", MetadataInfo: &tfbridge0.MetadataInfo{}, - Resources: map[string]*tfbridge0.ResourceInfo{ + Resources: map[string]*info.Resource{ "testprovider_bedrockagent": &res, }, } - encoding := convert.NewEncoding(info.P, &info) - objType := convert.InferObjectType(info.P.ResourcesMap().Get("testprovider_bedrockagent").Schema(), nil) + encoding := convert.NewEncoding(providerInfo.P, &providerInfo) + objType := convert.InferObjectType(providerInfo.P.ResourcesMap().Get("testprovider_bedrockagent").Schema(), nil) _, err := encoding.NewResourceEncoder("testprovider_bedrockagent", objType) assert.NoError(t, err) } diff --git a/pkg/pf/tests/provider_read_test.go b/pkg/pf/tests/provider_read_test.go index c1e16f8a3..0d04e2973 100644 --- a/pkg/pf/tests/provider_read_test.go +++ b/pkg/pf/tests/provider_read_test.go @@ -28,7 +28,6 @@ import ( pb "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/providerbuilder" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/testprovider" tfpf "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) @@ -373,7 +372,7 @@ func TestRefreshResourceNotFound(t *testing.T) { r, }, }) - info := tfbridge.ProviderInfo{ + providerInfo := info.Provider{ Name: "my", P: tfpf.ShimProvider(p), MetadataInfo: &info.Metadata{}, @@ -393,7 +392,7 @@ func TestRefreshResourceNotFound(t *testing.T) { }, }, } - server, err := newProviderServer(t, info) + server, err := newProviderServer(t, providerInfo) require.NoError(t, err) testCase := ` diff --git a/pkg/pf/tests/provider_transform_outputs_test.go b/pkg/pf/tests/provider_transform_outputs_test.go index 9697bac0f..6c671357e 100644 --- a/pkg/pf/tests/provider_transform_outputs_test.go +++ b/pkg/pf/tests/provider_transform_outputs_test.go @@ -27,7 +27,7 @@ import ( "github.com/stretchr/testify/require" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/testprovider" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) func TestPFTransformOutputs(t *testing.T) { @@ -173,7 +173,7 @@ func TestPFTransformFromState(t *testing.T) { var called bool t.Cleanup(func() { assert.True(t, called, "Transform was not called") }) - p.Resources["assert_echo"] = &tfbridge.ResourceInfo{ + p.Resources["assert_echo"] = &info.Resource{ Tok: "assert:index/echo:Echo", TransformFromState: func( ctx context.Context, diff --git a/pkg/pf/tests/pulcheck/pulcheck.go b/pkg/pf/tests/pulcheck/pulcheck.go index 3e1fce24c..032f74beb 100644 --- a/pkg/pf/tests/pulcheck/pulcheck.go +++ b/pkg/pf/tests/pulcheck/pulcheck.go @@ -22,7 +22,6 @@ import ( crosstestsimpl "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/tests/cross-tests/impl" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfgen" - tfbridge0 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) @@ -47,7 +46,7 @@ func testSink(t T) diag.Sink { return testSink } -func genMetadata(t T, info tfbridge0.ProviderInfo) (tfbridge.ProviderMetadata, error) { +func genMetadata(t T, info info.Provider) (tfbridge.ProviderMetadata, error) { generated, err := tfgen.GenerateSchema(context.Background(), tfgen.GenerateSchemaOptions{ ProviderInfo: info, DiagnosticsSink: testSink(t), @@ -59,7 +58,7 @@ func genMetadata(t T, info tfbridge0.ProviderInfo) (tfbridge.ProviderMetadata, e return generated.ProviderMetadata, nil } -func newProviderServer(t T, info tfbridge0.ProviderInfo) (pulumirpc.ResourceProviderServer, error) { +func newProviderServer(t T, info info.Provider) (pulumirpc.ResourceProviderServer, error) { ctx := context.Background() meta, err := genMetadata(t, info) if err != nil { diff --git a/pkg/pf/tests/schema_and_program_test.go b/pkg/pf/tests/schema_and_program_test.go index 730613a46..c57167127 100644 --- a/pkg/pf/tests/schema_and_program_test.go +++ b/pkg/pf/tests/schema_and_program_test.go @@ -267,7 +267,7 @@ func TestIDAttribute(t *testing.T) { }, } - var computeIDField tfbridge.ComputeID + var computeIDField info.ComputeID var idSchema info.Schema if tc.schemaName != "" { idSchema = info.Schema{Name: tc.schemaName} diff --git a/pkg/pf/tests/schema_test.go b/pkg/pf/tests/schema_test.go index 998dfcb24..1ded93429 100644 --- a/pkg/pf/tests/schema_test.go +++ b/pkg/pf/tests/schema_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/testprovider" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen" ) @@ -77,8 +77,8 @@ func TestSchemaGenInSync(t *testing.T) { type testCase struct { name string file string - pf tfbridge.ProviderInfo - provider tfbridge.ProviderInfo + pf info.Provider + provider info.Provider } testCases := []testCase{ @@ -109,7 +109,7 @@ func TestSchemaGenInSync(t *testing.T) { require.NoError(t, err) err = json.Unmarshal(b, &out) require.NoError(t, err) - return + return out } for _, tc := range testCases { diff --git a/pkg/pf/tests/schemas.go b/pkg/pf/tests/schemas.go index 52bcb5cec..50b072aac 100644 --- a/pkg/pf/tests/schemas.go +++ b/pkg/pf/tests/schemas.go @@ -27,11 +27,11 @@ import ( tfpf "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfgen" - tfbridge0 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" tfgen0 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen" ) -func genMetadata(t *testing.T, info tfbridge0.ProviderInfo) (tfpf.ProviderMetadata, error) { +func genMetadata(t *testing.T, info info.Provider) (tfpf.ProviderMetadata, error) { generated, err := tfgen.GenerateSchema(context.Background(), tfgen.GenerateSchemaOptions{ ProviderInfo: info, DiagnosticsSink: testSink(t), @@ -62,7 +62,7 @@ func testSink(t *testing.T) diag.Sink { return testSink } -func genSDKSchema(t *testing.T, info tfbridge0.ProviderInfo) []byte { +func genSDKSchema(t *testing.T, info info.Provider) []byte { pkg, err := tfgen0.GenerateSchema(info, testSink(t)) require.NoError(t, err) bytes, err := json.MarshalIndent(pkg, "", " ") diff --git a/pkg/pf/tests/schemashim_test.go b/pkg/pf/tests/schemashim_test.go index f16bcbf4b..4be58734b 100644 --- a/pkg/pf/tests/schemashim_test.go +++ b/pkg/pf/tests/schemashim_test.go @@ -1118,7 +1118,7 @@ func checkShim(t *testing.T, tc shimTestCase) { rtok := "testprov:index:R1" - info := info.Provider{ + providerInfo := info.Provider{ Name: "testprov", P: shimmedProvider, Resources: map[string]*info.Resource{ @@ -1129,7 +1129,7 @@ func checkShim(t *testing.T, tc shimTestCase) { } nilSink := diag.DefaultSink(io.Discard, io.Discard, diag.FormatOptions{Color: colors.Never}) - pSpec, err := tfgen.GenerateSchema(info, nilSink) + pSpec, err := tfgen.GenerateSchema(providerInfo, nilSink) require.NoError(t, err) type miniSpec struct { diff --git a/pkg/pf/tests/util.go b/pkg/pf/tests/util.go index 5d148c5a0..eebfd2b1f 100644 --- a/pkg/pf/tests/util.go +++ b/pkg/pf/tests/util.go @@ -23,10 +23,10 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/internal/logging" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge" - tfbridge0 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) -func newProviderServer(t *testing.T, info tfbridge0.ProviderInfo) (pulumirpc.ResourceProviderServer, error) { +func newProviderServer(t *testing.T, info info.Provider) (pulumirpc.ResourceProviderServer, error) { ctx := context.Background() meta, err := genMetadata(t, info) if err != nil { @@ -37,7 +37,7 @@ func newProviderServer(t *testing.T, info tfbridge0.ProviderInfo) (pulumirpc.Res return srv, nil } -func newMuxedProviderServer(t *testing.T, info tfbridge0.ProviderInfo) pulumirpc.ResourceProviderServer { +func newMuxedProviderServer(t *testing.T, info info.Provider) pulumirpc.ResourceProviderServer { ctx := context.Background() meta := genSDKSchema(t, info) p, err := tfbridge.MakeMuxedServer(ctx, info.Name, info, meta)(nil) diff --git a/pkg/pf/tfbridge/detect_check_failures.go b/pkg/pf/tfbridge/detect_check_failures.go index 4e4ce39fd..b9a43e1dd 100644 --- a/pkg/pf/tfbridge/detect_check_failures.go +++ b/pkg/pf/tfbridge/detect_check_failures.go @@ -27,6 +27,7 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" ) @@ -35,7 +36,7 @@ func (p *provider) detectCheckFailure( urn resource.URN, isProvider bool, schemaMap shim.SchemaMap, - schemaInfos map[string]*tfbridge.SchemaInfo, + schemaInfos map[string]*info.Schema, diag *tfprotov6.Diagnostic, ) *plugin.CheckFailure { // For anything less critical than Error, refuse to treat it as a CheckFailure. Doing so @@ -73,7 +74,7 @@ func (p *provider) detectCheckFailure( func formatAttributePathAsPropertyPath( schemaMap shim.SchemaMap, - schemaInfos map[string]*tfbridge.SchemaInfo, + schemaInfos map[string]*info.Schema, attrPath *tftypes.AttributePath, ) (ret tfbridge.CheckFailurePath, finalErr error) { steps := attrPath.Steps() diff --git a/pkg/pf/tfbridge/ids.go b/pkg/pf/tfbridge/ids.go index 748793f75..c84dbe4d2 100644 --- a/pkg/pf/tfbridge/ids.go +++ b/pkg/pf/tfbridge/ids.go @@ -21,13 +21,13 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/resource" "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) func extractID( ctx context.Context, resname string, - info *tfbridge.ResourceInfo, + info *info.Resource, state resource.PropertyMap, ) (resource.ID, error) { if info != nil && info.ComputeID != nil { diff --git a/pkg/pf/tfbridge/main.go b/pkg/pf/tfbridge/main.go index f628066dc..fe1929de7 100644 --- a/pkg/pf/tfbridge/main.go +++ b/pkg/pf/tfbridge/main.go @@ -31,6 +31,7 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf" pfmuxer "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/muxer" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/x/muxer" "github.com/pulumi/pulumi-terraform-bridge/v3/unstable/metadata" ) @@ -38,9 +39,9 @@ import ( // Implements main() or a bridged Pulumi plugin, complete with argument parsing. // // info.P must be constructed with ShimProvider or ShimProviderWithContext. -func Main(ctx context.Context, pkg string, prov tfbridge.ProviderInfo, meta ProviderMetadata) { +func Main(ctx context.Context, pkg string, prov info.Provider, meta ProviderMetadata) { handleFlags(ctx, prov.Version, - func() (*tfbridge.MarshallableProviderInfo, error) { + func() (*info.MarshallableProvider, error) { pp, err := newProviderWithContext(ctx, prov, meta) if err != nil { return nil, err @@ -57,7 +58,7 @@ func Main(ctx context.Context, pkg string, prov tfbridge.ProviderInfo, meta Prov func handleFlags( ctx context.Context, version string, - getProviderInfo func() (*tfbridge.MarshallableProviderInfo, error), + getProviderInfo func() (*info.MarshallableProvider, error), ) { // Look for a request to dump the provider info to stdout. flags := flag.NewFlagSet("tf-provider-flags", flag.ContinueOnError) @@ -104,16 +105,16 @@ func handleFlags( // Implements main() or a bridged Pulumi plugin, complete with argument parsing. // // This is an experimental API. -func MainWithMuxer(ctx context.Context, pkg string, info tfbridge.ProviderInfo, schema []byte) { - if len(info.MuxWith) > 0 { - panic("mixin providers via tfbridge.ProviderInfo.MuxWith is currently not supported") +func MainWithMuxer(ctx context.Context, pkg string, providerInfo info.Provider, schema []byte) { + if len(providerInfo.MuxWith) > 0 { + panic("mixin providers via info.Provider.MuxWith is currently not supported") } - handleFlags(ctx, info.Version, func() (*tfbridge.MarshallableProviderInfo, error) { - info := info + handleFlags(ctx, providerInfo.Version, func() (*info.MarshallableProvider, error) { + info := providerInfo return tfbridge.MarshalProviderInfo(&info), nil }) - f := MakeMuxedServer(ctx, pkg, info, schema) + f := MakeMuxedServer(ctx, pkg, providerInfo, schema) err := rprovider.Main(pkg, f) if err != nil { @@ -126,7 +127,7 @@ func MainWithMuxer(ctx context.Context, pkg string, info tfbridge.ProviderInfo, // This function exposes implementation details for testing. It should not be used outside // of pulumi-terraform-bridge. This is an experimental API. func MakeMuxedServer( - ctx context.Context, pkg string, info tfbridge.ProviderInfo, schema []byte, + ctx context.Context, pkg string, info info.Provider, schema []byte, ) func(*rprovider.HostClient) (pulumirpc.ResourceProviderServer, error) { shim, ok := info.P.(*pfmuxer.ProviderShim) contract.Assertf(ok, "MainWithMuxer must have a ProviderInfo.P created with AugmentShimWithPF") diff --git a/pkg/pf/tfbridge/provider.go b/pkg/pf/tfbridge/provider.go index 6ae562ff6..b89892d78 100644 --- a/pkg/pf/tfbridge/provider.go +++ b/pkg/pf/tfbridge/provider.go @@ -45,6 +45,7 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/schemashim" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/providerserver" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/valueshim" ) @@ -80,7 +81,7 @@ func getProviderOptions(opts []providerOption) (providerOptions, error) { // https://www.terraform.io/plugin/framework type provider struct { tfServer tfprotov6.ProviderServer - info tfbridge.ProviderInfo + info info.Provider resources runtypes.Resources datasources runtypes.DataSources pulumiSchema func(context.Context, plugin.GetSchemaRequest) ([]byte, error) @@ -107,7 +108,7 @@ var _ pl.ProviderWithContext = &provider{} // functional binary. // // info.P must be constructed with ShimProvider or ShimProviderWithContext. -func NewProvider(ctx context.Context, info tfbridge.ProviderInfo, meta ProviderMetadata) (plugin.Provider, error) { +func NewProvider(ctx context.Context, info info.Provider, meta ProviderMetadata) (plugin.Provider, error) { pwc, err := newProviderWithContext(ctx, info, meta) if err != nil { return nil, err @@ -125,7 +126,7 @@ func ShimProviderWithContext(ctx context.Context, p pfprovider.Provider) shim.Pr return schemashim.ShimSchemaOnlyProvider(ctx, p) } -func newProviderWithContext(ctx context.Context, info tfbridge.ProviderInfo, +func newProviderWithContext(ctx context.Context, info info.Provider, meta ProviderMetadata, ) (configencoding.Provider[*provider], error) { const infoPErrMSg string = "info.P must be constructed with ShimProvider or ShimProviderWithContext" @@ -212,7 +213,7 @@ func (p *provider) GetConfigEncoding(context.Context) *tfbridge.ConfigEncoding { func NewProviderServer( ctx context.Context, logSink logging.Sink, - info tfbridge.ProviderInfo, + info info.Provider, meta ProviderMetadata, ) (pulumirpc.ResourceProviderServer, error) { p, err := newProviderWithContext(ctx, info, meta) @@ -243,13 +244,13 @@ func (p *provider) Pkg() tokens.Package { type xResetProviderKey struct{} -type xParameterizeResetProviderFunc = func(context.Context, tfbridge.ProviderInfo, ProviderMetadata) error +type xParameterizeResetProviderFunc = func(context.Context, info.Provider, ProviderMetadata) error // XParameterizeResetProvider resets the enclosing PF provider with a new info and meta combination. // // XParameterizeResetProvider is an unstable method and may change in any bridge // release. It is intended only for internal use. -func XParameterizeResetProvider(ctx context.Context, info tfbridge.ProviderInfo, meta ProviderMetadata) error { +func XParameterizeResetProvider(ctx context.Context, info info.Provider, meta ProviderMetadata) error { return ctx.Value(xResetProviderKey{}).(xParameterizeResetProviderFunc)(ctx, info, meta) } @@ -262,7 +263,7 @@ func (p *provider) ParameterizeWithContext( } ctx = context.WithValue(ctx, xResetProviderKey{}, - func(ctx context.Context, info tfbridge.ProviderInfo, meta ProviderMetadata) error { + func(ctx context.Context, info info.Provider, meta ProviderMetadata) error { pp, err := newProviderWithContext(ctx, info, meta) if err != nil { return err diff --git a/pkg/pf/tfbridge/provider_check.go b/pkg/pf/tfbridge/provider_check.go index d6334a9bb..4c2bc7db1 100644 --- a/pkg/pf/tfbridge/provider_check.go +++ b/pkg/pf/tfbridge/provider_check.go @@ -68,7 +68,7 @@ func (p *provider) CheckWithContext( news := defaults.ApplyDefaultInfoValues(ctx, defaults.ApplyDefaultInfoValuesArgs{ SchemaMap: rh.schemaOnlyShimResource.Schema(), SchemaInfos: rh.pulumiResourceInfo.Fields, - ComputeDefaultOptions: tfbridge.ComputeDefaultOptions{ + ComputeDefaultOptions: info.ComputeDefaultOptions{ URN: urn, Properties: checkedInputs, Seed: randomSeed, diff --git a/pkg/pf/tfbridge/provider_configure.go b/pkg/pf/tfbridge/provider_configure.go index 0cdab1aa4..4648dd755 100644 --- a/pkg/pf/tfbridge/provider_configure.go +++ b/pkg/pf/tfbridge/provider_configure.go @@ -24,13 +24,14 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/convert" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" ) // This function iterates over the diagnostics and replaces the names of tf config properties // with their corresponding Pulumi names. func replaceConfigInDiagnostics( - config map[string]*tfbridge.SchemaInfo, + config map[string]*info.Schema, schema shim.SchemaMap, diags []*tfprotov6.Diagnostic, ) []*tfprotov6.Diagnostic { diff --git a/pkg/pf/tfbridge/provider_datasources.go b/pkg/pf/tfbridge/provider_datasources.go index 5dae74dcb..fbbf9aa36 100644 --- a/pkg/pf/tfbridge/provider_datasources.go +++ b/pkg/pf/tfbridge/provider_datasources.go @@ -22,7 +22,7 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/convert" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/runtypes" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" ) @@ -33,7 +33,7 @@ type datasourceHandle struct { encoder convert.Encoder decoder convert.Decoder schemaOnlyShim shim.Resource - pulumiDataSourceInfo *tfbridge.DataSourceInfo // optional + pulumiDataSourceInfo *info.DataSource // optional } func (p *provider) datasourceHandle(ctx context.Context, token tokens.ModuleMember) (datasourceHandle, error) { diff --git a/pkg/pf/tfbridge/provider_diff.go b/pkg/pf/tfbridge/provider_diff.go index a006402de..06edf9fa4 100644 --- a/pkg/pf/tfbridge/provider_diff.go +++ b/pkg/pf/tfbridge/provider_diff.go @@ -25,6 +25,7 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/convert" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" "github.com/pulumi/pulumi-terraform-bridge/v3/unstable/propertyvalue" ) @@ -182,7 +183,7 @@ func calculateDetailedDiff( // For each path x.y.z extracts the next step x and converts it to a matching Pulumi key. Removes // duplicates and orders the result. func topLevelPropertyKeySet( - sch shim.SchemaMap, ps map[string]*tfbridge.SchemaInfo, paths []*tftypes.AttributePath, + sch shim.SchemaMap, ps map[string]*info.Schema, paths []*tftypes.AttributePath, ) []resource.PropertyKey { found := map[resource.PropertyKey]struct{}{} for _, path := range paths { diff --git a/pkg/pf/tfbridge/provider_get_mapping.go b/pkg/pf/tfbridge/provider_get_mapping.go index 9bcc88359..c3eb66f40 100644 --- a/pkg/pf/tfbridge/provider_get_mapping.go +++ b/pkg/pf/tfbridge/provider_get_mapping.go @@ -20,6 +20,7 @@ import ( "fmt" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) func (p *provider) GetMappingWithContext(ctx context.Context, key, provider string) ([]byte, string, error) { @@ -50,7 +51,7 @@ func (p *provider) GetMappingWithContext(ctx context.Context, key, provider stri return []byte{}, "", nil } -func (p *provider) marshalProviderInfo(ctx context.Context) *tfbridge.MarshallableProviderInfo { +func (p *provider) marshalProviderInfo(ctx context.Context) *info.MarshallableProvider { providerInfoCopy := p.info providerInfoCopy.P = p.info.P return tfbridge.MarshalProviderInfo(&providerInfoCopy) diff --git a/pkg/pf/tfbridge/provider_info_test.go b/pkg/pf/tfbridge/provider_info_test.go index e9b9e13ad..d20a0a92c 100644 --- a/pkg/pf/tfbridge/provider_info_test.go +++ b/pkg/pf/tfbridge/provider_info_test.go @@ -17,14 +17,14 @@ package tfbridge import ( "testing" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) func TestSetAutoNamingDoesNotPanic(t *testing.T) { t.Parallel() - prov := tfbridge.ProviderInfo{ + prov := info.Provider{ P: nil, - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "x": {}, }, } diff --git a/pkg/pf/tfbridge/provider_resources.go b/pkg/pf/tfbridge/provider_resources.go index a3a7d8c60..3b923e580 100644 --- a/pkg/pf/tfbridge/provider_resources.go +++ b/pkg/pf/tfbridge/provider_resources.go @@ -24,7 +24,7 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/convert" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/runtypes" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" ) @@ -32,7 +32,7 @@ type resourceHandle struct { token tokens.Type terraformResourceName string schema runtypes.Schema - pulumiResourceInfo *tfbridge.ResourceInfo // optional + pulumiResourceInfo *info.Resource // optional encoder convert.Encoder decoder convert.Decoder schemaOnlyShimResource shim.Resource diff --git a/pkg/pf/tfbridge/provider_test.go b/pkg/pf/tfbridge/provider_test.go index ff08edcc5..2d38232a9 100644 --- a/pkg/pf/tfbridge/provider_test.go +++ b/pkg/pf/tfbridge/provider_test.go @@ -20,15 +20,15 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/resource" "github.com/stretchr/testify/assert" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) func TestTerraformResourceName(t *testing.T) { t.Parallel() urn := resource.URN("urn:pulumi:dev::stack1::random:index/randomInteger:RandomInteger::priority") p := &provider{ - info: tfbridge.ProviderInfo{ - Resources: map[string]*tfbridge.ResourceInfo{ + info: info.Provider{ + Resources: map[string]*info.Resource{ "random_integer": {Tok: "random:index/randomInteger:RandomInteger"}, }, }, diff --git a/pkg/pf/tfbridge/resource_state.go b/pkg/pf/tfbridge/resource_state.go index 3cb45fedb..e57575a52 100644 --- a/pkg/pf/tfbridge/resource_state.go +++ b/pkg/pf/tfbridge/resource_state.go @@ -31,6 +31,7 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/convert" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/reservedkeys" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/valueshim" ) @@ -210,7 +211,7 @@ func (p *provider) parseAndUpgradeResourceState( var err error // Possibly modify stateVersion. - stateVersion, props, err = rh.pulumiResourceInfo.PreStateUpgradeHook(tfbridge.PreStateUpgradeHookArgs{ + stateVersion, props, err = rh.pulumiResourceInfo.PreStateUpgradeHook(info.PreStateUpgradeHookArgs{ ResourceSchemaVersion: rh.schema.ResourceSchemaVersion(), PriorState: props.Copy(), PriorStateSchemaVersion: parsedMeta.SchemaVersion, diff --git a/pkg/pf/tfbridge/serve.go b/pkg/pf/tfbridge/serve.go index d9c888e7b..0f0bcceaa 100644 --- a/pkg/pf/tfbridge/serve.go +++ b/pkg/pf/tfbridge/serve.go @@ -20,10 +20,10 @@ import ( rprovider "github.com/pulumi/pulumi/pkg/v3/resource/provider" pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) -func serve(ctx context.Context, pkg string, prov tfbridge.ProviderInfo, meta ProviderMetadata) error { +func serve(ctx context.Context, pkg string, prov info.Provider, meta ProviderMetadata) error { return rprovider.Main(pkg, func(host *rprovider.HostClient) (pulumirpc.ResourceProviderServer, error) { return NewProviderServer(ctx, host, prov, meta) }) diff --git a/pkg/pf/tfgen/gen.go b/pkg/pf/tfgen/gen.go index 5e327398f..abb0003c7 100644 --- a/pkg/pf/tfgen/gen.go +++ b/pkg/pf/tfgen/gen.go @@ -25,12 +25,12 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/check" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge" - sdkbridge "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" realtfgen "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen" ) type GenerateSchemaOptions struct { - ProviderInfo sdkbridge.ProviderInfo + ProviderInfo info.Provider DiagnosticsSink diag.Sink XInMemoryDocs bool } diff --git a/pkg/pf/tfgen/main.go b/pkg/pf/tfgen/main.go index 0f82f51aa..a82c4015b 100644 --- a/pkg/pf/tfgen/main.go +++ b/pkg/pf/tfgen/main.go @@ -22,7 +22,7 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/check" pfmuxer "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/muxer" - sdkBridge "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen" "github.com/pulumi/pulumi-terraform-bridge/v3/unstable/metadata" ) @@ -37,7 +37,7 @@ import ( // info.P must be constructed with ShimProvider or ShimProviderWithContext. // // [Pulumi Package Schema]: https://www.pulumi.com/docs/guides/pulumi-packages/schema/ -func Main(provider string, info sdkBridge.ProviderInfo) { +func Main(provider string, info info.Provider) { version := info.Version tfgen.MainWithCustomGenerate(provider, version, info, func(opts tfgen.GeneratorOptions) error { @@ -69,9 +69,9 @@ func Main(provider string, info sdkBridge.ProviderInfo) { // This is an experimental API. // // [Pulumi Package Schema]: https://www.pulumi.com/docs/guides/pulumi-packages/schema/ -func MainWithMuxer(provider string, info sdkBridge.ProviderInfo) { +func MainWithMuxer(provider string, info info.Provider) { if len(info.MuxWith) > 0 { - panic("mixin providers via tfbridge.ProviderInfo.MuxWith is currently not supported") + panic("mixin providers via info.Provider.MuxWith is currently not supported") } shim, ok := info.P.(*pfmuxer.ProviderShim) diff --git a/pkg/pf/tfgen/tfgen_test.go b/pkg/pf/tfgen/tfgen_test.go index b0c89627d..bb2145aa7 100644 --- a/pkg/pf/tfgen/tfgen_test.go +++ b/pkg/pf/tfgen/tfgen_test.go @@ -36,6 +36,7 @@ import ( pftfbridge "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) // Regressing an issue with AWS provider not recognizing that assume_role config setting is singular via @@ -61,7 +62,7 @@ func TestMaxItemsOne(t *testing.T) { }, } res, err := GenerateSchema(ctx, GenerateSchemaOptions{ - ProviderInfo: tfbridge.ProviderInfo{ + ProviderInfo: info.Provider{ Name: "testprovider", P: pftfbridge.ShimProvider(&schemaTestProvider{schema: s}), }, @@ -153,7 +154,7 @@ func TestTypeOverride(t *testing.T) { tests := []struct { name string schema rschema.Schema - info *tfbridge.ResourceInfo + info *info.Resource expectedError autogold.Value }{ { @@ -183,9 +184,9 @@ func TestTypeOverride(t *testing.T) { }, }, }, - info: &tfbridge.ResourceInfo{Fields: map[string]*tfbridge.SchemaInfo{ - "a1": {Elem: &tfbridge.SchemaInfo{ - Fields: map[string]*tfbridge.SchemaInfo{ + info: &info.Resource{Fields: map[string]*info.Schema{ + "a1": {Elem: &info.Schema{ + Fields: map[string]*info.Schema{ "n1": {Type: "number"}, }, }}, @@ -204,8 +205,8 @@ func TestTypeOverride(t *testing.T) { }, }, }, - info: &tfbridge.ResourceInfo{Fields: map[string]*tfbridge.SchemaInfo{ - "a1": {Elem: &tfbridge.SchemaInfo{ + info: &info.Resource{Fields: map[string]*info.Schema{ + "a1": {Elem: &info.Schema{ Type: "testprovider:index:SomeOtherType", }}, }}, @@ -223,12 +224,12 @@ func TestTypeOverride(t *testing.T) { }, }, }, - info: &tfbridge.ResourceInfo{Fields: map[string]*tfbridge.SchemaInfo{ + info: &info.Resource{Fields: map[string]*info.Schema{ "a1": { MaxItemsOne: tfbridge.True(), - Elem: &tfbridge.SchemaInfo{ - Elem: &tfbridge.SchemaInfo{ - Fields: map[string]*tfbridge.SchemaInfo{ + Elem: &info.Schema{ + Elem: &info.Schema{ + Fields: map[string]*info.Schema{ "n1": {Name: "foo"}, }, }, @@ -248,8 +249,8 @@ func TestTypeOverride(t *testing.T) { }, }, }, - info: &tfbridge.ResourceInfo{Fields: map[string]*tfbridge.SchemaInfo{ - "a1": {Fields: map[string]*tfbridge.SchemaInfo{ + info: &info.Resource{Fields: map[string]*info.Schema{ + "a1": {Fields: map[string]*info.Schema{ "invalid": {}, }}, }}, @@ -265,9 +266,9 @@ func TestTypeOverride(t *testing.T) { }, }, }, - info: &tfbridge.ResourceInfo{ - Fields: map[string]*tfbridge.SchemaInfo{ - "a1": {Elem: &tfbridge.SchemaInfo{ + info: &info.Resource{ + Fields: map[string]*info.Schema{ + "a1": {Elem: &info.Schema{ Type: "number", }}, }, @@ -287,11 +288,11 @@ func TestTypeOverride(t *testing.T) { }, }, }, - info: &tfbridge.ResourceInfo{ - Fields: map[string]*tfbridge.SchemaInfo{ - "a1": {Elem: &tfbridge.SchemaInfo{ - Elem: &tfbridge.SchemaInfo{ - Fields: map[string]*tfbridge.SchemaInfo{ + info: &info.Resource{ + Fields: map[string]*info.Schema{ + "a1": {Elem: &info.Schema{ + Elem: &info.Schema{ + Fields: map[string]*info.Schema{ "n1": {Type: "number"}, }, }, @@ -309,9 +310,9 @@ func TestTypeOverride(t *testing.T) { }, }, }, - info: &tfbridge.ResourceInfo{ - Fields: map[string]*tfbridge.SchemaInfo{ - "a1": {Fields: map[string]*tfbridge.SchemaInfo{ + info: &info.Resource{ + Fields: map[string]*info.Schema{ + "a1": {Fields: map[string]*info.Schema{ "invalid": {}, }}, }, @@ -328,8 +329,8 @@ func TestTypeOverride(t *testing.T) { }, }, }, - info: &tfbridge.ResourceInfo{ - Fields: map[string]*tfbridge.SchemaInfo{ + info: &info.Resource{ + Fields: map[string]*info.Schema{ "a1": {MaxItemsOne: tfbridge.True()}, }, }, @@ -345,9 +346,9 @@ func TestTypeOverride(t *testing.T) { }, }, }, - info: &tfbridge.ResourceInfo{ - Fields: map[string]*tfbridge.SchemaInfo{ - "a1": {Elem: &tfbridge.SchemaInfo{ + info: &info.Resource{ + Fields: map[string]*info.Schema{ + "a1": {Elem: &info.Schema{ Type: "number", }}, }, @@ -363,9 +364,9 @@ func TestTypeOverride(t *testing.T) { }, }, }, - info: &tfbridge.ResourceInfo{ - Fields: map[string]*tfbridge.SchemaInfo{ - "a1": {Fields: map[string]*tfbridge.SchemaInfo{ + info: &info.Resource{ + Fields: map[string]*info.Schema{ + "a1": {Fields: map[string]*info.Schema{ "invalid": {}, }}, }, @@ -382,9 +383,9 @@ func TestTypeOverride(t *testing.T) { }, }, }, - info: &tfbridge.ResourceInfo{ - Fields: map[string]*tfbridge.SchemaInfo{ - "a1": {Elem: &tfbridge.SchemaInfo{ + info: &info.Resource{ + Fields: map[string]*info.Schema{ + "a1": {Elem: &info.Schema{ Type: "number", }}, }, @@ -400,8 +401,8 @@ func TestTypeOverride(t *testing.T) { }, }, }, - info: &tfbridge.ResourceInfo{ - Fields: map[string]*tfbridge.SchemaInfo{ + info: &info.Resource{ + Fields: map[string]*info.Schema{ "a1": {MaxItemsOne: tfbridge.True()}, }, }, @@ -416,9 +417,9 @@ func TestTypeOverride(t *testing.T) { }, }, }, - info: &tfbridge.ResourceInfo{ - Fields: map[string]*tfbridge.SchemaInfo{ - "a1": {Fields: map[string]*tfbridge.SchemaInfo{ + info: &info.Resource{ + Fields: map[string]*info.Schema{ + "a1": {Fields: map[string]*info.Schema{ "invalid": {}, }}, }, @@ -433,15 +434,15 @@ func TestTypeOverride(t *testing.T) { t.Parallel() ctx := context.Background() if tt.info == nil { - tt.info = &tfbridge.ResourceInfo{} + tt.info = &info.Resource{} } tt.info.Tok = "testprovider:index:Res" - tt.info.Docs = &tfbridge.DocInfo{Markdown: []byte{' '}} + tt.info.Docs = &info.Doc{Markdown: []byte{' '}} if _, ok := tt.schema.Attributes["id"]; !ok { tt.schema.Attributes["id"] = rschema.StringAttribute{Computed: true} } res, err := GenerateSchema(ctx, GenerateSchemaOptions{ - ProviderInfo: tfbridge.ProviderInfo{ + ProviderInfo: info.Provider{ Name: "testprovider", UpstreamRepoPath: ".", // no invalid mappings warnings P: pftfbridge.ShimProvider(&schemaTestProvider{ @@ -449,7 +450,7 @@ func TestTypeOverride(t *testing.T) { "res": tt.schema, }, }), - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "test_res": tt.info, }, // Trim the schema for easier comparison @@ -488,9 +489,9 @@ func TestWriteOnlyOmit(t *testing.T) { }, } - info := &tfbridge.ResourceInfo{ + resourceInfo := &info.Resource{ Tok: "testprovider:index:Res", - Docs: &tfbridge.DocInfo{Markdown: []byte{' '}}, + Docs: &info.Doc{Markdown: []byte{' '}}, } if _, ok := schema.Attributes["id"]; !ok { @@ -498,7 +499,7 @@ func TestWriteOnlyOmit(t *testing.T) { } res, err := GenerateSchema(context.Background(), GenerateSchemaOptions{ - ProviderInfo: tfbridge.ProviderInfo{ + ProviderInfo: info.Provider{ Name: "testprovider", UpstreamRepoPath: ".", // no invalid mappings warnings P: pftfbridge.ShimProvider(&schemaTestProvider{ @@ -506,8 +507,8 @@ func TestWriteOnlyOmit(t *testing.T) { "res": schema, }, }), - Resources: map[string]*tfbridge.ResourceInfo{ - "test_res": info, + Resources: map[string]*info.Resource{ + "test_res": resourceInfo, }, // Trim the schema for easier comparison SchemaPostProcessor: func(p *puschema.PackageSpec) { @@ -542,13 +543,13 @@ func TestPFRequiredInputWithDefault(t *testing.T) { }, } - info := &tfbridge.ResourceInfo{ + resourceInfo := &info.Resource{ Tok: "testprovider:index:Res", - Docs: &tfbridge.DocInfo{Markdown: []byte{' '}}, + Docs: &info.Doc{Markdown: []byte{' '}}, } res, err := GenerateSchema(context.Background(), GenerateSchemaOptions{ - ProviderInfo: tfbridge.ProviderInfo{ + ProviderInfo: info.Provider{ Name: "testprovider", UpstreamRepoPath: ".", // no invalid mappings warnings P: pftfbridge.ShimProvider(&schemaTestProvider{ @@ -556,8 +557,8 @@ func TestPFRequiredInputWithDefault(t *testing.T) { "res": schema, }, }), - Resources: map[string]*tfbridge.ResourceInfo{ - "test_res": info, + Resources: map[string]*info.Resource{ + "test_res": resourceInfo, }, }, }) diff --git a/pkg/tests/autonaming_test.go b/pkg/tests/autonaming_test.go index 380cb32fa..5ff4d4412 100644 --- a/pkg/tests/autonaming_test.go +++ b/pkg/tests/autonaming_test.go @@ -9,6 +9,7 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/tests/pulcheck" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) func TestSDKv2Autonaming(t *testing.T) { @@ -25,9 +26,9 @@ func TestSDKv2Autonaming(t *testing.T) { } tfp := &schema.Provider{ResourcesMap: resMap} bridgedProvider := pulcheck.BridgedProvider(t, "prov", tfp) - bridgedProvider.Resources["prov_test"] = &tfbridge.ResourceInfo{ + bridgedProvider.Resources["prov_test"] = &info.Resource{ Tok: "prov:index:Test", - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "name": tfbridge.AutoName("name", 50, "-"), }, } diff --git a/pkg/tests/invoke_raw_config_test.go b/pkg/tests/invoke_raw_config_test.go index 7f9504c28..358947342 100644 --- a/pkg/tests/invoke_raw_config_test.go +++ b/pkg/tests/invoke_raw_config_test.go @@ -23,6 +23,7 @@ import ( testutils "github.com/pulumi/providertest/replay" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) @@ -57,21 +58,21 @@ func TestInvokeRawConfigDoesNotPanic(t *testing.T) { p := shimv2.NewProvider(tfProvider) - info := tfbridge.ProviderInfo{ + providerInfo := info.Provider{ P: p, Name: "aws", - DataSources: map[string]*tfbridge.DataSourceInfo{ + DataSources: map[string]*info.DataSource{ "aws_rds_engine_version": {Tok: "aws:rds/getEngineVersion:getEngineVersion"}, }, } server := tfbridge.NewProvider(ctx, - nil, /* hostClient */ - "aws", /* module */ - "", /* version */ - p, /* tf */ - info, /* info */ - []byte{}, /* pulumiSchema */ + nil, /* hostClient */ + "aws", /* module */ + "", /* version */ + p, /* tf */ + providerInfo, /* info */ + []byte{}, /* pulumiSchema */ ) testCase := ` diff --git a/pkg/tests/mux_with_test.go b/pkg/tests/mux_with_test.go index 52abb533f..3648e0147 100644 --- a/pkg/tests/mux_with_test.go +++ b/pkg/tests/mux_with_test.go @@ -34,6 +34,7 @@ import ( "google.golang.org/protobuf/types/known/structpb" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen" shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) @@ -47,10 +48,10 @@ func newTFProvider() *schema.Provider { } err = rd.Set("value", v.(int)*10) if err != nil { - return + return err } rd.SetId("1") - return + return err }, Schema: map[string]*schema.Schema{ "seed": { @@ -69,10 +70,10 @@ func newTFProvider() *schema.Provider { Read: func(rd *schema.ResourceData, i interface{}) (err error) { err = rd.Set("number", 10) if err != nil { - return + return err } rd.SetId("1") - return + return err }, Schema: map[string]*schema.Schema{ "number": { @@ -93,7 +94,7 @@ func newTFProvider() *schema.Provider { } } -func newProviderServer(info tfbridge.ProviderInfo) (server pulumirpc.ResourceProviderServer, err error) { +func newProviderServer(info info.Provider) (server pulumirpc.ResourceProviderServer, err error) { ctx := context.Background() schema, err := tfgen.GenerateSchema(info, diag.DefaultSink(io.Discard, io.Discard, diag.FormatOptions{ Color: colors.Never, @@ -113,12 +114,12 @@ func newProviderServer(info tfbridge.ProviderInfo) (server pulumirpc.ResourcePro info, /* info */ data, /* pulumiSchema */ ) - return + return server, err } func TestMuxWithProvider(t *testing.T) { t.Parallel() - info := tfbridge.ProviderInfo{ + providerInfo := info.Provider{ P: shimv2.NewProvider(newTFProvider()), Name: "random", Keywords: []string{"pulumi", "random"}, @@ -126,19 +127,19 @@ func TestMuxWithProvider(t *testing.T) { Homepage: "https://pulumi.io", Repository: "https://github.com/pulumi/pulumi-random", Version: "0.0.3", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "random_number": { Tok: "random:index/randomNumber:RandomNumber", }, }, - DataSources: map[string]*tfbridge.DataSourceInfo{ + DataSources: map[string]*info.DataSource{ "random_number": { Tok: "random:index/getRandomNumber:getRandomNumber", }, }, } - server, err := newProviderServer(info) + server, err := newProviderServer(providerInfo) assert.NoError(t, err) grpcTestCases := []string{ @@ -182,12 +183,12 @@ func TestMuxWithProvider(t *testing.T) { testutils.Replay(t, server, grpcTestCases[i]) } - info.MetadataInfo = tfbridge.NewProviderMetadata(nil) - info.MuxWith = []tfbridge.MuxProvider{ + providerInfo.MetadataInfo = tfbridge.NewProviderMetadata(nil) + providerInfo.MuxWith = []tfbridge.MuxProvider{ newMuxProvider(), } - server, err = newProviderServer(info) + server, err = newProviderServer(providerInfo) assert.NoError(t, err) grpcMuxTestCases := []string{ @@ -289,5 +290,5 @@ func (p *tfMuxProvider) Invoke(ctx context.Context, req *pulumirpc.InvokeRequest return nil, fmt.Errorf("tfMuxProvider::Invoke: %q not supported", req.Tok) } res = &pulumirpc.InvokeResponse{Return: result} - return + return res, err } diff --git a/pkg/tests/regress_1020_test.go b/pkg/tests/regress_1020_test.go index ed5ce44d0..26237bec8 100644 --- a/pkg/tests/regress_1020_test.go +++ b/pkg/tests/regress_1020_test.go @@ -24,6 +24,7 @@ import ( pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) @@ -142,7 +143,7 @@ func TestRegress1020(t *testing.T) { } server := func(p shim.Provider) pulumirpc.ResourceProviderServer { - info := tfbridge.ProviderInfo{ + providerInfo := info.Provider{ P: p, Name: "aws", Description: "A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.", @@ -151,17 +152,17 @@ func TestRegress1020(t *testing.T) { Homepage: "https://pulumi.io", Repository: "https://github.com/pulumi/pulumi-aws", Version: "0.0.2", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "aws_wafv2_ip_set": {Tok: "aws:wafv2/ipSet:IpSet"}, }, } return tfbridge.NewProvider(ctx, - nil, /* hostClient */ - "aws", /* module */ - "", /* version */ - p, /* tf */ - info, /* info */ - []byte{}, /* pulumiSchema */ + nil, /* hostClient */ + "aws", /* module */ + "", /* version */ + p, /* tf */ + providerInfo, /* info */ + []byte{}, /* pulumiSchema */ ) } diff --git a/pkg/tests/regress_923_test.go b/pkg/tests/regress_923_test.go index 4365106b5..e69840743 100644 --- a/pkg/tests/regress_923_test.go +++ b/pkg/tests/regress_923_test.go @@ -24,6 +24,7 @@ import ( testutils "github.com/pulumi/providertest/replay" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) @@ -86,7 +87,7 @@ func TestRegress923(t *testing.T) { p := shimv2.NewProvider(tfProvider) - info := tfbridge.ProviderInfo{ + providerInfo := info.Provider{ P: p, Name: "azure", Keywords: []string{"pulumi", "azure"}, @@ -94,18 +95,18 @@ func TestRegress923(t *testing.T) { Homepage: "https://pulumi.io", Repository: "https://github.com/pulumi/pulumi-azure", Version: "0.0.2", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "az_webhook": {Tok: "azure:containerservice/registryWebhook:RegistryWebhook"}, }, } server := tfbridge.NewProvider(ctx, - nil, /* hostClient */ - "azure", /* module */ - "", /* version */ - p, /* tf */ - info, /* info */ - []byte{}, /* pulumiSchema */ + nil, /* hostClient */ + "azure", /* module */ + "", /* version */ + p, /* tf */ + providerInfo, /* info */ + []byte{}, /* pulumiSchema */ ) testCase := ` diff --git a/pkg/tests/regress_aws_1423_test.go b/pkg/tests/regress_aws_1423_test.go index 717f81653..d2cb2ca60 100644 --- a/pkg/tests/regress_aws_1423_test.go +++ b/pkg/tests/regress_aws_1423_test.go @@ -23,6 +23,7 @@ import ( webaclschema "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tests/internal/webaclschema" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) @@ -41,7 +42,7 @@ func TestRegressAws1423(t *testing.T) { p := shimv2.NewProvider(tfProvider) - info := tfbridge.ProviderInfo{ + providerInfo := info.Provider{ P: p, Name: "aws", Description: "A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.", @@ -50,18 +51,18 @@ func TestRegressAws1423(t *testing.T) { Homepage: "https://pulumi.io", Repository: "https://github.com/phillipedwards/pulumi-aws", Version: "0.0.2", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "aws_wafv2_web_acl": {Tok: "aws:wafv2/webAcl:WebAcl"}, }, } server := tfbridge.NewProvider(ctx, - nil, /* hostClient */ - "aws", /* module */ - "", /* version */ - p, /* tf */ - info, /* info */ - []byte{}, /* pulumiSchema */ + nil, /* hostClient */ + "aws", /* module */ + "", /* version */ + p, /* tf */ + providerInfo, /* info */ + []byte{}, /* pulumiSchema */ ) testCase1 := ` diff --git a/pkg/tests/regress_aws_2352_test.go b/pkg/tests/regress_aws_2352_test.go index b8f294ee9..c4f4422a4 100644 --- a/pkg/tests/regress_aws_2352_test.go +++ b/pkg/tests/regress_aws_2352_test.go @@ -25,6 +25,7 @@ import ( testutils "github.com/pulumi/providertest/replay" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) @@ -118,7 +119,7 @@ func TestRegressAws2352(t *testing.T) { p := shimv2.NewProvider(tfProvider) - info := tfbridge.ProviderInfo{ + providerInfo := info.Provider{ P: p, Name: "aws", Description: "A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.", @@ -127,18 +128,18 @@ func TestRegressAws2352(t *testing.T) { Homepage: "https://pulumi.io", Repository: "https://github.com/phillipedwards/pulumi-aws", Version: "0.0.2", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "aws_route53_resolver_endpoint": {Tok: "aws:route53/resolverEndpoint:ResolverEndpoint"}, }, } server := tfbridge.NewProvider(ctx, - nil, /* hostClient */ - "aws", /* module */ - "", /* version */ - p, /* tf */ - info, /* info */ - []byte{}, /* pulumiSchema */ + nil, /* hostClient */ + "aws", /* module */ + "", /* version */ + p, /* tf */ + providerInfo, /* info */ + []byte{}, /* pulumiSchema */ ) testCase := ` diff --git a/pkg/tests/regress_hcloud_175_test.go b/pkg/tests/regress_hcloud_175_test.go index 766ec8842..be6749e6d 100644 --- a/pkg/tests/regress_hcloud_175_test.go +++ b/pkg/tests/regress_hcloud_175_test.go @@ -22,6 +22,7 @@ import ( testutils "github.com/pulumi/providertest/replay" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) @@ -77,25 +78,25 @@ func TestRegressHCloud175(t *testing.T) { p := shimv2.NewProvider(tfProvider) - info := tfbridge.ProviderInfo{ + providerInfo := info.Provider{ P: p, Name: "hcloud", Description: "etc", Keywords: []string{"pulumi", "hcloud"}, License: "Apache-2.0", Version: "0.0.1", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "hcloud_subnet": {Tok: "hcloud:index/networkSubnet:NetworkSubnet"}, }, } server := tfbridge.NewProvider(ctx, - nil, /* hostClient */ - "hcloud", /* module */ - "", /* version */ - p, /* tf */ - info, /* info */ - []byte{}, /* pulumiSchema */ + nil, /* hostClient */ + "hcloud", /* module */ + "", /* version */ + p, /* tf */ + providerInfo, /* info */ + []byte{}, /* pulumiSchema */ ) testCase := ` diff --git a/pkg/tests/schema_pulumi_test.go b/pkg/tests/schema_pulumi_test.go index 9d25f7106..05b085c4b 100644 --- a/pkg/tests/schema_pulumi_test.go +++ b/pkg/tests/schema_pulumi_test.go @@ -101,9 +101,9 @@ func TestBigIntOverride(t *testing.T) { tfp := &schema.Provider{ResourcesMap: resMap} opts := []pulcheck.BridgedProviderOpt{} bridgedProvider := pulcheck.BridgedProvider(t, "prov", tfp, opts...) - bridgedProvider.Resources["prov_test"] = &tfbridge.ResourceInfo{ + bridgedProvider.Resources["prov_test"] = &info.Resource{ Tok: "prov:index:Test", - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "managed_zone_id": { Type: "string", }, diff --git a/pkg/tf2pulumi/convert/tf12.go b/pkg/tf2pulumi/convert/tf12.go index 21bfeba71..bd352ea1f 100644 --- a/pkg/tf2pulumi/convert/tf12.go +++ b/pkg/tf2pulumi/convert/tf12.go @@ -22,6 +22,7 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tf2pulumi/internal/addrs" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tf2pulumi/internal/configs" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/schema" ) @@ -114,7 +115,7 @@ func convertTF12(files []*syntax.File, opts EjectOptions) ([]*syntax.File, *pcl. pulumiOptions: pulumiOptions, filterResourceNames: opts.FilterResourceNames, providerInfo: opts.ProviderInfoSource, - providers: map[string]*tfbridge.ProviderInfo{}, + providers: map[string]*info.Provider{}, binding: codegen.Set{}, bound: codegen.Set{}, conditionals: newConditionalAnalyzer(), @@ -189,7 +190,7 @@ type tf12binder struct { filterResourceNames bool providerInfo il.ProviderInfoSource - providers map[string]*tfbridge.ProviderInfo + providers map[string]*info.Provider binding codegen.Set bound codegen.Set @@ -649,7 +650,7 @@ func (b *tf12binder) annotateExpressionsWithSchemas(item model.BodyItem) { } if s.Pulumi != nil { - schemas.Pulumi = &tfbridge.SchemaInfo{Elem: s.Pulumi} + schemas.Pulumi = &info.Schema{Elem: s.Pulumi} } b.exprToSchemas[x] = schemas @@ -827,8 +828,8 @@ func (b *tf12binder) bindResource(r *resource) hcl.Diagnostics { } b.variableToSchemas[r.rangeVariable] = func() il.Schemas { return il.Schemas{ - Pulumi: &tfbridge.SchemaInfo{ - Fields: map[string]*tfbridge.SchemaInfo{ + Pulumi: &info.Schema{ + Fields: map[string]*info.Schema{ "index": {Name: "value"}, }, }, @@ -1111,7 +1112,7 @@ func terraformToPulumiName(tfName string, schemas il.Schemas) string { } return tfbridge.TerraformToPulumiNameV2( tfName, schema.SchemaMap{tfName: schemas.TF}, - map[string]*tfbridge.SchemaInfo{tfName: schemas.Pulumi}) + map[string]*info.Schema{tfName: schemas.Pulumi}) } func (rr *resourceRewriter) terraformToPulumiName(tfName string) string { @@ -1528,7 +1529,7 @@ func (b *tf12binder) rewriteScopeTraversal(n *model.ScopeTraversalExpression, } else { traverser.Name = tfbridge.TerraformToPulumiNameV2( traverser.Name, schema.SchemaMap{traverser.Name: schemas.TF}, - map[string]*tfbridge.SchemaInfo{traverser.Name: schemas.Pulumi}) + map[string]*info.Schema{traverser.Name: schemas.Pulumi}) } newTraversal = append(newTraversal, traverser) case hcl.TraverseIndex: @@ -1732,7 +1733,7 @@ func (b *tf12binder) resourceType(addr addrs.Resource, ) (string, il.Schemas, model.Type, hcl.Diagnostics) { providerName := addr.ImpliedProvider() - info, ok := b.providers[providerName] + providerInfo, ok := b.providers[providerName] if !ok { i, err := b.providerInfo.GetProviderInfo("", "", providerName, "") if err != nil { @@ -1744,28 +1745,28 @@ func (b *tf12binder) resourceType(addr addrs.Resource, Detail: fmt.Sprintf("unknown provider '%s'", providerName), }} } - info, b.providers[providerName] = i, i + providerInfo, b.providers[providerName] = i, i } token := addr.Type var schemas il.Schemas if addr.Mode == addrs.ManagedResourceMode { - schemaInfo := &tfbridge.SchemaInfo{} - if resInfo, ok := info.Resources[addr.Type]; ok { + schemaInfo := &info.Schema{} + if resInfo, ok := providerInfo.Resources[addr.Type]; ok { token = string(resInfo.Tok) schemaInfo.Fields = resInfo.Fields } - if r := info.P.ResourcesMap().Get(addr.Type); r != nil { + if r := providerInfo.P.ResourcesMap().Get(addr.Type); r != nil { schemas.TFRes = r.Schema() } schemas.Pulumi = schemaInfo } else { - schemaInfo := &tfbridge.SchemaInfo{} - if dsInfo, ok := info.DataSources[addr.Type]; ok { + schemaInfo := &info.Schema{} + if dsInfo, ok := providerInfo.DataSources[addr.Type]; ok { token = string(dsInfo.Tok) schemaInfo.Fields = dsInfo.Fields } - if d := info.P.DataSourcesMap().Get(addr.Type); d != nil { + if d := providerInfo.P.DataSourcesMap().Get(addr.Type); d != nil { schemas.TFRes = d.Schema() } schemas.Pulumi = schemaInfo @@ -1783,7 +1784,7 @@ func (b *tf12binder) providerType(providerName string, ) (string, il.Schemas, model.Type, hcl.Diagnostics) { tok := "pulumi:providers:" + providerName - info, ok := b.providers[providerName] + providerInfo, ok := b.providers[providerName] if !ok { i, err := b.providerInfo.GetProviderInfo("", "", providerName, "") if err != nil { @@ -1793,14 +1794,14 @@ func (b *tf12binder) providerType(providerName string, Detail: fmt.Sprintf("unknown provider '%s'", providerName), }} } - info, b.providers[providerName] = i, i + providerInfo, b.providers[providerName] = i, i } schemas := il.Schemas{ - Pulumi: &tfbridge.SchemaInfo{ - Fields: info.Config, + Pulumi: &info.Schema{ + Fields: providerInfo.Config, }, - TFRes: info.P.Schema(), + TFRes: providerInfo.P.Schema(), } return tok, schemas, schemas.ModelType(), nil } diff --git a/pkg/tf2pulumi/il/graph.go b/pkg/tf2pulumi/il/graph.go index 48fd50e74..6b9c7744f 100644 --- a/pkg/tf2pulumi/il/graph.go +++ b/pkg/tf2pulumi/il/graph.go @@ -29,6 +29,7 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tf2pulumi/internal/config" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tf2pulumi/internal/config/module" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/schema" ) @@ -118,7 +119,7 @@ type ProviderNode struct { // Info is the set of Pulumi-specific information about this particular resource provider. Of particular interest // is per-{resource,data source} schema information, which is used to calculate names and types for resources and // their properties. - Info *tfbridge.ProviderInfo + Info *info.Provider // PluginName is the name of the Pulumi plugin associated with this provider. PluginName string // Implicit is true if this provider node was generated by an implicit provider block. @@ -286,7 +287,7 @@ func (r *ResourceNode) Schemas() Schemas { case r.Provider == nil || r.Provider.Info == nil: return Schemas{TFRes: EnsureSchemaMapID(schema.SchemaMap{})} case !r.IsDataSource: - schemaInfo := &tfbridge.SchemaInfo{} + schemaInfo := &info.Schema{} if resInfo, ok := r.Provider.Info.Resources[r.Type]; ok { schemaInfo.Fields = resInfo.Fields } @@ -299,7 +300,7 @@ func (r *ResourceNode) Schemas() Schemas { Pulumi: schemaInfo, } default: - schemaInfo := &tfbridge.SchemaInfo{} + schemaInfo := &info.Schema{} if dsInfo, ok := r.Provider.Info.DataSources[r.Type]; ok { schemaInfo.Fields = dsInfo.Fields } @@ -587,7 +588,7 @@ func (b *builder) buildDeps(deps nodeSet, dependsOn []string, providers []string // getProviderInfo fetches the tfbridge information for a particular provider. It does so by launching the provider // plugin with the "-get-provider-info" flag and deserializing the JSON representation dumped to stdout. -func (b *builder) getProviderInfo(p *ProviderNode) (*tfbridge.ProviderInfo, string, error) { +func (b *builder) getProviderInfo(p *ProviderNode) (*info.Provider, string, error) { info, err := b.providerInfo.GetProviderInfo("", "", p.Name, "") if err != nil { return nil, "", err @@ -736,7 +737,7 @@ func buildIgnoreChanges(tfIgnoreChanges []string, schemas Schemas) []string { } else { elementKey := tfbridge.TerraformToPulumiNameV2(element, schema.SchemaMap{element: elemSchemas.TF}, - map[string]*tfbridge.SchemaInfo{element: elemSchemas.Pulumi}) + map[string]*info.Schema{element: elemSchemas.Pulumi}) if path == "" { path = elementKey } else { diff --git a/pkg/tf2pulumi/il/plugin_info.go b/pkg/tf2pulumi/il/plugin_info.go index 8fae7a598..fd2c1ef88 100644 --- a/pkg/tf2pulumi/il/plugin_info.go +++ b/pkg/tf2pulumi/il/plugin_info.go @@ -33,17 +33,17 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" "github.com/pulumi/pulumi/sdk/v3/go/common/workspace" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) // ProviderInfoSource abstracts the ability to fetch tfbridge information for a Terraform provider. This is abstracted // primarily for testing purposes. type ProviderInfoSource interface { // GetProviderInfo returns the tfbridge information for the indicated Terraform provider. - GetProviderInfo(registry, namespace, name, version string) (*tfbridge.ProviderInfo, error) + GetProviderInfo(registry, namespace, name, version string) (*info.Provider, error) } -// mapperProviderInfoSource wraps a convert.Mapper to return tfbridge.ProviderInfo +// mapperProviderInfoSource wraps a convert.Mapper to return info.Provider type mapperProviderInfoSource struct { mapper convert.Mapper } @@ -54,7 +54,7 @@ func NewMapperProviderInfoSource(mapper convert.Mapper) ProviderInfoSource { func (mapper *mapperProviderInfoSource) GetProviderInfo( registryName, namespace, name, version string, -) (*tfbridge.ProviderInfo, error) { +) (*info.Provider, error) { data, err := mapper.mapper.GetMapping(context.TODO(), name, &convert.MapperPackageHint{ PluginName: GetPulumiProviderName(name), }) @@ -68,7 +68,7 @@ func (mapper *mapperProviderInfoSource) GetProviderInfo( return nil, errors.New(message) } - var info *tfbridge.MarshallableProviderInfo + var info *info.MarshallableProvider err = json.Unmarshal(data, &info) if err != nil { return nil, fmt.Errorf("could not decode schema information for provider %s: %w", name, err) @@ -81,7 +81,7 @@ type CachingProviderInfoSource struct { m sync.RWMutex source ProviderInfoSource - entries map[string]*tfbridge.ProviderInfo + entries map[string]*info.Provider } func (cache *CachingProviderInfoSource) cacheKey(registry, namespace, name, version string) string { @@ -89,7 +89,7 @@ func (cache *CachingProviderInfoSource) cacheKey(registry, namespace, name, vers url.PathEscape(registry), url.PathEscape(namespace), url.PathEscape(name), url.PathEscape(version)) } -func (cache *CachingProviderInfoSource) getProviderInfo(key string) (*tfbridge.ProviderInfo, bool) { +func (cache *CachingProviderInfoSource) getProviderInfo(key string) (*info.Provider, bool) { cache.m.RLock() defer cache.m.RUnlock() @@ -101,7 +101,7 @@ func (cache *CachingProviderInfoSource) getProviderInfo(key string) (*tfbridge.P // corresponding Pulumi resource provider. func (cache *CachingProviderInfoSource) GetProviderInfo( registryName, namespace, name, version string, -) (*tfbridge.ProviderInfo, error) { +) (*info.Provider, error) { key := cache.cacheKey(registryName, namespace, name, version) if info, ok := cache.getProviderInfo(key); ok { @@ -123,7 +123,7 @@ func (cache *CachingProviderInfoSource) GetProviderInfo( func NewCachingProviderInfoSource(source ProviderInfoSource) *CachingProviderInfoSource { return &CachingProviderInfoSource{ source: source, - entries: map[string]*tfbridge.ProviderInfo{}, + entries: map[string]*info.Provider{}, } } @@ -135,7 +135,7 @@ func NewMultiProviderInfoSource(sources ...ProviderInfoSource) ProviderInfoSourc func (s multiProviderInfoSource) GetProviderInfo( registryName, namespace, name, version string, -) (*tfbridge.ProviderInfo, error) { +) (*info.Provider, error) { for _, s := range s { if s != nil { if info, err := s.GetProviderInfo(registryName, namespace, name, version); err == nil && info != nil { @@ -176,7 +176,7 @@ func GetPulumiProviderName(terraformProviderName string) string { } // GetTerraformProviderName returns the canonical Terraform provider name for the given provider info. -func GetTerraformProviderName(info tfbridge.ProviderInfo) string { +func GetTerraformProviderName(info info.Provider) string { if info.Name == "google-beta" { return "google" } @@ -187,7 +187,7 @@ func GetTerraformProviderName(info tfbridge.ProviderInfo) string { // corresponding Pulumi resource provider. func (pluginProviderInfoSource) GetProviderInfo( registryName, namespace, name, version string, -) (*tfbridge.ProviderInfo, error) { +) (*info.Provider, error) { tfProviderName := name pluginName := GetPulumiProviderName(tfProviderName) @@ -216,7 +216,7 @@ func (pluginProviderInfoSource) GetProviderInfo( return nil, errors.Wrapf(err, "failed to load plugin %s for provider %s", pluginName, tfProviderName) } - var info *tfbridge.MarshallableProviderInfo + var info *info.MarshallableProvider err = jsoniter.NewDecoder(out).Decode(&info) if cErr := cmd.Wait(); cErr != nil { diff --git a/pkg/tf2pulumi/il/schemas.go b/pkg/tf2pulumi/il/schemas.go index e9d4072c8..8b2c09ffc 100644 --- a/pkg/tf2pulumi/il/schemas.go +++ b/pkg/tf2pulumi/il/schemas.go @@ -19,7 +19,7 @@ import ( "github.com/pulumi/pulumi/pkg/v3/codegen/hcl2/model" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/schema" ) @@ -32,7 +32,7 @@ import ( type Schemas struct { TF shim.Schema TFRes shim.SchemaMap - Pulumi *tfbridge.SchemaInfo + Pulumi *info.Schema } // PropertySchemas returns the Schemas for the child property with the given name. If the name is an integer, this diff --git a/pkg/tf2pulumi/test/provider_info.go b/pkg/tf2pulumi/test/provider_info.go index 0c4c92492..c0e4f413e 100644 --- a/pkg/tf2pulumi/test/provider_info.go +++ b/pkg/tf2pulumi/test/provider_info.go @@ -22,17 +22,17 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) type ProviderInfoSource struct { m sync.RWMutex infoDirectoryPath string - entries map[string]*tfbridge.ProviderInfo + entries map[string]*info.Provider } -func (s *ProviderInfoSource) getProviderInfo(tfProviderName string) (*tfbridge.ProviderInfo, bool) { +func (s *ProviderInfoSource) getProviderInfo(tfProviderName string) (*info.Provider, bool) { s.m.RLock() defer s.m.RUnlock() @@ -44,7 +44,7 @@ func (s *ProviderInfoSource) getProviderInfo(tfProviderName string) (*tfbridge.P // corresponding Pulumi resource provider. func (s *ProviderInfoSource) GetProviderInfo( registryName, namespace, name, version string, -) (*tfbridge.ProviderInfo, error) { +) (*info.Provider, error) { if info, ok := s.getProviderInfo(name); ok { return info, nil } @@ -58,7 +58,7 @@ func (s *ProviderInfoSource) GetProviderInfo( } defer contract.IgnoreClose(f) - var m tfbridge.MarshallableProviderInfo + var m info.MarshallableProvider if err = json.NewDecoder(f).Decode(&m); err != nil { return nil, err } @@ -72,6 +72,6 @@ func (s *ProviderInfoSource) GetProviderInfo( func NewProviderInfoSource(path string) *ProviderInfoSource { return &ProviderInfoSource{ infoDirectoryPath: path, - entries: map[string]*tfbridge.ProviderInfo{}, + entries: map[string]*info.Provider{}, } } diff --git a/pkg/tfbridge/check_failures.go b/pkg/tfbridge/check_failures.go index 3f6a94c76..5d3ad063b 100644 --- a/pkg/tfbridge/check_failures.go +++ b/pkg/tfbridge/check_failures.go @@ -403,5 +403,5 @@ func lookupDescription(pp CheckFailurePath, schemaMap shim.SchemaMap) (desc stri // little better in our console output. desc = strings.ReplaceAll(s.Description(), "\n", " ") } - return + return desc } diff --git a/pkg/tfbridge/detailed_diff.go b/pkg/tfbridge/detailed_diff.go index 0d64b08f5..b869b4dca 100644 --- a/pkg/tfbridge/detailed_diff.go +++ b/pkg/tfbridge/detailed_diff.go @@ -589,7 +589,7 @@ func computeSetHashChanges( return added[i] < added[j] }) - return + return removed, added } // matchPlanElementsToInputs is used to match the plan elements to the inputs. diff --git a/pkg/tfbridge/provider.go b/pkg/tfbridge/provider.go index 44af91262..fbd830880 100644 --- a/pkg/tfbridge/provider.go +++ b/pkg/tfbridge/provider.go @@ -411,10 +411,10 @@ func (p *Provider) initResourceMaps() { // then that overrides the ignore directive. // // This is because there have been providers in the wild that is - // [tfbridge.ProviderInfo.IgnoreMappings] to specify a Datasource to + // [info.Provider.IgnoreMappings] to specify a Datasource to // ignore, then manually map the Resource (or vice versa). We don't want // to break those providers when implementing support for - // [tfbridge.ProviderInfo.IgnoreMappings] in the resource map. + // [info.Provider.IgnoreMappings] in the resource map. if ignoredTokens[name] && !ok { return true // continue } diff --git a/pkg/tfbridge/tests/provider_test.go b/pkg/tfbridge/tests/provider_test.go index 7b918906a..94701521c 100644 --- a/pkg/tfbridge/tests/provider_test.go +++ b/pkg/tfbridge/tests/provider_test.go @@ -37,7 +37,7 @@ import ( func TestWithNewTestProvider(t *testing.T) { t.Parallel() ctx := context.Background() - p := newTestProvider(ctx, tfbridge.ProviderInfo{ + p := newTestProvider(ctx, info.Provider{ P: shimv2.NewProvider(&schema.Provider{ Schema: map[string]*schema.Schema{}, ResourcesMap: map[string]*schema.Resource{ @@ -56,7 +56,7 @@ func TestWithNewTestProvider(t *testing.T) { }), Name: "testprov", ResourcePrefix: "example", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "example_resource": {Tok: "testprov:index:ExampleResource"}, }, }, newTestProviderOptions{}) @@ -88,7 +88,7 @@ func TestWithNewTestProvider(t *testing.T) { func TestRegress1932(t *testing.T) { t.Parallel() ctx := context.Background() - p := newTestProvider(ctx, tfbridge.ProviderInfo{ + p := newTestProvider(ctx, info.Provider{ P: shimv2.NewProvider(&schema.Provider{ Schema: map[string]*schema.Schema{}, ResourcesMap: map[string]*schema.Resource{ @@ -113,7 +113,7 @@ func TestRegress1932(t *testing.T) { }), Name: "aws", ResourcePrefix: "example", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "aws_launch_template": {Tok: "aws:ec2/launchTemplate:LaunchTemplate"}, }, }, newTestProviderOptions{}) @@ -228,7 +228,7 @@ func TestReproMinimalDiffCycle(t *testing.T) { return actual } ctx := context.Background() - p := newTestProvider(ctx, tfbridge.ProviderInfo{ + p := newTestProvider(ctx, info.Provider{ P: shimv2.NewProvider(&schema.Provider{ Schema: map[string]*schema.Schema{}, ResourcesMap: map[string]*schema.Resource{ @@ -237,7 +237,7 @@ func TestReproMinimalDiffCycle(t *testing.T) { }), Name: "testprov", ResourcePrefix: "example", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "example_resource": {Tok: "testprov:index:ExampleResource"}, }, }, newTestProviderOptions{}) @@ -298,7 +298,7 @@ func TestReproMinimalDiffCycle(t *testing.T) { func TestValidateConfig(t *testing.T) { ctx := context.Background() - p := newTestProvider(ctx, tfbridge.ProviderInfo{ + p := newTestProvider(ctx, info.Provider{ P: shimv2.NewProvider(&schema.Provider{ Schema: map[string]*schema.Schema{ "endpoints": { @@ -387,7 +387,7 @@ func TestTypeCheckingMistypedBooleansWithUnknowns(t *testing.T) { schemaProvider := &schema.Provider{ResourcesMap: resMap} - p := newTestProvider(ctx, tfbridge.ProviderInfo{ + p := newTestProvider(ctx, info.Provider{ P: shimv2.NewProvider(schemaProvider), Name: "aws", ResourcePrefix: "aws", @@ -435,7 +435,7 @@ func nilSink() diag.Sink { // Variation of NewProvider to facilitate white-box testing. func newTestProvider( ctx context.Context, - info tfbridge.ProviderInfo, + info info.Provider, opts newTestProviderOptions, ) pulumirpc.ResourceProviderServer { if opts.version == "" { diff --git a/pkg/tfbridge/tokens/fallbackstrat/fallback_strategy_test.go b/pkg/tfbridge/tokens/fallbackstrat/fallback_strategy_test.go index e19f7a1e5..238adc52d 100644 --- a/pkg/tfbridge/tokens/fallbackstrat/fallback_strategy_test.go +++ b/pkg/tfbridge/tokens/fallbackstrat/fallback_strategy_test.go @@ -8,13 +8,14 @@ import ( "github.com/stretchr/testify/require" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/tokens/fallbackstrat" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/schema" ) func TestTokensMappedModulesWithInferredFallback(t *testing.T) { t.Parallel() - info := tfbridge.ProviderInfo{ + providerInfo := info.Provider{ P: (&schema.Provider{ ResourcesMap: schema.ResourceMap{ "cs101_fizz_buzz_one_five": nil, @@ -26,7 +27,7 @@ func TestTokensMappedModulesWithInferredFallback(t *testing.T) { }).Shim(), } strategy, err := fallbackstrat.MappedModulesWithInferredFallback( - &info, + &providerInfo, "cs101_", "", map[string]string{ "fizz_": "fIzZ", "fizz_buzz_": "fizZBuzz", @@ -37,23 +38,23 @@ func TestTokensMappedModulesWithInferredFallback(t *testing.T) { ) require.NoError(t, err) - err = info.ComputeTokens(tfbridge.Strategy{ + err = providerInfo.ComputeTokens(tfbridge.Strategy{ Resource: strategy.Resource, }) require.NoError(t, err) - assert.Equal(t, map[string]*tfbridge.ResourceInfo{ + assert.Equal(t, map[string]*info.Resource{ "cs101_fizz_buzz_one_five": {Tok: "cs101:fizZBuzz:OneFive"}, "cs101_fizz_three": {Tok: "cs101:fIzZ:Three"}, "cs101_fizz_three_six": {Tok: "cs101:fIzZ:ThreeSix"}, // inferred "cs101_buzz_five": {Tok: "cs101:buzz:Five"}, "cs101_buzz_ten": {Tok: "cs101:buzz:Ten"}, - }, info.Resources) + }, providerInfo.Resources) } func TestTokensKnownModulesWithInferredFallback(t *testing.T) { t.Parallel() - info := tfbridge.ProviderInfo{ + providerInfo := info.Provider{ P: (&schema.Provider{ ResourcesMap: schema.ResourceMap{ "cs101_fizz_buzz_one_five": nil, @@ -65,7 +66,7 @@ func TestTokensKnownModulesWithInferredFallback(t *testing.T) { }).Shim(), } - strategy, err := fallbackstrat.KnownModulesWithInferredFallback(&info, + strategy, err := fallbackstrat.KnownModulesWithInferredFallback(&providerInfo, "cs101_", "", []string{ "fizz_", "fizz_buzz_", }, func(module, name string) (string, error) { @@ -73,17 +74,17 @@ func TestTokensKnownModulesWithInferredFallback(t *testing.T) { }) require.NoError(t, err) - err = info.ComputeTokens(tfbridge.Strategy{ + err = providerInfo.ComputeTokens(tfbridge.Strategy{ Resource: strategy.Resource, }) require.NoError(t, err) - assert.Equal(t, map[string]*tfbridge.ResourceInfo{ + assert.Equal(t, map[string]*info.Resource{ "cs101_fizz_buzz_one_five": {Tok: "cs101:fizzBuzz:OneFive"}, "cs101_fizz_three": {Tok: "cs101:fizz:Three"}, "cs101_fizz_three_six": {Tok: "cs101:fizz:ThreeSix"}, // inferred "cs101_buzz_five": {Tok: "cs101:buzz:Five"}, "cs101_buzz_ten": {Tok: "cs101:buzz:Ten"}, - }, info.Resources) + }, providerInfo.Resources) } diff --git a/pkg/tfbridge/x/apply.go b/pkg/tfbridge/x/apply.go index e2cf212e6..b0bde9beb 100644 --- a/pkg/tfbridge/x/apply.go +++ b/pkg/tfbridge/x/apply.go @@ -20,7 +20,7 @@ import ( "github.com/hashicorp/go-multierror" - b "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" ) @@ -28,7 +28,7 @@ import ( // // Deprecated: This item has been moved to // [github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge.ComputeTokens] -func ComputeDefaults(info *b.ProviderInfo, opts DefaultStrategy) error { +func ComputeDefaults(info *info.Provider, opts DefaultStrategy) error { var errs multierror.Error ignored := ignoredTokens(info) @@ -44,7 +44,7 @@ func ComputeDefaults(info *b.ProviderInfo, opts DefaultStrategy) error { return errs.ErrorOrNil() } -func ignoredTokens(info *b.ProviderInfo) map[string]bool { +func ignoredTokens(info *info.Provider) map[string]bool { ignored := map[string]bool{} if info == nil { return ignored @@ -55,29 +55,31 @@ func ignoredTokens(info *b.ProviderInfo) map[string]bool { return ignored } -func computeDefaultResources(info *b.ProviderInfo, strategy ResourceStrategy, ignored map[string]bool) error { +func computeDefaultResources(providerInfo *info.Provider, strategy ResourceStrategy, ignored map[string]bool) error { if strategy == nil { return nil } - if info.Resources == nil { - info.Resources = map[string]*b.ResourceInfo{} + if providerInfo.Resources == nil { + providerInfo.Resources = map[string]*info.Resource{} } - return applyComputedTokens(info.P.ResourcesMap(), info.Resources, strategy, ignored) + return applyComputedTokens(providerInfo.P.ResourcesMap(), providerInfo.Resources, strategy, ignored) } -func computeDefaultDataSources(info *b.ProviderInfo, strategy DataSourceStrategy, ignored map[string]bool) error { +func computeDefaultDataSources( + providerInfo *info.Provider, strategy DataSourceStrategy, ignored map[string]bool, +) error { if strategy == nil { return nil } - if info.DataSources == nil { - info.DataSources = map[string]*b.DataSourceInfo{} + if providerInfo.DataSources == nil { + providerInfo.DataSources = map[string]*info.DataSource{} } - return applyComputedTokens(info.P.DataSourcesMap(), info.DataSources, strategy, ignored) + return applyComputedTokens(providerInfo.P.DataSourcesMap(), providerInfo.DataSources, strategy, ignored) } // For each key in the info map not present in the result map, compute a result and store // it in the result map. -func applyComputedTokens[T b.ResourceInfo | b.DataSourceInfo]( +func applyComputedTokens[T info.Resource | info.DataSource]( infoMap shim.ResourceMap, resultMap map[string]*T, tks Strategy[T], ignoredMappings map[string]bool, ) error { diff --git a/pkg/tfbridge/x/strategy.go b/pkg/tfbridge/x/strategy.go index a336009cb..92749b089 100644 --- a/pkg/tfbridge/x/strategy.go +++ b/pkg/tfbridge/x/strategy.go @@ -14,15 +14,13 @@ package x -import ( - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" -) +import "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" // A generic remapping strategy. // // Deprecated: This item has been moved to // [github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge.ElementStrategy] -type Strategy[T tfbridge.ResourceInfo | tfbridge.DataSourceInfo] func(tfToken string) (*T, error) +type Strategy[T info.Resource | info.DataSource] func(tfToken string) (*T, error) // Describe the mapping from resource and datasource tokens to Pulumi resources and // datasources. @@ -38,10 +36,10 @@ type DefaultStrategy struct { // // Deprecated: This item has been moved to // [github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge.ResourceStrategy] -type ResourceStrategy = Strategy[tfbridge.ResourceInfo] +type ResourceStrategy = Strategy[info.Resource] // A strategy for generating missing datasources. // // Deprecated: This item has been moved to // [github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge.DataSourceStrategy] -type DataSourceStrategy = Strategy[tfbridge.DataSourceInfo] +type DataSourceStrategy = Strategy[info.DataSource] diff --git a/pkg/tfbridge/x/tokens.go b/pkg/tfbridge/x/tokens.go index af079a7c5..217ae4589 100644 --- a/pkg/tfbridge/x/tokens.go +++ b/pkg/tfbridge/x/tokens.go @@ -26,6 +26,7 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" b "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" md "github.com/pulumi/pulumi-terraform-bridge/v3/unstable/metadata" ) @@ -63,7 +64,7 @@ func TokensSingleModule( return TokensKnownModules(tfPackagePrefix, moduleName, nil, finalize) } -func tokensKnownModules[T b.ResourceInfo | b.DataSourceInfo]( +func tokensKnownModules[T info.Resource | info.DataSource]( prefix, defaultModule string, modules []string, new func(string, string) (*T, error), moduleTransform func(string) string, @@ -103,20 +104,20 @@ func TokensKnownModules( return DefaultStrategy{ Resource: tokensKnownModules(tfPackagePrefix, defaultModule, modules, - func(mod, tk string) (*b.ResourceInfo, error) { + func(mod, tk string) (*info.Resource, error) { tk, err := finalize(mod, tk) if err != nil { return nil, err } - return &b.ResourceInfo{Tok: tokens.Type(tk)}, nil + return &info.Resource{Tok: tokens.Type(tk)}, nil }, camelCase), DataSource: tokensKnownModules(tfPackagePrefix, defaultModule, modules, - func(mod, tk string) (*b.DataSourceInfo, error) { + func(mod, tk string) (*info.DataSource, error) { tk, err := finalize(mod, "get"+tk) if err != nil { return nil, err } - return &b.DataSourceInfo{Tok: tokens.ModuleMember(tk)}, nil + return &info.DataSource{Tok: tokens.ModuleMember(tk)}, nil }, camelCase), } } @@ -151,20 +152,20 @@ func TokensMappedModules( return DefaultStrategy{ Resource: tokensKnownModules(tfPackagePrefix, defaultModule, mods, - func(mod, tk string) (*b.ResourceInfo, error) { + func(mod, tk string) (*info.Resource, error) { tk, err := finalize(mod, tk) if err != nil { return nil, err } - return &b.ResourceInfo{Tok: tokens.Type(tk)}, nil + return &info.Resource{Tok: tokens.Type(tk)}, nil }, transform), DataSource: tokensKnownModules(tfPackagePrefix, defaultModule, mods, - func(mod, tk string) (*b.DataSourceInfo, error) { + func(mod, tk string) (*info.DataSource, error) { tk, err := finalize(mod, "get"+tk) if err != nil { return nil, err } - return &b.DataSourceInfo{Tok: tokens.ModuleMember(tk)}, nil + return &info.DataSource{Tok: tokens.ModuleMember(tk)}, nil }, transform), } } @@ -227,12 +228,12 @@ type InferredModulesOpts struct { // Deprecated: This item has been moved to // [github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/tokens.InferredModules] func TokensInferredModules( - info *b.ProviderInfo, finalize MakeToken, opts *InferredModulesOpts, + providerInfo *info.Provider, finalize MakeToken, opts *InferredModulesOpts, ) (DefaultStrategy, error) { if opts == nil { opts = &InferredModulesOpts{} } - err := opts.ensurePrefix(info) + err := opts.ensurePrefix(providerInfo) if err != nil { return DefaultStrategy{}, fmt.Errorf("inferring pkg prefix: %w", err) } @@ -247,19 +248,19 @@ func TokensInferredModules( opts.MainModule = "index" } - tokenMap := opts.computeTokens(info) + tokenMap := opts.computeTokens(providerInfo) return DefaultStrategy{ - Resource: tokenFromMap(tokenMap, finalize, func(tk string) *b.ResourceInfo { - return &b.ResourceInfo{Tok: tokens.Type(tk)} + Resource: tokenFromMap(tokenMap, finalize, func(tk string) *info.Resource { + return &info.Resource{Tok: tokens.Type(tk)} }), - DataSource: tokenFromMap(tokenMap, finalize, func(tk string) *b.DataSourceInfo { - return &b.DataSourceInfo{Tok: tokens.ModuleMember(tk)} + DataSource: tokenFromMap(tokenMap, finalize, func(tk string) *info.DataSource { + return &info.DataSource{Tok: tokens.ModuleMember(tk)} }), }, nil } -func (opts *InferredModulesOpts) ensurePrefix(info *b.ProviderInfo) error { +func (opts *InferredModulesOpts) ensurePrefix(providerInfo *info.Provider) error { prefix := opts.TfPkgPrefix var noCommonality bool findPrefix := func(key string, _ shim.Resource) bool { @@ -278,7 +279,7 @@ func (opts *InferredModulesOpts) ensurePrefix(info *b.ProviderInfo) error { return true } - mapProviderItems(info, findPrefix) + mapProviderItems(providerInfo, findPrefix) if noCommonality { return fmt.Errorf("no common prefix detected") } @@ -381,7 +382,7 @@ func (n *node) dfsInner(parentStack *[]*node, iter func(parent func(int) *node, // Precompute the mapping from tf tokens to pulumi modules. // // The resulting map is complete for all TF resources and datasources in info.P. -func (opts *InferredModulesOpts) computeTokens(info *b.ProviderInfo) map[string]tokenInfo { +func (opts *InferredModulesOpts) computeTokens(info *info.Provider) map[string]tokenInfo { contract.Assertf(opts.TfPkgPrefix != "", "TF package prefix not provided or computed") tree := &node{segment: opts.TfPkgPrefix} @@ -473,7 +474,7 @@ func (opts *InferredModulesOpts) computeTokens(info *b.ProviderInfo) map[string] return output } -func mapProviderItems(info *b.ProviderInfo, each func(string, shim.Resource) bool) { +func mapProviderItems(info *info.Provider, each func(string, shim.Resource) bool) { ignored := ignoredTokens(info) info.P.ResourcesMap().Range(func(key string, value shim.Resource) bool { if ignored[key] { @@ -507,7 +508,7 @@ func sharedPrefix(s1, s2 string) string { type tokenInfo struct{ mod, name string } -func tokenFromMap[T b.ResourceInfo | b.DataSourceInfo]( +func tokenFromMap[T info.Resource | info.DataSource]( tokenMap map[string]tokenInfo, finalize MakeToken, new func(tk string) *T, ) Strategy[T] { return func(tfToken string) (*T, error) { @@ -554,8 +555,8 @@ type fieldHistory struct { } // Deprecated: This item has been moved to -// [github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge.ProviderInfo.ApplyAutoAliases] -func AutoAliasing(providerInfo *b.ProviderInfo, artifact b.ProviderMetadata) error { +// [github.com/pulumi/pulumi-terraform-bridge/v3/pkg/info.Provider.ApplyAutoAliases] +func AutoAliasing(providerInfo *info.Provider, artifact info.ProviderMetadata) error { hist, err := getHistory(artifact) if err != nil { return err @@ -620,7 +621,7 @@ func AutoAliasing(providerInfo *b.ProviderInfo, artifact b.ProviderMetadata) err const aliasMetadataKey = "auto-aliasing" -func getHistory(artifact b.ProviderMetadata) (aliasHistory, error) { +func getHistory(artifact info.ProviderMetadata) (aliasHistory, error) { hist, ok, err := md.Get[aliasHistory](artifact, aliasMetadataKey) if err != nil { return aliasHistory{}, err @@ -635,9 +636,9 @@ func getHistory(artifact b.ProviderMetadata) (aliasHistory, error) { } func aliasResource( - p *b.ProviderInfo, res shim.Resource, + p *info.Provider, res shim.Resource, applyResourceAliases *[]func(), - hist map[string]*tokenHistory[tokens.Type], computed *b.ResourceInfo, + hist map[string]*tokenHistory[tokens.Type], computed *info.Resource, tfToken string, version int, ) { prev, hasPrev := hist[tfToken] @@ -678,7 +679,7 @@ func aliasResource( // applyResourceMaxItemsOneAliasing traverses a shim.Resource, applying walk to each field in the resource. func applyResourceMaxItemsOneAliasing( - r shim.Resource, hist *map[string]*fieldHistory, info *map[string]*b.SchemaInfo, + r shim.Resource, hist *map[string]*fieldHistory, info *map[string]*info.Schema, ) (bool, bool) { if r == nil { return hist != nil, info != nil @@ -751,22 +752,22 @@ func applyResourceMaxItemsOneAliasing( // applyMaxItemsOneAliasing traverses a generic shim.Schema recursively, applying fieldHistory to // SchemaInfo and vise versa as necessary to avoid breaking changes in the // resulting sdk. -func applyMaxItemsOneAliasing(schema shim.Schema, h *fieldHistory, info *b.SchemaInfo) (hasH bool, hasI bool) { +func applyMaxItemsOneAliasing(schema shim.Schema, h *fieldHistory, schemaInfo *info.Schema) (hasH bool, hasI bool) { //revive:disable-next-line:empty-block if schema == nil || (schema.Type() != shim.TypeList && schema.Type() != shim.TypeSet) { // MaxItemsOne does not apply, so do nothing - } else if info.MaxItemsOne != nil { + } else if schemaInfo.MaxItemsOne != nil { // The user has overwritten the value, so we will just record that. - h.MaxItemsOne = info.MaxItemsOne + h.MaxItemsOne = schemaInfo.MaxItemsOne hasH = true } else if h.MaxItemsOne != nil { // If we have a previous value in the history, we keep it as is. - info.MaxItemsOne = h.MaxItemsOne + schemaInfo.MaxItemsOne = h.MaxItemsOne hasI = true } else { // There is no history for this value, so we bake it into the // alias history. - h.MaxItemsOne = b.BoolRef(b.IsMaxItemsOne(schema, info)) + h.MaxItemsOne = b.BoolRef(b.IsMaxItemsOne(schema, schemaInfo)) hasH = true } @@ -781,8 +782,8 @@ func applyMaxItemsOneAliasing(schema shim.Schema, h *fieldHistory, info *b.Schem } else { hasElemH = true } - if info.Elem == nil { - info.Elem = &b.SchemaInfo{} + if schemaInfo.Elem == nil { + schemaInfo.Elem = &info.Schema{} } else { hasElemI = true } @@ -798,7 +799,7 @@ func applyMaxItemsOneAliasing(schema shim.Schema, h *fieldHistory, info *b.Schem h.Elem = nil } if !hasElemI { - info.Elem = nil + schemaInfo.Elem = nil } } @@ -806,11 +807,11 @@ func applyMaxItemsOneAliasing(schema shim.Schema, h *fieldHistory, info *b.Schem switch e := e.(type) { case shim.Resource: populateElem() - eHasH, eHasI := applyResourceMaxItemsOneAliasing(e, &h.Elem.Fields, &info.Elem.Fields) + eHasH, eHasI := applyResourceMaxItemsOneAliasing(e, &h.Elem.Fields, &schemaInfo.Elem.Fields) cleanupElem(eHasH, eHasI) case shim.Schema: populateElem() - eHasH, eHasI := applyMaxItemsOneAliasing(e, h.Elem, info.Elem) + eHasH, eHasI := applyMaxItemsOneAliasing(e, h.Elem, schemaInfo.Elem) cleanupElem(eHasH, eHasI) } @@ -835,8 +836,8 @@ func getNonNil[K comparable, V any](m *map[K]*V, key K) (_ *V, alreadyThere bool } func aliasOrRenameResource( - p *b.ProviderInfo, - res *b.ResourceInfo, tfToken string, + p *info.Provider, + res *info.Resource, tfToken string, hist *tokenHistory[tokens.Type], currentVersion int, ) { var alreadyPresent bool @@ -862,16 +863,16 @@ func aliasOrRenameResource( res.Tok.Module().Name().String(), res) } else { res.Aliases = append(res.Aliases, - b.AliasInfo{Type: (*string)(&legacy)}) + info.Alias{Type: (*string)(&legacy)}) } } } func aliasDataSource( - p *b.ProviderInfo, + p *info.Provider, ds shim.Resource, hist map[string]*tokenHistory[tokens.ModuleMember], - computed *b.DataSourceInfo, + computed *info.DataSource, tfToken string, version int, ) { @@ -901,7 +902,7 @@ func aliasDataSource( } func aliasOrRenameDataSource( - p *b.ProviderInfo, tfToken string, + p *info.Provider, tfToken string, prev *tokenHistory[tokens.ModuleMember], currentVersion int, ) { diff --git a/pkg/tfgen/convert_cli.go b/pkg/tfgen/convert_cli.go index a21e71162..e88ee32ad 100644 --- a/pkg/tfgen/convert_cli.go +++ b/pkg/tfgen/convert_cli.go @@ -41,6 +41,7 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen/internal/autofill" ) @@ -62,9 +63,9 @@ func cliConverterEnabled() bool { // Note that once examples are converted to PCL, they continue to be processed with in-process // target language specific generators to produce TypeScript, YAML, Python etc target code. type cliConverter struct { - info tfbridge.ProviderInfo // provider declaration - pluginHost plugin.Host // the plugin host for PCL conversion - packageCache *pcl.PackageCache // the package cache for PCL conversion + info info.Provider // provider declaration + pluginHost plugin.Host // the plugin host for PCL conversion + packageCache *pcl.PackageCache // the package cache for PCL conversion hcls map[string]struct{} // set of observed HCL snippets @@ -215,7 +216,7 @@ func (cc *cliConverter) bulkConvert() error { examples[fileName] = hcl n++ } - result, err := cc.convertViaPulumiCLI(cc.autoFill(examples), []tfbridge.ProviderInfo{ + result, err := cc.convertViaPulumiCLI(cc.autoFill(examples), []info.Provider{ cc.info, }) if err != nil { @@ -264,7 +265,7 @@ func (cc *cliConverter) autoFill(examples map[string]string) map[string]string { // include additional providers used in examples. func (cc *cliConverter) convertViaPulumiCLI( examples map[string]string, - mappings []tfbridge.ProviderInfo, + mappings []info.Provider, ) (map[string]translatedExample, error) { translated, err := cc.convertViaPulumiCLIStep(examples, mappings) if err == nil { @@ -310,7 +311,7 @@ func (*cliConverter) split2(xs map[string]string) (map[string]string, map[string // To help with debugging failures prepares a temp folder with a repro script and returns a path to it. func (cc *cliConverter) convertViaPulumiPrepareDebugFolder( examples map[string]string, - mappings []tfbridge.ProviderInfo, + mappings []info.Provider, ) (string, error) { d, err := os.MkdirTemp("", "convert-examples-repro") if err != nil { @@ -346,7 +347,7 @@ pulumi %s func (cc *cliConverter) convertViaPulumiCLICommandArgs( examples map[string]string, - mappings []tfbridge.ProviderInfo, + mappings []info.Provider, outDir string, examplesJSONPath string, ) (string, []string, error) { @@ -407,7 +408,7 @@ func (cc *cliConverter) convertViaPulumiCLICommandArgs( func (cc *cliConverter) convertViaPulumiCLIStep( examples map[string]string, - mappings []tfbridge.ProviderInfo, + mappings []info.Provider, ) ( output map[string]translatedExample, finalError error, @@ -477,7 +478,7 @@ func (cc *cliConverter) convertViaPulumiCLIStep( return result, nil } -func (*cliConverter) mappingsFile(mappingsDir string, info tfbridge.ProviderInfo) string { +func (*cliConverter) mappingsFile(mappingsDir string, info info.Provider) string { // This seems to be what the converter expects the filename to be. For providers // like "aws" this is simply the provider name, but there are exceptions such as // "azure" where this has to be "azurerm.json" to match the prefix on the Terraform @@ -637,7 +638,7 @@ func (*cliConverter) ensureNotSupportedLifecycleHooksIsError(d *hcl.Diagnostic) // Function for one-off example converson HCL --> PCL using pulumi-converter-terraform func (cc *cliConverter) singleExampleFromHCLToPCL(path, hclCode string) (translatedExample, error) { key := path - result, err := cc.convertViaPulumiCLI(map[string]string{key: hclCode}, []tfbridge.ProviderInfo{cc.info}) + result, err := cc.convertViaPulumiCLI(map[string]string{key: hclCode}, []info.Provider{cc.info}) if err != nil { return translatedExample{}, nil } diff --git a/pkg/tfgen/convert_cli_test.go b/pkg/tfgen/convert_cli_test.go index 4cc747a9d..fd8ea95ee 100644 --- a/pkg/tfgen/convert_cli_test.go +++ b/pkg/tfgen/convert_cli_test.go @@ -39,7 +39,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) @@ -63,7 +63,7 @@ output "some_output" { value = simple_resource.a_resource.result }` - p := tfbridge.ProviderInfo{ + p := info.Provider{ Name: "simple", P: shimv2.NewProvider(&schema.Provider{ ResourcesMap: map[string]*schema.Resource{ @@ -86,15 +86,15 @@ output "some_output" { }, }, }), - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "simple_resource": { Tok: "simple:index:resource", - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "input_one": { Name: "renamedInput1", }, }, - Docs: &tfbridge.DocInfo{ + Docs: &info.Doc{ Markdown: []byte(fmt.Sprintf( "Sample resource.\n## Example Usage\n\n"+ "```hcl\n%s\n```\n\n##Extras\n\n", @@ -103,7 +103,7 @@ output "some_output" { }, }, }, - DataSources: map[string]*tfbridge.DataSourceInfo{ + DataSources: map[string]*info.DataSource{ "simple_data_source": { Tok: "simple:index:dataSource", }, @@ -146,7 +146,7 @@ output "someOutput" { out, err := cc.convertViaPulumiCLI(map[string]string{ "example1": simpleResourceTF, "example2": simpleDataSourceTF, - }, []tfbridge.ProviderInfo{p}) + }, []info.Provider{p}) require.NoError(t, err) assert.Equal(t, 2, len(out)) @@ -226,9 +226,9 @@ Converted 100.00% of yaml examples (1/1) t.Run("mappingsFile", func(t *testing.T) { c := &cliConverter{} - aws := tfbridge.ProviderInfo{Name: "aws"} + aws := info.Provider{Name: "aws"} assert.Equal(t, filepath.Join(".", "aws.json"), c.mappingsFile(".", aws)) - withPrefix := tfbridge.ProviderInfo{Name: "p", ResourcePrefix: "prov"} + withPrefix := info.Provider{Name: "p", ResourcePrefix: "prov"} assert.Equal(t, filepath.Join(".", "prov.json"), c.mappingsFile(".", withPrefix)) }) @@ -267,14 +267,14 @@ resource "azurerm_web_pubsub_custom_certificate" "test" { }, }, } - pi := tfbridge.ProviderInfo{ + pi := info.Provider{ P: shimv2.NewProvider(p), Name: "azurerm", Version: "0.0.1", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "azurerm_web_pubsub_custom_certificate": { Tok: "azure:webpubsub/customCertificate:CustomCertificate", - Docs: &tfbridge.DocInfo{Markdown: md}, + Docs: &info.Doc{Markdown: md}, }, }, } @@ -317,14 +317,14 @@ This is some intentionally broken HCL that should not convert. }, }, } - pi := tfbridge.ProviderInfo{ + pi := info.Provider{ P: shimv2.NewProvider(p), Name: "azurerm", Version: "0.0.1", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "azurerm_web_pubsub_custom_certificate": { Tok: "azure:webpubsub/customCertificate:CustomCertificate", - Docs: &tfbridge.DocInfo{Markdown: md}, + Docs: &info.Doc{Markdown: md}, }, }, } @@ -391,14 +391,14 @@ This is some intentionally broken HCL that should not convert. }, }, } - pi := tfbridge.ProviderInfo{ + pi := info.Provider{ P: shimv2.NewProvider(p), Name: "aws", Version: "0.0.1", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "aws_launch_template": { Tok: "aws:index:LaunchTemplate", - Docs: &tfbridge.DocInfo{Markdown: md}, + Docs: &info.Doc{Markdown: md}, }, }, } diff --git a/pkg/tfgen/docs.go b/pkg/tfgen/docs.go index 928568f17..a2563bd11 100644 --- a/pkg/tfgen/docs.go +++ b/pkg/tfgen/docs.go @@ -182,14 +182,14 @@ func formatEntityName(rawname string) string { // getDocsForResource extracts documentation details for the given package from // TF website documentation markdown content func getDocsForResource(g *Generator, source DocsSource, kind DocKind, - rawname string, info tfbridge.ResourceOrDataSourceInfo, + rawname string, resourceInfo info.ResourceOrDataSource, ) (entityDocs, error) { if g.skipDocs { return entityDocs{}, nil } - var docInfo *tfbridge.DocInfo - if info != nil { - docInfo = info.GetDocs() + var docInfo *info.Doc + if resourceInfo != nil { + docInfo = resourceInfo.GetDocs() } var docFile *DocFile @@ -217,7 +217,7 @@ func getDocsForResource(g *Generator, source DocsSource, kind DocKind, if docFile == nil { entitiesMissingDocs++ msg := fmt.Sprintf("could not find docs for %v %v. Override the Docs property in the %v mapping. See "+ - "type tfbridge.DocInfo for details.", kind, formatEntityName(rawname), kind) + "type info.Doc for details.", kind, formatEntityName(rawname), kind) if cmdutil.IsTruthy(os.Getenv("PULUMI_MISSING_DOCS_ERROR")) { if docInfo == nil || !docInfo.AllowMissing { @@ -236,7 +236,7 @@ func getDocsForResource(g *Generator, source DocsSource, kind DocKind, markdownBytes, markdownFileName := docFile.Content, docFile.FileName - doc, err := parseTFMarkdown(g, info, kind, markdownBytes, markdownFileName, rawname) + doc, err := parseTFMarkdown(g, resourceInfo, kind, markdownBytes, markdownFileName, rawname) if err != nil { return entityDocs{}, err } @@ -458,12 +458,12 @@ func splitStringsAtIndexes(s string, splits []int) []string { // parseTFMarkdown takes a TF website markdown doc and extracts a structured representation for use in // generating doc comments -func parseTFMarkdown(g *Generator, info tfbridge.ResourceOrDataSourceInfo, kind DocKind, +func parseTFMarkdown(g *Generator, resourceInfo info.ResourceOrDataSource, kind DocKind, markdown []byte, markdownFileName, rawname string, ) (entityDocs, error) { p := &tfMarkdownParser{ sink: g, - info: info, + info: resourceInfo, kind: kind, markdownFileName: markdownFileName, rawname: rawname, @@ -486,7 +486,7 @@ type diagsSink interface { type tfMarkdownParser struct { sink diagsSink - info tfbridge.ResourceOrDataSourceInfo + info info.ResourceOrDataSource kind DocKind markdownFileName string rawname string @@ -1774,7 +1774,7 @@ func (g *Generator) convert( SkipResourceTypechecking: true, }) - return + return files, diags, err } func (g *Generator) legacyConvert( @@ -2154,7 +2154,7 @@ const elidedDocComment = "" type infoContext struct { language Language pkg tokens.Package - info tfbridge.ProviderInfo + info info.Provider } type spanValues struct { diff --git a/pkg/tfgen/docs_test.go b/pkg/tfgen/docs_test.go index 2e02f7301..c1ddcc8a6 100644 --- a/pkg/tfgen/docs_test.go +++ b/pkg/tfgen/docs_test.go @@ -37,7 +37,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen/internal/testprovider" ) @@ -82,9 +82,9 @@ func TestReformatText(t *testing.T) { infoCtx := infoContext{ pkg: "google", language: "nodejs", - info: tfbridge.ProviderInfo{ + info: info.Provider{ Name: "google", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "google_container_node_pool": {Tok: "google:container/nodePool:NodePool"}, }, }, @@ -1939,7 +1939,7 @@ func TestParseImports_WithOverride(t *testing.T) { t.Parallel() parser := tfMarkdownParser{ info: &mockResource{ - docs: tfbridge.DocInfo{ + docs: info.Doc{ ImportDetails: "overridden import details", }, }, @@ -2030,16 +2030,16 @@ func TestConvertExamples(t *testing.T) { t.Run(tc.name, func(t *testing.T) { inmem := afero.NewMemMapFs() - info := testprovider.ProviderMiniRandom() + providerInfo := testprovider.ProviderMiniRandom() language := Schema if tc.language != nil { language = *tc.language } g, err := NewGenerator(GeneratorOptions{ - Package: info.Name, - Version: info.Version, + Package: providerInfo.Name, + Version: providerInfo.Version, Language: language, - ProviderInfo: info, + ProviderInfo: providerInfo, Root: inmem, Sink: diag.DefaultSink(io.Discard, io.Discard, diag.FormatOptions{ Color: colors.Never, @@ -2072,12 +2072,12 @@ func TestConvertExamplesInner(t *testing.T) { } inmem := afero.NewMemMapFs() - info := testprovider.ProviderMiniRandom() + providerInfo := testprovider.ProviderMiniRandom() g, err := NewGenerator(GeneratorOptions{ - Package: info.Name, - Version: info.Version, + Package: providerInfo.Name, + Version: providerInfo.Version, Language: Schema, - ProviderInfo: info, + ProviderInfo: providerInfo, Root: inmem, Sink: diag.DefaultSink(io.Discard, io.Discard, diag.FormatOptions{ Color: colors.Never, @@ -2133,12 +2133,12 @@ func TestFalsePositiveCodeFences(t *testing.T) { t.Parallel() inmem := afero.NewMemMapFs() - info := testprovider.ProviderMiniRandom() + providerInfo := testprovider.ProviderMiniRandom() g, err := NewGenerator(GeneratorOptions{ - Package: info.Name, - Version: info.Version, + Package: providerInfo.Name, + Version: providerInfo.Version, Language: Schema, - ProviderInfo: info, + ProviderInfo: providerInfo, Root: inmem, Sink: diag.DefaultSink(io.Discard, io.Discard, diag.FormatOptions{ Color: colors.Never, @@ -2167,12 +2167,12 @@ func TestSkipLastCodeFenceAfterError(t *testing.T) { t.Parallel() inmem := afero.NewMemMapFs() - info := testprovider.ProviderMiniRandom() + providerInfo := testprovider.ProviderMiniRandom() g, err := NewGenerator(GeneratorOptions{ - Package: info.Name, - Version: info.Version, + Package: providerInfo.Name, + Version: providerInfo.Version, Language: Schema, - ProviderInfo: info, + ProviderInfo: providerInfo, Root: inmem, Sink: diag.DefaultSink(io.Discard, io.Discard, diag.FormatOptions{ Color: colors.Never, @@ -2294,7 +2294,7 @@ func TestFindFencesAndHeaders(t *testing.T) { func TestExampleGeneration(t *testing.T) { t.Parallel() - info := testprovider.ProviderMiniRandom() + providerInfo := testprovider.ProviderMiniRandom() markdown := []byte(` ## Examples @@ -2308,17 +2308,17 @@ throw new Exception("!"); markdown = bytes.ReplaceAll(markdown, []byte("~~~"), []byte("```")) - info.Resources["random_integer"].Docs = &tfbridge.DocInfo{ + providerInfo.Resources["random_integer"].Docs = &info.Doc{ Markdown: markdown, } inmem := afero.NewMemMapFs() g, err := NewGenerator(GeneratorOptions{ - Package: info.Name, - Version: info.Version, + Package: providerInfo.Name, + Version: providerInfo.Version, Language: Schema, - ProviderInfo: info, + ProviderInfo: providerInfo, Root: inmem, Sink: diag.DefaultSink(io.Discard, io.Discard, diag.FormatOptions{ Color: colors.Never, @@ -2348,8 +2348,8 @@ func TestParseTFMarkdown(t *testing.T) { // `name`. name string - info tfbridge.ResourceOrDataSourceInfo - providerInfo tfbridge.ProviderInfo + info info.ResourceOrDataSource + providerInfo info.Provider kind DocKind rawName string @@ -2374,14 +2374,14 @@ func TestParseTFMarkdown(t *testing.T) { } editRule := func(edit func(string, []byte) ([]byte, error)) func(*testCase) { - rule := tfbridge.DocsEdit{ + rule := info.DocsEdit{ Path: "*", Edit: edit, } return func(tc *testCase) { - tc.providerInfo.DocRules = &tfbridge.DocRuleInfo{ - EditRules: func(defaults []tfbridge.DocsEdit) []tfbridge.DocsEdit { - return append([]tfbridge.DocsEdit{rule}, defaults...) + tc.providerInfo.DocRules = &info.DocRule{ + EditRules: func(defaults []info.DocsEdit) []info.DocsEdit { + return append([]info.DocsEdit{rule}, defaults...) }, } } @@ -2414,7 +2414,7 @@ This should be interpolated in. return nil, fmt.Errorf("invalid path %q", name) } } - tc.info = &tfbridge.ResourceInfo{Docs: &tfbridge.DocInfo{ + tc.info = &info.Resource{Docs: &info.Doc{ ReplaceExamplesSection: true, }} }), @@ -2460,7 +2460,7 @@ This should be interpolated in. func TestErrorMissingDocs(t *testing.T) { tests := []struct { - docs tfbridge.DocInfo + docs info.Doc forbidMissingDocsEnv string source DocsSource expectErr bool @@ -2486,7 +2486,7 @@ func TestErrorMissingDocs(t *testing.T) { // override locally, so no error { source: mockSource{}, - docs: tfbridge.DocInfo{AllowMissing: true}, + docs: info.Doc{AllowMissing: true}, forbidMissingDocsEnv: "true", }, // DocInfo is nil so we error because docs are missing @@ -2525,15 +2525,15 @@ func TestErrorNilDocs(t *testing.T) { } rawName := "nil_docs" t.Setenv("PULUMI_MISSING_DOCS_ERROR", "true") - info := mockNilDocsResource{token: tokens.Token(rawName)} - _, err := getDocsForResource(g, mockSource{}, ResourceDocs, rawName, &info) + providerInfo := mockNilDocsResource{token: tokens.Token(rawName)} + _, err := getDocsForResource(g, mockSource{}, ResourceDocs, rawName, &providerInfo) assert.NotNil(t, err) }) } type mockSource map[string]string -func (m mockSource) getResource(rawname string, info *tfbridge.DocInfo) (*DocFile, error) { +func (m mockSource) getResource(rawname string, info *info.Doc) (*DocFile, error) { f, ok := m[rawname] if !ok { return nil, nil @@ -2544,11 +2544,11 @@ func (m mockSource) getResource(rawname string, info *tfbridge.DocInfo) (*DocFil }, nil } -func (m mockSource) getDatasource(rawname string, info *tfbridge.DocInfo) (*DocFile, error) { +func (m mockSource) getDatasource(rawname string, info *info.Doc) (*DocFile, error) { return nil, nil } -func (m mockSource) getInstallation(info *tfbridge.DocInfo) (*DocFile, error) { +func (m mockSource) getInstallation(info *info.Doc) (*DocFile, error) { f, ok := m["index.md"] if !ok { return nil, nil @@ -2576,19 +2576,19 @@ func (mockSink) Stringify(sev diag.Severity, diag *diag.Diag, args ...interface{ } type mockResource struct { - docs tfbridge.DocInfo + docs info.Doc token tokens.Token } -func (r *mockResource) GetFields() map[string]*tfbridge.SchemaInfo { - return map[string]*tfbridge.SchemaInfo{} +func (r *mockResource) GetFields() map[string]*info.Schema { + return map[string]*info.Schema{} } func (r *mockResource) ReplaceExamplesSection() bool { return r.docs.ReplaceExamplesSection } -func (r *mockResource) GetDocs() *tfbridge.DocInfo { +func (r *mockResource) GetDocs() *info.Doc { return &r.docs } @@ -2601,7 +2601,7 @@ type mockNilDocsResource struct { mockResource } -func (nr *mockNilDocsResource) GetDocs() *tfbridge.DocInfo { +func (nr *mockNilDocsResource) GetDocs() *info.Doc { return nil } @@ -2764,8 +2764,8 @@ func TestFixupPropertyReference(t *testing.T) { expected: "Use the `random.RandomPet` resource to generate pet names.", ctx: infoContext{ pkg: "random", - info: tfbridge.ProviderInfo{ - Resources: map[string]*tfbridge.ResourceInfo{ + info: info.Provider{ + Resources: map[string]*info.Resource{ "random_pet": {Tok: "random:index/randomPet:RandomPet"}, }, }, @@ -2777,8 +2777,8 @@ func TestFixupPropertyReference(t *testing.T) { expected: "Use the `random.RandomId` data source to get random IDs.", ctx: infoContext{ pkg: "random", - info: tfbridge.ProviderInfo{ - DataSources: map[string]*tfbridge.DataSourceInfo{ + info: info.Provider{ + DataSources: map[string]*info.DataSource{ "random_id": {Tok: "random:index/randomId:RandomId"}, }, }, @@ -2790,7 +2790,7 @@ func TestFixupPropertyReference(t *testing.T) { expected: "The `length` property controls the output length.", ctx: infoContext{ pkg: "random", - info: tfbridge.ProviderInfo{}, + info: info.Provider{}, }, }, { @@ -2799,7 +2799,7 @@ func TestFixupPropertyReference(t *testing.T) { expected: "The length must also be greater than `min_upper`.", ctx: infoContext{ pkg: "random", - info: tfbridge.ProviderInfo{}, + info: info.Provider{}, }, }, { @@ -2808,8 +2808,8 @@ func TestFixupPropertyReference(t *testing.T) { expected: "Use random.RandomPet resource to generate pet names.", ctx: infoContext{ pkg: "random", - info: tfbridge.ProviderInfo{ - Resources: map[string]*tfbridge.ResourceInfo{ + info: info.Provider{ + Resources: map[string]*info.Resource{ "random_pet": {Tok: "random:index/randomPet:RandomPet"}, }, }, @@ -2821,11 +2821,11 @@ func TestFixupPropertyReference(t *testing.T) { expected: "Use `random.RandomPet` and `random.RandomId` together.", ctx: infoContext{ pkg: "random", - info: tfbridge.ProviderInfo{ - Resources: map[string]*tfbridge.ResourceInfo{ + info: info.Provider{ + Resources: map[string]*info.Resource{ "random_pet": {Tok: "random:index/randomPet:RandomPet"}, }, - DataSources: map[string]*tfbridge.DataSourceInfo{ + DataSources: map[string]*info.DataSource{ "random_id": {Tok: "random:index/randomId:RandomId"}, }, }, @@ -2837,8 +2837,8 @@ func TestFixupPropertyReference(t *testing.T) { expected: "Use random.RandomPet resource to generate pet names.", ctx: infoContext{ pkg: "random", - info: tfbridge.ProviderInfo{ - Resources: map[string]*tfbridge.ResourceInfo{ + info: info.Provider{ + Resources: map[string]*info.Resource{ "random_pet": {Tok: "random:index/randomPet:RandomPet"}, }, }, diff --git a/pkg/tfgen/edit_rules.go b/pkg/tfgen/edit_rules.go index 7f8c8aa37..f32722674 100644 --- a/pkg/tfgen/edit_rules.go +++ b/pkg/tfgen/edit_rules.go @@ -20,7 +20,6 @@ import ( "path/filepath" "regexp" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) @@ -82,7 +81,7 @@ func defaultEditRules() editRules { } } -type editRules []tfbridge.DocsEdit +type editRules []info.DocsEdit func (rr editRules) apply(fileName string, contents []byte, phase info.EditPhase) ([]byte, error) { for _, rule := range rr { @@ -105,7 +104,7 @@ func (rr editRules) apply(fileName string, contents []byte, phase info.EditPhase // // getEditRules is only called once during `tfgen`, so we move the cost of compiling // regexes into getEditRules, avoiding a marginal startup time penalty. -func getEditRules(info *tfbridge.DocRuleInfo) editRules { +func getEditRules(info *info.DocRule) editRules { defaults := defaultEditRules() if info == nil || info.EditRules == nil { return defaults @@ -116,10 +115,10 @@ func getEditRules(info *tfbridge.DocRuleInfo) editRules { // Create a regexp based replace rule that is bounded by non-ascii letter text. // // This function is not appropriate to be called in hot loops. -func boundedReplace(from, to string) tfbridge.DocsEdit { +func boundedReplace(from, to string) info.DocsEdit { r := regexp.MustCompile(fmt.Sprintf(`([^a-zA-Z]|^)%s([^a-zA-Z]|$)`, from)) bTo := []byte(fmt.Sprintf("${1}%s${%d}", to, r.NumSubexp())) - return tfbridge.DocsEdit{ + return info.DocsEdit{ Path: "*", Edit: func(_ string, content []byte) ([]byte, error) { return r.ReplaceAll(content, bTo), nil @@ -128,10 +127,10 @@ func boundedReplace(from, to string) tfbridge.DocsEdit { } // reReplace creates a regex based replace. -func reReplace(from, to string, phase info.EditPhase) tfbridge.DocsEdit { +func reReplace(from, to string, phase info.EditPhase) info.DocsEdit { r := regexp.MustCompile(from) bTo := []byte(to) - return tfbridge.DocsEdit{ + return info.DocsEdit{ Path: "*", Edit: func(_ string, content []byte) ([]byte, error) { return r.ReplaceAll(content, bTo), nil @@ -140,7 +139,7 @@ func reReplace(from, to string, phase info.EditPhase) tfbridge.DocsEdit { } } -func fixupImports() tfbridge.DocsEdit { +func fixupImports() info.DocsEdit { inlineImportRegexp := regexp.MustCompile("% [tT]erraform import.*") quotedImportRegexp := regexp.MustCompile("`[tT]erraform import`") @@ -148,7 +147,7 @@ func fixupImports() tfbridge.DocsEdit { blockImportRegexp := regexp.MustCompile("(?s)In [tT]erraform v[0-9]+\\.[0-9]+\\.[0-9]+ and later," + " use an `import` block.*?```.+?```\n") - return tfbridge.DocsEdit{ + return info.DocsEdit{ Path: "*", Edit: func(_ string, content []byte) ([]byte, error) { // Strip import blocks diff --git a/pkg/tfgen/edit_rules_test.go b/pkg/tfgen/edit_rules_test.go index 0fa953d25..0b5c8f169 100644 --- a/pkg/tfgen/edit_rules_test.go +++ b/pkg/tfgen/edit_rules_test.go @@ -7,7 +7,6 @@ import ( "github.com/stretchr/testify/require" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) @@ -333,7 +332,7 @@ func TestApplyCustomEditRules(t *testing.T) { expected: []byte("This provider has a horrific unreadable typo, which is now fixed"), edits: append( defaultEditRules(), - tfbridge.DocsEdit{ + info.DocsEdit{ Path: "testfile.md", Edit: func(_ string, content []byte) ([]byte, error) { return bytes.ReplaceAll( diff --git a/pkg/tfgen/examples_cache.go b/pkg/tfgen/examples_cache.go index 2fec4cf41..c68630c16 100644 --- a/pkg/tfgen/examples_cache.go +++ b/pkg/tfgen/examples_cache.go @@ -34,6 +34,7 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) const ( @@ -60,7 +61,7 @@ func (g *Generator) getOrCreateExamplesCache() *examplesCache { return g.examplesCache } -func newExamplesCache(info *tfbridge.ProviderInfo, cacheDir string) *examplesCache { +func newExamplesCache(info *info.Provider, cacheDir string) *examplesCache { providerName := info.Name dir := cacheDir enabled := true @@ -218,7 +219,7 @@ func (ec *examplesCache) filehash(p string) string { return ec.checksum(bytes) } -func (ec *examplesCache) computeProviderInfoHash(info *tfbridge.ProviderInfo) { +func (ec *examplesCache) computeProviderInfoHash(info *info.Provider) { mpi := tfbridge.MarshalProviderInfo(info) bytes, err := json.Marshal(mpi) contract.AssertNoErrorf(err, "failed to marshal MarshallableProviderInfo to JSON") diff --git a/pkg/tfgen/examples_cache_test.go b/pkg/tfgen/examples_cache_test.go index 977c15d8b..bb5c8a79c 100644 --- a/pkg/tfgen/examples_cache_test.go +++ b/pkg/tfgen/examples_cache_test.go @@ -19,13 +19,13 @@ import ( "github.com/stretchr/testify/assert" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) func TestExamplesCache(t *testing.T) { t.Parallel() - exInfo := &tfbridge.ProviderInfo{ + exInfo := &info.Provider{ Name: "ex", Version: "0.0.1", } diff --git a/pkg/tfgen/generate.go b/pkg/tfgen/generate.go index 6eb29d07a..4d71e81a6 100644 --- a/pkg/tfgen/generate.go +++ b/pkg/tfgen/generate.go @@ -47,6 +47,7 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tf2pulumi/il" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen/internal/paths" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/schema" @@ -62,7 +63,7 @@ type Generator struct { pkg tokens.Package // the Pulumi package name (e.g. `gcp`) version string // the package version. language Language // the language runtime to generate. - info tfbridge.ProviderInfo // the provider info for customizing code generation + info info.Provider // the provider info for customizing code generation root afero.Fs // the output virtual filesystem. providerShim *inmemoryProvider // a provider shim to hold the provider schema during example conversion. pluginHost plugin.Host // the plugin host for tf2pulumi. @@ -214,7 +215,7 @@ func runPulumiPackageGenSDK( return dirToBytesMap(fs, filepath.Join(outDir, string(l))) } -func (l Language) emitSDK(pkg *pschema.Package, info tfbridge.ProviderInfo, root afero.Fs, +func (l Language) emitSDK(pkg *pschema.Package, info info.Provider, root afero.Fs, ) (map[string][]byte, error) { var extraFiles map[string][]byte var err error @@ -468,25 +469,25 @@ func (g *Generator) Sink() diag.Sink { } func (g *Generator) makePropertyType(typePath paths.TypePath, - objectName string, sch shim.Schema, info *tfbridge.SchemaInfo, out bool, + objectName string, sch shim.Schema, schemaInfo *info.Schema, out bool, entityDocs entityDocs, ) (*propertyType, error) { t := &propertyType{} - if info != nil { - t.typeName = info.TypeName + if schemaInfo != nil { + t.typeName = schemaInfo.TypeName } - var elemInfo *tfbridge.SchemaInfo - if info != nil { - t.typ = info.Type - t.nestedType = info.NestedType - t.altTypes = info.AltTypes - t.asset = info.Asset - elemInfo = info.Elem + var elemInfo *info.Schema + if schemaInfo != nil { + t.typ = schemaInfo.Type + t.nestedType = schemaInfo.NestedType + t.altTypes = schemaInfo.AltTypes + t.asset = schemaInfo.Asset + elemInfo = schemaInfo.Elem } if sch == nil { - contract.Assertf(info != nil, "missing info when sch is nil on type: %s", typePath.String()) + contract.Assertf(schemaInfo != nil, "missing info when sch is nil on type: %s", typePath.String()) return t, nil } @@ -517,7 +518,7 @@ func (g *Generator) makePropertyType(typePath paths.TypePath, } // IsMaxItemOne lists and sets are flattened, transforming List[T] or Set[T] to T. Detect if this is the case. - flatten := tfbridge.IsMaxItemsOne(sch, info) + flatten := tfbridge.IsMaxItemsOne(sch, schemaInfo) // The remaining cases are collections, List[T], Set[T] or Map[T], and recursion needs NewElementPath except for // flattening that stays at the current path. @@ -576,35 +577,35 @@ func getDocsFromSchemaMap(key string, schemaMap shim.SchemaMap) string { } func (g *Generator) makeObjectPropertyType(typePath paths.TypePath, - res shim.Resource, info *tfbridge.SchemaInfo, + res shim.Resource, schemaInfo *info.Schema, out bool, entityDocs entityDocs, ) (*propertyType, error) { // If the user supplied an explicit Type token override, omit generating types and short-circuit. - if info != nil && info.OmitType { - if info.Type == "" { + if schemaInfo != nil && schemaInfo.OmitType { + if schemaInfo.Type == "" { return nil, fmt.Errorf("Cannot set info.OmitType without also setting info.Type") } - return &propertyType{typ: info.Type}, nil + return &propertyType{typ: schemaInfo.Type}, nil } t := &propertyType{ kind: kindObject, } - if info != nil { - t.typeName = info.TypeName + if schemaInfo != nil { + t.typeName = schemaInfo.TypeName } - if info != nil { - t.typ = info.Type - t.nestedType = info.NestedType - t.altTypes = info.AltTypes - t.asset = info.Asset + if schemaInfo != nil { + t.typ = schemaInfo.Type + t.nestedType = schemaInfo.NestedType + t.altTypes = schemaInfo.AltTypes + t.asset = schemaInfo.Asset } - var propertyInfos map[string]*tfbridge.SchemaInfo - if info != nil { - propertyInfos = info.Fields + var propertyInfos map[string]*info.Schema + if schemaInfo != nil { + propertyInfos = schemaInfo.Fields } // Look up the parent path and prepend it to the docs path, to allow for precise lookup in the entityDocs. @@ -739,7 +740,7 @@ type variable struct { rawdoc string schema shim.Schema - info *tfbridge.SchemaInfo + info *info.Schema typ *propertyType @@ -780,7 +781,7 @@ func (v *variable) forceNew() bool { // optional checks whether the given property is optional, either due to Terraform or an overlay. func (v *variable) optional() bool { return v.opt || isOptional(v.info, v.schema, v.out, v.config) } -func isOptional(info *tfbridge.SchemaInfo, schema shim.Schema, out bool, config bool) bool { +func isOptional(info *info.Schema, schema shim.Schema, out bool, config bool) bool { // if we have an explicit marked as optional then let's return that if info != nil && info.MarkAsOptional != nil { return *info.MarkAsOptional @@ -808,7 +809,7 @@ type resourceType struct { argst *propertyType // input properties. statet *propertyType // output properties (all optional). schema shim.Resource - info *tfbridge.ResourceInfo + info *info.Resource entityDocs entityDocs // parsed docs. resourcePath *paths.ResourcePath @@ -826,7 +827,7 @@ func (rt *resourceType) TypeToken() tokens.Type { func newResourceType(resourcePath *paths.ResourcePath, mod tokens.Module, name tokens.TypeName, entityDocs entityDocs, - schema shim.Resource, info *tfbridge.ResourceInfo, + schema shim.Resource, info *info.Resource, isProvider bool, ) *resourceType { // We want to add the import details to the description so we can display those for the user @@ -859,7 +860,7 @@ type resourceFunc struct { argst *propertyType retst *propertyType schema shim.Resource - info *tfbridge.DataSourceInfo + info *info.DataSource entityDocs entityDocs dataSourcePath *paths.DataSourcePath } @@ -881,7 +882,7 @@ func (of *overlayFile) Name() string { return of.name } func (of *overlayFile) Doc() string { return "" } func (of *overlayFile) Copy() bool { return of.src != "" } -func GenerateSchema(info tfbridge.ProviderInfo, sink diag.Sink) (pschema.PackageSpec, error) { +func GenerateSchema(info info.Provider, sink diag.Sink) (pschema.PackageSpec, error) { res, err := GenerateSchemaWithOptions(GenerateSchemaOptions{ ProviderInfo: info, DiagnosticsSink: sink, @@ -893,7 +894,7 @@ func GenerateSchema(info tfbridge.ProviderInfo, sink diag.Sink) (pschema.Package } type GenerateSchemaOptions struct { - ProviderInfo tfbridge.ProviderInfo + ProviderInfo info.Provider DiagnosticsSink diag.Sink XInMemoryDocs bool } @@ -926,7 +927,7 @@ type GeneratorOptions struct { Package string Version string Language Language - ProviderInfo tfbridge.ProviderInfo + ProviderInfo info.Provider Root afero.Fs ProviderInfoSource il.ProviderInfoSource PluginHost plugin.Host @@ -1392,7 +1393,7 @@ func (g *Generator) gatherConfig() (*module, error) { } // Now, if there are any extra config variables, that are Pulumi-only, add them. - extraConfigInfo := map[string]*tfbridge.SchemaInfo{} + extraConfigInfo := map[string]*info.Schema{} extraConfigMap := schema.SchemaMap{} for key, val := range g.info.ExtraConfig { extraConfigInfo[key] = val.Info @@ -1418,11 +1419,11 @@ func (g *Generator) gatherProvider() (*resourceType, error) { if cfg == nil { cfg = schema.SchemaMap{} } - info := &tfbridge.ResourceInfo{ + resourceInfo := &info.Resource{ Tok: tokens.Type(g.pkg.String()), Fields: g.info.Config, } - res, err := g.gatherResource("", (&schema.Resource{Schema: cfg}).Shim(), info, true) + res, err := g.gatherResource("", (&schema.Resource{Schema: cfg}).Shim(), resourceInfo, true) return res, err } @@ -1506,7 +1507,7 @@ func (g *Generator) gatherResources() (moduleMap, error) { // gatherResource returns the module name and one or more module members to represent the given resource. func (g *Generator) gatherResource(rawname string, - schema shim.Resource, info *tfbridge.ResourceInfo, isProvider bool, + schema shim.Resource, info *info.Resource, isProvider bool, ) (*resourceType, error) { // Get the resource's module and name. name, moduleName := resourceName(g.info.Name, rawname, info, isProvider) @@ -1709,16 +1710,16 @@ func (g *Generator) gatherDataSources() (moduleMap, error) { // gatherDataSource returns the module name and members for the given data source function. func (g *Generator) gatherDataSource(rawname string, - ds shim.Resource, info *tfbridge.DataSourceInfo, + ds shim.Resource, sourceInfo *info.DataSource, ) (*resourceFunc, error) { // Generate the name and module for this data source. - name, moduleName := dataSourceName(g.info.Name, rawname, info) + name, moduleName := dataSourceName(g.info.Name, rawname, sourceInfo) mod := tokens.NewModuleToken(g.pkg, moduleName) dataSourcePath := paths.NewDataSourcePath(rawname, tokens.NewModuleMemberToken(mod, name)) // Collect documentation information for this data source. source := NewGitRepoDocsSource(g) - entityDocs, err := getDocsForResource(g, source, DataSourceDocs, rawname, info) + entityDocs, err := getDocsForResource(g, source, DataSourceDocs, rawname, sourceInfo) if err != nil && !g.checkNoDocsError(err) { return nil, err } @@ -1730,7 +1731,7 @@ func (g *Generator) gatherDataSource(rawname string, doc: entityDocs.Description, reqargs: make(map[string]bool), schema: ds, - info: info, + info: sourceInfo, entityDocs: entityDocs, dataSourcePath: dataSourcePath, } @@ -1741,7 +1742,7 @@ func (g *Generator) gatherDataSource(rawname string, if sch.Removed() != "" { continue } - cust := info.Fields[arg] + cust := sourceInfo.Fields[arg] // Remember detailed information for every input arg (we will use it below). if input(sch, cust) { @@ -1754,7 +1755,7 @@ func (g *Generator) gatherDataSource(rawname string, } argvar, err := g.propertyVariable(dataSourcePath.Args(), - arg, ds.Schema(), info.Fields, doc, "", false /*out*/, entityDocs) + arg, ds.Schema(), sourceInfo.Fields, doc, "", false /*out*/, entityDocs) if err != nil { return nil, err } @@ -1768,7 +1769,7 @@ func (g *Generator) gatherDataSource(rawname string, // Also remember properties for the resulting return data structure. // Emit documentation for the property if available - p, err := g.propertyVariable(dataSourcePath.Results(), arg, ds.Schema(), info.Fields, + p, err := g.propertyVariable(dataSourcePath.Results(), arg, ds.Schema(), sourceInfo.Fields, entityDocs.Attributes[arg], "", true /*out*/, entityDocs) if err != nil { return nil, err @@ -1781,7 +1782,7 @@ func (g *Generator) gatherDataSource(rawname string, // If the data source's schema doesn't expose an id property, make one up since we'd like to expose it for data // sources. if id, has := ds.Schema().GetOk("id"); !has || id.Removed() != "" { - cust := map[string]*tfbridge.SchemaInfo{"id": {}} + cust := map[string]*info.Schema{"id": {}} rawdoc := "The provider-assigned unique ID for this managed resource." idSchema := schema.SchemaMap(map[string]shim.Schema{ "id": (&schema.Schema{Type: shim.TypeString, Computed: true}).Shim(), @@ -1822,7 +1823,7 @@ func (g *Generator) gatherOverlays() (moduleMap, error) { modules := make(moduleMap) // Pluck out the overlay info from the right structure. This is language dependent. - var overlay *tfbridge.OverlayInfo + var overlay *info.Overlay switch g.language { case NodeJS: if jsinfo := g.info.JavaScript; jsinfo != nil { @@ -1901,13 +1902,13 @@ The original error is: %s` correction = fmt.Sprintf(` The upstream repository path has been overridden, but the specified path is invalid. You should check the value of: -tfbridge.ProviderInfo{ +info.Provider{ UpstreamRepoPath: %q, }`, g.info.UpstreamRepoPath) } else { correction = fmt.Sprintf(` If the expected path is not correct, you should check the values of these fields (current values shown): -tfbridge.ProviderInfo{ +info.Provider{ GitHubHost: %q, GitHubOrg: %q, Name: %q, @@ -1932,7 +1933,7 @@ func (g *Generator) emitProjectMetadata(name tokens.Package, language Language) } // input checks whether the given property is supplied by the user (versus being always computed). -func input(sch shim.Schema, info *tfbridge.SchemaInfo) bool { +func input(sch shim.Schema, info *info.Schema) bool { return (sch.Optional() || sch.Required()) && (info == nil || info.MarkAsComputedOnly == nil || !*info.MarkAsComputedOnly) } @@ -1942,7 +1943,7 @@ func input(sch shim.Schema, info *tfbridge.SchemaInfo) bool { // // would need to understand how to unmarshal names in a language-idiomatic way (and specifically reverse the // name transformation process). This isn't impossible, but certainly complicates matters. -func propertyName(key string, sch shim.SchemaMap, custom map[string]*tfbridge.SchemaInfo) string { +func propertyName(key string, sch shim.SchemaMap, custom map[string]*info.Schema) string { // BUGBUG: work around issue in the Elastic Transcoder where a field has a trailing ":". key = strings.TrimSuffix(key, ":") return tfbridge.TerraformToPulumiNameV2(key, sch, custom) @@ -1954,10 +1955,10 @@ func propertyName(key string, sch shim.SchemaMap, custom map[string]*tfbridge.Sc // // parentPath together with key uniquely locates the property in the Terraform schema. func (g *Generator) propertyVariable(parentPath paths.TypePath, key string, - schemaMap shim.SchemaMap, info map[string]*tfbridge.SchemaInfo, + schemaMap shim.SchemaMap, schemaInfo map[string]*info.Schema, doc string, rawdoc string, out bool, entityDocs entityDocs, ) (*variable, error) { - if name := propertyName(key, schemaMap, info); name != "" { + if name := propertyName(key, schemaMap, schemaInfo); name != "" { propName := paths.PropertyName{Key: key, Name: tokens.Name(name)} typePath := paths.NewProperyPath(parentPath, propName) @@ -1969,21 +1970,21 @@ func (g *Generator) propertyVariable(parentPath paths.TypePath, key string, // TODO[pulumi/pulumi-terraform-bridge#2938] remove when the bridge fully supports write-only fields. if shimSchema.WriteOnly() { - if info == nil { - info = make(map[string]*tfbridge.SchemaInfo) + if schemaInfo == nil { + schemaInfo = make(map[string]*info.Schema) } - if val, ok := info[key]; ok { + if val, ok := schemaInfo[key]; ok { val.Omit = true } else { - info[key] = &tfbridge.SchemaInfo{ + schemaInfo[key] = &info.Schema{ Omit: true, } } } - var varInfo *tfbridge.SchemaInfo - if info != nil { - varInfo = info[key] + var varInfo *info.Schema + if schemaInfo != nil { + varInfo = schemaInfo[key] } // If a variable is marked as omitted, omit it. @@ -2021,7 +2022,7 @@ func (g *Generator) propertyVariable(parentPath paths.TypePath, key string, // dataSourceName translates a Terraform name into its Pulumi name equivalent. func dataSourceName(provider string, rawname string, - info *tfbridge.DataSourceInfo, + info *info.DataSource, ) (tokens.ModuleMemberName, tokens.ModuleName) { if info == nil || info.Tok == "" { // default transformations. @@ -2035,7 +2036,7 @@ func dataSourceName(provider string, rawname string, // resourceName translates a Terraform name into its Pulumi name equivalent, plus a module name. func resourceName(provider string, rawname string, - info *tfbridge.ResourceInfo, isProvider bool, + info *info.Resource, isProvider bool, ) (tokens.TypeName, tokens.ModuleName) { if isProvider { return "Provider", indexMod @@ -2095,7 +2096,7 @@ func upperFirst(s string) string { return string(unicode.ToUpper(c)) + s[rest:] } -func generateManifestDescription(info tfbridge.ProviderInfo) string { +func generateManifestDescription(info info.Provider) string { if info.TFProviderVersion == "" { return info.Description } @@ -2104,7 +2105,7 @@ func generateManifestDescription(info tfbridge.ProviderInfo) string { info.TFProviderVersion) } -func getLicenseTypeURL(license tfbridge.TFProviderLicense) string { +func getLicenseTypeURL(license info.TFProviderLicense) string { switch license { case tfbridge.MITLicenseType: return "https://mit-license.org/" @@ -2120,7 +2121,7 @@ func getLicenseTypeURL(license tfbridge.TFProviderLicense) string { } } -func getOverlayFilesImpl(overlay *tfbridge.OverlayInfo, extension string, +func getOverlayFilesImpl(overlay *info.Overlay, extension string, fs afero.Fs, srcRoot, dir string, files map[string][]byte, ) error { for _, f := range overlay.DestFiles { @@ -2151,7 +2152,7 @@ func getOverlayFilesImpl(overlay *tfbridge.OverlayInfo, extension string, return nil } -func getOverlayFiles(overlay *tfbridge.OverlayInfo, extension string, root afero.Fs) (map[string][]byte, error) { +func getOverlayFiles(overlay *info.Overlay, extension string, root afero.Fs) (map[string][]byte, error) { files := map[string][]byte{} if err := getOverlayFilesImpl(overlay, extension, root, "", "", files); err != nil { return nil, err diff --git a/pkg/tfgen/generate_schema.go b/pkg/tfgen/generate_schema.go index f3d28dc70..854523c28 100644 --- a/pkg/tfgen/generate_schema.go +++ b/pkg/tfgen/generate_schema.go @@ -43,6 +43,7 @@ import ( "golang.org/x/text/language" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen/internal/paths" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/x/muxer" "github.com/pulumi/pulumi-terraform-bridge/v3/unstable/metadata" @@ -55,7 +56,7 @@ const ( type schemaGenerator struct { pkg tokens.Package version string - info tfbridge.ProviderInfo + info info.Provider language Language } @@ -228,7 +229,7 @@ func rawMessage(v interface{}) pschema.RawMessage { } func genPulumiSchema( - pack *pkg, name tokens.Package, version string, info tfbridge.ProviderInfo, + pack *pkg, name tokens.Package, version string, info info.Provider, logSink diag.Sink, ) (pschema.PackageSpec, error) { g := &schemaGenerator{ @@ -526,7 +527,7 @@ func sinkHclDiagnostics(sink diag.Sink, diags hcl.Diagnostics) { } } -func javaLanguageExtensions(providerInfo *tfbridge.ProviderInfo) pschema.RawMessage { +func javaLanguageExtensions(providerInfo *info.Provider) pschema.RawMessage { // The definition is copied here to avoid linking the dependency in directly, see: // https://github.com/pulumi/pulumi-java/blob/main/pkg/codegen/java/package_info.go#L35C1-L108C1 type PackageInfo struct { @@ -539,7 +540,7 @@ func javaLanguageExtensions(providerInfo *tfbridge.ProviderInfo) pschema.RawMess } j := providerInfo.Java if j == nil { - j = &tfbridge.JavaInfo{} + j = &info.Java{} } info := &PackageInfo{ Packages: j.Packages, @@ -552,10 +553,10 @@ func javaLanguageExtensions(providerInfo *tfbridge.ProviderInfo) pschema.RawMess return rawMessage(info) } -func csharpLanguageExtensions(providerInfo *tfbridge.ProviderInfo) pschema.RawMessage { +func csharpLanguageExtensions(providerInfo *info.Provider) pschema.RawMessage { c := providerInfo.CSharp if c == nil { - c = &tfbridge.CSharpInfo{} + c = &info.CSharp{} } info := &csgen.CSharpPackageInfo{ Compatibility: tfbridge20, @@ -570,10 +571,10 @@ func csharpLanguageExtensions(providerInfo *tfbridge.ProviderInfo) pschema.RawMe return rawMessage(info) } -func goLanguageExtensions(providerInfo *tfbridge.ProviderInfo) pschema.RawMessage { +func goLanguageExtensions(providerInfo *info.Provider) pschema.RawMessage { g := providerInfo.Golang if g == nil { - g = &tfbridge.GolangInfo{} + g = &info.Golang{} } info := &gogen.GoPackageInfo{ ImportBasePath: g.ImportBasePath, @@ -596,10 +597,10 @@ func goLanguageExtensions(providerInfo *tfbridge.ProviderInfo) pschema.RawMessag return rawMessage(info) } -func pythonLanguageExtensions(providerInfo *tfbridge.ProviderInfo, readme string) pschema.RawMessage { +func pythonLanguageExtensions(providerInfo *info.Provider, readme string) pschema.RawMessage { p := providerInfo.Python if p == nil { - p = &tfbridge.PythonInfo{} + p = &info.Python{} } info := &pygen.PackageInfo{ Compatibility: tfbridge20, @@ -616,10 +617,10 @@ func pythonLanguageExtensions(providerInfo *tfbridge.ProviderInfo, readme string return rawMessage(info) } -func nodeLanguageExtensions(providerInfo *tfbridge.ProviderInfo, readme string) pschema.RawMessage { +func nodeLanguageExtensions(providerInfo *info.Provider, readme string) pschema.RawMessage { j := providerInfo.JavaScript if j == nil { - j = &tfbridge.JavaScriptInfo{} + j = &info.JavaScript{} } info := &tsgen.NodePackageInfo{ Compatibility: tfbridge20, @@ -644,7 +645,7 @@ func nodeLanguageExtensions(providerInfo *tfbridge.ProviderInfo, readme string) } func getDefaultReadme(pulumiPackageName tokens.Package, tfProviderShortName string, tfGitHubOrg string, - pulumiProvLicense tfbridge.TFProviderLicense, pulumiProvLicenseURI string, githubHost string, + pulumiProvLicense info.TFProviderLicense, pulumiProvLicenseURI string, githubHost string, sourceRepo string, ) string { //nolint:lll diff --git a/pkg/tfgen/generate_schema_test.go b/pkg/tfgen/generate_schema_test.go index 87d018eaf..c36fe2967 100644 --- a/pkg/tfgen/generate_schema_test.go +++ b/pkg/tfgen/generate_schema_test.go @@ -367,7 +367,7 @@ func TestNestedMaxItemsOne(t *testing.T) { // TestNestedTypeSingularization shows that we singularize types associated with list // properties. // -// The test also shows that we can override this behavior by setting [tfbridge.SchemaInfo.NestedType]. +// The test also shows that we can override this behavior by setting [info.Schema.NestedType]. // //nolint:lll // Long type names make it arduous to stay under the 120 char limit. func TestNestedTypeSingularization(t *testing.T) { @@ -400,7 +400,7 @@ func TestNestedTypeSingularization(t *testing.T) { actionParameters := provider.Resources["cloudflare_ruleset"].Fields["rules"].Elem.Fields["action_parameters"] actionParameters.MaxItemsOne = nil actionParameters.Elem.Fields["phases"].MaxItemsOne = nil - actionParameters.Elem.Fields["phases"].Elem = &tfbridge.SchemaInfo{NestedType: "RulesetRuleActionParameterPhases"} + actionParameters.Elem.Fields["phases"].Elem = &info.Schema{NestedType: "RulesetRuleActionParameterPhases"} } actual, err := GenerateSchema(provider, diag.DefaultSink(io.Discard, io.Discard, diag.FormatOptions{ Color: colors.Never, @@ -621,31 +621,31 @@ func TestPropagateLanguageOptions(t *testing.T) { require.Nil(t, provider.Golang) - provider.Golang = &tfbridge.GolangInfo{ + provider.Golang = &info.Golang{ RespectSchemaVersion: true, DisableFunctionOutputVersions: true, } require.Nil(t, provider.Python) - provider.Python = &tfbridge.PythonInfo{ + provider.Python = &info.Python{ RespectSchemaVersion: true, } require.Nil(t, provider.JavaScript) - provider.JavaScript = &tfbridge.JavaScriptInfo{ + provider.JavaScript = &info.JavaScript{ RespectSchemaVersion: true, } require.Nil(t, provider.CSharp) - provider.CSharp = &tfbridge.CSharpInfo{ + provider.CSharp = &info.CSharp{ RespectSchemaVersion: true, } require.Nil(t, provider.Java) - provider.Java = &tfbridge.JavaInfo{ + provider.Java = &info.Java{ BuildFiles: "gradle", } diff --git a/pkg/tfgen/generate_test.go b/pkg/tfgen/generate_test.go index aae27064c..e6e640a79 100644 --- a/pkg/tfgen/generate_test.go +++ b/pkg/tfgen/generate_test.go @@ -36,6 +36,7 @@ import ( bridgetesting "github.com/pulumi/pulumi-terraform-bridge/v3/internal/testing" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tf2pulumi/il" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen/internal/paths" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" shimschema "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/schema" @@ -67,7 +68,7 @@ func Test_DeprecationMessage(t *testing.T) { { name: "From Pulumi Resources File Overrides TF Schema", variable: &variable{ - info: &tfbridge.SchemaInfo{DeprecationMessage: "Pulumi says this is deprecated"}, + info: &info.Schema{DeprecationMessage: "Pulumi says this is deprecated"}, schema: shimv1.NewSchema(&schema.Schema{Deprecated: "Terraform says this is deprecated"}), }, expectedMessage: "Pulumi says this is deprecated", @@ -96,7 +97,7 @@ func Test_ForceNew(t *testing.T) { schema: shimv1.NewSchema(&schema.Schema{ Type: schema.TypeString, }), - info: &tfbridge.SchemaInfo{ + info: &info.Schema{ ForceNew: tfbridge.True(), }, }, @@ -308,7 +309,7 @@ func Test_makePropertyType(t *testing.T) { func Test_ProviderWithOmittedTypes(t *testing.T) { t.Parallel() - gen := func(t *testing.T, f func(*tfbridge.ResourceInfo)) pschema.PackageSpec { + gen := func(t *testing.T, f func(*info.Resource)) pschema.PackageSpec { strType := (&shimschema.Schema{Type: shim.TypeString}).Shim() nestedObj := (&shimschema.Schema{ Type: shim.TypeMap, @@ -344,7 +345,7 @@ func Test_ProviderWithOmittedTypes(t *testing.T) { Color: colors.Never, }) - res := &tfbridge.ResourceInfo{ + res := &info.Resource{ Tok: "test:index:Bar", } if f != nil { @@ -353,10 +354,10 @@ func Test_ProviderWithOmittedTypes(t *testing.T) { r, err := GenerateSchemaWithOptions(GenerateSchemaOptions{ DiagnosticsSink: nilSink, - ProviderInfo: tfbridge.ProviderInfo{ + ProviderInfo: info.Provider{ Name: "test", P: p, - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "test_res": res, }, }, @@ -373,8 +374,8 @@ func Test_ProviderWithOmittedTypes(t *testing.T) { }) t.Run("omit-top-level-prop", func(t *testing.T) { - spec := gen(t, func(info *tfbridge.ResourceInfo) { - info.Fields = map[string]*tfbridge.SchemaInfo{ + spec := gen(t, func(res *info.Resource) { + res.Fields = map[string]*info.Schema{ "obj": {Omit: true}, } }) @@ -384,11 +385,11 @@ func Test_ProviderWithOmittedTypes(t *testing.T) { }) t.Run("omit-nested-prop", func(t *testing.T) { - spec := gen(t, func(info *tfbridge.ResourceInfo) { - info.Fields = map[string]*tfbridge.SchemaInfo{ + spec := gen(t, func(res *info.Resource) { + res.Fields = map[string]*info.Schema{ "obj": { - Elem: &tfbridge.SchemaInfo{ - Fields: map[string]*tfbridge.SchemaInfo{ + Elem: &info.Schema{ + Fields: map[string]*info.Schema{ "nested": {Omit: true}, }, }, @@ -424,10 +425,10 @@ func TestBridgeOmitsWriteOnlyFields(t *testing.T) { }).Shim(), }, }).Shim() - resWO := &tfbridge.ResourceInfo{ + resWO := &info.Resource{ Tok: "test:index:WriteOnly", } - resNoWO := &tfbridge.ResourceInfo{ + resNoWO := &info.Resource{ Tok: "test:index:NoWriteOnly", } nilSink := diag.DefaultSink(io.Discard, io.Discard, diag.FormatOptions{ @@ -435,10 +436,10 @@ func TestBridgeOmitsWriteOnlyFields(t *testing.T) { }) schemaResult, err := GenerateSchemaWithOptions(GenerateSchemaOptions{ DiagnosticsSink: nilSink, - ProviderInfo: tfbridge.ProviderInfo{ + ProviderInfo: info.Provider{ Name: "test", P: p, - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "test_res_with_wo": resWO, "test_res_no_wo": resNoWO, }, @@ -467,7 +468,7 @@ func TestOmitWriteOnlyFieldsErrorWhenNotOptional(t *testing.T) { }).Shim(), }, }).Shim() - resWO := &tfbridge.ResourceInfo{ + resWO := &info.Resource{ Tok: "test:index:WriteOnly", } nilSink := diag.DefaultSink(io.Discard, io.Discard, diag.FormatOptions{ @@ -475,10 +476,10 @@ func TestOmitWriteOnlyFieldsErrorWhenNotOptional(t *testing.T) { }) _, err := GenerateSchemaWithOptions(GenerateSchemaOptions{ DiagnosticsSink: nilSink, - ProviderInfo: tfbridge.ProviderInfo{ + ProviderInfo: info.Provider{ Name: "test", P: p, - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "test_res_wo": resWO, }, }, @@ -771,10 +772,10 @@ func TestExtraMappingError(t *testing.T) { }) // Create provider info with mappings for existing resources and extra mappings that don't exist - infoWithResources := tfbridge.ProviderInfo{ + infoWithResources := info.Provider{ Name: "test", Version: "1.0.0", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "existing_resource": { Tok: tokens.Type("test:index:ExistingResource"), }, @@ -782,7 +783,7 @@ func TestExtraMappingError(t *testing.T) { Tok: tokens.Type("test:index:UnmappedResource"), }, }, - DataSources: map[string]*tfbridge.DataSourceInfo{ + DataSources: map[string]*info.DataSource{ "existing_datasource": { Tok: tokens.ModuleMember("test:index:existingDatasource"), }, @@ -792,15 +793,15 @@ func TestExtraMappingError(t *testing.T) { // Create provider info with mappings for existing resources and extra data source mappings that don't exist // this is necessary because Generate() exits early if Resources fail. - infoWithDataSources := tfbridge.ProviderInfo{ + infoWithDataSources := info.Provider{ Name: "test", Version: "1.0.0", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "existing_resource": { Tok: tokens.Type("test:index:ExistingResource"), }, }, - DataSources: map[string]*tfbridge.DataSourceInfo{ + DataSources: map[string]*info.DataSource{ "existing_datasource": { Tok: tokens.ModuleMember("test:index:existingDatasource"), }, @@ -812,13 +813,13 @@ func TestExtraMappingError(t *testing.T) { } // Create provider info with extra field mappings that don't exist in the schema - infoWithExtraFields := tfbridge.ProviderInfo{ + infoWithExtraFields := info.Provider{ Name: "test", Version: "1.0.0", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "existing_resource": { Tok: tokens.Type("test:index:ExistingResource"), - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "unmapped_field": { Name: "unmappedField", }, @@ -833,7 +834,7 @@ func TestExtraMappingError(t *testing.T) { envVars map[string]string expectError bool expectedErrors []string - info tfbridge.ProviderInfo + info info.Provider }{ { name: "Providers should error on extra resource mapping", diff --git a/pkg/tfgen/installation_docs.go b/pkg/tfgen/installation_docs.go index afce13895..a1c4de4ed 100644 --- a/pkg/tfgen/installation_docs.go +++ b/pkg/tfgen/installation_docs.go @@ -16,7 +16,6 @@ import ( "golang.org/x/text/cases" "golang.org/x/text/language" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen/parse" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen/parse/section" @@ -448,9 +447,9 @@ func SkipSectionByHeaderContent( } // Edit Rule for skipping headers. -func skipSectionHeadersEdit() tfbridge.DocsEdit { +func skipSectionHeadersEdit() info.DocsEdit { defaultHeaderSkipRegexps := getDefaultHeadersToSkip() - return tfbridge.DocsEdit{ + return info.DocsEdit{ Path: "*", Edit: func(_ string, content []byte) ([]byte, error) { return SkipSectionByHeaderContent(content, func(headerText string) bool { @@ -491,9 +490,9 @@ func getTfVersionsToRemove() []*regexp.Regexp { return tfVersionsToRemove } -func removeTfVersionMentions() tfbridge.DocsEdit { +func removeTfVersionMentions() info.DocsEdit { tfVersionsToRemove := getTfVersionsToRemove() - return tfbridge.DocsEdit{ + return info.DocsEdit{ Path: "*", Edit: func(_ string, content []byte) ([]byte, error) { for _, tfVersion := range tfVersionsToRemove { diff --git a/pkg/tfgen/installation_docs_test.go b/pkg/tfgen/installation_docs_test.go index 42b8cbf7d..1bc91afaa 100644 --- a/pkg/tfgen/installation_docs_test.go +++ b/pkg/tfgen/installation_docs_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" "github.com/yuin/goldmark" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" sdkv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) @@ -28,7 +28,7 @@ func TestPlainDocsParser(t *testing.T) { edits editRules } // Mock provider for test conversion - p := tfbridge.ProviderInfo{ + p := info.Provider{ Name: "simple", P: sdkv2.NewProvider(&schema.Provider{ ResourcesMap: map[string]*schema.Resource{ @@ -68,7 +68,7 @@ func TestPlainDocsParser(t *testing.T) { }, edits: append( defaultEditRules(), - tfbridge.DocsEdit{ + info.DocsEdit{ Edit: func(_ string, content []byte) ([]byte, error) { return bytes.ReplaceAll( content, @@ -99,8 +99,8 @@ func TestPlainDocsParser(t *testing.T) { } g := &Generator{ sink: mockSink{t}, - info: tfbridge.ProviderInfo{ - Golang: &tfbridge.GolangInfo{ + info: info.Provider{ + Golang: &info.Golang{ ImportBasePath: "github.com/pulumi/pulumi-libvirt/sdk/go/libvirt", }, Repository: "https://github.com/pulumi/pulumi-libvirt", @@ -163,7 +163,7 @@ func TestDisplayNameFallback(t *testing.T) { t.Skipf("Skipping on Windows due to a newline handling issue") } g := &Generator{ - info: tfbridge.ProviderInfo{ + info: info.Provider{ DisplayName: tt.displayName, }, pkg: tokens.NewPackageToken(tokens.PackageName(tt.pkgName)), @@ -424,7 +424,7 @@ func TestTranslateCodeBlocks(t *testing.T) { contentStr string g *Generator } - providerInfo := tfbridge.ProviderInfo{ + providerInfo := info.Provider{ Name: "simple", P: sdkv2.NewProvider(&schema.Provider{ ResourcesMap: map[string]*schema.Resource{ @@ -447,17 +447,17 @@ func TestTranslateCodeBlocks(t *testing.T) { }, }, }), - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "simple_resource": { Tok: "simple:index:resource", - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "input_one": { Name: "renamedInput1", }, }, }, }, - DataSources: map[string]*tfbridge.DataSourceInfo{ + DataSources: map[string]*info.DataSource{ "simple_data_source": { Tok: "simple:index:dataSource", }, diff --git a/pkg/tfgen/internal/testprovider/defaultinfo.go b/pkg/tfgen/internal/testprovider/defaultinfo.go index 732d4ad65..377f2a706 100644 --- a/pkg/tfgen/internal/testprovider/defaultinfo.go +++ b/pkg/tfgen/internal/testprovider/defaultinfo.go @@ -17,11 +17,12 @@ package testprovider import ( testproviderdata "github.com/pulumi/pulumi-terraform-bridge/v3/internal/testprovider" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) -func ProviderDefaultInfo() tfbridge.ProviderInfo { - return tfbridge.ProviderInfo{ +func ProviderDefaultInfo() info.Provider { + return info.Provider{ P: shimv2.NewProvider(testproviderdata.ProviderDefaultInfo()), Name: "default-info", Description: "", @@ -29,22 +30,22 @@ func ProviderDefaultInfo() tfbridge.ProviderInfo { License: "Apache-2.0", Homepage: "https://pulumi.io", Repository: "", - Config: map[string]*tfbridge.SchemaInfo{ + Config: map[string]*info.Schema{ "project": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ Value: []string{"default_project"}, }, }, }, - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "default_ruleset": { Tok: tfbridge.MakeResource("cloudflare", "index", "Ruleset"), - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "rules": { - Elem: &tfbridge.SchemaInfo{ - Fields: map[string]*tfbridge.SchemaInfo{ + Elem: &info.Schema{ + Fields: map[string]*info.Schema{ "id": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ Value: []string{"default_id"}, }, }, diff --git a/pkg/tfgen/internal/testprovider/miniaws.go b/pkg/tfgen/internal/testprovider/miniaws.go index bd2c4e0af..114948bef 100644 --- a/pkg/tfgen/internal/testprovider/miniaws.go +++ b/pkg/tfgen/internal/testprovider/miniaws.go @@ -20,12 +20,12 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/tokens" testproviderdata "github.com/pulumi/pulumi-terraform-bridge/v3/internal/testprovider" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) -func ProviderMiniAws() tfbridge.ProviderInfo { - return tfbridge.ProviderInfo{ +func ProviderMiniAws() info.Provider { + return info.Provider{ P: shimv2.NewProvider(testproviderdata.ProviderMiniAws()), Name: "aws", Description: "A Pulumi package to safely use aws in Pulumi programs.", @@ -33,8 +33,8 @@ func ProviderMiniAws() tfbridge.ProviderInfo { License: "Apache-2.0", Homepage: "https://pulumi.io", Repository: "https://github.com/pulumi/pulumi-aws", - DocRules: &tfbridge.DocRuleInfo{EditRules: func(defaults []tfbridge.DocsEdit) []tfbridge.DocsEdit { - return []tfbridge.DocsEdit{ + DocRules: &info.DocRule{EditRules: func(defaults []info.DocsEdit) []info.DocsEdit { + return []info.DocsEdit{ { Path: "*", Edit: func(_ string, content []byte) ([]byte, error) { @@ -55,13 +55,13 @@ func ProviderMiniAws() tfbridge.ProviderInfo { } }}, UpstreamRepoPath: "./test_data", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "aws_s3_bucket_acl": { Tok: tokens.Type(tokens.ModuleMember("aws:s3/bucketAclV2:BucketAclV2")), }, "aws_s3_bucket": { Tok: tokens.Type(tokens.ModuleMember("aws:s3/bucketV2:BucketV2")), - Aliases: []tfbridge.AliasInfo{ + Aliases: []info.Alias{ { Type: ref("aws:s3/bucket:Bucket"), }, diff --git a/pkg/tfgen/internal/testprovider/minicloudflare.go b/pkg/tfgen/internal/testprovider/minicloudflare.go index 424a75478..3fbd7e612 100644 --- a/pkg/tfgen/internal/testprovider/minicloudflare.go +++ b/pkg/tfgen/internal/testprovider/minicloudflare.go @@ -17,11 +17,12 @@ package testprovider import ( testproviderdata "github.com/pulumi/pulumi-terraform-bridge/v3/internal/testprovider" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) -func ProviderMiniCloudflare() tfbridge.ProviderInfo { - return tfbridge.ProviderInfo{ +func ProviderMiniCloudflare() info.Provider { + return info.Provider{ P: shimv2.NewProvider(testproviderdata.ProviderMiniCloudflare()), Name: "cloudflare", Description: "A Pulumi package to safely use cloudflare in Pulumi programs.", @@ -29,17 +30,17 @@ func ProviderMiniCloudflare() tfbridge.ProviderInfo { License: "Apache-2.0", Homepage: "https://pulumi.io", Repository: "https://github.com/pulumi/pulumi-cloudflare", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "cloudflare_ruleset": { Tok: tfbridge.MakeResource("cloudflare", "index", "Ruleset"), - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "rules": { - Elem: &tfbridge.SchemaInfo{ - Fields: map[string]*tfbridge.SchemaInfo{ + Elem: &info.Schema{ + Fields: map[string]*info.Schema{ "action_parameters": { MaxItemsOne: tfbridge.True(), - Elem: &tfbridge.SchemaInfo{ - Fields: map[string]*tfbridge.SchemaInfo{ + Elem: &info.Schema{ + Fields: map[string]*info.Schema{ "phases": {MaxItemsOne: tfbridge.True()}, }, }, diff --git a/pkg/tfgen/internal/testprovider/minimuxed.go b/pkg/tfgen/internal/testprovider/minimuxed.go index 29c11de1b..6535c0b15 100644 --- a/pkg/tfgen/internal/testprovider/minimuxed.go +++ b/pkg/tfgen/internal/testprovider/minimuxed.go @@ -9,14 +9,15 @@ import ( testproviderdata "github.com/pulumi/pulumi-terraform-bridge/v3/internal/testprovider" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) -func ProviderMiniMuxed() tfbridge.ProviderInfo { +func ProviderMiniMuxed() info.Provider { minimuxedPkg := "minimuxed" minimuxedMod := "index" - return tfbridge.ProviderInfo{ + return info.Provider{ P: shimv2.NewProvider(testproviderdata.ProviderMiniMuxed()), Name: "minimuxed", Description: "A Pulumi package to safely use minimuxed resources in Pulumi programs.", @@ -24,7 +25,7 @@ func ProviderMiniMuxed() tfbridge.ProviderInfo { License: "Apache-2.0", Homepage: "https://pulumi.io", Repository: "https://github.com/pulumi/pulumi-minimuxed", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "minimuxed_integer": {Tok: tfbridge.MakeResource(minimuxedPkg, minimuxedMod, "MinimuxedInteger")}, }, MuxWith: []tfbridge.MuxProvider{ diff --git a/pkg/tfgen/internal/testprovider/minimuxed_replace.go b/pkg/tfgen/internal/testprovider/minimuxed_replace.go index c850f0503..0e3a77549 100644 --- a/pkg/tfgen/internal/testprovider/minimuxed_replace.go +++ b/pkg/tfgen/internal/testprovider/minimuxed_replace.go @@ -9,14 +9,15 @@ import ( testproviderdata "github.com/pulumi/pulumi-terraform-bridge/v3/internal/testprovider" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) -func ProviderMiniMuxedReplace() tfbridge.ProviderInfo { +func ProviderMiniMuxedReplace() info.Provider { minimuxedPkg := "minimuxed" minimuxedMod := "index" - return tfbridge.ProviderInfo{ + return info.Provider{ P: shimv2.NewProvider(testproviderdata.ProviderMiniMuxed()), Name: "minimuxed", Description: "A Pulumi package to safely use minimuxed resources in Pulumi programs.", @@ -24,7 +25,7 @@ func ProviderMiniMuxedReplace() tfbridge.ProviderInfo { License: "Apache-2.0", Homepage: "https://pulumi.io", Repository: "https://github.com/pulumi/pulumi-minimuxed", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "minimuxed_integer": {Tok: tfbridge.MakeResource(minimuxedPkg, minimuxedMod, "MinimuxedInteger")}, }, MuxWith: []tfbridge.MuxProvider{ diff --git a/pkg/tfgen/internal/testprovider/minirandom.go b/pkg/tfgen/internal/testprovider/minirandom.go index dfd05110a..4c99c602e 100644 --- a/pkg/tfgen/internal/testprovider/minirandom.go +++ b/pkg/tfgen/internal/testprovider/minirandom.go @@ -20,11 +20,11 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/tokens" testproviderdata "github.com/pulumi/pulumi-terraform-bridge/v3/internal/testprovider" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) -func ProviderMiniRandom() tfbridge.ProviderInfo { +func ProviderMiniRandom() info.Provider { randomPkg := "random" randomMod := "index" @@ -41,7 +41,7 @@ func ProviderMiniRandom() tfbridge.ProviderInfo { return randomType(mod+"/"+fn, res) } - return tfbridge.ProviderInfo{ + return info.Provider{ P: shimv2.NewProvider(testproviderdata.ProviderMiniRandom()), Name: "random", Description: "A Pulumi package to safely use randomness in Pulumi programs.", @@ -49,13 +49,13 @@ func ProviderMiniRandom() tfbridge.ProviderInfo { License: "Apache-2.0", Homepage: "https://pulumi.io", Repository: "https://github.com/pulumi/pulumi-random", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "random_integer": {Tok: randomResource(randomMod, "RandomInteger")}, }, } } -func ProviderMiniRandomCSharp() tfbridge.ProviderInfo { +func ProviderMiniRandomCSharp() info.Provider { randomPkg := "random" randomMod := "index" @@ -72,7 +72,7 @@ func ProviderMiniRandomCSharp() tfbridge.ProviderInfo { return randomType(mod+"/"+fn, res) } - return tfbridge.ProviderInfo{ + return info.Provider{ P: shimv2.NewProvider(testproviderdata.ProviderMiniRandom()), Name: "random", Description: "A Pulumi package to safely use randomness in Pulumi programs.", @@ -80,11 +80,11 @@ func ProviderMiniRandomCSharp() tfbridge.ProviderInfo { License: "Apache-2.0", Homepage: "https://pulumi.io", Repository: "https://github.com/pulumi/pulumi-random", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "random_integer": { Tok: randomResource(randomMod, "RandomInteger"), CSharpName: "CSharpRandomInteger", - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "seed": { CSharpName: "CSharpSeed", }, diff --git a/pkg/tfgen/internal/testprovider/minitalos.go b/pkg/tfgen/internal/testprovider/minitalos.go index e030ba6ea..9f75f7955 100644 --- a/pkg/tfgen/internal/testprovider/minitalos.go +++ b/pkg/tfgen/internal/testprovider/minitalos.go @@ -19,10 +19,11 @@ import ( pschema "github.com/pulumi/pulumi/pkg/v3/codegen/schema" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) -func ProviderMiniTalos() tfbridge.ProviderInfo { +func ProviderMiniTalos() info.Provider { const ( talosPkg = "talos" machineMod = "machine" @@ -44,15 +45,15 @@ func ProviderMiniTalos() tfbridge.ProviderInfo { }, } - info := tfbridge.ProviderInfo{ + providerInfo := info.Provider{ P: shimv2.NewProvider(schemaProvider), Name: "talos", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "talos_machine_secrets": { Tok: tfbridge.MakeResource(talosPkg, machineMod, "Secrets"), - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "machine_secrets": { - Elem: &tfbridge.SchemaInfo{ + Elem: &info.Schema{ Type: "talos:machine/generated:MachineSecrets", }, }, @@ -68,5 +69,5 @@ func ProviderMiniTalos() tfbridge.ProviderInfo { }, } - return info + return providerInfo } diff --git a/pkg/tfgen/internal/testprovider/nesteddescriptions.go b/pkg/tfgen/internal/testprovider/nesteddescriptions.go index 3d34f69a0..bf3cbf2b7 100644 --- a/pkg/tfgen/internal/testprovider/nesteddescriptions.go +++ b/pkg/tfgen/internal/testprovider/nesteddescriptions.go @@ -17,11 +17,12 @@ package testprovider import ( testproviderdata "github.com/pulumi/pulumi-terraform-bridge/v3/internal/testprovider" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) -func ProviderNestedDescriptions() tfbridge.ProviderInfo { - return tfbridge.ProviderInfo{ +func ProviderNestedDescriptions() info.Provider { + return info.Provider{ P: shimv2.NewProvider(testproviderdata.ProviderNestedDescriptions()), Name: "cloudflare", Description: "A Pulumi package to safely use cloudflare in Pulumi programs.", @@ -29,13 +30,13 @@ func ProviderNestedDescriptions() tfbridge.ProviderInfo { License: "Apache-2.0", Homepage: "https://pulumi.io", Repository: "https://github.com/pulumi/pulumi-cloudflare", - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ "cloudflare_ruleset": { Tok: tfbridge.MakeResource("cloudflare", "index", "Ruleset"), - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "rules": { - Elem: &tfbridge.SchemaInfo{ - Fields: map[string]*tfbridge.SchemaInfo{ + Elem: &info.Schema{ + Fields: map[string]*info.Schema{ "action_parameters": { MaxItemsOne: tfbridge.True(), }, diff --git a/pkg/tfgen/internal/testprovider/regress611.go b/pkg/tfgen/internal/testprovider/regress611.go index 5d4ce08d6..db0dcd2dc 100644 --- a/pkg/tfgen/internal/testprovider/regress611.go +++ b/pkg/tfgen/internal/testprovider/regress611.go @@ -23,12 +23,13 @@ import ( testproviderdata "github.com/pulumi/pulumi-terraform-bridge/v3/internal/testprovider" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" ) // Minified variant of pulumi-aws provider extracted from // pulumi/pulumi-terraform-bridge#611 issue. -func ProviderRegress611() tfbridge.ProviderInfo { +func ProviderRegress611() info.Provider { awsMod := "index" awsPkg := "aws" iamMod := "Iam" @@ -84,7 +85,7 @@ func ProviderRegress611() tfbridge.ProviderInfo { return awsMember(mod, fn, res, true) } - prov := tfbridge.ProviderInfo{ + prov := info.Provider{ P: p, Name: "aws", Description: "A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.", @@ -94,25 +95,25 @@ func ProviderRegress611() tfbridge.ProviderInfo { Repository: "https://github.com/phillipedwards/pulumi-aws", Version: "0.0.2", GitHubOrg: "hashicorp", - Config: map[string]*tfbridge.SchemaInfo{ + Config: map[string]*info.Schema{ "region": { Type: awsTypeDefaultFile(awsMod, "Region"), - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ EnvVars: []string{"AWS_REGION", "AWS_DEFAULT_REGION"}, }, }, "skip_get_ec2_platforms": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ Value: true, }, }, "skip_region_validation": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ Value: true, }, }, "skip_credentials_validation": { - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ // This is required to now be false! When this is true, we defer // the AWS credentials validation check to happen at resource // creation time. Although it may be a little slower validating @@ -126,17 +127,17 @@ func ProviderRegress611() tfbridge.ProviderInfo { }, "skip_metadata_api_check": { Type: "boolean", - Default: &tfbridge.DefaultInfo{ + Default: &info.Default{ Value: true, }, }, }, - Resources: map[string]*tfbridge.ResourceInfo{ + Resources: map[string]*info.Resource{ // Identity and Access Management (IAM) "aws_iam_access_key": {Tok: awsResource(iamMod, "AccessKey")}, "aws_iam_account_alias": { Tok: awsResource(iamMod, "AccountAlias"), - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "account_alias": { CSharpName: "Alias", }, @@ -145,7 +146,7 @@ func ProviderRegress611() tfbridge.ProviderInfo { "aws_iam_account_password_policy": {Tok: awsResource(iamMod, "AccountPasswordPolicy")}, "aws_iam_group_policy": { Tok: awsResource(iamMod, "GroupPolicy"), - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "policy": { Type: "string", AltTypes: []tokens.Type{awsType(iamMod, "documents", "PolicyDocument")}, @@ -157,7 +158,7 @@ func ProviderRegress611() tfbridge.ProviderInfo { "aws_iam_group_membership": {Tok: awsResource(iamMod, "GroupMembership")}, "aws_iam_group_policy_attachment": { Tok: awsResource(iamMod, "GroupPolicyAttachment"), - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "group": { Type: "string", AltTypes: []tokens.Type{awsTypeDefaultFile(iamMod, "Group")}, @@ -173,7 +174,7 @@ func ProviderRegress611() tfbridge.ProviderInfo { }, "aws_iam_instance_profile": { Tok: awsResource(iamMod, "InstanceProfile"), - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "role": { Type: "string", AltTypes: []tokens.Type{awsTypeDefaultFile(iamMod, "Role")}, @@ -183,7 +184,7 @@ func ProviderRegress611() tfbridge.ProviderInfo { "aws_iam_openid_connect_provider": {Tok: awsResource(iamMod, "OpenIdConnectProvider")}, "aws_iam_policy": { Tok: awsResource(iamMod, "Policy"), - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "policy": { Type: "string", AltTypes: []tokens.Type{awsType(iamMod, "documents", "PolicyDocument")}, @@ -194,21 +195,21 @@ func ProviderRegress611() tfbridge.ProviderInfo { }, "aws_iam_policy_attachment": { Tok: awsResource(iamMod, "PolicyAttachment"), - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "users": { - Elem: &tfbridge.SchemaInfo{ + Elem: &info.Schema{ Type: "string", AltTypes: []tokens.Type{awsTypeDefaultFile(iamMod, "User")}, }, }, "roles": { - Elem: &tfbridge.SchemaInfo{ + Elem: &info.Schema{ Type: "string", AltTypes: []tokens.Type{awsTypeDefaultFile(iamMod, "Role")}, }, }, "groups": { - Elem: &tfbridge.SchemaInfo{ + Elem: &info.Schema{ Type: "string", AltTypes: []tokens.Type{awsTypeDefaultFile(iamMod, "Group")}, }, @@ -224,7 +225,7 @@ func ProviderRegress611() tfbridge.ProviderInfo { }, "aws_iam_role_policy_attachment": { Tok: awsResource(iamMod, "RolePolicyAttachment"), - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "role": { Type: "string", AltTypes: []tokens.Type{awsTypeDefaultFile(iamMod, "Role")}, @@ -240,7 +241,7 @@ func ProviderRegress611() tfbridge.ProviderInfo { }, "aws_iam_role_policy": { Tok: awsResource(iamMod, "RolePolicy"), - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "role": { Type: "string", AltTypes: []tokens.Type{awsTypeDefaultFile(iamMod, "Role")}, @@ -254,7 +255,7 @@ func ProviderRegress611() tfbridge.ProviderInfo { }, "aws_iam_role": { Tok: awsResource(iamMod, "Role"), - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "name": tfbridge.AutoName("name", 64, "-"), "assume_role_policy": { Type: "string", @@ -269,7 +270,7 @@ func ProviderRegress611() tfbridge.ProviderInfo { "aws_iam_user_group_membership": {Tok: awsResource(iamMod, "UserGroupMembership")}, "aws_iam_user_policy_attachment": { Tok: awsResource(iamMod, "UserPolicyAttachment"), - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "user": { Type: "string", AltTypes: []tokens.Type{awsTypeDefaultFile(iamMod, "User")}, @@ -285,7 +286,7 @@ func ProviderRegress611() tfbridge.ProviderInfo { }, "aws_iam_user_policy": { Tok: awsResource(iamMod, "UserPolicy"), - Fields: map[string]*tfbridge.SchemaInfo{ + Fields: map[string]*info.Schema{ "policy": { Type: "string", AltTypes: []tokens.Type{awsType(iamMod, "documents", "PolicyDocument")}, @@ -300,7 +301,7 @@ func ProviderRegress611() tfbridge.ProviderInfo { "aws_iam_signing_certificate": {Tok: awsResource(iamMod, "SigningCertificate")}, "aws_iam_virtual_mfa_device": {Tok: awsResource(iamMod, "VirtualMfaDevice")}, }, - DataSources: map[string]*tfbridge.DataSourceInfo{ + DataSources: map[string]*info.DataSource{ // AWS "aws_arn": {Tok: awsDataSource(awsMod, "getArn")}, "aws_availability_zone": {Tok: awsDataSource(awsMod, "getAvailabilityZone")}, diff --git a/pkg/tfgen/main.go b/pkg/tfgen/main.go index 14b54da2a..b3e26e2e2 100644 --- a/pkg/tfgen/main.go +++ b/pkg/tfgen/main.go @@ -29,11 +29,11 @@ import ( "github.com/spf13/afero" "github.com/spf13/cobra" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) // Main executes the TFGen process for the given package pkg and provider prov. -func Main(pkg string, version string, prov tfbridge.ProviderInfo) { +func Main(pkg string, version string, prov info.Provider) { err := prov.P.InternalValidate() if err != nil { _, fmterr := fmt.Fprintf(os.Stderr, "Internal validation of the provider failed: %v\n", err) @@ -55,7 +55,7 @@ func Main(pkg string, version string, prov tfbridge.ProviderInfo) { } // Like Main but allows to customize the generation logic past the parsing of cmd-line arguments. -func MainWithCustomGenerate(pkg string, version string, prov tfbridge.ProviderInfo, +func MainWithCustomGenerate(pkg string, version string, prov info.Provider, gen func(GeneratorOptions) error, ) { if err := newTFGenCmd(pkg, version, prov, gen).Execute(); err != nil { @@ -65,7 +65,7 @@ func MainWithCustomGenerate(pkg string, version string, prov tfbridge.ProviderIn } } -func newTFGenCmd(pkg string, version string, prov tfbridge.ProviderInfo, +func newTFGenCmd(pkg string, version string, prov info.Provider, gen func(GeneratorOptions) error, ) *cobra.Command { var logToStderr bool diff --git a/pkg/tfgen/pluginHost.go b/pkg/tfgen/pluginHost.go index 180e083ff..406c899e6 100644 --- a/pkg/tfgen/pluginHost.go +++ b/pkg/tfgen/pluginHost.go @@ -28,6 +28,7 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tf2pulumi/il" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) var _ = (plugin.Provider)((*inmemoryProvider)(nil)) @@ -37,10 +38,10 @@ type inmemoryProvider struct { name tokens.Package schema []byte - info tfbridge.ProviderInfo + info info.Provider } -func newInMemoryProvider(name tokens.Package, schema []byte, info tfbridge.ProviderInfo) *inmemoryProvider { +func newInMemoryProvider(name tokens.Package, schema []byte, info info.Provider) *inmemoryProvider { // Round-trip the info through a marshaler to normalize the types to the schema shim. return &inmemoryProvider{ name: name, @@ -143,7 +144,7 @@ func (host *inmemoryProviderHost) ResolvePlugin(spec workspace.PluginSpec) (*wor func (host *inmemoryProviderHost) GetProviderInfo( registryName, namespace, name, version string, -) (*tfbridge.ProviderInfo, error) { +) (*info.Provider, error) { if name == il.GetTerraformProviderName(host.provider.info) { return &host.provider.info, nil } diff --git a/pkg/tfgen/source.go b/pkg/tfgen/source.go index 37fb941cf..1e4bc3abc 100644 --- a/pkg/tfgen/source.go +++ b/pkg/tfgen/source.go @@ -25,18 +25,19 @@ import ( "sync" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) // A source of documentation bytes. type DocsSource interface { // Get the bytes for a resource with TF token rawname. - getResource(rawname string, info *tfbridge.DocInfo) (*DocFile, error) + getResource(rawname string, info *info.Doc) (*DocFile, error) // Get the bytes for a datasource with TF token rawname. - getDatasource(rawname string, info *tfbridge.DocInfo) (*DocFile, error) + getDatasource(rawname string, info *info.Doc) (*DocFile, error) // Get the bytes for the provider installation doc. - getInstallation(info *tfbridge.DocInfo) (*DocFile, error) + getInstallation(info *info.Doc) (*DocFile, error) } type DocFile struct { @@ -57,7 +58,7 @@ func NewGitRepoDocsSource(g *Generator) DocsSource { } type gitRepoSource struct { - docRules *tfbridge.DocRuleInfo + docRules *info.DocRule upstreamRepoPath string org string provider string @@ -66,22 +67,22 @@ type gitRepoSource struct { githost string } -func (gh *gitRepoSource) getResource(rawname string, info *tfbridge.DocInfo) (*DocFile, error) { +func (gh *gitRepoSource) getResource(rawname string, info *info.Doc) (*DocFile, error) { return gh.getFile(rawname, info, ResourceDocs) } -func (gh *gitRepoSource) getDatasource(rawname string, info *tfbridge.DocInfo) (*DocFile, error) { +func (gh *gitRepoSource) getDatasource(rawname string, info *info.Doc) (*DocFile, error) { return gh.getFile(rawname, info, DataSourceDocs) } -func (gh *gitRepoSource) getInstallation(info *tfbridge.DocInfo) (*DocFile, error) { +func (gh *gitRepoSource) getInstallation(info *info.Doc) (*DocFile, error) { // The installation docs do not have a rawname. return gh.getFile("", info, InstallationDocs) } // getFile implements the private logic necessary to get a file from a TF Git repo's website section. func (gh *gitRepoSource) getFile( - rawname string, info *tfbridge.DocInfo, kind DocKind, + rawname string, info *info.Doc, kind DocKind, ) (*DocFile, error) { if info != nil && len(info.Markdown) != 0 { return &DocFile{Content: info.Markdown}, nil @@ -182,7 +183,7 @@ func getRepoPath(gitHost string, org string, provider string, version string) (_ return target.Dir, nil } -func getMarkdownNames(packagePrefix, rawName string, globalInfo *tfbridge.DocRuleInfo) []string { +func getMarkdownNames(packagePrefix, rawName string, globalInfo *info.DocRule) []string { // Handle resources/datasources renamed with the tfbridge.RenamedEntitySuffix, `_legacy_` // We want to be finding docs for the rawName _without_ the suffix, so we trim it if present. trimmedName := strings.TrimSuffix(rawName, tfbridge.RenamedEntitySuffix) @@ -202,7 +203,7 @@ func getMarkdownNames(packagePrefix, rawName string, globalInfo *tfbridge.DocRul if globalInfo != nil && globalInfo.AlternativeNames != nil { // We look at user generated names before we look at default names - possibleMarkdownNames = append(globalInfo.AlternativeNames(tfbridge.DocsPathInfo{ + possibleMarkdownNames = append(globalInfo.AlternativeNames(info.DocsPath{ TfToken: rawName, }), possibleMarkdownNames...) } diff --git a/pkg/tfgen/source_test.go b/pkg/tfgen/source_test.go index 3535519c4..8f76eca57 100644 --- a/pkg/tfgen/source_test.go +++ b/pkg/tfgen/source_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) func TestGetDocsPath(t *testing.T) { @@ -99,7 +99,7 @@ func TestGetNarkdownNames(t *testing.T) { name string packagePrefix string rawName string - globalInfo *tfbridge.DocRuleInfo + globalInfo *info.DocRule expectedNames []string }{ { diff --git a/scripts/build.go b/scripts/build.go index 4561bfe23..8d5322f32 100644 --- a/scripts/build.go +++ b/scripts/build.go @@ -108,7 +108,7 @@ func (e *execError) Write(sink io.Writer) (err error) { w("%s\n", e.err.Error()) w("\n") - return + return err } func (e *execError) MustWrite(sink io.Writer) {