英文:
Run cloud function on pubsub message arrival using Terraform
问题
### 需求 ###
需要创建Terraform IAC以在pubsub事件触发时运行云函数。
我不需要在我的IAC中创建pubsub资源,因为它是由其他团队创建的。
### 我的尝试1 ###
event_trigger {
event_type = "google.pubsub.topic.publish"
resource = "project/${var.project_id}/topics/${var.environment}_my_topic"
}
尝试1出错
│ 错误:googleapi:错误400:请求存在错误
│ 详情:
│ [
│ {
│ "@type": "type.googleapis.com/google.rpc.BadRequest",
│ "fieldViolations": [
│ {
│ "description": "Pub/Sub主题名称projects/myprojectID/topics/project/myprojectID/topics/my_topic与预期模式不匹配",
│ "field": "pubsub_topic"
│ }
│ ]
│ }
│ ]
│ ,badRequest
### 我的尝试2 ###
event_trigger {
event_type = "google.pubsub.topic.publish"
resource = {
service = "pubsub.googleapis.com"
name = "project/${var.project_id}/topics/${var.environment}_my_topic"
type = "type.googleapis.com/google.pubsub.v1.PubsubMessage"
}
}
尝试2出错
│ var.environment是一个字符串,只能在应用后知道
│ var.project_id是一个字符串,只能在应用后知道
│
│ 对于属性"resource"的值不合适:需要一个字符串。
请帮忙解决。
英文:
Requirement
Need to create Terraform IAC to run cloud function on pubsub event_trigger.
I don't need to create the pubsub resources in my iac because it was created by other team.
My try 1
event_trigger {
event_type = "google.pubsub.topic.publish"
resource = "project/${var.project_id}/topics/${var.environment}_my_topic"
}
error on try1
│ Error: googleapi: Error 400: The request has errors
│ Details:
│ [
│ {
│ "@type": "type.googleapis.com/google.rpc.BadRequest",
│ "fieldViolations": [
│ {
│ "description": "Pub/Sub topic name projects/myprojectID/topics/project/myprojectID/topics/my_topic does not match the expected pattern",
│ "field": "pubsub_topic"
│ }
│ ]
│ }
│ ]
│ , badRequest
My try 2
event_trigger {
event_type = "google.pubsub.topic.publish"
resource = {
service = "pubsub.googleapis.com"
name = "project/${var.project_id}/topics/${var.environment}_my_topic"
type = "type.googleapis.com/google.pubsub.v1.PubsubMessage"
}
}
error on try2
│ │ var.environment is a string, known only after apply
│ │ var.project_id is a string, known only after apply
│
│ Inappropriate value for attribute "resource": string required.
Please help
答案1
得分: 0
我已更正资源路径。
应该以 projects/...
开头。
我的尝试1已更改如下,并且运行正常。
event_trigger {
event_type = "google.pubsub.topic.publish"
resource = "projects/${var.project_id}/topics/${var.environment}_my_topic"
}
英文:
I have corrected the resource path.
It should be starting with projects/...
My try1 has been changed like this and it worked.
event_trigger {
event_type = "google.pubsub.topic.publish"
resource = "projects/${var.project_id}/topics/${var.environment}_my_topic"
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论