» google_app_engine_flexible_app_version

Flexible App Version resource to create a new version of flexible GAE Application. Based on Google Compute Engine, the App Engine flexible environment automatically scales your app up and down while also balancing the load. Learn about the differences between the standard environment and the flexible environment at https://cloud.google.com/appengine/docs/the-appengine-environments.

To get more information about FlexibleAppVersion, see:

» Example Usage - App Engine Flexible App Version

resource "google_project" "my_project" {
  name = "appeng-flex"
  project_id = "appeng-flex"
  org_id = "123456789"
  billing_account = "000000-0000000-0000000-000000"
}

resource "google_app_engine_application" "app" {
  project     = google_project.my_project.project_id
  location_id = "us-central"
}

resource "google_project_service" "service" {
  project = google_project.my_project.project_id
  service = "appengineflex.googleapis.com"

  disable_dependent_services = false
}

resource "google_project_iam_member" "gae_api" {
  project = google_project_service.service.project
  role    = "roles/compute.networkUser"
  member  = "serviceAccount:service-${google_project.my_project.number}@gae-api-prod.google.com.iam.gserviceaccount.com"
}

resource "google_app_engine_flexible_app_version" "myapp_v1" {
  version_id = "v1"
  project    = google_project_iam_member.gae_api.project
  service    = "default"
  runtime    = "nodejs"

  entrypoint {
    shell = "node ./app.js"
  }

  deployment {
    zip {
      source_url = "https://storage.googleapis.com/${google_storage_bucket.bucket.name}/${google_storage_bucket_object.object.name}"
    }
  }

  liveness_check {
    path = "/"
  }

  readiness_check {
    path = "/"
  }

  env_variables = {
    port = "8080"
  }

  handlers {
    url_regex        = ".*\\/my-path\\/*"
    security_level   = "SECURE_ALWAYS"
    login            = "LOGIN_REQUIRED"
    auth_fail_action = "AUTH_FAIL_ACTION_REDIRECT"

    static_files {
      path = "my-other-path"
      upload_path_regex = ".*\\/my-path\\/*"
    }
  }

  automatic_scaling {
    cool_down_period = "120s"
    cpu_utilization {
      target_utilization = 0.5
    }
  }

  noop_on_destroy = true
}

resource "google_storage_bucket" "bucket" {
  project = google_project.my_project.project_id
  name = "appengine-static-content"
}

resource "google_storage_bucket_object" "object" {
  name   = "hello-world.zip"
  bucket = google_storage_bucket.bucket.name
  source = "./test-fixtures/appengine/hello-world.zip"
}

» Argument Reference

The following arguments are supported:

  • runtime - (Required) Desired runtime. Example python27.

  • readiness_check - (Required) Configures readiness health checking for instances. Unhealthy instances are not put into the backend traffic rotation. Structure is documented below.

  • liveness_check - (Required) Health checking configuration for VM instances. Unhealthy instances are killed and replaced with new instances. Structure is documented below.

  • service - (Required) AppEngine service resource

The readiness_check block supports:

  • path - (Required) The request path.

  • host - (Optional) Host header to send when performing a HTTP Readiness check. Example: "myapp.appspot.com"

  • failure_threshold - (Optional) Number of consecutive failed checks required before removing traffic. Default: 2.

  • success_threshold - (Optional) Number of consecutive successful checks required before receiving traffic. Default: 2.

  • check_interval - (Optional) Interval between health checks. Default: "5s".

  • timeout - (Optional) Time before the check is considered failed. Default: "4s"

  • app_start_timeout - (Optional) A maximum time limit on application initialization, measured from moment the application successfully replies to a healthcheck until it is ready to serve traffic. Default: "300s"

