Search code examples
terraformazure-custom-providers

Error with compiling Terrform custom provider related to GRPCProviderServer


In the process of building Terraform custom provider using terraform-plugin-framework. After updating bunch of dependencies, hit the following snag:

> make build
env GOOS=`uname | tr '[:upper:]' '[:lower:]'` GOARCH=amd64 GO111MODULE=on go build -o terraform-provider-core_v3.0.0_x1 -gcflags="all=-N -l" -ldflags "-X=main.Version=3.0.0 -X=main.Build=1"
# github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema
vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema/provider.go:508:9: cannot use NewGRPCProviderServer(p) (value of type *GRPCProviderServer) as tfprotov5.ProviderServer value in return statement: *GRPCProviderServer does not implement tfprotov5.ProviderServer (missing method GetMetadata)
make: *** [build] Error 1

Since I'm using Terraform Framework (instead of SDK), this reference should not even be there terraform-plugin-sdk/v2/helper/schema/provider.go

I tried removing ./vendor directory and downloading all packages from scratch, but the issue still persists. Appreciate any help.


Solution

  • Finally found the solution for this issue. Apparently this happened due to Go dependency super weird situation, for more details see this framework issue.

    And the way it gets resolved by manually updating version of github.com/hashicorp/terraform-plugin-sdk/v2 package in go.mod to set as v2.30.0 like so

    go 1.19
    
    require (
    ...
        github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0
    ...
    )
    
    

    Keep in mind, if you try to build the code right after manual version update of the package, it'll fail agin:

    env GOOS=`uname | tr '[:upper:]' '[:lower:]'` GOARCH=amd64 GO111MODULE=on go build -o terraform-provider-core_v3.0.0_x1 -gcflags="all=-N -l" -ldflags "-X=main.Version=3.0.0 -X=main.Build=1"
    go: inconsistent vendoring in /Users/iamuser/terraform-provider-core:
        github.com/hashicorp/terraform-plugin-sdk/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
        github.com/apparentlymart/go-textseg/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
        github.com/hashicorp/hcl/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
        github.com/zclconf/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
        golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
        golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
        golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
        google.golang.org/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
        github.com/apparentlymart/go-textseg/[email protected]: is marked as explicit in vendor/modules.txt, but not explicitly required in go.mod
        github.com/hashicorp/hcl/[email protected]: is marked as explicit in vendor/modules.txt, but not explicitly required in go.mod
        github.com/hashicorp/terraform-plugin-sdk/[email protected]: is marked as explicit in vendor/modules.txt, but not explicitly required in go.mod
        github.com/zclconf/[email protected]: is marked as explicit in vendor/modules.txt, but not explicitly required in go.mod
        golang.org/x/[email protected]: is marked as explicit in vendor/modules.txt, but not explicitly required in go.mod
        golang.org/x/[email protected]: is marked as explicit in vendor/modules.txt, but not explicitly required in go.mod
        golang.org/x/[email protected]: is marked as explicit in vendor/modules.txt, but not explicitly required in go.mod
        google.golang.org/[email protected]: is marked as explicit in vendor/modules.txt, but not explicitly required in go.mod
    
        To ignore the vendor directory, use -mod=readonly or -mod=mod.
        To sync the vendor directory, run:
            go mod vendor
    make: *** [build] Error 1
    

    So, first thing you need to run is go mod vendor to properly update dependancies, and then, you can build the code.

    Hope this helps anyone who encounters such issue.