-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement GCP modules for API management, budget, and Firestore, including variables, resources, and outputs #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
1eee850
45e7fa2
ce8228b
58be412
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| terraform { | ||
| required_version = ">= 1.14.0" | ||
| required_providers { | ||
| google = { | ||
| source = "hashicorp/google" | ||
| version = ">= 7.26.0" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| resource "google_project_service" "enabled_apis" { | ||
| for_each = toset(var.gcp_service_list) | ||
|
|
||
| project = var.gcp_project_id | ||
| service = each.key | ||
|
|
||
| disable_on_destroy = false | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| output "enabled_services" { | ||
| value = [for s in google_project_service.enabled_apis : s.service] | ||
| description = "The list of services that were enabled" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| variable "gcp_project_id" { | ||
| description = "The ID of the project where APIs will be enabled" | ||
| type = string | ||
| } | ||
|
|
||
| variable "gcp_service_list" { | ||
| description = "The list of APIs to enable" | ||
| type = list(string) | ||
| default = [] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| data "google_billing_account" "account" { | ||
| display_name = var.billing_account_name | ||
| open = true | ||
| } | ||
|
Comment on lines
+1
to
+4
|
||
|
|
||
| resource "google_monitoring_notification_channel" "email_devops" { | ||
| project = var.project_id | ||
| display_name = "Budget Alert Email" | ||
| type = "email" | ||
|
|
||
| labels = { | ||
| email_address = var.billing_notification_email | ||
| } | ||
| } | ||
|
|
||
| resource "google_billing_budget" "monthly_limit" { | ||
| billing_account = data.google_billing_account.account.id | ||
| display_name = var.budget_name | ||
|
|
||
| budget_filter { | ||
| projects = ["projects/${var.project_id}"] | ||
| } | ||
|
|
||
| amount { | ||
| specified_amount { | ||
| currency_code = "USD" | ||
| units = tostring(var.limit_amount_usd) | ||
| } | ||
| } | ||
|
|
||
| threshold_rules { | ||
| threshold_percent = 0.5 | ||
| } | ||
|
|
||
| threshold_rules { | ||
| threshold_percent = 0.9 | ||
| } | ||
|
|
||
| threshold_rules { | ||
| threshold_percent = 1.0 | ||
| spend_basis = "FORECASTED_SPEND" | ||
| } | ||
|
|
||
| all_updates_rule { | ||
| monitoring_notification_channels = [ | ||
| google_monitoring_notification_channel.email_devops.id | ||
| ] | ||
|
|
||
| disable_default_iam_recipients = false | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| output "budget_name" { | ||
| description = "Name of the GCP budget." | ||
| value = google_billing_budget.monthly_limit.display_name | ||
| } | ||
|
|
||
| output "budget_id" { | ||
| description = "The GCP budget resource name." | ||
| value = google_billing_budget.monthly_limit.name | ||
| } |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,33 @@ | ||||
| variable "project_id" { | ||||
| description = "The GCP project ID for the budget." | ||||
| type = string | ||||
| } | ||||
|
|
||||
| variable "billing_account_name" { | ||||
| description = "Name of the GCP billing account to create the budget under." | ||||
| type = string | ||||
| default = "durianpy-cms" | ||||
|
||||
| default = "durianpy-cms" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| resource "google_project_service" "firestore" { | ||
| project = var.project_id | ||
| service = var.api_service_name | ||
|
Comment on lines
+1
to
+3
|
||
| disable_on_destroy = false | ||
| } | ||
|
Comment on lines
+1
to
+5
|
||
|
|
||
| resource "google_firestore_database" "this" { | ||
| project = var.project_id | ||
| name = var.database_name | ||
| location_id = var.region | ||
| type = var.database_type | ||
| concurrency_mode = var.concurrency_mode | ||
| app_engine_integration_mode = var.app_engine_integration_mode | ||
| database_edition = var.database_edition | ||
|
|
||
| mongodb_compatible_data_access_mode = var.mongodb_compatible_data_access_mode | ||
| delete_protection_state = var.delete_protection_state | ||
|
|
||
| depends_on = [google_project_service.firestore] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| output "firestore_db_id" { | ||
| description = "The Firestore database resource name." | ||
| value = google_firestore_database.this.name | ||
| } | ||
|
|
||
| output "firestore_db_project" { | ||
| description = "The project that owns the Firestore database." | ||
| value = google_firestore_database.this.project | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| variable "project_id" { | ||
| description = "The GCP project ID where Firestore will be created." | ||
| type = string | ||
| } | ||
|
|
||
| variable "region" { | ||
| description = "The Firestore location ID." | ||
| type = string | ||
| } | ||
|
|
||
| variable "database_name" { | ||
| description = "The Firestore database name." | ||
| type = string | ||
| default = "payloadcms-poc-db" | ||
| } | ||
|
|
||
| variable "api_service_name" { | ||
| description = "The Google API service to enable before creating Firestore." | ||
| type = string | ||
| default = "firestore.googleapis.com" | ||
| } | ||
|
|
||
| variable "database_type" { | ||
| description = "The Firestore database type." | ||
| type = string | ||
| default = "FIRESTORE_NATIVE" | ||
| } | ||
|
|
||
| variable "concurrency_mode" { | ||
| description = "The Firestore concurrency mode." | ||
| type = string | ||
| default = "OPTIMISTIC" | ||
| } | ||
|
|
||
| variable "app_engine_integration_mode" { | ||
| description = "The App Engine integration mode for Firestore." | ||
| type = string | ||
| default = "DISABLED" | ||
| } | ||
|
|
||
| variable "database_edition" { | ||
| description = "The Firestore database edition." | ||
| type = string | ||
| default = "ENTERPRISE" | ||
| } | ||
|
|
||
| variable "mongodb_compatible_data_access_mode" { | ||
| description = "MongoDB-compatible data access mode for Firestore." | ||
| type = string | ||
| default = "DATA_ACCESS_MODE_ENABLED" | ||
| } | ||
|
|
||
| variable "delete_protection_state" { | ||
| description = "Delete protection state for the Firestore database." | ||
| type = string | ||
| default = "DELETE_PROTECTION_DISABLED" | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,11 +8,11 @@ terraform { | |
| } | ||
| google = { | ||
| source = "hashicorp/google" | ||
| version = ">= 6.0" | ||
| version = ">= 7.26.0" | ||
| } | ||
| google-beta = { | ||
| source = "hashicorp/google-beta" | ||
| version = ">= 6.0" | ||
| version = ">= 7.26.0" | ||
| } | ||
|
Comment on lines
9
to
16
|
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -43,3 +43,37 @@ module "vpc" { | |||||||
| "10.20.80.0/20", | ||||||||
| ] | ||||||||
| } | ||||||||
|
|
||||||||
| module "gcp_project_apis" { | ||||||||
| source = "../../modules/gcp/api" | ||||||||
| gcp_project_id = var.gcp_project_id | ||||||||
|
|
||||||||
| gcp_service_list = [ | ||||||||
| "billingbudgets.googleapis.com", | ||||||||
| "monitoring.googleapis.com", | ||||||||
| "iam.googleapis.com", | ||||||||
| "serviceusage.googleapis.com", | ||||||||
| "cloudresourcemanager.googleapis.com", | ||||||||
| "firestore.googleapis.com" | ||||||||
|
||||||||
| "cloudresourcemanager.googleapis.com", | |
| "firestore.googleapis.com" | |
| "cloudresourcemanager.googleapis.com" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The input variable is named
gcp_project_id, but the other GCP modules in this repo useproject_id(e.g.,modules/gcp/firestore/variables.tf:1,modules/gcp/budget/variables.tf:1). For a consistent module API and less glue code in callers, consider renaming this toproject_id.