Skip to content

Commit

Permalink
chore: add format enforcement for Terraform files (cloudspannerecosys…
Browse files Browse the repository at this point in the history
  • Loading branch information
nielm authored Sep 26, 2024
1 parent fe84d5c commit 04b0ee2
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 42 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/codehealth.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion terraform/gke/decoupled/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ terraform {
version = ">= 6.3.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
source = "hashicorp/kubernetes"
version = ">= 2.32.0"
}
}
Expand Down
2 changes: 1 addition & 1 deletion terraform/gke/unified/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ terraform {
version = ">= 6.3.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
source = "hashicorp/kubernetes"
version = "~> 2.32.0"
}
}
Expand Down
8 changes: 4 additions & 4 deletions terraform/modules/autoscaler-base/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand All @@ -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" {
Expand Down
4 changes: 2 additions & 2 deletions terraform/modules/autoscaler-base/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
18 changes: 9 additions & 9 deletions terraform/modules/autoscaler-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions terraform/modules/autoscaler-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
12 changes: 11 additions & 1 deletion terraform/modules/autoscaler-functions/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion terraform/modules/monitoring/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions terraform/modules/scheduler/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit 04b0ee2

Please sign in to comment.