Review fixes.
* Refactor trigger_config and trigger_config_v2 into one structure * bump default python version to 3.10 * typo fixes
This commit is contained in:
parent
303b51a0a9
commit
9e37a915c8
|
@ -79,19 +79,18 @@ module "cf" {
|
|||
name = var.name
|
||||
bucket_name = "${var.name}-${random_pet.random.id}"
|
||||
bucket_config = {
|
||||
location = var.region
|
||||
lifecycle_delete_age = null
|
||||
location = var.region
|
||||
}
|
||||
bundle_config = {
|
||||
source_dir = "cf"
|
||||
output_path = var.bundle_path
|
||||
excludes = null
|
||||
}
|
||||
service_account = module.service-account.email
|
||||
trigger_config = {
|
||||
event = "google.pubsub.topic.publish"
|
||||
resource = module.pubsub.topic.id
|
||||
retry = null
|
||||
v1 = {
|
||||
event = "google.pubsub.topic.publish"
|
||||
resource = module.pubsub.topic.id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -137,15 +137,13 @@ module "cloud-function" {
|
|||
name = "network-dashboard-cloud-function"
|
||||
bucket_name = "${local.monitoring_project}-network-dashboard-bucket"
|
||||
bucket_config = {
|
||||
location = var.region
|
||||
lifecycle_delete_age = null
|
||||
location = var.region
|
||||
}
|
||||
region = var.region
|
||||
|
||||
bundle_config = {
|
||||
source_dir = "cloud-function"
|
||||
output_path = "cloud-function.zip"
|
||||
excludes = null
|
||||
}
|
||||
|
||||
function_config = {
|
||||
|
@ -169,10 +167,17 @@ module "cloud-function" {
|
|||
# Internal only doesn't seem to work with CFv2:
|
||||
ingress_settings = var.cf_version == "V2" ? "ALLOW_ALL" : "ALLOW_INTERNAL_ONLY"
|
||||
|
||||
trigger_config = {
|
||||
event = "google.pubsub.topic.publish"
|
||||
resource = module.pubsub.topic.id
|
||||
retry = null
|
||||
trigger_config = var.cf_version == "V2" ? {
|
||||
v2 = {
|
||||
event_type = "google.cloud.pubsub.topic.v1.messagePublished"
|
||||
pubsub_topic = module.pubsub.topic.id
|
||||
# TODO: service_account_email
|
||||
}
|
||||
} : {
|
||||
v1 = {
|
||||
event = "google.pubsub.topic.publish"
|
||||
resource = module.pubsub.topic.id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,13 +52,11 @@ module "cf" {
|
|||
name = var.name
|
||||
bucket_name = "${var.name}-${random_pet.random.id}"
|
||||
bucket_config = {
|
||||
location = var.region
|
||||
lifecycle_delete_age = null
|
||||
location = var.region
|
||||
}
|
||||
bundle_config = {
|
||||
source_dir = "cf"
|
||||
output_path = var.bundle_path
|
||||
excludes = null
|
||||
}
|
||||
# https://github.com/hashicorp/terraform-provider-archive/issues/40
|
||||
# https://issuetracker.google.com/issues/155215191
|
||||
|
@ -68,9 +66,10 @@ module "cf" {
|
|||
}
|
||||
service_account_create = true
|
||||
trigger_config = {
|
||||
event = "google.pubsub.topic.publish"
|
||||
resource = module.pubsub.topic.id
|
||||
retry = null
|
||||
v1 = {
|
||||
event = "google.pubsub.topic.publish"
|
||||
resource = module.pubsub.topic.id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -91,19 +91,18 @@ module "cf" {
|
|||
name = var.name
|
||||
bucket_name = "${var.name}-${random_pet.random.id}"
|
||||
bucket_config = {
|
||||
location = var.region
|
||||
lifecycle_delete_age = null
|
||||
location = var.region
|
||||
}
|
||||
bundle_config = {
|
||||
source_dir = "cf"
|
||||
output_path = var.bundle_path
|
||||
excludes = null
|
||||
}
|
||||
service_account = module.service-account.email
|
||||
trigger_config = {
|
||||
event = "google.pubsub.topic.publish"
|
||||
resource = module.pubsub.topic.id
|
||||
retry = null
|
||||
v1 = {
|
||||
event = "google.pubsub.topic.publish"
|
||||
resource = module.pubsub.topic.id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,9 +124,11 @@ module "cffile" {
|
|||
}
|
||||
service_account = module.service-account.email
|
||||
trigger_config = {
|
||||
event = "google.pubsub.topic.publish"
|
||||
resource = module.pubsub_file.topic.id
|
||||
retry = null
|
||||
v1 = {
|
||||
event = "google.pubsub.topic.publish"
|
||||
resource = module.pubsub_file.topic.id
|
||||
retry = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -114,13 +114,11 @@ module "cf-restarter" {
|
|||
region = var.region
|
||||
bucket_name = "cf-bundle-bucket-${random_pet.random.id}"
|
||||
bucket_config = {
|
||||
location = var.region
|
||||
lifecycle_delete_age = null
|
||||
location = var.region
|
||||
}
|
||||
bundle_config = {
|
||||
source_dir = "${path.module}/function/restarter"
|
||||
output_path = "restarter.zip"
|
||||
excludes = []
|
||||
}
|
||||
service_account = module.service-account-restarter.email
|
||||
|
||||
|
@ -134,9 +132,10 @@ module "cf-restarter" {
|
|||
}
|
||||
|
||||
trigger_config = {
|
||||
event = "google.pubsub.topic.publish"
|
||||
resource = module.pubsub.topic.id
|
||||
retry = null
|
||||
v1 = {
|
||||
event = "google.pubsub.topic.publish"
|
||||
resource = module.pubsub.topic.id
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -151,7 +150,6 @@ module "cf-healthchecker" {
|
|||
bundle_config = {
|
||||
source_dir = "${path.module}/function/healthchecker"
|
||||
output_path = "healthchecker.zip"
|
||||
excludes = []
|
||||
}
|
||||
service_account = module.service-account-healthchecker.email
|
||||
|
||||
|
|
|
@ -195,11 +195,9 @@ module "function-hello" {
|
|||
bundle_config = {
|
||||
source_dir = "${path.module}/assets"
|
||||
output_path = "bundle.zip"
|
||||
excludes = null
|
||||
}
|
||||
bucket_config = {
|
||||
location = var.region
|
||||
lifecycle_delete_age = null
|
||||
location = var.region
|
||||
}
|
||||
iam = {
|
||||
"roles/cloudfunctions.invoker" = ["allUsers"]
|
||||
|
|
|
@ -50,23 +50,25 @@ Other trigger types other than HTTP are configured via the `trigger_config` vari
|
|||
|
||||
```hcl
|
||||
module "cf-http" {
|
||||
source = "./fabric/modules/cloud-function"
|
||||
project_id = "my-project"
|
||||
name = "test-cf-http"
|
||||
bucket_name = "test-cf-bundles"
|
||||
source = "./fabric/modules/cloud-function"
|
||||
project_id = "my-project"
|
||||
name = "test-cf-http"
|
||||
bucket_name = "test-cf-bundles"
|
||||
bundle_config = {
|
||||
source_dir = "fabric/assets/"
|
||||
output_path = "bundle.zip"
|
||||
}
|
||||
trigger_config = {
|
||||
event = "google.pubsub.topic.publish"
|
||||
resource = "local.my-topic"
|
||||
v1 = {
|
||||
event = "google.pubsub.topic.publish"
|
||||
resource = "local.my-topic"
|
||||
}
|
||||
}
|
||||
}
|
||||
# tftest modules=1 resources=2
|
||||
```
|
||||
|
||||
Cloud Functions 2nd gen support only [Eventarc](https://cloud.google.com/eventarc/docs) and user separate structure
|
||||
Cloud Functions 2nd gen support only [Eventarc](https://cloud.google.com/eventarc/docs) and uses separate structure
|
||||
to configure:
|
||||
```hcl
|
||||
module "trigger-service-account" {
|
||||
|
@ -81,19 +83,21 @@ module "trigger-service-account" {
|
|||
}
|
||||
|
||||
module "cf-http" {
|
||||
source = "./fabric/modules/cloud-function"
|
||||
project_id = "my-project"
|
||||
v2 = true
|
||||
name = "test-cf-http"
|
||||
bucket_name = "test-cf-bundles"
|
||||
source = "./fabric/modules/cloud-function"
|
||||
project_id = "my-project"
|
||||
v2 = true
|
||||
name = "test-cf-http"
|
||||
bucket_name = "test-cf-bundles"
|
||||
bundle_config = {
|
||||
source_dir = "fabric/assets/"
|
||||
output_path = "bundle.zip"
|
||||
}
|
||||
trigger_config_v2 = {
|
||||
event_type = "google.cloud.pubsub.topic.v1.messagePublished"
|
||||
pubsub_topic = "local.my-topic"
|
||||
service_account_email = module.trigger-service-account.email
|
||||
trigger_config = {
|
||||
v2 = {
|
||||
event_type = "google.cloud.pubsub.topic.v1.messagePublished"
|
||||
pubsub_topic = "local.my-topic"
|
||||
service_account_email = module.trigger-service-account.email
|
||||
}
|
||||
}
|
||||
}
|
||||
# tftest modules=2 resources=4
|
||||
|
@ -230,20 +234,19 @@ module "cf-http" {
|
|||
| [build_worker_pool](variables.tf#L31) | Build worker pool, in projects/<PROJECT-ID>/locations/<REGION>/workerPools/<POOL_NAME> format | <code>string</code> | | <code>null</code> |
|
||||
| [description](variables.tf#L46) | Optional description. | <code>string</code> | | <code>"Terraform managed."</code> |
|
||||
| [environment_variables](variables.tf#L52) | Cloud function environment variables. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [function_config](variables.tf#L58) | Cloud function configuration. Defaults to using main as entrypoint, 1 instance with 256MiB of memory, and 180 second timeout | <code title="object({ entry_point = optional(string, "main") instances = optional(number, 1) memory = optional(number, 256) # Memory in MB runtime = optional(string, "python37") timeout = optional(number, 180) })">object({…})</code> | | <code title="{ entry_point = "main" instances = 1 memory = 256 runtime = "python37" timeout = 180 }">{…}</code> |
|
||||
| [function_config](variables.tf#L58) | Cloud function configuration. Defaults to using main as entrypoint, 1 instance with 256MiB of memory, and 180 second timeout | <code title="object({ entry_point = optional(string, "main") instances = optional(number, 1) memory = optional(number, 256) # Memory in MB runtime = optional(string, "python310") timeout = optional(number, 180) })">object({…})</code> | | <code title="{ entry_point = "main" instances = 1 memory = 256 runtime = "python37" timeout = 180 }">{…}</code> |
|
||||
| [iam](variables.tf#L76) | IAM bindings for topic in {ROLE => [MEMBERS]} format. | <code>map(list(string))</code> | | <code>{}</code> |
|
||||
| [ingress_settings](variables.tf#L82) | Control traffic that reaches the cloud function. Allowed values are ALLOW_ALL, ALLOW_INTERNAL_AND_GCLB and ALLOW_INTERNAL_ONLY . | <code>string</code> | | <code>null</code> |
|
||||
| [labels](variables.tf#L88) | Resource labels. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [prefix](variables.tf#L99) | Optional prefix used for resource names. | <code>string</code> | | <code>null</code> |
|
||||
| [region](variables.tf#L114) | Region used for all resources. | <code>string</code> | | <code>"europe-west1"</code> |
|
||||
| [secrets](variables.tf#L120) | Secret Manager secrets. Key is the variable name or mountpoint, volume versions are in version:path format. | <code title="map(object({ is_volume = bool project_id = number secret = string versions = list(string) }))">map(object({…}))</code> | | <code>{}</code> |
|
||||
| [service_account](variables.tf#L132) | Service account email.service_account Unused if service account is auto-created. | <code>string</code> | | <code>null</code> |
|
||||
| [service_account](variables.tf#L132) | Service account email. Unused if service account is auto-created. | <code>string</code> | | <code>null</code> |
|
||||
| [service_account_create](variables.tf#L138) | Auto-create service account. | <code>bool</code> | | <code>false</code> |
|
||||
| [trigger_config](variables.tf#L144) | Function trigger configuration. Leave null for HTTP trigger. | <code title="object({ event = string resource = string retry = optional(bool) })">object({…})</code> | | <code>null</code> |
|
||||
| [trigger_config_v2](variables.tf#L154) | Function trigger configuration. Leave null for HTTP trigger. | <code title="object({ region = optional(string) event_type = optional(string) pubsub_topic = optional(string) event_filters = optional(list(object({ attribute = string value = string operator = string })), []) service_account_email = optional(string) retry_policy = optional(string) })">object({…})</code> | | <code>null</code> |
|
||||
| [v2](variables.tf#L190) | Whether to use Cloud Function version 2nd Gen or 1st Gen. | <code>bool</code> | | <code>false</code> |
|
||||
| [vpc_connector](variables.tf#L171) | VPC connector configuration. Set create to 'true' if a new connector needs to be created. | <code title="object({ create = bool name = string egress_settings = string })">object({…})</code> | | <code>null</code> |
|
||||
| [vpc_connector_config](variables.tf#L181) | VPC connector network configuration. Must be provided if new VPC connector is being created. | <code title="object({ ip_cidr_range = string network = string })">object({…})</code> | | <code>null</code> |
|
||||
| [trigger_config](variables.tf#L144) | Function trigger configuration. Leave null for HTTP trigger. | <code title="object({ v1 = optional(object({ event = string resource = string retry = optional(bool) })), v2 = optional(object({ region = optional(string) event_type = optional(string) pubsub_topic = optional(string) event_filters = optional(list(object({ attribute = string value = string operator = string }))) service_account_email = optional(string) retry_policy = optional(string) })) })">object({…})</code> | | <code>null</code> |
|
||||
| [v2](variables.tf#L191) | Whether to use Cloud Function version 2nd Gen or 1st Gen. | <code>bool</code> | | <code>false</code> |
|
||||
| [vpc_connector](variables.tf#L172) | VPC connector configuration. Set create to 'true' if a new connector needs to be created. | <code title="object({ create = bool name = string egress_settings = string })">object({…})</code> | | <code>null</code> |
|
||||
| [vpc_connector_config](variables.tf#L182) | VPC connector network configuration. Must be provided if new VPC connector is being created. | <code title="object({ ip_cidr_range = string network = string })">object({…})</code> | | <code>null</code> |
|
||||
|
||||
## Outputs
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ resource "google_cloudfunctions_function" "function" {
|
|||
source_archive_bucket = local.bucket
|
||||
source_archive_object = google_storage_bucket_object.bundle.name
|
||||
labels = var.labels
|
||||
trigger_http = var.trigger_config == null ? true : null
|
||||
trigger_http = try(var.trigger_config.v1 == null, true) ? true : null
|
||||
ingress_settings = var.ingress_settings
|
||||
build_worker_pool = var.build_worker_pool
|
||||
|
||||
|
@ -85,14 +85,14 @@ resource "google_cloudfunctions_function" "function" {
|
|||
)
|
||||
|
||||
dynamic "event_trigger" {
|
||||
for_each = var.trigger_config == null ? [] : [""]
|
||||
for_each = try(var.trigger_config.v1 == null, true) ? [] : [""]
|
||||
content {
|
||||
event_type = var.trigger_config.event
|
||||
resource = var.trigger_config.resource
|
||||
event_type = var.trigger_config.v1.event
|
||||
resource = var.trigger_config.v1.resource
|
||||
dynamic "failure_policy" {
|
||||
for_each = var.trigger_config.retry == null ? [] : [""]
|
||||
for_each = var.trigger_config.v1.retry == null ? [] : [""]
|
||||
content {
|
||||
retry = var.trigger_config.retry
|
||||
retry = var.trigger_config.v1.retry
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -148,13 +148,13 @@ resource "google_cloudfunctions2_function" "function" {
|
|||
}
|
||||
}
|
||||
dynamic "event_trigger" {
|
||||
for_each = var.trigger_config_v2 == null ? [] : [""]
|
||||
for_each = try(var.trigger_config.v2 == null, true) ? [] : [""]
|
||||
content {
|
||||
trigger_region = var.trigger_config_v2.region
|
||||
event_type = var.trigger_config_v2.event_type
|
||||
pubsub_topic = var.trigger_config_v2.pubsub_topic
|
||||
trigger_region = var.trigger_config.v2.region
|
||||
event_type = var.trigger_config.v2.event_type
|
||||
pubsub_topic = var.trigger_config.v2.pubsub_topic
|
||||
dynamic "event_filters" {
|
||||
for_each = var.trigger_config_v2.event_filters
|
||||
for_each = var.trigger_config.v2.event_filters == null ? [] : var.trigger_config.v2.event_filters
|
||||
iterator = event_filter
|
||||
content {
|
||||
attribute = event_filter.attribute
|
||||
|
@ -162,8 +162,8 @@ resource "google_cloudfunctions2_function" "function" {
|
|||
operator = event_filter.operator
|
||||
}
|
||||
}
|
||||
service_account_email = var.trigger_config_v2.service_account_email
|
||||
retry_policy = var.trigger_config_v2.retry_policy
|
||||
service_account_email = var.trigger_config.v2.service_account_email
|
||||
retry_policy = var.trigger_config.v2.retry_policy
|
||||
}
|
||||
}
|
||||
service_config {
|
||||
|
|
|
@ -61,7 +61,7 @@ variable "function_config" {
|
|||
entry_point = optional(string, "main")
|
||||
instances = optional(number, 1)
|
||||
memory = optional(number, 256) # Memory in MB
|
||||
runtime = optional(string, "python37")
|
||||
runtime = optional(string, "python310")
|
||||
timeout = optional(number, 180)
|
||||
})
|
||||
default = {
|
||||
|
@ -130,7 +130,7 @@ variable "secrets" {
|
|||
}
|
||||
|
||||
variable "service_account" {
|
||||
description = "Service account email.service_account Unused if service account is auto-created."
|
||||
description = "Service account email. Unused if service account is auto-created."
|
||||
type = string
|
||||
default = null
|
||||
}
|
||||
|
@ -144,28 +144,29 @@ variable "service_account_create" {
|
|||
variable "trigger_config" {
|
||||
description = "Function trigger configuration. Leave null for HTTP trigger."
|
||||
type = object({
|
||||
event = string
|
||||
resource = string
|
||||
retry = optional(bool)
|
||||
})
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "trigger_config_v2" {
|
||||
description = "Function trigger configuration. Leave null for HTTP trigger."
|
||||
type = object({
|
||||
region = optional(string)
|
||||
event_type = optional(string)
|
||||
pubsub_topic = optional(string)
|
||||
event_filters = optional(list(object({
|
||||
attribute = string
|
||||
value = string
|
||||
operator = string
|
||||
})), [])
|
||||
service_account_email = optional(string)
|
||||
retry_policy = optional(string)
|
||||
v1 = optional(object({
|
||||
event = string
|
||||
resource = string
|
||||
retry = optional(bool)
|
||||
})),
|
||||
v2 = optional(object({
|
||||
region = optional(string)
|
||||
event_type = optional(string)
|
||||
pubsub_topic = optional(string)
|
||||
event_filters = optional(list(object({
|
||||
attribute = string
|
||||
value = string
|
||||
operator = string
|
||||
})))
|
||||
service_account_email = optional(string)
|
||||
retry_policy = optional(string)
|
||||
}))
|
||||
})
|
||||
default = null
|
||||
validation {
|
||||
condition = try(((var.trigger_config.v1 == null) != (var.trigger_config.v2 == null)), var.trigger_config == null)
|
||||
error_message = "Provide configuration for only one generation - either v1 or v2"
|
||||
}
|
||||
}
|
||||
|
||||
variable "vpc_connector" {
|
||||
|
|
Loading…
Reference in New Issue