google-cloud-platform - 使用 terraform 部署 google 功能
问题描述
我正在尝试使用 terraform 部署谷歌云功能。该函数需要对该函数进行压缩。我需要一个带有 terraform 和 nodejs 的 hello world 项目。过去几天我一直在尝试设置它,但没有成功。
解决方案
样本 Terraform
resource "google_cloudfunctions_function" "test" {
name = "[FunctionName]"
entry_point = "helloGET"
available_memory_mb = 128
timeout = 61
project = "[GCPProjectName]"
region = "us-central1"
trigger_http = true
trigger_topic = "[PubSubTopic]"
trigger_bucket = "[StorageBucketName]"
source_archive_bucket = "${google_storage_bucket.bucket.name}"
source_archive_object = "${google_storage_bucket_object.archive.name}"
labels {
deployment_name = "test"
}
}
resource "google_storage_bucket" "bucket" {
name = "cloudfunction-deploy-test1"
}
data "archive_file" "http_trigger" {
type = "zip"
output_path = "${path.module}/files/http_trigger.zip"
source {
content = "${file("${path.module}/files/http_trigger.js")}"
filename = "index.js"
}
}
resource "google_storage_bucket_object" "archive" {
name = "http_trigger.zip"
bucket = "${google_storage_bucket.bucket.name}"
source = "${path.module}/files/http_trigger.zip"
depends_on = ["data.archive_file.http_trigger"]
}
示例 nodejs
/**
* HTTP Cloud Function.
*
* @param {Object} req Cloud Function request context.
* @param {Object} res Cloud Function response context.
*/
exports.helloGET = function helloGET (req, res) {
res.send(`Hello ${req.body.name || 'World'}!`);
};
推荐阅读
- sql - 用于更正数据的 Sql 脚本
- java - 在两个 Websphere 服务器之间获取 SSLHandshake 异常
- java - 查找用户位置
- npm - 由于“selenium webdriver promise defer error”,Sendkeys 在量角器中不起作用
- angular - 如何使用 ngFor 向 div 添加分页功能
- three.js - 无法加载 .obj 和 .mtl
- c# - 如何转换线程代码(VB.net 到 C#)..?
- for-loop - 新使用 for 循环
- javascript - 如何在处理 HTTP 请求之前将 csv 文件同步加载到内存中
- javascript - 使用 javascript 从 ul li 获取每个层次结构级别的字符串行