Skip to content

Commit f56aca2

Browse files
committed
feat(infra): Allow for separate IAC environments with separate state files
- Separate out common infra from service-specific infra - Create modules for reusing resource definitions
1 parent 8f6f0b9 commit f56aca2

28 files changed

Lines changed: 760 additions & 436 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ htmlcov/
2626
*.py[co]
2727

2828
# environment
29-
env*/
29+
env/
3030
.env*
3131
.auto.tfvars
3232

infra/gcp/.terraform.lock.hcl

Lines changed: 0 additions & 55 deletions
This file was deleted.

infra/gcp/cloudrun.tf

Lines changed: 0 additions & 101 deletions
This file was deleted.

infra/gcp/db.tf

Lines changed: 0 additions & 28 deletions
This file was deleted.

infra/gcp/envs/common/.terraform.lock.hcl

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infra/gcp/envs/common/main.tf

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
terraform {
2+
required_providers {
3+
google = {
4+
source = "hashicorp/google"
5+
version = ">= 4.0"
6+
}
7+
}
8+
9+
backend "gcs" {
10+
bucket = "${var.project_id}-tfstate"
11+
prefix = "api/common"
12+
}
13+
}
14+
15+
provider "google" {
16+
project = var.project_id
17+
region = var.region
18+
}
19+
20+
module "common" {
21+
source = "../../modules/common"
22+
23+
project_id = var.project_id
24+
region = var.region
25+
service_name = var.service_name
26+
}
27+
28+
output "vpc_connector_id" {
29+
value = module.common.vpc_connector_id
30+
}
31+
32+
output "db_instance_name" {
33+
value = module.common.db_instance_name
34+
}
35+
36+
output "db_private_ip" {
37+
value = module.common.db_private_ip
38+
}
39+
40+
output "redis_host" {
41+
value = module.common.redis_host
42+
}
43+
44+
output "redis_port" {
45+
value = module.common.redis_port
46+
}

infra/gcp/envs/common/variables.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
variable "project_id" {
2+
description = "GCP Project ID"
3+
type = string
4+
}
5+
6+
variable "region" {
7+
description = "GCP Region (e.g. us-central1)"
8+
type = string
9+
default = "us-central1"
10+
}
11+
12+
variable "service_name" {
13+
description = "Name of the service (used for naming resources)"
14+
type = string
15+
default = "shareabouts-api"
16+
}

infra/gcp/envs/dev/.terraform.lock.hcl

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infra/gcp/envs/dev/main.tf

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
terraform {
2+
required_providers {
3+
google = {
4+
source = "hashicorp/google"
5+
version = ">= 4.0"
6+
}
7+
}
8+
9+
backend "gcs" {
10+
bucket = "${var.project_id}-tfstate"
11+
prefix = "api/dev"
12+
}
13+
}
14+
15+
provider "google" {
16+
project = var.project_id
17+
region = var.region
18+
}
19+
20+
# ------------------------------------------------------------------------------
21+
# REMOTE STATE (COMMON)
22+
# ------------------------------------------------------------------------------
23+
24+
data "terraform_remote_state" "common" {
25+
backend = "gcs"
26+
27+
config = {
28+
bucket = "${var.project_id}-tfstate"
29+
prefix = "api/common"
30+
}
31+
}
32+
33+
# ------------------------------------------------------------------------------
34+
# SERVICE MODULE
35+
# ------------------------------------------------------------------------------
36+
37+
module "service" {
38+
source = "../../modules/shareabouts-service"
39+
40+
project_id = var.project_id
41+
region = var.region
42+
service_name = var.service_name
43+
environment = "dev"
44+
45+
# Inputs from Common
46+
vpc_connector_id = data.terraform_remote_state.common.outputs.vpc_connector_id
47+
db_instance_name = data.terraform_remote_state.common.outputs.db_instance_name
48+
db_private_ip = data.terraform_remote_state.common.outputs.db_private_ip
49+
redis_host = data.terraform_remote_state.common.outputs.redis_host
50+
redis_port = data.terraform_remote_state.common.outputs.redis_port
51+
52+
# Config
53+
domain_names = var.domain_names
54+
additional_allowed_hosts = var.additional_allowed_hosts
55+
}

0 commit comments

Comments
 (0)