jjzjj

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

coder 2024-07-08 原文

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

有关go - 需要一些帮助来使用 bazel 构建自定义 Terraform 提供程序的更多相关文章

  1. ruby - Facter::Util::Uptime:Module 的未定义方法 get_uptime (NoMethodError) - 2

    我正在尝试设置一个puppet节点,但ruby​​gems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由ruby​​gems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby

  2. ruby - 我需要将 Bundler 本身添加到 Gemfile 中吗? - 2

    当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/

  3. ruby-on-rails - Rails 3.2.1 中 ActionMailer 中的未定义方法 'default_content_type=' - 2

    我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer

  4. ruby-on-rails - form_for 中不在模型中的自定义字段 - 2

    我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢

  5. ruby - 主要 :Object when running build from sublime 的未定义方法 `require_relative' - 2

    我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby​​1.9+ 关于ruby-主要:Objectwhenrun

  6. ruby - rspec 需要 .rspec 文件中的 spec_helper - 2

    我注意到像bundler这样的项目在每个specfile中执行requirespec_helper我还注意到rspec使用选项--require,它允许您在引导rspec时要求一个文件。您还可以将其添加到.rspec文件中,因此只要您运行不带参数的rspec就会添加它。使用上述方法有什么缺点可以解释为什么像bundler这样的项目选择在每个规范文件中都需要spec_helper吗? 最佳答案 我不在Bundler上工作,所以我不能直接谈论他们的做法。并非所有项目都checkin.rspec文件。原因是这个文件,通常按照当前的惯例,只

  7. ruby - 如何在 Lion 上安装 Xcode 4.6,需要用 RVM 升级 ruby - 2

    我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121

  8. ruby - 在 Ruby 中有条件地定义函数 - 2

    我有一些代码在几个不同的位置之一运行:作为具有调试输出的命令行工具,作为不接受任何输出的更大程序的一部分,以及在Rails环境中。有时我需要根据代码的位置对代码进行细微的更改,我意识到以下样式似乎可行:print"Testingnestedfunctionsdefined\n"CLI=trueifCLIdeftest_printprint"CommandLineVersion\n"endelsedeftest_printprint"ReleaseVersion\n"endendtest_print()这导致:TestingnestedfunctionsdefinedCommandLin

  9. ruby - 定义方法参数的条件 - 2

    我有一个只接受一个参数的方法:defmy_method(number)end如果使用number调用方法,我该如何引发错误??通常,我如何定义方法参数的条件?比如我想在调用的时候报错:my_method(1) 最佳答案 您可以添加guard在函数的开头,如果参数无效则引发异常。例如:defmy_method(number)failArgumentError,"Inputshouldbegreaterthanorequalto2"ifnumbereputse.messageend#=>Inputshouldbegreaterthano

  10. ruby - 有人可以帮助解释类创建的 post_initialize 回调吗 (Sandi Metz) - 2

    我正在阅读SandiMetz的POODR,并且遇到了一个我不太了解的编码原则。这是代码:classBicycleattr_reader:size,:chain,:tire_sizedefinitialize(args={})@size=args[:size]||1@chain=args[:chain]||2@tire_size=args[:tire_size]||3post_initialize(args)endendclassMountainBike此代码将为其各自的属性输出1,2,3,4,5。我不明白的是查找方法。当一辆山地自行车被实例化时,因为它没有自己的initialize方法

随机推荐