Skip to content

Commit

Permalink
promote cfn2 to ga (#6388)
Browse files Browse the repository at this point in the history
  • Loading branch information
DrFaust92 authored Aug 16, 2022
1 parent b30c72e commit db56430
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 51 deletions.
4 changes: 3 additions & 1 deletion mmv1/products/cloudfunctions2/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ versions:
- !ruby/object:Api::Product::Version
name: beta
base_url: https://cloudfunctions.googleapis.com/v2beta/
- !ruby/object:Api::Product::Version
name: ga
base_url: https://cloudfunctions.googleapis.com/v2/
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}}
Expand Down
20 changes: 6 additions & 14 deletions mmv1/products/cloudfunctions2/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,29 @@ overrides: !ruby/object:Overrides::ResourceOverrides
examples:
- !ruby/object:Provider::Terraform::Examples
name: "cloudfunctions2_basic"
min_version: beta
primary_resource_id: "function"
primary_resource_name: "function"
primary_resource_name: "fmt.Sprintf(\"tf-test-function-v2%s\", context[\"random_suffix\"])"
vars:
function: "function-v2"
bucket_name: "gcf-source"
function: "test-function"
zip_path: "function-source.zip"
test_env_vars:
project: :PROJECT_NAME
test_vars_overrides:
zip_path: "\"./test-fixtures/cloudfunctions2/function-source.zip\""
primary_resource_id: "\"function\""
location: "\"us-central1\""
# 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: "function"
primary_resource_name: "function"
vars:
bucket_name: "gcf-source"
service_account: "test-sa"
service_account: "sa"
topic: "functions2-topic"
function: "test-function"
function: "function"
zip_path: "function-source.zip"
test_env_vars:
project: :PROJECT_NAME
Expand All @@ -61,13 +57,12 @@ overrides: !ruby/object:Overrides::ResourceOverrides
- "build_config.0.source.0.storage_source.0.bucket"
- !ruby/object:Provider::Terraform::Examples
name: "cloudfunctions2_basic_gcs"
min_version: beta
primary_resource_id: "function"
vars:
bucket_name_source: "gcf-source-bucket"
bucket_name_trigger: "gcf-trigger-bucket"
service_account: "test-sa"
function_name: "test-function"
service_account: "sa"
function_name: "function"
zip_path: "function-source.zip"
test_env_vars:
project: :PROJECT_NAME
Expand All @@ -80,7 +75,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
- "build_config.0.source.0.storage_source.0.bucket"
- !ruby/object:Provider::Terraform::Examples
name: "cloudfunctions2_basic_auditlogs"
min_version: beta
primary_resource_id: "function"
vars:
bucket_name_source: "gcf-source-bucket"
Expand Down Expand Up @@ -118,8 +112,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
eventTrigger.eventFilters: !ruby/object:Overrides::Terraform::PropertyOverride
is_set: true
iam_policy: !ruby/object:Api::Resource::IamPolicy
min_version: beta
parent_resource_attribute: 'cloud_function'
method_name_separator: ':'
import_format: ["projects/{{project}}/locations/{{location}}/functions/{{cloud_function}}", "{{cloud_function}}"]
example_config_body: 'templates/terraform/iam/example_config_body/cloudfunctions2_function.tf.erb'
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,19 @@ locals {
project = "<%= ctx[:test_env_vars]['project'] %>" # Google Cloud Platform Project ID
}

provider "google-beta" {
project = local.project
}

resource "google_storage_bucket" "bucket" {
provider = google-beta
name = "${local.project}-<%= ctx[:vars]['bucket_name'] %>" # Every bucket name must be globally unique
location = "US"
uniform_bucket_level_access = true
}

resource "google_storage_bucket_object" "object" {
provider = google-beta
name = "function-source.zip"
bucket = google_storage_bucket.bucket.name
source = "<%= ctx[:vars]['zip_path'] %>" # Add path to the zipped function source code
}

resource "google_cloudfunctions2_function" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta
name = "<%= ctx[:vars]['function'] %>"
location = "us-central1"
description = "a new function"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@
# https://cloud.google.com/eventarc/docs/path-patterns

resource "google_storage_bucket" "source-bucket" {
provider = google-beta
name = "<%= ctx[:vars]['bucket_name_source'] %>"
location = "US"
uniform_bucket_level_access = true
}

resource "google_storage_bucket_object" "object" {
provider = google-beta
name = "function-source.zip"
bucket = google_storage_bucket.source-bucket.name
source = "<%= ctx[:vars]['zip_path'] %>" # Add path to the zipped function source code
}