The liveness_check block supports:

  • path - (Required) The request path.

  • host - (Optional) Host header to send when performing a HTTP Readiness check. Example: "myapp.appspot.com"

  • failure_threshold - (Optional) Number of consecutive failed checks required before considering the VM unhealthy. Default: 4.

  • success_threshold - (Optional) Number of consecutive successful checks required before considering the VM healthy. Default: 2.

  • check_interval - (Optional) Interval between health checks.

  • timeout - (Optional) Time before the check is considered failed. Default: "4s"

  • initial_delay - (Optional) The initial delay before starting to execute the checks. Default: "300s"


  • version_id - (Optional) Relative name of the version within the service. For example, v1. Version names can contain only lowercase letters, numbers, or hyphens. Reserved names,"default", "latest", and any name with the prefix "ah-".

  • inbound_services - (Optional) Before an application can receive email or XMPP messages, the application must be configured to enable the service.

  • instance_class - (Optional) Instance class that is used to run this version. Valid values are AutomaticScaling: F1, F2, F4, F4_1G ManualScaling: B1, B2, B4, B8, B4_1G Defaults to F1 for AutomaticScaling and B1 for ManualScaling.

  • network - (Optional) Extra network settings Structure is documented below.

  • resources - (Optional) Machine resources for a version. Structure is documented below.

  • runtime_channel - (Optional) The channel of the runtime to use. Only available for some runtimes.

  • beta_settings - (Optional) Metadata settings that are supplied to this version to enable beta runtime features.

  • serving_status - (Optional) Current serving status of this version. Only the versions with a SERVING status create instances and can be billed. Default value is SERVING. Possible values are SERVING and STOPPED.

  • runtime_api_version - (Optional) The version of the API in the given runtime environment. Please see the app.yaml reference for valid values at https://cloud.google.com/appengine/docs/standard//config/appref

  • handlers - (Optional) An ordered list of URL-matching patterns that should be applied to incoming requests. The first matching URL handles the request and other request handlers are not attempted. Structure is documented below.

  • runtime_main_executable_path - (Optional) The path or name of the app's main executable.

  • api_config - (Optional) Serving configuration for Google Cloud Endpoints. Structure is documented below.

  • env_variables - (Optional) Environment variables available to the application. As these are not returned in the API request, Terraform will not detect any changes made outside of the Terraform config.

  • default_expiration - (Optional) Duration that static files should be cached by web proxies and browsers. Only applicable if the corresponding StaticFilesHandler does not specify its own expiration time.

  • nobuild_files_regex - (Optional) Files that match this pattern will not be built into this version. Only applicable for Go runtimes.

  • deployment - (Optional) Code and application artifacts that make up this version. Structure is documented below.

  • endpoints_api_service - (Optional) Code and application artifacts that make up this version. Structure is documented below.

  • entrypoint - (Optional) The entrypoint for the application. Structure is documented below.

  • vpc_access_connector - (Optional) Enables VPC connectivity for standard apps. Structure is documented below.

  • automatic_scaling - (Optional) Automatic scaling is based on request rate, response latencies, and other application metrics. Structure is documented below.

  • manual_scaling - (Optional) A service with manual scaling runs continuously, allowing you to perform complex initialization and rely on the state of its memory over time. Structure is documented below.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

  • noop_on_destroy - (Optional) If set to true, the application version will not be deleted.

  • delete_service_on_destroy - (Optional) If set to true, the service will be deleted if it is the last version.

The network block supports:

  • forwarded_ports - (Optional) List of ports, or port pairs, to forward from the virtual machine to the application container.

  • instance_tag - (Optional) Tag to apply to the instance during creation.

  • name - (Required) Google Compute Engine network where the virtual machines are created. Specify the short name, not the resource path.

  • subnetwork - (Optional) Google Cloud Platform sub-network where the virtual machines are created. Specify the short name, not the resource path. If the network that the instance is being created in is a Legacy network, then the IP address is allocated from the IPv4Range. If the network that the instance is being created in is an auto Subnet Mode Network, then only network name should be specified (not the subnetworkName) and the IP address is created from the IPCidrRange of the subnetwork that exists in that zone for that network. If the network that the instance is being created in is a custom Subnet Mode Network, then the subnetworkName must be specified and the IP address is created from the IPCidrRange of the subnetwork. If specified, the subnetwork must exist in the same region as the App Engine flexible environment application.

  • session_affinity - (Optional) Enable session affinity.

The resources block supports:

  • cpu - (Optional) Number of CPU cores needed.

  • disk_gb - (Optional) Disk size (GB) needed.

  • memory_gb - (Optional) Memory (GB) needed.

  • volumes - (Optional) List of ports, or port pairs, to forward from the virtual machine to the application container. Structure is documented below.

The volumes block supports:

  • name - (Required) Unique name for the volume.

  • volume_type - (Required) Underlying volume type, e.g. 'tmpfs'.

  • size_gb - (Required) Volume size in gigabytes.

