Skip to content
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

fix: Some TF best practices and naming #2

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/main.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
provider "google" {
project = var.project_id
region = var.region
zone = var.zone
# zone = var.zone
}

provider "google-beta" {
project = var.project_id
region = var.region
zone = var.zone
# zone = var.zone
}

module "ctrlplane" {
Expand Down
4 changes: 3 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module "project_factory_project_services" {
source = "terraform-google-modules/project-factory/google//modules/project_services"
version = "~> 14.0"
version = "~> 16.0"
project_id = null
disable_dependent_services = false
disable_services_on_destroy = false
Expand All @@ -26,6 +26,8 @@ module "database" {
source = "./modules/database"
namespace = var.namespace
network_connection = local.network_connection
availability_type = var.database_availability_type
pg_version = var.database_version
}

module "service_accounts" {
Expand Down
7 changes: 4 additions & 3 deletions modules/database/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource "random_string" "master_password" {
resource "random_pet" "postgres" {
length = 2
keepers = {
namespace = var.database_version
namespace = var.pg_version
}
}

Expand All @@ -19,10 +19,11 @@ locals {

resource "google_sql_database_instance" "postgres" {
name = local.master_instance_name
database_version = var.database_version
database_version = var.pg_version

settings {
tier = var.tier
tier = var.tier
availability_type = var.availability_type
ip_configuration {
ipv4_enabled = false
private_network = var.network_connection.network
Expand Down
8 changes: 7 additions & 1 deletion modules/database/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ variable "namespace" {
type = string
}

variable "database_version" {
variable "pg_version" {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version is a reserved word in tf or I would use it 🤦

description = "Version for Postgres"
type = string
default = "POSTGRES_16"
Expand All @@ -19,3 +19,9 @@ variable "tier" {
type = string
default = "db-f1-micro"
}

variable "availability_type" {
description = "The availability type for the Postgres instance"
type = string
default = "REGIONAL"
}
4 changes: 2 additions & 2 deletions modules/networking/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ resource "google_compute_subnetwork" "default" {
network = google_compute_network.vpc.self_link
}

resource "google_compute_global_address" "private_ip_address" {
resource "google_compute_global_address" "private" {
name = "${var.namespace}-private-ip-address"
purpose = "VPC_PEERING"
address_type = "INTERNAL"
Expand All @@ -21,5 +21,5 @@ resource "google_compute_global_address" "private_ip_address" {
resource "google_service_networking_connection" "default" {
network = google_compute_network.vpc.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_address.name]
reserved_peering_ranges = [google_compute_global_address.private.name]
}
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,15 @@ variable "namespace" {
type = string
description = "The name prefix for all resources created."
}

variable "database_availability_type" {
description = "The availability type for the Postgres instance"
type = string
default = "REGIONAL"
}

variable "database_version" {
description = "The version of the database to use."
type = string
default = "POSTGRES_16"
}