-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: Init terraform #1
Changes from all commits
23cc86a
514c7cf
66f2944
4dd21cd
25c0459
8a475b4
44b60dc
c71c4e5
22fb097
3e3be32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
provider "google" { | ||
project = var.project_id | ||
region = var.region | ||
zone = var.zone | ||
} | ||
|
||
provider "google-beta" { | ||
project = var.project_id | ||
region = var.region | ||
zone = var.zone | ||
} | ||
|
||
module "ctrlplane" { | ||
source = "../" | ||
namespace = var.namespace | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
variable "project_id" { | ||
type = string | ||
description = "Project ID" | ||
} | ||
|
||
variable "region" { | ||
type = string | ||
description = "Google region" | ||
} | ||
|
||
variable "zone" { | ||
type = string | ||
description = "Google zone" | ||
} | ||
|
||
variable "namespace" { | ||
type = string | ||
description = "Namespace prefix used for resources" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
module "project_factory_project_services" { | ||
source = "terraform-google-modules/project-factory/google//modules/project_services" | ||
version = "~> 16.0" | ||
project_id = null | ||
disable_dependent_services = false | ||
disable_services_on_destroy = false | ||
activate_apis = [ | ||
"sqladmin.googleapis.com", // Database | ||
"networkmanagement.googleapis.com", // Networking | ||
"servicenetworking.googleapis.com", // Networking | ||
] | ||
} | ||
|
||
module "networking" { | ||
source = "./modules/networking" | ||
namespace = var.namespace | ||
|
||
depends_on = [module.project_factory_project_services] | ||
} | ||
|
||
module "database" { | ||
source = "./modules/database" | ||
namespace = var.namespace | ||
|
||
network_connection_string = module.networking.network_connection_string | ||
|
||
postgres_tier = var.postgres_tier | ||
postgres_version = var.postgres_version | ||
|
||
deletion_protection = var.deletion_protection | ||
|
||
depends_on = [module.networking] | ||
} | ||
|
||
module "redis" { | ||
source = "./modules/redis" | ||
namespace = var.namespace | ||
|
||
tier = var.redis_tier | ||
memory_size_gb = var.redis_memory_size_gb | ||
|
||
network_id = module.networking.network_id | ||
} | ||
|
||
module "service_accounts" { | ||
source = "./modules/service_accounts" | ||
namespace = var.namespace | ||
} | ||
|
||
module "gke" { | ||
source = "./modules/gke" | ||
namespace = var.namespace | ||
|
||
deletion_protection = var.deletion_protection | ||
|
||
network_self_link = module.networking.network_self_link | ||
subnetwork_self_link = module.networking.subnetwork_self_link | ||
|
||
service_account_email = module.service_accounts.service_account_email | ||
|
||
depends_on = [module.networking, module.service_accounts] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
resource "random_string" "this" { | ||
length = 32 | ||
special = false | ||
} | ||
|
||
resource "random_pet" "this" { | ||
length = 2 | ||
keepers = { | ||
namespace = var.postgres_version | ||
} | ||
} | ||
|
||
locals { | ||
database_name = "ctrlplane" | ||
master_username = "ctrlplane" | ||
master_password = random_string.this.result | ||
master_instance_name = "${var.namespace}-${random_pet.this.id}" | ||
} | ||
|
||
resource "google_sql_database_instance" "this" { | ||
name = local.master_instance_name | ||
database_version = var.postgres_version | ||
|
||
settings { | ||
tier = var.postgres_tier | ||
ip_configuration { | ||
ipv4_enabled = false | ||
private_network = var.network_connection_string | ||
} | ||
} | ||
} | ||
|
||
resource "google_sql_database" "this" { | ||
name = local.database_name | ||
instance = google_sql_database_instance.this.name | ||
} | ||
|
||
resource "google_sql_user" "this" { | ||
instance = google_sql_database_instance.this.name | ||
name = local.master_username | ||
password = local.master_password | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
output "database_name" { | ||
value = google_sql_database.this.name | ||
description = "The name of the database." | ||
} | ||
|
||
output "sql_user_username" { | ||
value = google_sql_user.this.name | ||
description = "The name of the database user." | ||
} | ||
|
||
output "sql_user_password" { | ||
value = google_sql_user.this.password | ||
description = "The password of the database user." | ||
} | ||
|
||
output "database_instance_private_ip_address" { | ||
value = google_sql_database_instance.this.private_ip_address | ||
description = "The private IP address of the database instance." | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
variable "namespace" { | ||
description = "Namespace for the database" | ||
type = string | ||
} | ||
|
||
variable "postgres_version" { | ||
description = "Version for Postgres" | ||
type = string | ||
default = "POSTGRES_16" | ||
} | ||
|
||
variable "network_connection_string" { | ||
description = "The private service networking connection string that will connect Postgres to the network." | ||
type = string | ||
} | ||
|
||
variable "postgres_tier" { | ||
description = "The tier for the Postgres instance" | ||
type = string | ||
} | ||
|
||
variable "deletion_protection" { | ||
description = "Whether to enable deletion protection for the database instance." | ||
type = bool | ||
default = true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
resource "google_container_cluster" "this" { | ||
name = "${var.namespace}-cluster" | ||
|
||
network = var.network_self_link | ||
subnetwork = var.subnetwork_self_link | ||
|
||
enable_autopilot = true | ||
|
||
deletion_protection = var.deletion_protection | ||
|
||
node_config { | ||
service_account = var.service_account_email | ||
} | ||
|
||
release_channel { | ||
channel = "STABLE" | ||
} | ||
|
||
master_auth { | ||
client_certificate_config { | ||
issue_client_certificate = false | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
variable "namespace" { | ||
description = "Namespace for the GKE cluster" | ||
type = string | ||
} | ||
|
||
variable "service_account_email" { | ||
description = "The service account email associated with the GKE cluster instances to host Ctrlplane." | ||
type = string | ||
} | ||
|
||
variable "network_self_link" { | ||
description = "The network self link." | ||
type = string | ||
} | ||
|
||
variable "subnetwork_self_link" { | ||
description = "The subnetwork self link." | ||
type = string | ||
} | ||
|
||
variable "deletion_protection" { | ||
description = "Whether to enable deletion protection for the database instance." | ||
type = bool | ||
default = true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
resource "google_compute_network" "this" { | ||
name = "${var.namespace}-vpc" | ||
description = "Ctrlplane VPC Network" | ||
auto_create_subnetworks = false | ||
} | ||
|
||
resource "google_compute_subnetwork" "this" { | ||
name = "${var.namespace}-subnet" | ||
ip_cidr_range = "10.10.0.0/16" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a huge range just FYI. 65534 ip's. |
||
network = google_compute_network.this.self_link | ||
} | ||
|
||
resource "google_compute_global_address" "this" { | ||
name = "${var.namespace}-private-ip-address" | ||
purpose = "VPC_PEERING" | ||
address_type = "INTERNAL" | ||
prefix_length = 16 | ||
network = google_compute_network.this.id | ||
} | ||
|
||
resource "google_service_networking_connection" "this" { | ||
network = google_compute_network.this.id | ||
service = "servicenetworking.googleapis.com" | ||
reserved_peering_ranges = [google_compute_global_address.this.name] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
output "network_id" { | ||
value = google_compute_network.this.id | ||
description = "The network id." | ||
} | ||
|
||
output "network_self_link" { | ||
value = google_compute_network.this.self_link | ||
description = "The network self link." | ||
} | ||
|
||
output "subnetwork_self_link" { | ||
value = google_compute_subnetwork.this.self_link | ||
description = "The subnetwork self link." | ||
} | ||
|
||
output "network_connection_string" { | ||
description = "The private connection string between the network and GCP services." | ||
value = google_service_networking_connection.this.network | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
variable "namespace" { | ||
type = string | ||
description = "The name prefix for all resources created." | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
resource "google_redis_instance" "this" { | ||
name = "${var.namespace}-redis" | ||
display_name = "${var.namespace} Ctrlplane Instance" | ||
|
||
tier = var.tier | ||
memory_size_gb = var.memory_size_gb | ||
|
||
authorized_network = var.network_id | ||
|
||
auth_enabled = true | ||
|
||
transit_encryption_mode = "SERVER_AUTHENTICATION" | ||
} |
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.
kept this because the comment seemed like we should keep it