diff --git a/.github/workflows/codehealth.yaml b/.github/workflows/codehealth.yaml index 04cfdfb1..503255d1 100644 --- a/.github/workflows/codehealth.yaml +++ b/.github/workflows/codehealth.yaml @@ -24,6 +24,9 @@ jobs: node-version: 20 check-latest: true + - name: Use terraform + uses: hashicorp/setup-terraform@v3 + - name: Install node modules run: npm install @@ -34,7 +37,7 @@ jobs: run: npm run eslint - name: Execute "npm run check-format" - run: npm run check-format -- --log-level warn + run: npm run check-format - name: Execute "npm run mdlint" run: npm run mdlint @@ -45,8 +48,5 @@ jobs: - name: Execute "npm run markdown-link-check" run: npm run markdown-link-check - - name: Use terraform - uses: hashicorp/setup-terraform@v3 - - name: terraform validate deployments run: npm run terraform-validate diff --git a/package.json b/package.json index cba28d0a..8f19b6c9 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "author": "Google Inc.", "main": "src/functions.js", "scripts": { - "check-format": "prettier --check .", + "check-format": "npm run prettier-check && npm run terraform-fmt-check", "debug-poller-function": "node --inspect node_modules/@google-cloud/functions-framework --target=checkSpannerScaleMetricsHTTP", "debug-scaler-function": "node --inspect node_modules/@google-cloud/functions-framework --target=scaleSpannerInstanceHTTP --port=8081", "debug-forwarder-function": "node --inspect node_modules/@google-cloud/functions-framework --target=forwardFromHTTP", @@ -20,10 +20,13 @@ "poller-job": "node -e \"require('./src/poller/index').main()\"", "prepare": "{ git rev-parse --is-inside-work-tree >/dev/null 2>/dev/null && test \"$NODE_ENV\" != production -a \"$CI\" != true && husky ; } || true", "prettier": "prettier --write .", + "prettier-check": "prettier --check .", "scaler-service": "node -e \"require('./src/scaler/index').main()\"", "start-forwarder-function": "functions-framework --target=forwardFromHTTP", "start-poller-function": "functions-framework --target=checkSpannerScaleMetricsHTTP", "start-scaler-function": "functions-framework --target=scaleSpannerInstanceHTTP --port=8081", + "terraform-fmt": "echo 'Running Terraform fmt'; find . -name '*.tf' -print0 | xargs -0 terraform fmt", + "terraform-fmt-check": "echo 'Checking Terraform format'; if ! find . -name '*.tf' -print0 | xargs -0 terraform fmt -check; then echo 'Files need reformatting: npm run terraform-fmt'; exit 1; fi", "terraform-validate": "set -e ; package_root=\"$(pwd)\"; for x in gke/decoupled gke/unified cloud-functions/distributed/app-project cloud-functions/distributed/autoscaler-project cloud-functions/per-project ; do cd \"$package_root/terraform/$x\" ; echo \"\n\nValidating Terraform in $PWD\n\n\" ; terraform init ; terraform validate; done", "test": "NODE_ENV=test nyc --reporter=text mocha --recursive src --extension=.test.js", "test-e2e": "pushd terraform/cloud-functions/per-project/test && go test -run . -timeout 60m --tags=e2e && popd", diff --git a/terraform/gke/decoupled/main.tf b/terraform/gke/decoupled/main.tf index 7160a648..ce1a1d63 100644 --- a/terraform/gke/decoupled/main.tf +++ b/terraform/gke/decoupled/main.tf @@ -21,7 +21,7 @@ terraform { version = ">= 6.3.0" } kubernetes = { - source = "hashicorp/kubernetes" + source = "hashicorp/kubernetes" version = ">= 2.32.0" } } diff --git a/terraform/gke/unified/main.tf b/terraform/gke/unified/main.tf index 3631ad84..735ab124 100644 --- a/terraform/gke/unified/main.tf +++ b/terraform/gke/unified/main.tf @@ -21,7 +21,7 @@ terraform { version = ">= 6.3.0" } kubernetes = { - source = "hashicorp/kubernetes" + source = "hashicorp/kubernetes" version = "~> 2.32.0" } } diff --git a/terraform/modules/autoscaler-base/main.tf b/terraform/modules/autoscaler-base/main.tf index 06350c7c..6b181dd8 100644 --- a/terraform/modules/autoscaler-base/main.tf +++ b/terraform/modules/autoscaler-base/main.tf @@ -29,7 +29,7 @@ resource "google_pubsub_topic" "downstream_topic" { depends_on = [google_pubsub_schema.scaler_downstream_pubsub_schema] schema_settings { - schema = google_pubsub_schema.scaler_downstream_pubsub_schema.id + schema = google_pubsub_schema.scaler_downstream_pubsub_schema.id encoding = "JSON" } @@ -46,9 +46,9 @@ resource "google_pubsub_topic_iam_member" "scaler_downstream_pub_iam" { } resource "google_pubsub_schema" "scaler_downstream_pubsub_schema" { - name = "downstream-schema" - type = "PROTOCOL_BUFFER" - definition = "${file("${path.module}/../../../src/scaler/scaler-core/downstream.schema.proto")}" + name = "downstream-schema" + type = "PROTOCOL_BUFFER" + definition = file("${path.module}/../../../src/scaler/scaler-core/downstream.schema.proto") } resource "google_project_iam_member" "metrics_publisher_iam_poller" { diff --git a/terraform/modules/autoscaler-base/outputs.tf b/terraform/modules/autoscaler-base/outputs.tf index 5a0be154..de1694df 100644 --- a/terraform/modules/autoscaler-base/outputs.tf +++ b/terraform/modules/autoscaler-base/outputs.tf @@ -17,10 +17,10 @@ output "build_sa_id" { value = google_service_account.build_sa.id description = "Service account ID for Builder SA" - depends_on = [ google_project_iam_binding.build_iam ] + depends_on = [google_project_iam_binding.build_iam] } output "build_sa_email" { value = google_service_account.build_sa.email description = "Service account email for Builder SA" - depends_on = [ google_project_iam_binding.build_iam ] + depends_on = [google_project_iam_binding.build_iam] } diff --git a/terraform/modules/autoscaler-cluster/main.tf b/terraform/modules/autoscaler-cluster/main.tf index 23748f22..930e4b09 100644 --- a/terraform/modules/autoscaler-cluster/main.tf +++ b/terraform/modules/autoscaler-cluster/main.tf @@ -131,9 +131,9 @@ resource "kubernetes_namespace" "autoscaler_namespace" { } module "workload_identity_poller" { - count = var.unified_components ? 0 : 1 - source = "terraform-google-modules/kubernetes-engine/google//modules/workload-identity" - version = ">= 33.0.4" + count = var.unified_components ? 0 : 1 + source = "terraform-google-modules/kubernetes-engine/google//modules/workload-identity" + version = ">= 33.0.4" project_id = var.project_id namespace = "spanner-autoscaler" @@ -144,8 +144,8 @@ module "workload_identity_poller" { } module "workload_identity_scaler" { - source = "terraform-google-modules/kubernetes-engine/google//modules/workload-identity" - version = ">= 33.0.4" + source = "terraform-google-modules/kubernetes-engine/google//modules/workload-identity" + version = ">= 33.0.4" project_id = var.project_id namespace = "spanner-autoscaler" @@ -157,8 +157,8 @@ module "workload_identity_scaler" { module "workload_identity_otel_collector" { - source = "terraform-google-modules/kubernetes-engine/google//modules/workload-identity" - version = ">= 33.0.4" + source = "terraform-google-modules/kubernetes-engine/google//modules/workload-identity" + version = ">= 33.0.4" project_id = var.project_id namespace = "spanner-autoscaler" @@ -170,8 +170,8 @@ module "workload_identity_otel_collector" { module "cluster" { - source = "terraform-google-modules/kubernetes-engine/google//modules/private-cluster" - version = ">= 33.0.4" + source = "terraform-google-modules/kubernetes-engine/google//modules/private-cluster" + version = ">= 33.0.4" project_id = var.project_id name = var.name diff --git a/terraform/modules/autoscaler-cluster/variables.tf b/terraform/modules/autoscaler-cluster/variables.tf index 803783cb..f89eaca1 100644 --- a/terraform/modules/autoscaler-cluster/variables.tf +++ b/terraform/modules/autoscaler-cluster/variables.tf @@ -70,9 +70,9 @@ variable "scaler_sa_email" { } variable "otel_collector_sa_name" { - type = string + type = string description = "The name of the service account and workload identity to be created and used by the OpenTelemetry Collector workload" - default = "otel-collector-sa" + default = "otel-collector-sa" } variable "unified_components" { diff --git a/terraform/modules/autoscaler-functions/main.tf b/terraform/modules/autoscaler-functions/main.tf index 36e9037e..d28d5a41 100644 --- a/terraform/modules/autoscaler-functions/main.tf +++ b/terraform/modules/autoscaler-functions/main.tf @@ -74,7 +74,17 @@ data "archive_file" "local_source" { type = "zip" source_dir = abspath("${path.module}/../../..") output_path = "${var.local_output_path}/src.zip" - excludes = [ ".git", ".github", ".nyc_output", ".vscode", "kubernetes", "node_modules", "resources", "scaler", "terraform" ] + excludes = [ + ".git", + ".github", + ".nyc_output", + ".vscode", + "kubernetes", + "node_modules", + "resources", + "scaler", + "terraform" + ] } resource "google_storage_bucket_object" "gcs_functions_source" { diff --git a/terraform/modules/monitoring/main.tf b/terraform/modules/monitoring/main.tf index 133993d9..9e509a4d 100644 --- a/terraform/modules/monitoring/main.tf +++ b/terraform/modules/monitoring/main.tf @@ -15,7 +15,7 @@ */ resource "google_monitoring_dashboard" "dashboard" { - project = var.project_id + project = var.project_id dashboard_json = templatefile("${path.module}/dashboard.json.tftpl", { thresholds_high_priority_cpu_percentage = var.dashboard_threshold_high_priority_cpu_percentage thresholds_rolling_24hr_cpu_percentage = var.dashboard_threshold_rolling_24_hr_percentage diff --git a/terraform/modules/scheduler/main.tf b/terraform/modules/scheduler/main.tf index 281be79b..ebccd27e 100644 --- a/terraform/modules/scheduler/main.tf +++ b/terraform/modules/scheduler/main.tf @@ -16,26 +16,26 @@ locals { config = var.json_config != "" ? var.json_config : base64encode(jsonencode([ - merge ({ - "projectId" : "${var.project_id}", - "instanceId" : "${var.spanner_name}", - "scalerPubSubTopic" : "${var.target_pubsub_topic}", - "units" : "${var.units}", - "minSize" : var.min_size, - "maxSize" : var.max_size, - "scalingMethod" : "${var.scaling_method}", - "stateDatabase": var.terraform_spanner_state ? { - "name": "spanner", - "instanceId": "${var.spanner_state_name}" - "databaseId": "spanner-autoscaler-state" + merge({ + "projectId" : "${var.project_id}", + "instanceId" : "${var.spanner_name}", + "scalerPubSubTopic" : "${var.target_pubsub_topic}", + "units" : "${var.units}", + "minSize" : var.min_size, + "maxSize" : var.max_size, + "scalingMethod" : "${var.scaling_method}", + "stateDatabase" : var.terraform_spanner_state ? { + "name" : "spanner", + "instanceId" : "${var.spanner_state_name}" + "databaseId" : "spanner-autoscaler-state" } : { - "name": "firestore", - } + "name" : "firestore", + } }, var.state_project_id != null ? { "stateProjectId" : "${var.state_project_id}" - } : {}) - ])) + } : {}) + ])) } resource "google_app_engine_application" "app" {