Bazel googleapi gRPC cc_grpc_library output was not created - google-api

I am running into Bazel build issues when I try to build googleapis texttospeech_proto and speech_proto with gRPC service. In the root directory of my project, I receive the following error:
ERROR: <>/BUILD:42:1: output 'external/com_google_googleapis/google/cloud/texttospeech/v1/cloud_tts.grpc.pb.h' was not created
ERROR: <>/BUILD:42:1: output 'external/com_google_googleapis/google/cloud/texttospeech/v1/cloud_tts.grpc.pb.cc' was not created
ERROR: <>/BUILD:42:1: not all outputs were created or valid
My BUILD/WORKSPACE files are below:
BUILD
load("#com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")
cc_proto_library(
name = "speech_cc_proto",
deps = [
"#com_google_googleapis//google/cloud/speech/v1p1beta1:speech_proto",
],
visibility = ["//visibility:public"],
)
cc_grpc_library(
name = "cloud_speech_grpc",
srcs = [
"#com_google_googleapis//google/cloud/speech/v1p1beta1:speech_proto",
],
deps = [
":speech_cc_proto",
],
grpc_only = 1,
use_external = 1,
visibility = ["//visibility:public"],
)
cc_proto_library(
name = "texttospeech_cc_proto",
deps = [
"#com_google_googleapis//google/cloud/texttospeech/v1:texttospeech_proto",
],
visibility = ["//visibility:public"],
)
cc_grpc_library(
name = "cloud_texttospeech_grpc",
srcs = [
"#com_google_googleapis//google/cloud/texttospeech/v1:texttospeech_proto",
],
deps = [
":texttospeech_cc_proto",
],
grpc_only = 1,
use_external = 1,
visibility = ["//visibility:public"],
)
WORKSPACE
git_repository(
name = "com_github_grpc_grpc",
remote = "https://github.com/grpc/grpc.git",
tag = "v1.27.0-pre1",
)
load("#com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
grpc_deps()
load("#com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
grpc_extra_deps()
load("#io_bazel_rules_python//python:pip.bzl", "pip_import", "pip_repositories")
pip_import(
name = "grpc_python_dependencies",
requirements = "#com_github_grpc_grpc//:requirements.bazel.txt",
)
load("#grpc_python_dependencies//:requirements.bzl", "pip_install")
pip_repositories()
pip_install()
git_repository(
name = "com_google_googleapis",
remote = "https://github.com/googleapis/googleapis.git",
commit = "3c39a1d6e23c1ef63c7fba4019c25e76c40dfe19",
)
load("#com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
switched_rules_by_language(
name = "com_google_googleapis_imports",
cc = True,
grpc = True,
)
If I move my BUILD file out of the root workspace (into a child workspace/folder), I receive a different error saying the cloud_speech.proto / cloud_tts.proto files are not within the child workspace.

Related

Getting terraform error: Error: "expected create_option to be one of [Attach Empty], got FromImage"

I am trying to create azure cyclecloud server using terraform , my code is below
note: remove the actual disk id ,vm id, public key etc
resource "azurerm_virtual_machine_data_disk_attachment" "res-0" {
caching = "None"
create_option = "FromImage"
lun = 0
managed_disk_id = "Disk_id"
virtual_machine_id = "vm_id"
depends_on = [
azurerm_linux_virtual_machine.res-0,
]
}
resource "azurerm_linux_virtual_machine" "res-0" {
admin_username = "cyclecloud"
location = "westus2"
name = "cc3"
network_interface_ids = network_interfaces_id"
resource_group_name = "myrg"
size = "Standard_DS1_v2"
admin_ssh_key {
public_key = "my_public_key"
username = "cyclecloud"
}
boot_diagnostics {
}
os_disk {
caching = "ReadWrite"
storage_account_type = "Premium_LRS"
}
plan {
name = "cyclecloud-81"
product = "azure-cyclecloud"
publisher = "azurecyclecloud"
}
source_image_reference {
offer = "azure-cyclecloud"
publisher = "azurecyclecloud"
sku = "cyclecloud-81"
version = "latest"
}
}
while running :
terraform apply ,getting the below error:
Error: expected create_option to be one of [Attach Empty], got FromImage
with azurerm_virtual_machine_data_disk_attachment.res-0,
on main.tf line 3, in resource "azurerm_virtual_machine_data_disk_attachment" "res-0":
3: create_option = "FromImage"
Please assist
note i am using the below provider:
terraform {
backend "local" {}
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.31.0"
}
}
}
provider "azurerm" {
features {}
}
The error clearly says that you are passing an unsupported value to the create_option attribute of resource azurerm_virtual_machine_data_disk_attachment. The possible values are Empty or Attach.
resource "azurerm_virtual_machine_data_disk_attachment" "res-0" {
caching = "None"
create_option = "Empty" ## or ## "Attach" # <- Choose any of these values.
lun = 0
managed_disk_id = "Disk_id"
virtual_machine_id = "vm_id"
depends_on = [
azurerm_linux_virtual_machine.res-0,
]
}
Refer to attribute description:
create_option - (Optional) The Create Option of the Data Disk, such as Empty or Attach. Defaults to Attach. Changing this forces a new resource to be created.
Official Documentation: https://registry.terraform.io/providers/hashicorp/azurerm/3.31.0/docs/resources/virtual_machine_data_disk_attachment#create_option
After this may be network_interface_ids = network_interfaces_id" this might result in an error if no real network_interface_ids are provided as the attribute values.
Refer to official hashicorp example : https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine
Not Sure but if the goal is to attach an additional data disk to the machine then azurerm_managed_disk
resource is also required not only just attachment and there you can use create_option = FromImage attribute value.
create_option for the azurerm_managed_disk : https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/managed_disk#create_option

Terraform plugin crashed when provisioning the Azure Local Network Gateway

I am trying ti provision an azure local network gateway. When I try to terraform apply I get the following error:
module.local_gateway.azurerm_local_network_gateway.local_gw: Creating...
╷
│ Error: Plugin did not respond
│
│ with module.local_gateway.azurerm_local_network_gateway.local_gw,
│ on modules/local-gateway/main.tf line 6, in resource "azurerm_local_network_gateway" "local_gw":
│ 6: resource "azurerm_local_network_gateway" "local_gw" {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.
╵
Stack trace from the terraform-provider-azurerm_v3.0.0_x5 plugin:
panic: interface conversion: interface {} is nil, not string
goroutine 104 [running]:
github.com/hashicorp/terraform-provider-azurerm/internal/services/network.expandLocalNetworkGatewayAddressSpaces(0x14001f87f00)
/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-azurerm/internal/services/network/local_network_gateway_resource.go:271 +0x234
github.com/hashicorp/terraform-provider-azurerm/internal/services/network.resourceLocalNetworkGatewayCreateUpdate(0x14001f87f00, {0x1081089a0, 0x14001f8dc00})
/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-azurerm/internal/services/network/local_network_gateway_resource.go:160 +0xa5c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x14000dc6ee0, {0x108ae8b78, 0x14001cff880}, 0x14001f87f00, {0x1081089a0, 0x14001f8dc00})
/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema/resource.go:329 +0x170
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x14000dc6ee0, {0x108ae8b78, 0x14001cff880}, 0x14001a63ba0, 0x14001f87d80, {0x1081089a0, 0x14001f8dc00})
/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema/resource.go:467 +0x8d8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x140004fa750, {0x108ae8b78, 0x14001cff880}, 0x14001d12dc0)
/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema/grpc_provider.go:977 +0xe38
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0x14000237880, {0x108ae8c20, 0x14002009e30}, 0x14001c1ee00)
/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server/server.go:603 +0x338
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x10864d540, 0x14000237880}, {0x108ae8c20, 0x14002009e30}, 0x14001a51020, 0x0)
/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:380 +0x1c0
google.golang.org/grpc.(*Server).processUnaryRPC(0x140002a6fc0, {0x108b4df08, 0x14000448d80}, 0x14001a77680, 0x1400159c2a0, 0x10d0d0f40, 0x0)
/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:1292 +0xc04
google.golang.org/grpc.(*Server).handleStream(0x140002a6fc0, {0x108b4df08, 0x14000448d80}, 0x14001a77680, 0x0)
/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:1617 +0xa34
google.golang.org/grpc.(*Server).serveStreams.func1.2(0x1400156d0e0, 0x140002a6fc0, {0x108b4df08, 0x14000448d80}, 0x14001a77680)
/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:940 +0x94
created by google.golang.org/grpc.(*Server).serveStreams.func1
/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform->provider-azurerm/vendor/google.golang.org/grpc/server.go:938 +0x1f0
Error: The terraform-provider-azurerm_v3.0.0_x5 plugin crashed!
This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.
And here's my local_gw.tf code:
resource "azurerm_local_network_gateway" "local_gw" {
name = var.azurerm_local_network_gateway_name
location = var.location
resource_group_name = var.rg_name
gateway_address = var.gateway_address
address_space = var.local_gw_address_space # The gateway IP address to connect with
tags = merge(var.common_tags)
}
This is where it is being called as a module in main.tf
locals {
azurerm_local_network_gateway_name = "local-gw"
gateway_address = ""
local_gw_address_space = [""]
common_tags = {
"environment" = "test"
"managedby" = "devops"
"developedby" = "jananath"
}
project = "mysvg"
resource_location = "Germany West Central"
}
# Local Gateway
module "local_gateway" {
source = "./modules/local-gateway"
location = local.resource_location
rg_name = var.rg_name
azurerm_local_network_gateway_name = var.azurerm_local_network_gateway_name
gateway_address = var.gateway_address
local_gw_address_space = var.local_gw_address_space
common_tags = merge(
local.common_tags,
{
"Name" = "${local.project}-${var.azurerm_local_network_gateway_name}"
},
)
}
This is my provider.tf
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=3.0.0"
}
}
backend "azurerm" {
resource_group_name = "shared-resources"
storage_account_name = "janasvtfstate"
container_name = "tfstate"
key = "terraform.tfstate"
}
}
# Configure the Microsoft Azure Provider
provider "azurerm" {
features {}
}
Can someone help me fix this?
The multiple declarations of module “local_gateway” caused this problem. here is no need to declare the items again in the main TF file. As shown below, simply declaring a module suffices.
module "local_gateway" {
source = "./modules/local_gw/"
}
Variables are defined directly on the code in the updated code snippet below.
Step1:
main tf code as follows
locals {
azurerm_local_network_gateway_name = "local-gw"
gateway_address = ""
local_gw_address_space = [""]
common_tags = {
"environment" = "test"
"managedby" = "devops"
"developedby" = "jananath"
}
project = "mysvg"
resource_location = "Germany West Central"
}
module "local_gateway" {
source = "./modules/local_gw/"
}
Module ->local_gw->local_gw tf code as follows
resource "azurerm_local_network_gateway" "local_gw" {
name = "localgatewayswarnademo"
location = "Germany West Central"
resource_group_name = "rg-swarnademonew"
gateway_address = "12.13.14.15"
address_space = ["10.0.0.0/16"]
tags = merge("demo")
}
Provider tf file code as
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=3.0.0"
}
}
# backend "azurerm" {
# resource_group_name = "shared-resources"
# storage_account_name = "janasvtfstate"
# container_name = "tfstate"
# key = "terraform.tfstate"
# }
}
provider "azurerm" {
features {}
}
Note: Commented on the storage account. If required, create it manually.
Step2: run below commands
terraform plan
plan output
terraform apply -auto-approve
Apply output
Verification from portal.
Output:

