Skip to content

Commit d386579

Browse files
committed
Added prod environment
1 parent ce0234c commit d386579

File tree

5 files changed

+195
-0
lines changed

5 files changed

+195
-0
lines changed

environments/prod/.terraform.lock.hcl

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

environments/prod/backend.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
terraform {
2+
backend "gcs" {
3+
bucket = "learning-gcs-tfstate"
4+
prefix = "prod"
5+
}
6+
}

environments/prod/main.tf

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# VPC
2+
module "vpc-prod" {
3+
source = "../../modules/vpc"
4+
5+
vpcs = {
6+
"prod-vpc-a" = {
7+
name = "prod-vpc-a"
8+
},
9+
"prod-vpc-b" = {
10+
name = "prod-vpc-b"
11+
}
12+
}
13+
}
14+
15+
# Subnets
16+
module "subnets-prod" {
17+
source = "../../modules/subnets"
18+
depends_on = [module.vpc-prod]
19+
20+
subnets = {
21+
"prod-vpc-a-subnet-1" = {
22+
name = "prod-vpc-a-subnet-1"
23+
cidr = "10.110.0.0/16"
24+
region = var.region
25+
network = module.vpc-prod.vpc_network["prod-vpc-a"].self_link
26+
},
27+
"prod-vpc-a-subnet-2" = {
28+
name = "prod-vpc-a-subnet-2"
29+
cidr = "10.120.0.0/16"
30+
region = var.region
31+
network = module.vpc-prod.vpc_network["prod-vpc-a"].self_link
32+
},
33+
"prod-vpc-b-subnet-1" = {
34+
name = "prod-vpc-b-subnet-1"
35+
cidr = "10.130.0.0/16"
36+
region = var.region
37+
network = module.vpc-prod.vpc_network["prod-vpc-b"].self_link
38+
},
39+
"prod-vpc-b-subnet-2" = {
40+
name = "prod-vpc-b-subnet-2"
41+
cidr = "10.140.0.0/16"
42+
region = var.region
43+
network = module.vpc-prod.vpc_network["prod-vpc-b"].self_link
44+
}
45+
}
46+
}
47+
48+
# Cloud Router
49+
module "cloudrouter" {
50+
source = "../../modules/cloudrouter"
51+
depends_on = [module.vpc-prod, module.subnets-prod]
52+
53+
routers = {
54+
"prod-vpc-a-router" = {
55+
name = "prod-vpc-a-router"
56+
region = var.region
57+
network = module.vpc-prod.vpc_network["prod-vpc-a"].self_link
58+
},
59+
"prod-vpc-b-router" = {
60+
name = "prod-vpc-b-router"
61+
region = var.region
62+
network = module.vpc-prod.vpc_network["prod-vpc-b"].self_link
63+
}
64+
}
65+
}
66+
67+
# Cloud NAT
68+
module "nat_ip_vpc_a_1" {
69+
source = "../../modules/public_ip"
70+
depends_on = [module.vpc-prod]
71+
72+
name = "prod-nat-ip-vpc-a-1"
73+
region = var.region
74+
}
75+
76+
module "nat_ip_vpc_a_2" {
77+
source = "../../modules/public_ip"
78+
depends_on = [module.vpc-prod]
79+
80+
name = "prod-nat-ip-vpc-a-2"
81+
region = var.region
82+
}
83+
84+
module "nat_ip_vpc_b" {
85+
source = "../../modules/public_ip"
86+
depends_on = [module.vpc-prod]
87+
88+
name = "prod-nat-ip-vpc-b"
89+
region = var.region
90+
}
91+
92+
module "cloudnat" {
93+
source = "../../modules/cloudnat"
94+
project_id = var.project_id
95+
depends_on = [module.cloudrouter, module.nat_ip_vpc_a_1, module.nat_ip_vpc_a_2, module.nat_ip_vpc_b]
96+
97+
nats = {
98+
"prod-vpc-a-nat-1" = {
99+
name = "prod-vpc-a-nat-1"
100+
region = var.region
101+
router = module.cloudrouter.router_names["prod-vpc-a-router"]
102+
nat_ips = [module.nat_ip_vpc_a_1.name, module.nat_ip_vpc_a_2.name]
103+
},
104+
"prod-vpc-b-nat-1" = {
105+
name = "prod-vpc-b-nat-1"
106+
region = var.region
107+
router = module.cloudrouter.router_names["prod-vpc-b-router"]
108+
nat_ips = [module.nat_ip_vpc_b.name]
109+
}
110+
}
111+
}

environments/prod/provider.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
terraform {
2+
required_version = ">= 1.11.4"
3+
required_providers {
4+
google = {
5+
source = "hashicorp/google"
6+
version = "~> 5.29"
7+
}
8+
google-beta = {
9+
source = "hashicorp/google-beta"
10+
version = "~> 5.29"
11+
}
12+
}
13+
}
14+
15+
provider "google" {
16+
# Configuration options
17+
project = var.project_id
18+
region = var.region
19+
}
20+
21+
provider "google-beta" {
22+
# Configuration options
23+
project = var.project_id
24+
region = var.region
25+
}

environments/prod/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
variable "project_id" {
2+
description = "Project ID"
3+
type = string
4+
default = "learning-0165559734"
5+
}
6+
7+
variable "region" {
8+
description = "Region of the Project"
9+
type = string
10+
default = "asia-southeast1"
11+
}

0 commit comments

Comments
 (0)