Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-toncu committed Nov 23, 2023
0 parents commit de1056b
Show file tree
Hide file tree
Showing 14 changed files with 271 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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
# Passwords, 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

# 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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# terraform-google-vpc-network

Terraform Google VPC Network
24 changes: 24 additions & 0 deletions firewall-rule/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
resource "google_compute_firewall" "default" {
provider = google

name = var.name
description = var.description

network = var.network

priority = var.priority

dynamic "allow" {
for_each = var.allow

content {
ports = lookup(allow.value, "ports", null)
protocol = allow.value.protocol
}
}

source_ranges = var.source_ranges

source_tags = var.source_tags
target_tags = var.target_tags
}
Empty file added firewall-rule/output.tf
Empty file.
49 changes: 49 additions & 0 deletions firewall-rule/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
variable "name" {
type = string
description = "The name of the firewall rule"
}

variable "description" {
type = string
description = "The description of the firewall rule"
}

variable "network" {
type = string
description = "The network this firewall rule applies to"
}

variable "priority" {
type = string
description = "The firewall rule priority"

default = "1000"
}

variable "allow" {
type = list(any)
description = "The protocol and port to allow"

default = []
}

variable "source_ranges" {
type = list(string)
description = "A list of source CIDR ranges that this firewall applies to"

default = []
}

variable "source_tags" {
type = list(any)
description = "A list of source tags for this firewall rule"

default = []
}

variable "target_tags" {
type = list(any)
description = "A list of target tags for this firewall rule"

default = []
}
14 changes: 14 additions & 0 deletions firewall-rule/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_version = "~> v1.6.2"

required_providers {
google = {
source = "hashicorp/google"
version = "~> 5.4.0"
}
google-beta = {
source = "hashicorp/google-beta"
version = "~> 5.4.0"
}
}
}
26 changes: 26 additions & 0 deletions network/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
resource "google_compute_network" "default" {
provider = google

name = var.name
description = var.description

auto_create_subnetworks = var.auto_create_subnetworks
}

# tfsec:ignore:google-compute-no-public-ingress
module "icmp-access" {
source = "../firewall-rule"

name = "access-${var.name}-icmp"
description = "Access for internet control message protocol"

network = var.name

allow = [
{
protocol = "icmp"
}
]

source_ranges = ["0.0.0.0/0"]
}
7 changes: 7 additions & 0 deletions network/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "network" {
value = google_compute_network.default.name
}

output "network_link" {
value = google_compute_network.default.self_link
}
18 changes: 18 additions & 0 deletions network/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
variable "name" {
type = string
description = "Network name"
}

variable "description" {
type = string
description = "Network description"

default = ""
}

variable "auto_create_subnetworks" {
type = bool
description = "Auto create subnetworks"

default = false
}
14 changes: 14 additions & 0 deletions network/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_version = "~> v1.6.2"

required_providers {
google = {
source = "hashicorp/google"
version = "~> 5.4.0"
}
google-beta = {
source = "hashicorp/google-beta"
version = "~> 5.4.0"
}
}
}
24 changes: 24 additions & 0 deletions subnetwork/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# tfsec:ignore:google-compute-enable-vpc-flow-logs
resource "google_compute_subnetwork" "default" {
provider = google

name = var.name
description = var.description

region = var.region

network = var.network

private_ip_google_access = true

ip_cidr_range = var.cidr_range

dynamic "secondary_ip_range" {
for_each = var.secondary_ip_ranges

content {
ip_cidr_range = lookup(secondary_ip_range.value, "ip_cidr_range", null)
range_name = lookup(secondary_ip_range.value, "range_name", null)
}
}
}
11 changes: 11 additions & 0 deletions subnetwork/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
output "subnetwork" {
value = google_compute_subnetwork.default.name
}

output "subnetwork_link" {
value = google_compute_subnetwork.default.self_link
}

output "ip_cidr_range" {
value = google_compute_subnetwork.default.ip_cidr_range
}
33 changes: 33 additions & 0 deletions subnetwork/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
variable "name" {
type = string
description = "Subnetwork name"
}

variable "description" {
type = string
description = "Subnetwork description"

default = ""
}

variable "region" {
type = string
description = "Subnetwork region"
}

variable "network" {
type = string
description = "Subnetwork parent network"
}

variable "cidr_range" {
type = string
description = "Subnetwork ip cidr range"
}

variable "secondary_ip_ranges" {
type = list(any)
description = "Subnetwork secondary ip cidr ranges"

default = []
}
14 changes: 14 additions & 0 deletions subnetwork/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_version = "~> v1.6.2"

required_providers {
google = {
source = "hashicorp/google"
version = "~> 5.4.0"
}
google-beta = {
source = "hashicorp/google-beta"
version = "~> 5.4.0"
}
}
}

0 comments on commit de1056b

Please sign in to comment.