Skip to content

Commit

Permalink
Merge pull request #1 from borgeslima/main
Browse files Browse the repository at this point in the history
feat(first-commit)
  • Loading branch information
coffee-cloud-consulting authored Apr 15, 2024
2 parents 6b5a950 + 1540c9c commit d813b9a
Show file tree
Hide file tree
Showing 14 changed files with 388 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform.tfstate
terraform.tfstate.backup
.terraform
Empty file added README.md
Empty file.
Empty file added gcp/README.md
Empty file.
107 changes: 107 additions & 0 deletions gcp/computer_network/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# GCP VPC Terraform module

Terraform module which creates VPC resources on GCP.


## Usage

```hcl
module "network" {
source = "../.."
region = "us-east1"
name = "quark-labs"
project = "quarks-labs"
auto_create_subnetworks = false
subnetworks = {
subenet1 = {
name = "default-us-east1"
region = "us-east1"
ip_cidr_range = "172.28.0.0/27"
private_ip_google_access = false
nat = {
nat_ip_allocate_option = "MANUAL_ONLY"
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
}
secondary_ip_ranges = {
primary = {
range_name = "primary"
ip_cidr_range = "172.1.16.0/20"
}
secondary = {
range_name = "secondary"
ip_cidr_range = "172.1.32.0/20"
}
}
}
}
}
```


## Contributing

