Show / Hide Table of Contents

Class Function

Creates a new Cloud Function. For more information see the official documentation and API.

Warning: As of November 1, 2019, newly created Functions are private-by-default and will require appropriate IAM permissions to be invoked. See below examples for how to set up the appropriate permissions, or view the Cloud Functions IAM resources for Cloud Functions.

Example Usage - Public Function

using Pulumi;
using Gcp = Pulumi.Gcp;

class MyStack : Stack
{
public MyStack()
{
    var bucket = new Gcp.Storage.Bucket("bucket", new Gcp.Storage.BucketArgs
    {
    });
    var archive = new Gcp.Storage.BucketObject("archive", new Gcp.Storage.BucketObjectArgs
    {
        Bucket = bucket.Name,
        Source = new FileAsset("./path/to/zip/file/which/contains/code"),
    });
    var function = new Gcp.CloudFunctions.Function("function", new Gcp.CloudFunctions.FunctionArgs
    {
        Description = "My function",
        Runtime = "nodejs10",
        AvailableMemoryMb = 128,
        SourceArchiveBucket = bucket.Name,
        SourceArchiveObject = archive.Name,
        TriggerHttp = true,
        EntryPoint = "helloGET",
    });
    // IAM entry for all users to invoke the function
    var invoker = new Gcp.CloudFunctions.FunctionIamMember("invoker", new Gcp.CloudFunctions.FunctionIamMemberArgs
    {
        Project = function.Project,
        Region = function.Region,
        CloudFunction = function.Name,
        Role = "roles/cloudfunctions.invoker",
        Member = "allUsers",
    });
}

}

Example Usage - Single User

using Pulumi;
using Gcp = Pulumi.Gcp;

class MyStack : Stack
{
public MyStack()
{
    var bucket = new Gcp.Storage.Bucket("bucket", new Gcp.Storage.BucketArgs
    {
    });
    var archive = new Gcp.Storage.BucketObject("archive", new Gcp.Storage.BucketObjectArgs
    {
        Bucket = bucket.Name,
        Source = new FileAsset("./path/to/zip/file/which/contains/code"),
    });
    var function = new Gcp.CloudFunctions.Function("function", new Gcp.CloudFunctions.FunctionArgs
    {
        Description = "My function",
        Runtime = "nodejs10",
        AvailableMemoryMb = 128,
        SourceArchiveBucket = bucket.Name,
        SourceArchiveObject = archive.Name,
        TriggerHttp = true,
        Timeout = 60,
        EntryPoint = "helloGET",
        Labels = 
        {
            { "my-label", "my-label-value" },
        },
        EnvironmentVariables = 
        {
            { "MY_ENV_VAR", "my-env-var-value" },
        },
    });
    // IAM entry for a single user to invoke the function
    var invoker = new Gcp.CloudFunctions.FunctionIamMember("invoker", new Gcp.CloudFunctions.FunctionIamMemberArgs
    {
        Project = function.Project,
        Region = function.Region,
        CloudFunction = function.Name,
        Role = "roles/cloudfunctions.invoker",
        Member = "user:myFunctionInvoker@example.com",
    });
}

}
Inheritance
System.Object
Resource
CustomResource
Function
Inherited Members
CustomResource.Id
Resource.GetResourceType()
Resource.GetResourceName()
Resource.Urn
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Pulumi.Gcp.CloudFunctions
Assembly: Pulumi.Gcp.dll
Syntax
public class Function : CustomResource

Constructors

View Source

Function(String, FunctionArgs, CustomResourceOptions)

Create a Function resource with the given unique name, arguments, and options.

Declaration
public Function(string name, FunctionArgs args, CustomResourceOptions options = null)
Parameters
Type Name Description
System.String name

The unique name of the resource

FunctionArgs args

The arguments used to populate this resource's properties

CustomResourceOptions options

A bag of options that control this resource's behavior

Properties

View Source

AvailableMemoryMb

Memory (in MB), available to the function. Default value is 256MB. Allowed values are: 128MB, 256MB, 512MB, 1024MB, and 2048MB.

Declaration
public Output<int?> AvailableMemoryMb { get; }
Property Value
Type Description
Output<System.Nullable<System.Int32>>
View Source

Description

Description of the function.

Declaration
public Output<string> Description { get; }
Property Value
Type Description
Output<System.String>
View Source

EntryPoint

Name of the function that will be executed when the Google Cloud Function is triggered.

Declaration
public Output<string> EntryPoint { get; }
Property Value
Type Description
Output<System.String>
View Source

EnvironmentVariables

A set of key/value environment variable pairs to assign to the function.

Declaration
public Output<ImmutableDictionary<string, object>> EnvironmentVariables { get; }
Property Value
Type Description
Output<System.Collections.Immutable.ImmutableDictionary<System.String, System.Object>>
View Source

EventTrigger

A source that fires events in response to a condition in another service. Structure is documented below. Cannot be used with trigger_http.

