mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-01 07:42:40 +00:00
Add service_account_email to google_cloudfunctions_function (#2947)
Signed-off-by: Modular Magician <magic-modules@google.com>
This commit is contained in:
parent
08c73f2754
commit
385ac491f4
|
@ -190,6 +190,13 @@ func resourceCloudFunctionsFunction() *schema.Resource {
|
|||
Computed: true,
|
||||
},
|
||||
|
||||
"service_account_email": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"environment_variables": {
|
||||
Type: schema.TypeMap,
|
||||
Optional: true,
|
||||
|
@ -312,9 +319,10 @@ func resourceCloudFunctionsCreate(d *schema.ResourceData, meta interface{}) erro
|
|||
}
|
||||
|
||||
function := &cloudfunctions.CloudFunction{
|
||||
Name: cloudFuncId.cloudFunctionId(),
|
||||
Runtime: d.Get("runtime").(string),
|
||||
ForceSendFields: []string{},
|
||||
Name: cloudFuncId.cloudFunctionId(),
|
||||
Runtime: d.Get("runtime").(string),
|
||||
ServiceAccountEmail: d.Get("service_account_email").(string),
|
||||
ForceSendFields: []string{},
|
||||
}
|
||||
|
||||
sourceRepos := d.Get("source_repository").([]interface{})
|
||||
|
@ -406,6 +414,7 @@ func resourceCloudFunctionsRead(d *schema.ResourceData, meta interface{}) error
|
|||
d.Set("timeout", timeout)
|
||||
d.Set("labels", function.Labels)
|
||||
d.Set("runtime", function.Runtime)
|
||||
d.Set("service_account_email", function.ServiceAccountEmail)
|
||||
d.Set("environment_variables", function.EnvironmentVariables)
|
||||
if function.SourceArchiveUrl != "" {
|
||||
// sourceArchiveUrl should always be a Google Cloud Storage URL (e.g. gs://bucket/object)
|
||||
|
|
|
@ -258,6 +258,35 @@ func TestAccCloudFunctionsFunction_sourceRepo(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccCloudFunctionsFunction_serviceAccountEmail(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
funcResourceName := "google_cloudfunctions_function.function"
|
||||
functionName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
||||
bucketName := fmt.Sprintf("tf-test-bucket-%d", acctest.RandInt())
|
||||
zipFilePath, err := createZIPArchiveForIndexJs(testHTTPTriggerPath)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
defer os.Remove(zipFilePath) // clean up
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckCloudFunctionsFunctionDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccCloudFunctionsFunction_serviceAccountEmail(functionName, bucketName, zipFilePath),
|
||||
},
|
||||
{
|
||||
ResourceName: funcResourceName,
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccCheckCloudFunctionsFunctionDestroy(s *terraform.State) error {
|
||||
config := testAccProvider.Meta().(*Config)
|
||||
|
||||
|
@ -607,3 +636,30 @@ resource "google_cloudfunctions_function" "function" {
|
|||
}
|
||||
`, functionName, project)
|
||||
}
|
||||
|
||||
func testAccCloudFunctionsFunction_serviceAccountEmail(functionName, bucketName, zipFilePath string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_storage_bucket" "bucket" {
|
||||
name = "%s"
|
||||
}
|
||||
|
||||
resource "google_storage_bucket_object" "archive" {
|
||||
name = "index.zip"
|
||||
bucket = "${google_storage_bucket.bucket.name}"
|
||||
source = "%s"
|
||||
}
|
||||
|
||||
data "google_compute_default_service_account" "default" { }
|
||||
|
||||
resource "google_cloudfunctions_function" "function" {
|
||||
name = "%s"
|
||||
|
||||
source_archive_bucket = "${google_storage_bucket.bucket.name}"
|
||||
source_archive_object = "${google_storage_bucket_object.archive.name}"
|
||||
|
||||
service_account_email = "${data.google_compute_default_service_account.default.email}"
|
||||
|
||||
trigger_http = true
|
||||
entry_point = "helloGET"
|
||||
}`, bucketName, zipFilePath, functionName)
|
||||
}
|
||||
|
|
|
@ -69,6 +69,8 @@ The following arguments are supported:
|
|||
|
||||
* `runtime` - (Optional) The runtime in which the function is going to run. If empty, defaults to `"nodejs6"`.
|
||||
|
||||
* `service_account_email` - (Optional) If provided, the self-provided service account to run the function with.
|
||||
|
||||
* `environment_variables` - (Optional) A set of key/value environment variable pairs to assign to the function.
|
||||
|
||||
* `source_archive_bucket` - (Optional) The GCS bucket containing the zip archive which contains the function.
|
||||
|
|
Loading…
Reference in New Issue
Block a user