The handlers block supports:

  • url_regex - (Optional) URL prefix. Uses regular expression syntax, which means regexp special characters must be escaped, but should not contain groupings. All URLs that begin with this prefix are handled by this handler, using the portion of the URL after the prefix as part of the file path.

  • security_level - (Optional) Security (HTTPS) enforcement for this URL. Possible values are SECURE_DEFAULT, SECURE_NEVER, SECURE_OPTIONAL, and SECURE_ALWAYS.

  • login - (Optional) Methods to restrict access to a URL based on login status. Possible values are LOGIN_OPTIONAL, LOGIN_ADMIN, and LOGIN_REQUIRED.

  • auth_fail_action - (Optional) Actions to take when the user is not logged in. Possible values are AUTH_FAIL_ACTION_REDIRECT and AUTH_FAIL_ACTION_UNAUTHORIZED.

  • redirect_http_response_code - (Optional) 30x code to use when performing redirects for the secure field. Possible values are REDIRECT_HTTP_RESPONSE_CODE_301, REDIRECT_HTTP_RESPONSE_CODE_302, REDIRECT_HTTP_RESPONSE_CODE_303, and REDIRECT_HTTP_RESPONSE_CODE_307.

  • script - (Optional) Executes a script to handle the requests that match this URL pattern. Only the auto value is supported for Node.js in the App Engine standard environment, for example "script:" "auto". Structure is documented below.

  • static_files - (Optional) Files served directly to the user for a given URL, such as images, CSS stylesheets, or JavaScript source files. Static file handlers describe which files in the application directory are static files, and which URLs serve them. Structure is documented below.

The script block supports:

  • script_path - (Required) Path to the script from the application root directory.

The static_files block supports:

  • path - (Optional) Path to the static files matched by the URL pattern, from the application root directory. The path can refer to text matched in groupings in the URL pattern.

  • upload_path_regex - (Optional) Regular expression that matches the file paths for all files that should be referenced by this handler.

  • http_headers - (Optional) HTTP headers to use for all responses from these URLs. An object containing a list of "key:value" value pairs.".

  • mime_type - (Optional) MIME type used to serve all files served by this handler. Defaults to file-specific MIME types, which are derived from each file's filename extension.

  • expiration - (Optional) Time a static file served by this handler should be cached by web proxies and browsers. A duration in seconds with up to nine fractional digits, terminated by 's'. Example "3.5s". Default is '0s'

  • require_matching_file - (Optional) Whether this handler should match the request if the file referenced by the handler does not exist.

  • application_readable - (Optional) Whether files should also be uploaded as code data. By default, files declared in static file handlers are uploaded as static data and are only served to end users; they cannot be read by the application. If enabled, uploads are charged against both your code and static data storage resource quotas.

The api_config block supports:

  • auth_fail_action - (Optional) Action to take when users access resources that require authentication. Default value is AUTH_FAIL_ACTION_REDIRECT. Possible values are AUTH_FAIL_ACTION_REDIRECT and AUTH_FAIL_ACTION_UNAUTHORIZED.

  • login - (Optional) Level of login required to access this resource. Default value is LOGIN_OPTIONAL. Possible values are LOGIN_OPTIONAL, LOGIN_ADMIN, and LOGIN_REQUIRED.

  • script - (Required) Path to the script from the application root directory.

  • security_level - (Optional) Security (HTTPS) enforcement for this URL. Possible values are SECURE_DEFAULT, SECURE_NEVER, SECURE_OPTIONAL, and SECURE_ALWAYS.

  • url - (Optional) URL to serve the endpoint at.

The deployment block supports:

  • zip - (Optional) Zip File Structure is documented below.

  • files - (Optional) Manifest of the files stored in Google Cloud Storage that are included as part of this version. All files must be readable using the credentials supplied with this call. Structure is documented below.

  • container - (Optional) The Docker image for the container that runs the version. Structure is documented below.

  • cloud_build_options - (Optional) Options for the build operations performed as a part of the version deployment. Only applicable when creating a version using source code directly. Structure is documented below.

The zip block supports:

The files block supports:

  • name - (Required) The identifier for this object. Format specified above.

  • sha1_sum - (Optional) SHA1 checksum of the file

  • source_url - (Required) Source URL

