-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- One VPC + 2 Subnets for webapp and db each - Modularized the code based on the resources
- Loading branch information
Showing
10 changed files
with
227 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: "Terraform GCP Deploy" | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- feature/assignment-03 | ||
|
||
jobs: | ||
validate: | ||
name: "Validate Terraform Templates" | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Terraform | ||
uses: hashicorp/setup-terraform@v1 | ||
with: | ||
terraform_version: "1.7.3" | ||
|
||
- name: Terraform Initialization | ||
run: terraform init | ||
# Initializes Terraform, a necessary step before validation | ||
|
||
- name: Terraform Validate | ||
run: terraform validate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Local .terraform directories | ||
**/.terraform/* | ||
|
||
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* | ||
|
||
# Crash log files | ||
crash.log | ||
crash.*.log | ||
|
||
# Exclude all .tfvars files, which are likely to contain sensitive data, such as | ||
# password, private keys, and other secrets. These should not be part of version | ||
# control as they are data points which are potentially sensitive and subject | ||
# to change depending on the environment. | ||
*.tfvars | ||
*.tfvars.json | ||
|
||
# Ignore override files as they are usually used to override resources locally and so | ||
# are not checked in | ||
override.tf | ||
override.tf.json | ||
*_override.tf | ||
*_override.tf.json | ||
|
||
# Ignore transient lock info files created by terraform apply | ||
.terraform.tfstate.lock.info | ||
|
||
# Include override files you do wish to add to version control using negated pattern | ||
# !example_override.tf | ||
|
||
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan | ||
# example: *tfplan* | ||
|
||
# Ignore CLI configuration files | ||
.terraformrc | ||
terraform.rc |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# tf-gcp-infra-summer | ||
# tf-gcp-infra-summer | ||
|
||
Enabled GCP APIs: Compute Engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
provider "google" { | ||
project = var.project_id | ||
region = var.region | ||
} | ||
|
||
module "vpc" { | ||
source = "./vpc" | ||
vpc_name = var.vpc_name | ||
region = var.region | ||
webapp_subnet_cidr = var.webapp_subnet_cidr | ||
db_subnet_cidr = var.db_subnet_cidr | ||
subnet1 = var.subnet1 | ||
subnet2 = var.subnet2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
output "vpc_self_link" { | ||
description = "The self-link of the VPC" | ||
value = module.vpc.vpc_self_link | ||
} | ||
|
||
output "webapp_subnet_self_link" { | ||
description = "The self-link of the webapp subnet" | ||
value = module.vpc.webapp_subnet_self_link | ||
} | ||
|
||
output "db_subnet_self_link" { | ||
description = "The self-link of the db subnet" | ||
value = module.vpc.db_subnet_self_link | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
variable "project_id" { | ||
description = "The ID of the project in which to create the VPC" | ||
type = string | ||
} | ||
|
||
variable "region" { | ||
description = "The region in which to create the VPC and subnets" | ||
type = string | ||
default = "us-central1" | ||
} | ||
|
||
variable "vpc_name" { | ||
description = "The name of the VPC" | ||
type = string | ||
} | ||
|
||
variable "webapp_subnet_cidr" { | ||
description = "The CIDR range of the webapp subnet" | ||
type = string | ||
} | ||
|
||
variable "db_subnet_cidr" { | ||
description = "The CIDR range of the db subnet" | ||
type = string | ||
} | ||
|
||
variable "subnet1" { | ||
description = "The name of my subnet" | ||
type = string | ||
} | ||
|
||
variable "subnet2" { | ||
description = "The name of my subnet 2" | ||
type = string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
resource "google_compute_network" "vpc" { | ||
name = var.vpc_name | ||
auto_create_subnetworks = false | ||
routing_mode = "REGIONAL" | ||
} | ||
|
||
resource "google_compute_subnetwork" "webapp" { | ||
name = var.subnet1 | ||
ip_cidr_range = var.webapp_subnet_cidr | ||
region = var.region | ||
network = google_compute_network.vpc.self_link | ||
} | ||
|
||
resource "google_compute_subnetwork" "db" { | ||
name = var.subnet2 | ||
ip_cidr_range = var.db_subnet_cidr | ||
region = var.region | ||
network = google_compute_network.vpc.self_link | ||
} | ||
|
||
resource "google_compute_route" "webapp_default_route" { | ||
name = "webapp-default-route" | ||
network = google_compute_network.vpc.self_link | ||
dest_range = "0.0.0.0/0" | ||
next_hop_gateway = "default-internet-gateway" | ||
priority = 1000 | ||
|
||
tags = ["webapp"] | ||
|
||
depends_on = [google_compute_subnetwork.webapp] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
output "vpc_self_link" { | ||
description = "The self-link of the VPC" | ||
value = google_compute_network.vpc.self_link | ||
} | ||
|
||
output "webapp_subnet_self_link" { | ||
description = "The self-link of the webapp subnet" | ||
value = google_compute_subnetwork.webapp.self_link | ||
} | ||
|
||
output "db_subnet_self_link" { | ||
description = "The self-link of the db subnet" | ||
value = google_compute_subnetwork.db.self_link | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
variable "vpc_name" { | ||
description = "The name of the VPC" | ||
type = string | ||
} | ||
|
||
variable "webapp_subnet_cidr" { | ||
description = "The CIDR range of the webapp subnet" | ||
type = string | ||
} | ||
|
||
variable "db_subnet_cidr" { | ||
description = "The CIDR range of the db subnet" | ||
type = string | ||
} | ||
|
||
variable "region" { | ||
description = "The region in which to create the VPC and subnets" | ||
type = string | ||
} | ||
|
||
variable "subnet1" { | ||
description = "The name of my subnet" | ||
type = string | ||
} | ||
|
||
variable "subnet2" { | ||
description = "The name of my subnet 2" | ||
type = string | ||
} |