Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for updating function code in place #1781

Merged
merged 1 commit into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions google/resource_cloudfunctions_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,11 @@ func resourceCloudFunctionsFunction() *schema.Resource {
"source_archive_bucket": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"source_archive_object": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"description": {
Expand Down Expand Up @@ -412,6 +410,13 @@ func resourceCloudFunctionsUpdate(d *schema.ResourceData, meta interface{}) erro
updateMaskArr = append(updateMaskArr, "availableMemoryMb")
}

if d.HasChange("source_archive_bucket") || d.HasChange("source_archive_object") {
sourceArchiveBucket := d.Get("source_archive_bucket").(string)
sourceArchiveObj := d.Get("source_archive_object").(string)
function.SourceArchiveUrl = fmt.Sprintf("gs://%v/%v", sourceArchiveBucket, sourceArchiveObj)
updateMaskArr = append(updateMaskArr, "sourceArchiveUrl")
}

if d.HasChange("description") {
function.Description = d.Get("description").(string)
updateMaskArr = append(updateMaskArr, "description")
Expand Down
6 changes: 4 additions & 2 deletions google/resource_cloudfunctions_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
)

const testHTTPTriggerPath = "./test-fixtures/cloudfunctions/http_trigger.js"
const testHTTPTriggerUpdatePath = "./test-fixtures/cloudfunctions/http_trigger_update.js"
const testPubSubTriggerPath = "./test-fixtures/cloudfunctions/pubsub_trigger.js"
const testBucketTriggerPath = "./test-fixtures/cloudfunctions/bucket_trigger.js"

Expand Down Expand Up @@ -85,6 +86,7 @@ func TestAccCloudFunctionsFunction_update(t *testing.T) {
functionName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
bucketName := fmt.Sprintf("tf-test-bucket-%d", acctest.RandInt())
zipFilePath, err := createZIPArchiveForIndexJs(testHTTPTriggerPath)
zipFileUpdatePath, err := createZIPArchiveForIndexJs(testHTTPTriggerUpdatePath)
if err != nil {
t.Fatal(err.Error())
}
Expand All @@ -105,7 +107,7 @@ func TestAccCloudFunctionsFunction_update(t *testing.T) {
),
},
{
Config: testAccCloudFunctionsFunction_updated(functionName, bucketName, zipFilePath),
Config: testAccCloudFunctionsFunction_updated(functionName, bucketName, zipFileUpdatePath),
Check: resource.ComposeTestCheckFunc(
testAccCloudFunctionsFunctionExists(
funcResourceName, &function),
Expand Down Expand Up @@ -420,7 +422,7 @@ resource "google_storage_bucket" "bucket" {
}

resource "google_storage_bucket_object" "archive" {
name = "index.zip"
name = "index_update.zip"
bucket = "${google_storage_bucket.bucket.name}"
source = "%s"
}
Expand Down
9 changes: 9 additions & 0 deletions google/test-fixtures/cloudfunctions/http_trigger_update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* 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("Goodbye ${req.body.name || 'World'}!");
};