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

Adding initial support for GCF Gen2 terraform integration #5670

Merged
merged 5 commits into from
Mar 2, 2022
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
316 changes: 316 additions & 0 deletions mmv1/products/cloudfunctions2/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,316 @@
# Copyright 2022 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

--- !ruby/object:Api::Product
name: Cloudfunctions2
display_name: Cloud Functions (2nd gen)
scopes:
- https://www.googleapis.com/auth/cloud-platform
versions:
- !ruby/object:Api::Product::Version
name: beta
base_url: https://cloudfunctions.googleapis.com/v2beta/
apis_required:
- !ruby/object:Api::Product::ApiReference
name: Cloud Functions API
url: https://console.cloud.google.com/apis/library/cloudfunctions.googleapis.com/
objects:
- !ruby/object:Api::Resource
name: 'function'
min_version: beta
base_url: projects/{{project}}/locations/{{location}}/functions
create_url: projects/{{project}}/locations/{{location}}/functions?functionId={{name}}
self_link: projects/{{project}}/locations/{{location}}/functions/{{name}}
create_verb: :POST
references: !ruby/object:Api::Resource::ReferenceLinks
api: 'https://cloud.google.com/functions/docs/reference/rest/v2beta'
description: |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible include a references section, similar to

references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Automating builds using build triggers': 'https://cloud.google.com/cloud-build/docs/running-builds/automate-builds'
api: 'https://cloud.google.com/cloud-build/docs/api/reference/rest/v1/projects.triggers'

That'll link the API reference and a user guide from the provider docs for the resource.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a similar note- are those docs published somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have public docs since we're just going to Public Preview, I'll check with my lead on this one though. Let me know if you want to see the internal docs.

A Cloud Function that contains user computation executed in response to an event.
collection_url_key: 'functions'
update_mask: true
async: !ruby/object:Api::OpAsync
operation: !ruby/object:Api::OpAsync::Operation
path: 'name'
base_url: '{{op_id}}'
wait_ms: 1000
# It takes about 35-40 mins to get the resource created
timeouts: !ruby/object:Api::Timeouts
insert_minutes: 60
update_minutes: 60
delete_minutes: 60
result: !ruby/object:Api::OpAsync::Result
path: 'response'
resource_inside_response: true
status: !ruby/object:Api::OpAsync::Status
path: 'done'
complete: true
allowed:
- True
- False
error: !ruby/object:Api::OpAsync::Error
path: 'error'
message: 'message'
parameters:
- !ruby/object:Api::Type::String
name: 'location'
k-ezis marked this conversation as resolved.
Show resolved Hide resolved
input: true
url_param_only: true
description: The location of this cloud function.
properties:
- !ruby/object:Api::Type::String
name: 'name'
required: true
input: true
description: |
A user-defined name of the function. Function names must
be unique globally and match pattern `projects/*/locations/*/functions/*`.
pattern: projects/{{project}}/locations/{{location}}/functions/{{name}}
- !ruby/object:Api::Type::String
name: 'description'
description: 'User-provided description of a function.'
- !ruby/object:Api::Type::Enum
name: 'environment'
output: true
description: 'The environment the function is hosted on.'
values:
- :ENVIRONMENT_UNSPECIFIED
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all enums, X_UNSPECIFIED tends to be invalid to actually send to the API so we can omit it. If that's not the case, please ignore this though.