resource "google_service_account" "account" {
provider = google-beta
account_id = "<%= ctx[:vars]['service_account'] %>"
display_name = "Test Service Account - used for both the cloud function and eventarc trigger in the test"
}
Expand All @@ -28,36 +25,31 @@ resource "google_service_account" "account" {
# Here we use Audit Logs to monitor the bucket so path patterns can be used in the example of
# google_cloudfunctions2_function below (Audit Log events have path pattern support)
resource "google_storage_bucket" "audit-log-bucket" {
provider = google-beta
name = "<%= ctx[:vars]['bucket_name_auditlogs'] %>"
location = "us-central1" # The trigger must be in the same location as the bucket
uniform_bucket_level_access = true
}

# Permissions on the service account used by the function and Eventarc trigger
resource "google_project_iam_member" "invoking" {
provider = google-beta
project = "<%= ctx[:test_env_vars]['project'] %>"
role = "roles/run.invoker"
member = "serviceAccount:${google_service_account.account.email}"
}

resource "google_project_iam_member" "event-receiving" {
provider = google-beta
project = "<%= ctx[:test_env_vars]['project'] %>"
role = "roles/eventarc.eventReceiver"
member = "serviceAccount:${google_service_account.account.email}"
}

resource "google_project_iam_member" "artifactregistry-reader" {
provider = google-beta
project = "<%= ctx[:test_env_vars]['project'] %>"
role = "roles/artifactregistry.reader"
member = "serviceAccount:${google_service_account.account.email}"
}

resource "google_cloudfunctions2_function" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta
depends_on = [
google_project_iam_member.event-receiving,
google_project_iam_member.artifactregistry-reader,
Expand Down
10 changes: 0 additions & 10 deletions mmv1/templates/terraform/examples/cloudfunctions2_basic_gcs.tf.erb
Original file line number Diff line number Diff line change
@@ -1,69 +1,59 @@
# [START functions_v2_basic_gcs]

resource "google_storage_bucket" "source-bucket" {
provider = google-beta
name = "<%= ctx[:vars]['bucket_name_source'] %>"
location = "US"
uniform_bucket_level_access = true
}

resource "google_storage_bucket_object" "object" {
provider = google-beta
name = "function-source.zip"
bucket = google_storage_bucket.source-bucket.name
source = "<%= ctx[:vars]['zip_path'] %>" # Add path to the zipped function source code
}

resource "google_storage_bucket" "trigger-bucket" {
provider = google-beta
name = "<%= ctx[:vars]['bucket_name_trigger'] %>"
location = "us-central1" # The trigger must be in the same location as the bucket
uniform_bucket_level_access = true
}

data "google_storage_project_service_account" "gcs_account" {
provider = google-beta
}

# To use GCS CloudEvent triggers, the GCS service account requires the Pub/Sub Publisher(roles/pubsub.publisher) IAM role in the specified project.
# (See https://cloud.google.com/eventarc/docs/run/quickstart-storage#before-you-begin)
resource "google_project_iam_member" "gcs-pubsub-publishing" {
provider = google-beta
project = "<%= ctx[:test_env_vars]['project'] %>"
role = "roles/pubsub.publisher"
member = "serviceAccount:${data.google_storage_project_service_account.gcs_account.email_address}"
}

resource "google_service_account" "account" {
provider = google-beta
account_id = "<%= ctx[:vars]['service_account'] %>"
display_name = "Test Service Account - used for both the cloud function and eventarc trigger in the test"
}

# Permissions on the service account used by the function and Eventarc trigger
resource "google_project_iam_member" "invoking" {
provider = google-beta
project = "<%= ctx[:test_env_vars]['project'] %>"
role = "roles/run.invoker"
member = "serviceAccount:${google_service_account.account.email}"
}

resource "google_project_iam_member" "event-receiving" {
provider = google-beta
project = "<%= ctx[:test_env_vars]['project'] %>"
role = "roles/eventarc.eventReceiver"
member = "serviceAccount:${google_service_account.account.email}"
}

resource "google_project_iam_member" "artifactregistry-reader" {
provider = google-beta
project = "<%= ctx[:test_env_vars]['project'] %>"
role = "roles/artifactregistry.reader"
member = "serviceAccount:${google_service_account.account.email}"
}

resource "google_cloudfunctions2_function" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta
depends_on = [
google_project_iam_member.event-receiving,
google_project_iam_member.artifactregistry-reader,
Expand Down
9 changes: 0 additions & 9 deletions mmv1/templates/terraform/examples/cloudfunctions2_full.tf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,28 @@ locals {
project = "<%= ctx[:test_env_vars]['project'] %>" # Google Cloud Platform Project ID
}

provider "google-beta" {
project = local.project
}

resource "google_service_account" "account" {
provider = google-beta
account_id = "<%= ctx[:vars]['service_account'] %>"
display_name = "Test Service Account"
}

resource "google_pubsub_topic" "topic" {
provider = google-beta
name = "<%= ctx[:vars]['topic'] %>"
}

resource "google_storage_bucket" "bucket" {
provider = google-beta
name = "${local.project}-<%= ctx[:vars]['bucket_name'] %>" # Every bucket name must be globally unique
location = "US"
uniform_bucket_level_access = true
}

resource "google_storage_bucket_object" "object" {
provider = google-beta
name = "function-source.zip"
bucket = google_storage_bucket.bucket.name
source = "<%= ctx[:vars]['zip_path'] %>" # Add path to the zipped function source code
}

resource "google_cloudfunctions2_function" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta
name = "<%= ctx[:vars]['function'] %>"
location = "us-central1"
description = "a new function"
Expand Down

This file was deleted.

0 comments on commit db56430

Please sign in to comment.