Unable to build bazel - Getting error running bazel with gin package

I'm trying to add the gin package in the BUILD file. When I build the file I get the following error
no such package '#com_github_gin_gonic_gin//go_default_library': The repository '#com_github_gin_gonic_gin' could not be resolved: Repository '#com_github_gin_gonic_gin' is not defined and referenced by
load("#io_bazel_rules_go//go:def.bzl", "go_library")
load("#bazel_gazelle//:def.bzl", "gazelle")
package(default_visibility = ["//visibility:public"])
go_library(
name = "",
srcs = [""],
importpath = "",
visibility = ["//visibility:public"],
deps = [
"#com_github_gin_gonic_gin//go_default_library",
"#io_k8s_client_go//kubernetes",
"#io_k8s_client_go//tools/clientcmd",
"#io_k8s_client_go//util/homedir",
],
)
In your workspace file try calling go_rules_dependencies() first and then load other dependencies with respect to gin packages.

no such target '#maven//:io_lettuce_lettuce_core': target 'io_lettuce_lettuce_core' not declared in package

I am trying to write a very simple example in kotlin to interact with redis.
I want to use bazel to drive the build process.
Here is the WORKSOPACE file
workspace(
name = "com_ahwkong_kotlin",
managed_directories = {},
)
load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
RULES_KOTLIN_VERSION = "legacy-1.4.0-rc3"
RULES_KOTLIN_SHA = "da0e6e1543fcc79e93d4d93c3333378f3bd5d29e82c1bc2518de0dbe048e6598"
http_archive(
name = "io_bazel_rules_kotlin",
urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/%s/rules_kotlin_release.tgz" % RULES_KOTLIN_VERSION],
sha256 = RULES_KOTLIN_SHA,
)
load("#io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")
kotlin_repositories() # if you want the default. Otherwise see custom kotlinc distribution below
kt_register_toolchains() # to use the default toolchain, otherwise see toolchains below
# maven
RULES_JVM_EXTERNAL_TAG = "2.8"
RULES_JVM_EXTERNAL_SHA = "79c9850690d7614ecdb72d68394f994fef7534b292c4867ce5e7dec0aa7bdfad"
http_archive(
name = "rules_jvm_external",
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
sha256 = RULES_JVM_EXTERNAL_SHA,
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
)
load("#rules_jvm_external//:defs.bzl", "maven_install")
maven_install(
artifacts = [
"com.google.code.findbugs:jsr305:1.3.9",
"com.google.errorprone:error_prone_annotations:2.0.18",
"com.google.j2objc:j2objc-annotations:1.1",
],
repositories = [
"https://jcenter.bintray.com/",
"https://repo1.maven.org/maven2",
],
)
This is my BUILD file
load("#io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_compiler_plugin", "kt_jvm_library", "kt_jvm_binary")
kt_compiler_plugin(
name = "open_for_testing_plugin",
id = "org.jetbrains.kotlin.allopen",
options = {
"annotation": "plugin.allopen.OpenForTesting",
},
deps = [
"#com_github_jetbrains_kotlin//:allopen-compiler-plugin",
],
)
kt_jvm_library(
name = "ex1_lib",
srcs = glob(["ex1*/src/**/*.kt"]),
deps = [
"#maven//:io_lettuce_lettuce_core",
]
)
java_binary(
name = "ex1",
main_class = "ex1.App",
srcs = glob(["ex1*/src/**/*.kt"]),
visibility = ["//visibility:public"],
runtime_deps = [":ex1_lib"],
)
This is my kotlin file
package ex1
import io.lettuce.core.RedisClient
import io.lettuce.core.RedisReactiveCommandsImpl
import io.lettuce.core.RedisURI
import io.lettuce.core.api.StatefulRedisConnection
import io.lettuce.core.api.reactive.RedisReactiveCommands
import java.time.Duration
class ConnectionFactory {
// https://kotlinlang.org/docs/tutorials/kotlin-for-py/objects-and-companion-objects.html
// If you need a function or a property to be tied to a class rather than to instances of it
// (similar to #staticmethod in Python), you can declare it inside a companion object:
companion object {
fun createConnection(port: Int = 6380, host: String = "127.0.0.1"): RedisClient =
RedisClient.create(RedisURI.builder()
.withTimeout(Duration.ofMinutes(1))
.withHost(host)
.withPort(port)
.build())
}
}
Without the maven dependency I will not be able to compile the above code.
Here is the error message:
$ bazel build ex1
ERROR: /Users/antkong/dev/canva/kongakong-experiments.3.diagrams/tech_talk/kotlin/BUILD:26:1: no such target '#maven//:io_lettuce_lettuce_core': target 'io_lettuce_lettuce_core' not declared in package '' defined by /private/var/tmp/_bazel_antkong/3496a0772a2021d0f0b3c230bf912ab1/external/maven/BUILD and referenced by '//:ex1_lib'
ERROR: Analysis of target '//:ex1' failed; build aborted: Analysis failed
If the issue is "no such target '#maven//:io_lettuce_lettuce_core', how can I define this target?
I need to add this rule to the WORKSPACE
maven_repositories = [
"https://repo.maven.apache.org/maven2/",
"https://s3.amazonaws.com/maven.canva-build.com/release/",
"https://github.com/getdyspatch/dyspatch-java-mvn/raw/master/releases/",
]
maven_install(
artifacts = [
"io.lettuce:lettuce-core:jar:5.3.4.RELEASE",
],
repositories = maven_repositories,
)