Declaration
public Output<FunctionEventTrigger> EventTrigger { get; }
Property Value
Type Description
Output<FunctionEventTrigger>
View Source

HttpsTriggerUrl

URL which triggers function execution. Returned only if trigger_http is used.

Declaration
public Output<string> HttpsTriggerUrl { get; }
Property Value
Type Description
Output<System.String>
View Source

IngressSettings

String value that controls what traffic can reach the function. Allowed values are ALLOW_ALL and ALLOW_INTERNAL_ONLY. Changes to this field will recreate the cloud function.

Declaration
public Output<string> IngressSettings { get; }
Property Value
Type Description
Output<System.String>
View Source

Labels

A set of key/value label pairs to assign to the function. Label keys must follow the requirements at https://cloud.google.com/resource-manager/docs/creating-managing-labels#requirements.

Declaration
public Output<ImmutableDictionary<string, object>> Labels { get; }
Property Value
Type Description
Output<System.Collections.Immutable.ImmutableDictionary<System.String, System.Object>>
View Source

MaxInstances

The limit on the maximum number of function instances that may coexist at a given time.

Declaration
public Output<int?> MaxInstances { get; }
Property Value
Type Description
Output<System.Nullable<System.Int32>>
View Source

Name

A user-defined name of the function. Function names must be unique globally.

Declaration
public Output<string> Name { get; }
Property Value
Type Description
Output<System.String>
View Source

Project

Project of the function. If it is not provided, the provider project is used.

Declaration
public Output<string> Project { get; }
Property Value
Type Description
Output<System.String>
View Source

Region

Region of function. Currently can be only "us-central1". If it is not provided, the provider region is used.

Declaration
public Output<string> Region { get; }
Property Value
Type Description
Output<System.String>
View Source

Runtime

The runtime in which the function is going to run. Eg. &quot;nodejs8&quot;, &quot;nodejs10&quot;, &quot;python37&quot;, &quot;go111&quot;.

Declaration
public Output<string> Runtime { get; }
Property Value
Type Description
Output<System.String>
View Source

ServiceAccountEmail

If provided, the self-provided service account to run the function with.

Declaration
public Output<string> ServiceAccountEmail { get; }
Property Value
Type Description
Output<System.String>
View Source

SourceArchiveBucket

The GCS bucket containing the zip archive which contains the function.

Declaration
public Output<string> SourceArchiveBucket { get; }
Property Value
Type Description
Output<System.String>
View Source

SourceArchiveObject

The source archive object (file) in archive bucket.

Declaration
public Output<string> SourceArchiveObject { get; }
Property Value
Type Description
Output<System.String>
View Source

SourceRepository

Represents parameters related to source repository where a function is hosted. Cannot be set alongside source_archive_bucket or source_archive_object. Structure is documented below.

Declaration
public Output<FunctionSourceRepository> SourceRepository { get; }
Property Value
Type Description
Output<FunctionSourceRepository>
View Source

Timeout

Timeout (in seconds) for the function. Default value is 60 seconds. Cannot be more than 540 seconds.

Declaration
public Output<int?> Timeout { get; }
Property Value
Type Description
Output<System.Nullable<System.Int32>>
View Source

TriggerHttp

Boolean variable. Any HTTP request (of a supported type) to the endpoint will trigger function execution. Supported HTTP request types are: POST, PUT, GET, DELETE, and OPTIONS. Endpoint is returned as https_trigger_url. Cannot be used with trigger_bucket and trigger_topic.

Declaration
public Output<bool?> TriggerHttp { get; }
Property Value
Type Description
Output<System.Nullable<System.Boolean>>
View Source

VpcConnector

The VPC Network Connector that this cloud function can connect to. It can be either the fully-qualified URI, or the short name of the network connector resource. The format of this field is projects/*/locations/*/connectors/*.

Declaration
public Output<string> VpcConnector { get; }
Property Value
Type Description
Output<System.String>
View Source

VpcConnectorEgressSettings

The egress settings for the connector, controlling what traffic is diverted through it. Allowed values are ALL_TRAFFIC and PRIVATE_RANGES_ONLY. Defaults to PRIVATE_RANGES_ONLY. If unset, this field preserves the previously set value.

Declaration
public Output<string> VpcConnectorEgressSettings { get; }
Property Value
Type Description
Output<System.String>

Methods

View Source

Get(String, Input<String>, FunctionState, CustomResourceOptions)

Get an existing Function resource's state with the given name, ID, and optional extra properties used to qualify the lookup.

Declaration
public static Function Get(string name, Input<string> id, FunctionState state = null, CustomResourceOptions options = null)
Parameters
Type Name Description
System.String name

The unique name of the resulting resource.

Input<System.String> id

The unique provider ID of the resource to lookup.

FunctionState state

Any extra arguments used during the lookup.

CustomResourceOptions options

A bag of options that control this resource's behavior

Returns
Type Description
Function
  • View Source
Back to top Copyright 2016-2020, Pulumi Corporation.