我正在尝试构建一个自定义的Terraform提供程序作为链接:https://www.terraform.io/docs/extend/writing-custom-providers.html
使用go构建是好的。 但是我无法使构建与bazel一起使用。
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("@bazel_gazelle//:def.bzl", "gazelle")
# gazelle:prefix nox
gazelle(name = "gazelle")
go_library(
name = "go_default_library",
srcs = [
"main.go",
"provider.go",
"resource_server.go",
],
importpath = "nox",
visibility = ["//visibility:private"],
deps = [
"@com_github_hashicorp_terraform//helper/schema:go_default_library",
"@com_github_hashicorp_terraform//plugin:go_default_library",
"@com_github_hashicorp_terraform//terraform:go_default_library",
],
)
go_binary(
name = "nox",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)
错误:
/home/phuonglu/.cache/bazel/_bazel_phuonglu/1776745e55763483ee3d48d730fcf433/sandbox/linux-sandbox/935/execroot/__main__/external/com_github_hashicorp_terraform/vendor/google.golang
.org/api/option/option.go:163:54: cannot use "github.com/hashicorp/terraform/vendor/google.golang.org/api/internal".NewPoolResolver(int(w), o) (type *"github.com/hashicorp/terraform
/vendor/google.golang.org/api/internal".PoolResolver) as type "google.golang.org/grpc/naming".Resolver in argument to grpc.RoundRobin:
*"github.com/hashicorp/terraform/vendor/google.golang.org/api/internal".PoolResolver does not implement "google.golang.org/grpc/naming".Resolver (wrong type for Resolve meth
od)
have Resolve(string) ("github.com/hashicorp/terraform/vendor/google.golang.org/grpc/naming".Watcher, error)
want Resolve(string) ("google.golang.org/grpc/naming".Watcher, error)
其他错误:
ERROR: /home/phuonglu/.cache/bazel/_bazel_phuonglu/ad07032ffc2f7bfb6275d446f85e98cd/external/com_github_aws_aws_sdk_go/aws/signer/v4/BUILD.bazel:3:1: @com_github_aws_aws_sdk_go//aws
/signer/v4:go_default_library: no such attribute 'importpath_aliases' in 'go_library' rule
答案 0 :(得分:0)
从您粘贴的错误看来,软件包google.golang.org/grpc/naming
的两个副本已合并到同一二进制文件中。这会导致类型错误:这些包是不同的包(即使代码相同),并且它们的导出类型不可互换。
此处最好的做法可能是排除vendor
存储库中的github.com/hashicorp/terraform
目录。您可以在WORKSPACE中的相应go_repository
规则中向Gazelle添加参数。这样可以防止瞪羚生成规则并解决该目录中的依赖项。
go_repository(
name = "com_github_hashicorp_terraform",
importpath = "github.com/hashicorp/terraform",
# ...
build_extra_args = ["-exclude=vendor"],
)