The container block supports:

  • image - (Required) URI to the hosted container image in Google Container Registry. The URI must be fully qualified and include a tag or digest. Examples: "gcr.io/my-project/image:tag" or "gcr.io/my-project/image@digest"

The cloud_build_options block supports:

  • app_yaml_path - (Required) Path to the yaml file used in deployment, used to determine runtime configuration details.

  • cloud_build_timeout - (Optional) The Cloud Build timeout used as part of any dependent builds performed by version creation. Defaults to 10 minutes. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".

The endpoints_api_service block supports:

  • name - (Required) Endpoints service name which is the name of the "service" resource in the Service Management API. For example "myapi.endpoints.myproject.cloud.goog"

  • config_id - (Optional) Endpoints service configuration ID as specified by the Service Management API. For example "2016-09-19r1". By default, the rollout strategy for Endpoints is "FIXED". This means that Endpoints starts up with a particular configuration ID. When a new configuration is rolled out, Endpoints must be given the new configuration ID. The configId field is used to give the configuration ID and is required in this case. Endpoints also has a rollout strategy called "MANAGED". When using this, Endpoints fetches the latest configuration and does not need the configuration ID. In this case, configId must be omitted.

  • rollout_strategy - (Optional) Endpoints rollout strategy. If FIXED, configId must be specified. If MANAGED, configId must be omitted. Default value is FIXED. Possible values are FIXED and MANAGED.

  • disable_trace_sampling - (Optional) Enable or disable trace sampling. By default, this is set to false for enabled.

The entrypoint block supports:

  • shell - (Required) The format should be a shell command that can be fed to bash -c.

The vpc_access_connector block supports:

  • name - (Required) Full Serverless VPC Access Connector name e.g. /projects/my-project/locations/us-central1/connectors/c1.

The automatic_scaling block supports:

  • cool_down_period - (Optional) The time period that the Autoscaler should wait before it starts collecting information from a new instance. This prevents the autoscaler from collecting information when the instance is initializing, during which the collected usage would not be reliable. Default: 120s

  • cpu_utilization - (Required) Target scaling by CPU usage. Structure is documented below.

  • max_concurrent_requests - (Optional) Number of concurrent requests an automatic scaling instance can accept before the scheduler spawns a new instance. Defaults to a runtime-specific value.

  • max_idle_instances - (Optional) Maximum number of idle instances that should be maintained for this version.

  • max_total_instances - (Optional) Maximum number of instances that should be started to handle requests for this version. Default: 20

  • max_pending_latency - (Optional) Maximum amount of time that a request should wait in the pending queue before starting a new instance to handle it.

  • min_idle_instances - (Optional) Minimum number of idle instances that should be maintained for this version. Only applicable for the default version of a service.

  • min_total_instances - (Optional) Minimum number of running instances that should be maintained for this version. Default: 2

  • min_pending_latency - (Optional) Minimum amount of time a request should wait in the pending queue before starting a new instance to handle it.

  • request_utilization - (Optional) Target scaling by request utilization. Structure is documented below.

  • disk_utilization - (Optional) Target scaling by disk usage. Structure is documented below.

  • network_utilization - (Optional) Target scaling by network usage. Structure is documented below.

The cpu_utilization block supports:

The request_utilization block supports:

The disk_utilization block supports:

The network_utilization block supports:

The manual_scaling block supports:

  • instances - (Required) Number of instances to assign to the service at the start. Note: When managing the number of instances at runtime through the App Engine Admin API or the (now deprecated) Python 2 Modules API set_num_instances() you must use lifecycle.ignore_changes = ["manual_scaling"[0].instances] to prevent drift detection.

» Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

  • id - an identifier for the resource with format apps/{{project}}/services/{{service}}/versions/{{version_id}}

  • name - Full path to the Version resource in the API. Example, "v1".

» Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 10 minutes.
  • update - Default is 10 minutes.
  • delete - Default is 10 minutes.

» Import

FlexibleAppVersion can be imported using any of these accepted formats:

$ terraform import google_app_engine_flexible_app_version.default apps/{{project}}/services/{{service}}/versions/{{version_id}}
$ terraform import google_app_engine_flexible_app_version.default {{project}}/{{service}}/{{version_id}}
$ terraform import google_app_engine_flexible_app_version.default {{service}}/{{version_id}}

» User Project Overrides

This resource supports User Project Overrides.