我正在尝试使用terraform部署Google云功能。该功能需要压缩该功能。我需要一个带有Terraform和Node.js的Hello World项目。过去几天我一直在尝试进行设置,但没有成功。
答案 0 :(得分:1)
示例地形
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'}!`);
};