Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

[PROD-6200] Enhancement: Use configurable resources #5

Merged
merged 2 commits into from
Apr 12, 2021
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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ No modules.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_app_engine_application_location"></a> [app\_engine\_application\_location](#input\_app\_engine\_application\_location) | The location to serve the app from. | `string` | `"europe-west1"` | no |
| <a name="input_cloud_run_service_location"></a> [cloud\_run\_service\_location](#input\_cloud\_run\_service\_location) | The location of the cloud run instance. Make sure to provide a valid location. More at https://cloud.google.com/run/docs/locations | `string` | `"europe-west1"` | no |
| <a name="input_cloud_run_service_location"></a> [cloud\_run\_service\_location](#input\_cloud\_run\_service\_location) | The location of the cloud run instance. Make sure to provide a valid location. More at https://cloud.google.com/run/docs/locations. | `string` | `"europe-west1"` | no |
| <a name="input_cloud_run_service_maximum_instances"></a> [cloud\_run\_service\_maximum\_instances](#input\_cloud\_run\_service\_maximum\_instances) | The number of maximum instances to set for this revision. This value will be used in the `autoscaling.knative.dev/maxScale` annotation key. | `number` | `100` | no |
| <a name="input_cloud_run_service_name"></a> [cloud\_run\_service\_name](#input\_cloud\_run\_service\_name) | The name of the cloud run service. | `string` | `"gcr-cleaner"` | no |
| <a name="input_cloud_run_service_timeout_seconds"></a> [cloud\_run\_service\_timeout\_seconds](#input\_cloud\_run\_service\_timeout\_seconds) | TimeoutSeconds holds the max duration the instance is allowed for responding to a request. | `number` | `60` | no |
| <a name="input_cloud_scheduler_job_attempt_deadline"></a> [cloud\_scheduler\_job\_attempt\_deadline](#input\_cloud\_scheduler\_job\_attempt\_deadline) | The deadline for job attempts in seconds. If the request handler does not respond by this deadline then the request is cancelled and the attempt is marked as a `DEADLINE_EXCEEDED` failure. The failed attempt can be viewed in execution logs. Cloud Scheduler will retry the job according to the `RetryConfig`. Value must be between 15 seconds and 24 hours | `number` | `320` | no |
| <a name="input_cloud_scheduler_job_retry_count"></a> [cloud\_scheduler\_job\_retry\_count](#input\_cloud\_scheduler\_job\_retry\_count) | The number of attempts that the system will make to run a job using the exponential backoff procedure described by maxDoublings. Values greater than 5 and negative values are not allowed. | `number` | `1` | no |
| <a name="input_cloud_scheduler_job_schedule"></a> [cloud\_scheduler\_job\_schedule](#input\_cloud\_scheduler\_job\_schedule) | Describes the schedule on which the job will be executed. | `string` | `"0 4 * * 1"` | no |
| <a name="input_cloud_scheduler_job_time_zone"></a> [cloud\_scheduler\_job\_time\_zone](#input\_cloud\_scheduler\_job\_time\_zone) | Specifies the time zone to be used in interpreting schedule. The value of this field must be a time zone name from the tz database. More on https://en.wikipedia.org/wiki/List_of_tz_database_time_zones | `string` | `"Europe/Brussels"` | no |
| <a name="input_create_app_engine_app"></a> [create\_app\_engine\_app](#input\_create\_app\_engine\_app) | Whether to create an App Engine application. | `bool` | `false` | no |
Expand Down
16 changes: 10 additions & 6 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ module "gcr_cleaner" {
# If you want to create your App Engine Application using terraform, uncomment the following
# create_app_engine_app = true

app_engine_application_location = "europe-west3"
cloud_run_service_name = "gcr-cleaner-helsinki"
cloud_run_service_location = "europe-north1"
gcr_cleaner_image = "europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner"
cloud_scheduler_job_schedule = "0 2 * * 5"
cloud_scheduler_job_time_zone = "Europe/Helsinki"
app_engine_application_location = "europe-west3"
cloud_run_service_name = "gcr-cleaner-helsinki"
cloud_run_service_location = "europe-north1"
cloud_run_service_maximum_instances = 300
cloud_run_service_timeout_seconds = 300
gcr_cleaner_image = "europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner"
cloud_scheduler_job_schedule = "0 2 * * 5"
cloud_scheduler_job_time_zone = "Europe/Helsinki"
cloud_scheduler_job_attempt_deadline = 600
cloud_scheduler_job_retry_count = 3
gcr_repositories = [
{
storage_region = "eu"
Expand Down
20 changes: 14 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ resource "google_cloud_run_service" "this" {
location = var.cloud_run_service_location

template {
metadata {
annotations = {
"autoscaling.knative.dev/maxScale" = var.cloud_run_service_maximum_instances
"run.googleapis.com/client-name" = "cloud-scheduler"
}
}

spec {
containers {
image = var.gcr_cleaner_image
}
service_account_name = google_service_account.cleaner.email
timeout_seconds = 60
timeout_seconds = var.cloud_run_service_timeout_seconds
}
}

Expand Down Expand Up @@ -52,18 +59,19 @@ resource "google_cloud_scheduler_job" "this" {

# name must match the RE2 regular expression "[a-zA-Z\d_-]{1,500}"
# and be no more than 500 characters.
name = "gcr-cleaner_${replace(each.value, "/[.\\/]/", "_")}"
description = "Cleanup ${each.value}"
schedule = var.cloud_scheduler_job_schedule
time_zone = var.cloud_scheduler_job_time_zone
name = "gcr-cleaner_${replace(each.value, "/[.\\/]/", "_")}"
description = "Cleanup ${each.value}"
schedule = var.cloud_scheduler_job_schedule
time_zone = var.cloud_scheduler_job_time_zone
attempt_deadline = "${var.cloud_scheduler_job_attempt_deadline}s"
# Location must equal to the one of the App Engine app that is associated with this project
# /!\ Note that two locations, called europe-west and us-central in App Engine commands,
# are called, respectively, europe-west1 and us-central1 in Cloud Scheduler commands.
# More on https://cloud.google.com/appengine/docs/locations
region = contains(["europe-west", "us-central"], var.app_engine_application_location) == true ? "${var.app_engine_application_location}1" : var.app_engine_application_location

retry_config {
retry_count = 1
retry_count = var.cloud_scheduler_job_retry_count
}

http_target {
Expand Down
5 changes: 1 addition & 4 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ output "app_engine_application_name" {
output "cloud_scheduler_jobs" {
description = "List of the created scheduler jobs."
value = [
for job in google_cloud_scheduler_job.this : {
id : job.id
name : job.name
}
for job in google_cloud_scheduler_job.this : job.id
]
}
30 changes: 29 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@ variable "cloud_run_service_name" {
}

variable "cloud_run_service_location" {
description = "The location of the cloud run instance. Make sure to provide a valid location. More at https://cloud.google.com/run/docs/locations"
description = "The location of the cloud run instance. Make sure to provide a valid location. More at https://cloud.google.com/run/docs/locations."
type = string
default = "europe-west1"
}

variable "cloud_run_service_maximum_instances" {
description = "The number of maximum instances to set for this revision. This value will be used in the `autoscaling.knative.dev/maxScale` annotation key."
type = number
default = 100
}

variable "cloud_run_service_timeout_seconds" {
description = "TimeoutSeconds holds the max duration the instance is allowed for responding to a request."
type = number
default = 60
}

variable "create_app_engine_app" {
description = "Whether to create an App Engine application."
type = bool
Expand Down Expand Up @@ -79,3 +91,19 @@ variable "cloud_scheduler_job_time_zone" {
type = string
default = "Europe/Brussels"
}

variable "cloud_scheduler_job_attempt_deadline" {
description = "The deadline for job attempts in seconds. If the request handler does not respond by this deadline then the request is cancelled and the attempt is marked as a `DEADLINE_EXCEEDED` failure. The failed attempt can be viewed in execution logs. Cloud Scheduler will retry the job according to the `RetryConfig`. Value must be between 15 seconds and 24 hours"
type = number
default = 320
validation {
condition = var.cloud_scheduler_job_attempt_deadline >= 15 && var.cloud_scheduler_job_attempt_deadline <= 86400
error_message = "Value must be between 15 seconds and 24 hours."
}
}

variable "cloud_scheduler_job_retry_count" {
description = "The number of attempts that the system will make to run a job using the exponential backoff procedure described by maxDoublings. Values greater than 5 and negative values are not allowed."
type = number
default = 1
}