- :GEN_1
- :GEN_2
- !ruby/object:Api::Type::Enum
name: 'state'
output: true
description: 'Describes the current state of the function.'
values:
- :STATE_UNSPECIFIED
- :ACTIVE
- :FAILED
- :DEPLOYING
- :DELETING
- :UNKNOWN
- !ruby/object:Api::Type::NestedObject
name: 'buildConfig'
description: |
Describes the Build step of the function that builds a container
from the given source.
properties:
- !ruby/object:Api::Type::String
name: 'build'
description: |
The Cloud Build name of the latest successful
deployment of the function.
output: true
- !ruby/object:Api::Type::String
name: 'runtime'
description: |
The runtime in which to run the function. Required when deploying a new
function, optional when updating an existing function.
- !ruby/object:Api::Type::String
name: 'entryPoint'
description: |
The name of the function (as defined in source code) that will be executed.
Defaults to the resource name suffix, if not specified. For backward
compatibility, if function with given name is not found, then the system
will try to use function named "function". For Node.js this is name of a
function exported by the module specified in source_location.
- !ruby/object:Api::Type::NestedObject
name: 'source'
description: 'The location of the function source code.'
properties:
- !ruby/object:Api::Type::NestedObject
name: 'storageSource'
description: 'If provided, get the source from this location in Google Cloud Storage.'
exactly_one_of:
- storage_source
- repo_source
properties:
- !ruby/object:Api::Type::String
name: 'bucket'
description: 'Google Cloud Storage bucket containing the source'
- !ruby/object:Api::Type::String
name: 'object'
description: 'Google Cloud Storage object containing the source.'
- !ruby/object:Api::Type::Integer
name: 'generation'
description: |
Google Cloud Storage generation for the object. If the generation
is omitted, the latest generation will be used.
- !ruby/object:Api::Type::NestedObject
name: 'repoSource'
description: 'If provided, get the source from this location in a Cloud Source Repository.'
exactly_one_of:
- storage_source
- repo_source
properties:
- !ruby/object:Api::Type::String
name: 'projectId'
input: true
description: |
ID of the project that owns the Cloud Source Repository. If omitted, the
project ID requesting the build is assumed.
- !ruby/object:Api::Type::String
name: 'repoName'
description: 'Name of the Cloud Source Repository.'
- !ruby/object:Api::Type::String
name: 'branchName'
description: 'Regex matching branches to build.'
exactly_one_of:
- branch_name
- tag_name
- commit_sha
- !ruby/object:Api::Type::String
name: 'tagName'
description: 'Regex matching tags to build.'
exactly_one_of:
- branch_name
- tag_name
- commit_sha
- !ruby/object:Api::Type::String
name: 'commitSha'
description: 'Regex matching tags to build.'
exactly_one_of:
- branch_name
- tag_name
- commit_sha
- !ruby/object:Api::Type::String
name: 'dir'
description: |
Directory, relative to the source root, in which to run the build.
- !ruby/object:Api::Type::Boolean
name: 'invertRegex'
description: |
Only trigger a build if the revision regex does
NOT match the revision regex.
- !ruby/object:Api::Type::String
name: 'workerPool'
description: 'Name of the Cloud Build Custom Worker Pool that should be used to build the function.'
- !ruby/object:Api::Type::KeyValuePairs
name: 'environmentVariables'
description: |
User-provided build-time environment variables for the function.
- !ruby/object:Api::Type::String
name: 'dockerRepository'
description: |
User managed repository created in Artifact Registry optionally with a customer managed encryption key.
- !ruby/object:Api::Type::NestedObject
name: 'serviceConfig'
description: 'Describes the Service being deployed.'
properties:
- !ruby/object:Api::Type::String
name: 'service'
description: |
Name of the service associated with a Function.
- !ruby/object:Api::Type::Integer
name: 'timeoutSeconds'
description: |
The function execution timeout. Execution is considered failed and
can be terminated if the function is not completed at the end of the
timeout period. Defaults to 60 seconds.
- !ruby/object:Api::Type::String
name: 'availableMemory'
description: |
The amount of memory available for a function.
Defaults to 256M. Supported units are k, M, G, Mi, Gi. If no unit is
supplied the value is interpreted as bytes.
- !ruby/object:Api::Type::KeyValuePairs
name: 'environmentVariables'
description: 'Environment variables that shall be available during function execution.'
- !ruby/object:Api::Type::Integer
name: 'maxInstanceCount'
description: |
The limit on the maximum number of function instances that may coexist at a
given time.
- !ruby/object:Api::Type::Integer
name: 'minInstanceCount'
description: |
The limit on the minimum number of function instances that may coexist at a
given time.
- !ruby/object:Api::Type::String
name: 'vpcConnector'
description: 'The Serverless VPC Access connector that this cloud function can connect to.'
- !ruby/object:Api::Type::Enum
name: 'vpcConnectorEgressSettings'
description: 'Available egress settings.'
values:
- :VPC_CONNECTOR_EGRESS_SETTINGS_UNSPECIFIED
- :PRIVATE_RANGES_ONLY
- :ALL_TRAFFIC
- !ruby/object:Api::Type::Enum
name: 'ingressSettings'
description: 'Available ingress settings. Defaults to "ALLOW_ALL" if unspecified.'
values:
- :ALLOW_ALL
- :ALLOW_INTERNAL_ONLY
- :ALLOW_INTERNAL_AND_GCLB
default_value: :ALLOW_ALL
- !ruby/object:Api::Type::String
name: 'uri'
description: 'URI of the Service deployed.'
output: true
- !ruby/object:Api::Type::String
name: 'gcfUri'
description: 'URIs of the Service deployed'
output: true
- !ruby/object:Api::Type::String
name: 'serviceAccountEmail'
output: true
description: 'The email of the service account for this function.'
- !ruby/object:Api::Type::Boolean
name: 'allTrafficOnLatestRevision'
description: 'Whether 100% of traffic is routed to the latest revision. Defaults to true.'
default_value: true
- !ruby/object:Api::Type::NestedObject
name: 'eventTrigger'
description: |
An Eventarc trigger managed by Google Cloud Functions that fires events in
response to a condition in another service.
properties:
- !ruby/object:Api::Type::String
name: 'trigger'
description: 'The resource name of the Eventarc trigger.'
output: true
- !ruby/object:Api::Type::String
name: 'triggerRegion'
description: |
The region that the trigger will be in. The trigger will only receive
events originating in this region. It can be the same
region as the function, a different region or multi-region, or the global
region. If not provided, defaults to the same region as the function.
- !ruby/object:Api::Type::String
name: 'eventType'
description: 'Required. The type of event to observe.'
- !ruby/object:Api::Type::String
name: 'pubsubTopic'
description: |
The name of a Pub/Sub topic in the same project that will be used
as the transport topic for the event delivery.
- !ruby/object:Api::Type::String
name: 'serviceAccountEmail'
output: true
description: 'The email of the service account for this function.'
- !ruby/object:Api::Type::Enum
name: 'retryPolicy'
description: |
Describes the retry policy in case of function's execution failure.
Retried execution is charged as any other execution.
values:
- :RETRY_POLICY_UNSPECIFIED
- :RETRY_POLICY_DO_NOT_RETRY
- :RETRY_POLICY_RETRY
- !ruby/object:Api::Type::String
name: 'updateTime'
output: true
description: 'The last update timestamp of a Cloud Function.'
- !ruby/object:Api::Type::KeyValuePairs
name: 'labels'
description: |
A set of key/value label pairs associated with this Cloud Function.
64 changes: 64 additions & 0 deletions mmv1/products/cloudfunctions2/terraform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright 2022 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

