Skip to content

Commit

Permalink
fix extra config triggering pf check config errors
Browse files Browse the repository at this point in the history
  • Loading branch information
VenelinMartinov committed Dec 9, 2024
1 parent c1171a0 commit acf464d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pkg/pf/tests/provider_checkconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
rschema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/hexops/autogold/v2"
Expand All @@ -34,9 +35,11 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/structpb"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/providerbuilder"
pb "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/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"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
)

Expand Down Expand Up @@ -802,3 +805,36 @@ func makeProviderServer(
require.NoError(t, err)
return server
}

func TestExtraConfigDoesNotCauseCheckFailure(t *testing.T) {
t.Parallel()

provBuilder := providerbuilder.NewProvider(
providerbuilder.NewProviderArgs{
AllResources: []providerbuilder.Resource{
providerbuilder.NewResource(providerbuilder.NewResourceArgs{
ResourceSchema: rschema.Schema{
Attributes: map[string]rschema.Attribute{
"s": rschema.StringAttribute{Optional: true},
},
},
}),
},
ProviderSchema: schema.Schema{
Attributes: map[string]schema.Attribute{
"config": schema.StringAttribute{Optional: true},
},
},
})

prov := bridgedProvider(provBuilder)

prov.ExtraConfig["extra"] = &info.Config{
Schema: shim.Schema{

Check failure on line 833 in pkg/pf/tests/provider_checkconfig_test.go

View workflow job for this annotation

GitHub Actions / Test and Lint / lint

invalid composite literal type shim.Schema (typecheck)
Attributes: map[string]shim.SchemaAttribute{

Check failure on line 834 in pkg/pf/tests/provider_checkconfig_test.go

View workflow job for this annotation

GitHub Actions / Test and Lint / lint

undefined: shim.SchemaAttribute (typecheck)
"extra": shim.SchemaAttribute{Optional: true},

Check failure on line 835 in pkg/pf/tests/provider_checkconfig_test.go

View workflow job for this annotation

GitHub Actions / Test and Lint / lint

undefined: shim.SchemaAttribute (typecheck)
},
},
}

}
8 changes: 8 additions & 0 deletions pkg/pf/tfbridge/provider_checkconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package tfbridge
import (
"context"
"fmt"
"q"

Check failure on line 20 in pkg/pf/tfbridge/provider_checkconfig.go

View workflow job for this annotation

GitHub Actions / Test and Lint / test (1.22.x, ubuntu-latest, DEFAULT)

package q is not in std (/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.2.linux-amd64/src/q)

Check failure on line 20 in pkg/pf/tfbridge/provider_checkconfig.go

View workflow job for this annotation

GitHub Actions / Test and Lint / test (1.23.x, ubuntu-latest, DEFAULT)

package q is not in std (/opt/hostedtoolcache/go/1.23.3/x64/src/q)

Check failure on line 20 in pkg/pf/tfbridge/provider_checkconfig.go

View workflow job for this annotation

GitHub Actions / Test and Lint / test (1.23.x, ubuntu-latest, PULUMI_TF_BRIDGE_ACCURATE_BRIDGE_PREVIEW)

package q is not in std (/opt/hostedtoolcache/go/1.23.3/x64/src/q)
"strings"

"github.com/hashicorp/terraform-plugin-go/tfprotov6"
Expand Down Expand Up @@ -162,12 +163,15 @@ func (p *provider) validateProviderConfig(
return nil, err
}

q.Q(inputs)

resp, err := p.tfServer.ValidateProviderConfig(ctx, &tfprotov6.ValidateProviderConfigRequest{
Config: config,
})
if err != nil {
return nil, fmt.Errorf("error calling ValidateProviderConfig: %w", err)
}
q.Q(resp.Diagnostics)

// Note: according to the docs on resp.PrepareConfig for new providers it typically is equal to config passed in
// ValidateProviderConfigRequest so the code here ignores it for now.
Expand Down Expand Up @@ -197,6 +201,10 @@ func (p *provider) validateProviderConfig(
if k == "version" || k == "pluginDownloadURL" {
continue
}

if _, has := p.info.ExtraConfig[string(k)]; has {
continue
}
// TODO[https://github.com/pulumi/pulumi/issues/16757] While #16757 is
// outstanding, we need to filter out the keys for parameterized providers
// from the top level namespace.
Expand Down

0 comments on commit acf464d

Please sign in to comment.