Skip to content
Closed
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
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Make will use bash instead of sh
SHELL := /usr/bin/env bash

DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 1.24
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 1.25
DOCKER_IMAGE_DEVELOPER_TOOLS := cft/developer-tools
REGISTRY_URL := gcr.io/cloud-foundation-cicd

Expand Down Expand Up @@ -77,9 +77,10 @@ docker_test_lint:
.PHONY: docker_generate_docs
docker_generate_docs:
docker run --rm -it \
-e ENABLE_BPMETADATA=1 \
-v "$(CURDIR)":/workspace \
$(REGISTRY_URL)/${DOCKER_IMAGE_DEVELOPER_TOOLS}:${DOCKER_TAG_VERSION_DEVELOPER_TOOLS} \
/bin/bash -c 'source /usr/local/bin/task_helper_functions.sh && generate_docs'
/bin/bash -c 'source /usr/local/bin/task_helper_functions.sh && generate_docs display'

# Alias for backwards compatibility
.PHONY: generate_docs
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module "cloud_functions2" {
# Required variables
function_name = "<FUNCTION_NAME>"
project_id = "<PROJECT_ID>"
function_location = "<LOCATION>"
location = "<LOCATION>"
runtime = "<RUNTIME>"
entrypoint = "<ENTRYPOINT>"
storage_source = {
Expand All @@ -56,9 +56,10 @@ Functional examples are included in the
| docker\_repository | User managed repository created in Artifact Registry optionally with a customer managed encryption key. | `string` | `null` | no |
| entrypoint | The name of the function (as defined in source code) that will be executed. Defaults to the resource name suffix, if not specified | `string` | n/a | yes |
| event\_trigger | Event triggers for the function | <pre>object({<br> trigger_region = optional(string)<br> event_type = string<br> service_account_email = string<br> pubsub_topic = optional(string)<br> retry_policy = string<br> event_filters = optional(set(object({<br> attribute = string<br> attribute_value = string<br> operator = optional(string)<br> })))<br> })</pre> | `null` | no |
| function\_location | The location of this cloud function | `string` | n/a | yes |
| function\_location | DEPRECATED: Please use the 'location' variable instead. This will be removed in a future version. | `string` | `null` | no |
| function\_name | A user-defined name of the function | `string` | n/a | yes |
| labels | A set of key/value label pairs associated with this Cloud Function | `map(string)` | `null` | no |
| location | The location of this cloud function | `string` | n/a | yes |
| members | Cloud Function Invoker and Developer roles for Users/SAs. Key names must be developers and/or invokers | `map(list(string))` | `{}` | no |
| project\_id | Project ID to create Cloud Function | `string` | n/a | yes |
| repo\_source | Get the source from this location in a Cloud Source Repository | <pre>object({<br> project_id = optional(string)<br> repo_name = string<br> branch_name = string<br> dir = optional(string)<br> tag_name = optional(string)<br> commit_sha = optional(string)<br> invert_regex = optional(bool, false)<br> })</pre> | `null` | no |
Expand Down
4 changes: 2 additions & 2 deletions examples/cloud_function2_gcs_source/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ This example illustrates how to use the `cloud-functions` module.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| function\_location | The location of this cloud function | `string` | `"us-central1"` | no |
| location | The location of this cloud function | `string` | `"us-central1"` | no |
| project\_id | The ID of the project in which to provision resources. | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| function\_location | Location of the Cloud Function (Gen 2) |
| function\_name | Name of the Cloud Function (Gen 2) |
| function\_uri | URI of the Cloud Function (Gen 2) |
| location | Location of the Cloud Function (Gen 2) |
| project\_id | The project ID |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Expand Down
13 changes: 6 additions & 7 deletions examples/cloud_function2_gcs_source/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ resource "google_storage_bucket_object" "function-source" {
}

module "cloud_functions2" {
source = "GoogleCloudPlatform/cloud-functions/google"
version = "~> 0.6"
source = "GoogleCloudPlatform/cloud-functions/google"

project_id = var.project_id
function_name = "function2-gcs-source-py"
function_location = var.function_location
runtime = "python38"
entrypoint = "hello_http"
project_id = var.project_id
function_name = "function2-gcs-source-py"
location = var.location
runtime = "python310"
entrypoint = "hello_http"
storage_source = {
bucket = google_storage_bucket.bucket.name
object = google_storage_bucket_object.function-source.name
Expand Down
4 changes: 2 additions & 2 deletions examples/cloud_function2_gcs_source/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ output "function_name" {
value = module.cloud_functions2.function_name
}

output "function_location" {
output "location" {
description = "Location of the Cloud Function (Gen 2)"
value = var.function_location
value = var.location
}

output "project_id" {
Expand Down
2 changes: 1 addition & 1 deletion examples/cloud_function2_gcs_source/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ variable "project_id" {
type = string
}

variable "function_location" {
variable "location" {
description = "The location of this cloud function"
type = string
default = "us-central1"
Expand Down
4 changes: 2 additions & 2 deletions examples/cloud_function2_pubsub_trigger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ This example illustrates how to use the `cloud-functions` module.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| function\_location | The location of this cloud function | `string` | `"us-central1"` | no |
| location | The location of this cloud function | `string` | `"us-central1"` | no |
| project\_id | The ID of the project in which to provision resources. | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| function\_location | Location of the Cloud Function (Gen 2) |
| function\_name | Name of the Cloud Function (Gen 2) |
| function\_uri | URI of the Cloud Function (Gen 2) |
| location | Location of the Cloud Function (Gen 2) |
| project\_id | The project ID |
| pubsub\_topic | Name of the PubSub Topic |

Expand Down
13 changes: 6 additions & 7 deletions examples/cloud_function2_pubsub_trigger/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ module "pubsub" {
}

module "cloud_functions2" {
source = "GoogleCloudPlatform/cloud-functions/google"
version = "~> 0.6"
source = "GoogleCloudPlatform/cloud-functions/google"

project_id = var.project_id
function_name = "function2-pubsub-trigger-py"
function_location = var.function_location
runtime = "python38"
entrypoint = "hello_http"
project_id = var.project_id
function_name = "function2-pubsub-trigger-py"
location = var.location
runtime = "python310"
entrypoint = "hello_http"
storage_source = {
bucket = google_storage_bucket.bucket.name
object = google_storage_bucket_object.function-source.name
Expand Down
4 changes: 2 additions & 2 deletions examples/cloud_function2_pubsub_trigger/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ output "function_name" {
value = module.cloud_functions2.function_name
}

output "function_location" {
output "location" {
description = "Location of the Cloud Function (Gen 2)"
value = var.function_location
value = var.location
}

output "pubsub_topic" {
Expand Down
2 changes: 1 addition & 1 deletion examples/cloud_function2_pubsub_trigger/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ variable "project_id" {
type = string
}

variable "function_location" {
variable "location" {
description = "The location of this cloud function"
type = string
default = "us-central1"
Expand Down
12 changes: 6 additions & 6 deletions examples/secure_cloud_function_bigquery_trigger/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ module "secure_harness" {
version = "~> 0.21.5"

billing_account = var.billing_account
security_project_name = "prj-scf-security"
network_project_name = "prj-scf-restricted-shared"
serverless_project_names = ["prj-scf-bq-trigger"]
security_project_name = "prj-scf-sec-bq"
network_project_name = "prj-scf-r-sh-bq"
serverless_project_names = ["prj-scf-bq-trg"]
org_id = var.org_id
parent_folder_id = var.folder_id
serverless_folder_suffix = random_id.random_folder_suffix.hex
Expand All @@ -62,13 +62,13 @@ module "secure_harness" {
folder_deletion_protection = false

service_account_project_roles = {
"prj-scf-bq-trigger" = ["roles/eventarc.eventReceiver", "roles/viewer", "roles/compute.networkViewer", "roles/run.invoker"]
"prj-scf-bq-trg" = ["roles/eventarc.eventReceiver", "roles/viewer", "roles/compute.networkViewer", "roles/run.invoker"]
}

network_project_extra_apis = ["compute.googleapis.com", "networksecurity.googleapis.com"]

serverless_project_extra_apis = {
"prj-scf-bq-trigger" = ["compute.googleapis.com", "networksecurity.googleapis.com", "cloudfunctions.googleapis.com", "cloudbuild.googleapis.com", "eventarc.googleapis.com", "eventarcpublishing.googleapis.com"]
"prj-scf-bq-trg" = ["compute.googleapis.com", "networksecurity.googleapis.com", "cloudfunctions.googleapis.com", "cloudbuild.googleapis.com", "eventarc.googleapis.com", "eventarcpublishing.googleapis.com"]
}
}

Expand All @@ -92,7 +92,7 @@ module "cloudfunction_source_bucket" {
}

resource "google_project_service" "network_project_apis" {
for_each = toset(["networkservices.googleapis.com", "certificatemanager.googleapis.com"])
for_each = toset(["networkservices.googleapis.com", "certificatemanager.googleapis.com", "cloudbuild.googleapis.com"])
project = module.secure_harness.network_project_id[0]
service = each.value
disable_on_destroy = false
Expand Down
11 changes: 10 additions & 1 deletion examples/secure_cloud_function_internal_server/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module "secure_harness" {
version = "~> 0.21.5"

billing_account = var.billing_account
security_project_name = "prj-scf-security"
security_project_name = "prj-scf-security-cf"
network_project_name = "prj-scf-restricted-shared"
serverless_project_names = ["prj-scf-internal-server"]
org_id = var.org_id
Expand All @@ -61,6 +61,7 @@ module "secure_harness" {
time_to_wait_vpc_sc_propagation = "300s"
project_deletion_policy = "DELETE"
folder_deletion_protection = false
time_to_wait_service_identity_propagation = "300s"

service_account_project_roles = {
"prj-scf-internal-server" = [
Expand Down Expand Up @@ -91,6 +92,14 @@ module "secure_harness" {
}
}

resource "time_sleep" "wait_for_secure_harness" {
create_duration = "1m"

depends_on = [
null_resource.generate_certificate
]
}

module "cloudfunction_source_bucket" {
source = "terraform-google-modules/cloud-storage/google//modules/simple_bucket"
version = "~> 10.0"
Expand Down
4 changes: 2 additions & 2 deletions examples/secure_cloud_function_with_sql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ module "secure_harness" {
version = "~> 0.21.5"

billing_account = var.billing_account
security_project_name = "prj-scf-security"
network_project_name = "prj-scf-restricted-shared"
security_project_name = "prj-scf-sec-sql"
network_project_name = "prj-scf-sql-shared"
serverless_project_names = ["prj-scf-access-sql", "prj-scf-cloud-sql"]
org_id = var.org_id
parent_folder_id = var.folder_id
Expand Down
8 changes: 7 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@
* limitations under the License.
*/

locals {
# If var.location is set, use it. Otherwise, use var.function_location.
# This makes the change backward-compatible.
effective_location = coalesce(var.location, var.function_location)
}

/******************************************
Cloud Function Definition with
Repo/Storage Build Source and Event Trigger
*****************************************/
resource "google_cloudfunctions2_function" "function" {
name = var.function_name
location = var.function_location
location = local.effective_location
description = var.description
project = var.project_id

Expand Down
Loading