--- !ruby/object:Provider::Terraform::Config
overrides: !ruby/object:Overrides::ResourceOverrides
function: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: 'projects/{{project}}/locations/{{location}}/functions/{{name}}'
base_url: projects/{{project}}/locations/{{location}}/functions
import_format: ["projects/{{project}}/locations/{{location}}/functions/{{name}}"]
autogen_async: true
examples:
- !ruby/object:Provider::Terraform::Examples
name: "cloudfunctions2_basic"
min_version: beta
primary_resource_id: "terraform-test2"
primary_resource_name: "terraform-test2"
vars:
bucket_name: "cloudfunctions2-function-bucket"
function: "test-function"
zip_path: "path/to/index.zip"
test_vars_overrides:
zip_path: "\"./test-fixtures/cloudfunctions2/function-source.zip\""
# ignore these fields during import step
ignore_read_extra:
- "build_config.0.source.0.storage_source.0.object"
- "build_config.0.source.0.storage_source.0.bucket"
- !ruby/object:Provider::Terraform::Examples
name: "cloudfunctions2_full"
min_version: beta
primary_resource_id: "terraform-test"
primary_resource_name: "terraform-test"
vars:
bucket_name: "cloudfunctions2-function-bucket"
function: "test-function"
zip_path: "path/to/index.zip"
router: "gcf2-router"
test_vars_overrides:
zip_path: "\"./test-fixtures/cloudfunctions2/function-source.zip\""
# ignore these fields during import step
ignore_read_extra:
- "build_config.0.source.0.storage_source.0.object"
- "build_config.0.source.0.storage_source.0.bucket"
properties:
name: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb'
custom_expand: 'templates/terraform/custom_expand/shortname_to_url.go.erb'
buildConfig.source.storageSource.object: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: 'templates/terraform/custom_flatten/cloudfunctions2_function_source_object.go.erb'
buildConfig.source.storageSource.bucket: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: 'templates/terraform/custom_flatten/cloudfunctions2_function_source_bucket.go.erb'
buildConfig.environmentVariables: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
serviceConfig.service: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
Loading