@@ -66,6 +66,8 @@ func TestAccCloudFunctionsFunction_basic(t *testing.T) {
66
66
resource .TestCheckResourceAttr (funcResourceName ,
67
67
"trigger_http" , "true" ),
68
68
testAccCloudFunctionsFunctionHasLabel ("my-label" , "my-label-value" , & function ),
69
+ testAccCloudFunctionsFunctionHasEnvironmentVariable ("TEST_ENV_VARIABLE" ,
70
+ "test-env-variable-value" , & function ),
69
71
),
70
72
},
71
73
{
@@ -119,6 +121,10 @@ func TestAccCloudFunctionsFunction_update(t *testing.T) {
119
121
"timeout" , "91" ),
120
122
testAccCloudFunctionsFunctionHasLabel ("my-label" , "my-updated-label-value" , & function ),
121
123
testAccCloudFunctionsFunctionHasLabel ("a-new-label" , "a-new-label-value" , & function ),
124
+ testAccCloudFunctionsFunctionHasEnvironmentVariable ("TEST_ENV_VARIABLE" ,
125
+ "test-env-variable-value" , & function ),
126
+ testAccCloudFunctionsFunctionHasEnvironmentVariable ("NEW_ENV_VARIABLE" ,
127
+ "new-env-variable-value" , & function ),
122
128
),
123
129
},
124
130
},
@@ -347,6 +353,21 @@ func testAccCloudFunctionsFunctionHasLabel(key, value string,
347
353
}
348
354
}
349
355
356
+ func testAccCloudFunctionsFunctionHasEnvironmentVariable (key , value string ,
357
+ function * cloudfunctions.CloudFunction ) resource.TestCheckFunc {
358
+ return func (s * terraform.State ) error {
359
+ if val , ok := function .EnvironmentVariables [key ]; ok {
360
+ if val != value {
361
+ return fmt .Errorf ("Environment Variable value did not match for key %s: expected %s but found %s" ,
362
+ key , value , val )
363
+ }
364
+ } else {
365
+ return fmt .Errorf ("Environment Variable with key %s not found" , key )
366
+ }
367
+ return nil
368
+ }
369
+ }
370
+
350
371
func createZIPArchiveForIndexJs (sourcePath string ) (string , error ) {
351
372
source , err := ioutil .ReadFile (sourcePath )
352
373
if err != nil {
@@ -411,6 +432,9 @@ resource "google_cloudfunctions_function" "function" {
411
432
labels {
412
433
my-label = "my-label-value"
413
434
}
435
+ environment_variables {
436
+ TEST_ENV_VARIABLE = "test-env-variable-value"
437
+ }
414
438
}
415
439
` , bucketName , zipFilePath , functionName )
416
440
}
@@ -440,6 +464,10 @@ resource "google_cloudfunctions_function" "function" {
440
464
my-label = "my-updated-label-value"
441
465
a-new-label = "a-new-label-value"
442
466
}
467
+ environment_variables {
468
+ TEST_ENV_VARIABLE = "test-env-variable-value"
469
+ NEW_ENV_VARIABLE = "new-env-variable-value"
470
+ }
443
471
}` , bucketName , zipFilePath , functionName )
444
472
}
445
473
0 commit comments