gpt4 book ai didi

go - 需要一些帮助来使用 bazel 构建自定义 Terraform 提供程序

转载 作者:数据小太阳 更新时间:2023-10-29 03:18:14 24 4
gpt4 key购买 nike

我正在尝试构建一个自定义 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

最佳答案

从您粘贴的错误来看,包 google.golang.org/grpc/naming 的两个副本似乎被合并到同一个二进制文件中。这会导致类型错误:它们是不同的包(即使代码相同),并且它们的导出类型不可互换。

这里最好的做法可能是排除 github.com/hashicorp/terraform 存储库中的 vendor 目录。您可以在 WORKSPACE 中相应的 go_repository 规则中为 Gazelle 添加一个参数。这会阻止 Gazelle 在该目录中生成规则和解析依赖项。

go_repository(
name = "com_github_hashicorp_terraform",
importpath = "github.com/hashicorp/terraform",
# ...
build_extra_args = ["-exclude=vendor"],
)

关于go - 需要一些帮助来使用 bazel 构建自定义 Terraform 提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57863511/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com