-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Terraform config for Reporting system. (#994)
- Loading branch information
Showing
9 changed files
with
250 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Cross-Media Measurement System | ||
|
||
Root module for a single-project CMMS. This is generally only used for test | ||
environments, e.g. quality assurance (QA). | ||
Root module for a single-project CMMS and Reporting system. This is generally | ||
only used for test environments, e.g. quality assurance (QA). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Copyright 2023 The Cross-Media Measurement Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
module "reporting_cluster" { | ||
source = "../modules/cluster" | ||
|
||
name = local.reporting_cluster_name | ||
location = var.cluster_location | ||
secret_key = module.common.cluster_secret_key | ||
} | ||
|
||
data "google_container_cluster" "reporting" { | ||
name = local.reporting_cluster_name | ||
location = var.cluster_location | ||
|
||
# Defer reading of cluster resource until it exists. | ||
depends_on = [module.reporting_cluster] | ||
} | ||
|
||
module "reporting_default_node_pool" { | ||
source = "../modules/node-pool" | ||
|
||
name = "default" | ||
cluster = data.google_container_cluster.reporting | ||
service_account = module.common.cluster_service_account | ||
machine_type = "e2-small" | ||
max_node_count = 4 | ||
} | ||
|
||
provider "kubernetes" { | ||
# Due to the fact that this is using interpolation, the cluster must already exist. | ||
# See https://registry.terraform.io/providers/hashicorp/kubernetes/2.20.0/docs | ||
|
||
alias = "reporting" | ||
host = "https://${data.google_container_cluster.reporting.endpoint}" | ||
token = data.google_client_config.default.access_token | ||
cluster_ca_certificate = base64decode( | ||
data.google_container_cluster.reporting.master_auth[0].cluster_ca_certificate, | ||
) | ||
} | ||
|
||
module "reporting" { | ||
source = "../modules/reporting" | ||
|
||
providers = { | ||
google = google | ||
kubernetes = kubernetes.reporting | ||
} | ||
|
||
postgres_instance = google_sql_database_instance.postgres | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Reporting System | ||
|
||
Reusable module for the Halo Reporting system on Google Cloud. | ||
|
||
## Provider Configuration | ||
|
||
* `kubernetes` - Configured for the Kubernetes cluster. | ||
* `postgresql` - Configured for the PostgreSQL Cloud SQL instance with a user | ||
that can create and grant privileges to databases. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Copyright 2023 The Cross-Media Measurement Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
data "google_project" "project" {} | ||
|
||
locals { | ||
# All privileges for a PostgreSQL database. | ||
# | ||
# See https://www.postgresql.org/docs/14/ddl-priv.html#PRIVILEGES-SUMMARY-TABLE | ||
all_db_privileges = ["CREATE", "TEMPORARY", "CONNECT"] | ||
} | ||
|
||
module "reporting_internal" { | ||
source = "../workload-identity-user" | ||
|
||
k8s_service_account_name = "internal-reporting-server" | ||
iam_service_account_name = "reporting-internal" | ||
iam_service_account_description = "Reporting internal API server." | ||
} | ||
|
||
resource "google_sql_user" "reporting_internal" { | ||
instance = var.postgres_instance.name | ||
name = trimsuffix(module.reporting_internal.iam_service_account.email, ".gserviceaccount.com") | ||
type = "CLOUD_IAM_SERVICE_ACCOUNT" | ||
} | ||
|
||
resource "google_project_iam_member" "sql_user" { | ||
project = data.google_project.project.name | ||
role = "roles/cloudsql.instanceUser" | ||
member = module.reporting_internal.iam_service_account.member | ||
} | ||
|
||
resource "google_project_iam_member" "sql_client" { | ||
project = data.google_project.project.name | ||
role = "roles/cloudsql.client" | ||
member = module.reporting_internal.iam_service_account.member | ||
} | ||
|
||
resource "google_sql_database" "db" { | ||
name = "reporting" | ||
instance = var.postgres_instance.name | ||
} | ||
|
||
resource "postgresql_grant" "db" { | ||
role = google_sql_user.reporting_internal.name | ||
database = google_sql_database.db.name | ||
object_type = "database" | ||
privileges = local.all_db_privileges | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright 2023 The Cross-Media Measurement Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
variable "postgres_instance" { | ||
description = "PostgreSQL `google_sql_database_instance`." | ||
type = object({ | ||
name = string | ||
connection_name = string | ||
}) | ||
nullable = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2023 The Cross-Media Measurement Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
terraform { | ||
required_providers { | ||
google = { | ||
source = "hashicorp/google" | ||
version = ">= 4.63.0" | ||
} | ||
kubernetes = { | ||
source = "hashicorp/kubernetes" | ||
version = ">= 2.20.0" | ||
} | ||
postgresql = { | ||
source = "cyrilgdn/postgresql" | ||
version = ">= 1.19.0" | ||
} | ||
} | ||
} |