Report issues/questions/feature requests on in the [issues](https://github.com/terraform-gcp-modules/.../issues/new) section.

Full contributing [guidelines are covered here](.github/contributing.md).





<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.14 |
| <a name="requirement_google"></a> [google](#requirement\_google) | 5.24.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_google"></a> [google](#provider\_google) | 5.24.0 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [google_compute_address.this](https://registry.terraform.io/providers/hashicorp/google/5.24.0/docs/resources/compute_address) | resource |
| [google_compute_network.this](https://registry.terraform.io/providers/hashicorp/google/5.24.0/docs/resources/compute_network) | resource |
| [google_compute_router.this](https://registry.terraform.io/providers/hashicorp/google/5.24.0/docs/resources/compute_router) | resource |
| [google_compute_router_nat.this](https://registry.terraform.io/providers/hashicorp/google/5.24.0/docs/resources/compute_router_nat) | resource |
| [google_compute_subnetwork.this](https://registry.terraform.io/providers/hashicorp/google/5.24.0/docs/resources/compute_subnetwork) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_auto_create_subnetworks"></a> [auto\_create\_subnetworks](#input\_auto\_create\_subnetworks) | If auto\_crea\_subnetworks is true, subnet is created automality | `bool` | n/a | yes |
| <a name="input_name"></a> [name](#input\_name) | Name of GCP Network | `string` | n/a | yes |
| <a name="input_project"></a> [project](#input\_project) | Name of GCP Network | `string` | n/a | yes |
| <a name="input_region"></a> [region](#input\_region) | GCP Region | `string` | n/a | yes |
| <a name="input_subnetworks"></a> [subnetworks](#input\_subnetworks) | Name of GCP Network | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_google_compute_network_auto_create_subnetworks"></a> [google\_compute\_network\_auto\_create\_subnetworks](#output\_google\_compute\_network\_auto\_create\_subnetworks) | auto\_create\_subnetworks of network |
| <a name="output_google_compute_network_description"></a> [google\_compute\_network\_description](#output\_google\_compute\_network\_description) | Description of network |
| <a name="output_google_compute_network_gateway_ipv4"></a> [google\_compute\_network\_gateway\_ipv4](#output\_google\_compute\_network\_gateway\_ipv4) | gateway\_ipv4 of network |
| <a name="output_google_compute_network_id"></a> [google\_compute\_network\_id](#output\_google\_compute\_network\_id) | id of network |
| <a name="output_google_compute_network_internal_ipv6_range"></a> [google\_compute\_network\_internal\_ipv6\_range](#output\_google\_compute\_network\_internal\_ipv6\_range) | internal\_ipv6\_range of network |
| <a name="output_google_compute_network_name"></a> [google\_compute\_network\_name](#output\_google\_compute\_network\_name) | Name of network |
<!-- END_TF_DOCS -->
49 changes: 49 additions & 0 deletions gcp/computer_network/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.14 |
| <a name="requirement_google"></a> [google](#requirement\_google) | 5.24.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_google"></a> [google](#provider\_google) | 5.24.0 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [google_compute_address.this](https://registry.terraform.io/providers/hashicorp/google/5.24.0/docs/resources/compute_address) | resource |
| [google_compute_network.this](https://registry.terraform.io/providers/hashicorp/google/5.24.0/docs/resources/compute_network) | resource |
| [google_compute_router.this](https://registry.terraform.io/providers/hashicorp/google/5.24.0/docs/resources/compute_router) | resource |
| [google_compute_router_nat.this](https://registry.terraform.io/providers/hashicorp/google/5.24.0/docs/resources/compute_router_nat) | resource |
| [google_compute_subnetwork.this](https://registry.terraform.io/providers/hashicorp/google/5.24.0/docs/resources/compute_subnetwork) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_auto_create_subnetworks"></a> [auto\_create\_subnetworks](#input\_auto\_create\_subnetworks) | If auto\_crea\_subnetworks is true, subnet is created automality | `bool` | n/a | yes |
| <a name="input_name"></a> [name](#input\_name) | Name of GCP Network | `string` | n/a | yes |
| <a name="input_project"></a> [project](#input\_project) | Name of GCP Network | `string` | n/a | yes |
| <a name="input_region"></a> [region](#input\_region) | GCP Region | `string` | n/a | yes |
| <a name="input_subnetworks"></a> [subnetworks](#input\_subnetworks) | Name of GCP Network | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_google_compute_network_auto_create_subnetworks"></a> [google\_compute\_network\_auto\_create\_subnetworks](#output\_google\_compute\_network\_auto\_create\_subnetworks) | auto\_create\_subnetworks of network |
| <a name="output_google_compute_network_description"></a> [google\_compute\_network\_description](#output\_google\_compute\_network\_description) | Description of network |
| <a name="output_google_compute_network_gateway_ipv4"></a> [google\_compute\_network\_gateway\_ipv4](#output\_google\_compute\_network\_gateway\_ipv4) | gateway\_ipv4 of network |
| <a name="output_google_compute_network_id"></a> [google\_compute\_network\_id](#output\_google\_compute\_network\_id) | id of network |
| <a name="output_google_compute_network_internal_ipv6_range"></a> [google\_compute\_network\_internal\_ipv6\_range](#output\_google\_compute\_network\_internal\_ipv6\_range) | internal\_ipv6\_range of network |
| <a name="output_google_compute_network_name"></a> [google\_compute\_network\_name](#output\_google\_compute\_network\_name) | Name of network |
<!-- END_TF_DOCS -->
Empty file.
22 changes: 22 additions & 0 deletions gcp/computer_network/examples/simple-subnet/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions gcp/computer_network/examples/simple-subnet/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
provider "google" {}

locals {
name = "quark-labs"
region = "us-east1"
project = "quarks-labs"
auto_create_subnetworks = false
}

module "network" {
source = "../.."
region = local.region
name = local.name
auto_create_subnetworks = local.auto_create_subnetworks
project = local.project

subnetworks = {
subenet1 = {
name = "default-us-east1"
region = "us-east1"
ip_cidr_range = "172.28.0.0/27"
private_ip_google_access = false
nat = {
nat_ip_allocate_option = "MANUAL_ONLY"
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
}
secondary_ip_ranges = {
primary = {
range_name = "primary"
ip_cidr_range = "172.1.16.0/20"
}
secondary = {
range_name = "secondary"
ip_cidr_range = "172.1.32.0/20"
}
}
}
}
}
5 changes: 5 additions & 0 deletions gcp/computer_network/examples/simple-subnet/tf-backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
terraform {
backend "local" {
path = "terraform.tfstate"
}
}
98 changes: 98 additions & 0 deletions gcp/computer_network/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
################################################################################
# NETWORK
################################################################################

resource "google_compute_network" "this" {
name = lower(var.name)
auto_create_subnetworks = var.auto_create_subnetworks
project = var.project
}

################################################################################
# SUBNET
################################################################################

resource "google_compute_subnetwork" "this" {

for_each = var.subnetworks

name = lower(each.value.name)
project = google_compute_network.this.project
network = google_compute_network.this.name
ip_cidr_range = each.value.ip_cidr_range
region = each.value.region
private_ip_google_access = try(each.value.private_ip_google_access, true)

dynamic "secondary_ip_range" {

for_each = each.value.secondary_ip_ranges

content {
range_name = secondary_ip_range.value["range_name"]
ip_cidr_range = secondary_ip_range.value["ip_cidr_range"]
}
}

depends_on = [google_compute_network.this]
}

################################################################################
# ADDRESS
################################################################################

resource "google_compute_address" "this" {
for_each = var.subnetworks

name = format("%s-nat-ip", each.key)
project = google_compute_network.this.project
region = each.value.region
depends_on = [
google_compute_subnetwork.this
]
}


################################################################################
# ROUTER
################################################################################

resource "google_compute_router" "this" {
for_each = var.subnetworks

name = format("%s-cloud-router", google_compute_network.this.name)
project = google_compute_network.this.project
network = google_compute_network.this.name
region = each.value.region

depends_on = [google_compute_network.this]
}


################################################################################
# ROUTER NAT
################################################################################

resource "google_compute_router_nat" "this" {

for_each = var.subnetworks

name = format("%s-cloud-nat", google_compute_network.this.name)
project = google_compute_network.this.project
router = google_compute_router.this[each.key].name
region = each.value.region
nat_ips = toset([for address in google_compute_address.this : address.self_link ])
nat_ip_allocate_option = try(each.value.nat.nat_ip_allocate_option, "MANUAL_ONLY")
source_subnetwork_ip_ranges_to_nat = try(each.value.nat.source_subnetwork_ip_ranges_to_nat, "LIST_OF_SUBNETWORKS")


subnetwork {
name = google_compute_subnetwork.this[each.key].self_link
source_ip_ranges_to_nat = try(each.value.source_ip_ranges_to_nat, ["PRIMARY_IP_RANGE", "LIST_OF_SECONDARY_IP_RANGES"])
secondary_ip_range_names = toset([for range in each.value.secondary_ip_ranges : range.range_name ])
}


depends_on = [
google_compute_network.this
]
}
33 changes: 33 additions & 0 deletions gcp/computer_network/tf-outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
output "google_compute_network_name" {
value = google_compute_network.this.name
description = "Name of network"
}

output "google_compute_network_description" {
value = google_compute_network.this.description
description = "Description of network"
}

output "google_compute_network_id" {
value = google_compute_network.this.id
description = "id of network"
}

output "google_compute_network_internal_ipv6_range" {
value = google_compute_network.this.internal_ipv6_range
description = "internal_ipv6_range of network"
}

output "google_compute_network_gateway_ipv4" {
value = google_compute_network.this.gateway_ipv4
description = "gateway_ipv4 of network"
}

output "google_compute_network_auto_create_subnetworks" {
value = google_compute_network.this.auto_create_subnetworks
description = "auto_create_subnetworks of network"
}




Empty file.
23 changes: 23 additions & 0 deletions gcp/computer_network/tf-variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
variable "region" {
type = string
description = "GCP Region"
}

variable "name" {
type = string
description = "Name of GCP Network"
}
variable "project" {
type = string
description = "Name of GCP Network"
}
variable "subnetworks" {
type = any
description = "List of GCP Subnetworks"
}
variable "auto_create_subnetworks" {
type = bool
description = "If auto_crea_subnetworks is true, subnet is created automality"
}


Loading

0 comments on commit d813b9a

Please sign in to comment.