Bazel/Golang: rule 'go_embed_data' doesn't contain declared provider 'GoArchive'

I'm trying to create a Bazel rule for my project that just embeds a collection of files. The embed rule is as follows:
go_embed_data(
name = "my_files_go",
src = [
"embedded/src1", "embedded/src2"
],
package = "my_lib",
var = "myFiles",
)
Which I then add in my go_library rule:
go_library(
name = "library",
srcs = [
"library.go",
],
importpath = "github.com/nickfelker/golang-app",
deps = [
":my_files_go"
"//otherLib",
],
)
However when I try to build this, I end up getting an obscure error that I cannot find elsewhere.
Error: <target //library:my_files_go> (rule 'go_embed_data') doesn't contain declared provider 'GoArchive'
ERROR: Analysis of target '//:binary' failed; build aborted: Analysis of target '//library:library' failed
How am I supposed to get around this error?
The rule created for go_embed_data does not go as a dependency to the go_library rule. Instead, it should be considered one of the srcs, as so:
go_embed_data(
name = "my_files_go",
src = [
"embedded/src1", "embedded/src2"
],
package = "my_lib",
var = "myFiles",
)
go_library(
name = "library",
srcs = [
":my_files_go",
"library.go",
],
importpath = "github.com/nickfelker/golang-app",
deps = [
"//otherLib",
],
)

Resources