Skip to content

Commit

Permalink
Merge pull request #101 from averbuks/averbuks-network-peering
Browse files Browse the repository at this point in the history
network-peering submodule
  • Loading branch information
averbuks authored Nov 12, 2019
2 parents 53c0b7c + 966aec7 commit 8368373
Show file tree
Hide file tree
Showing 21 changed files with 575 additions and 2 deletions.
13 changes: 13 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,16 @@ suites:
backend: local
controls:
- gcloud
- name: "submodule_network_peering"
driver:
name: "terraform"
command_timeout: 1800
root_module_directory: test/fixtures/submodule_network_peering/
verifier:
name: terraform
color: true
systems:
- name: local
backend: local
controls:
- gcloud
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning][semver-site].

## [Unreleased]

## [1.5.0] - 2019-11-06

### Added

- Added submodule `network-peering` [#101]

## [1.4.3] - 2019-10-31

### Fixed
Expand Down Expand Up @@ -146,7 +152,8 @@ and this project adheres to [Semantic Versioning][semver-site].
- Subnets within the VPC
- Secondary ranges for the subnets (if applicable)

[Unreleased]: https://github.com/terraform-google-modules/terraform-google-network/compare/v1.4.3...HEAD
[Unreleased]: https://github.com/terraform-google-modules/terraform-google-network/compare/v1.5.0...HEAD
[1.5.0]: https://github.com/terraform-google-modules/terraform-google-network/compare/v1.4.3...v1.5.0
[1.4.3]: https://github.com/terraform-google-modules/terraform-google-network/compare/v1.4.2...v1.4.3
[1.4.2]: https://github.com/terraform-google-modules/terraform-google-network/compare/v1.4.1...v1.4.2
[1.4.1]: https://github.com/terraform-google-modules/terraform-google-network/compare/v1.4.0...v1.4.1
Expand All @@ -164,6 +171,7 @@ and this project adheres to [Semantic Versioning][semver-site].
[0.2.0]: https://github.com/terraform-google-modules/terraform-google-network/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/terraform-google-modules/terraform-google-network/releases/tag/v0.1.0

[#101]: https://github.com/terraform-google-modules/terraform-google-network/pull/101
[#95]: https://github.com/terraform-google-modules/terraform-google-network/issues/95
[#94]: https://github.com/terraform-google-modules/terraform-google-network/pull/94
[#92]: https://github.com/terraform-google-modules/terraform-google-network/issues/92
Expand Down
2 changes: 2 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
/modules/fabric-net-svpc-access/ @terraform-google-modules/cft-fabric
/modules/fabric-net-firewall/ @terraform-google-modules/cft-fabric
/examples/submodule_firewall/ @terraform-google-modules/cft-fabric
/modules/network-peering/ @terraform-google-modules/cft-fabric
/examples/submodule_network_peering/ @terraform-google-modules/cft-fabric
1 change: 1 addition & 0 deletions examples/submodule_network_peering/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.tfvars
19 changes: 19 additions & 0 deletions examples/submodule_network_peering/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Simple VPC Network Peering

This example creates a VPC Network peering between two VPCs.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| project\_id | The project ID to put the resources in | string | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| peering1 | Peering1 module output. |
| peering2 | Peering2 module output. |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
54 changes: 54 additions & 0 deletions examples/submodule_network_peering/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module "local-network" {
source = "../../"
project_id = var.project_id
network_name = "local-network"
subnets = []
}

module "peer-network-1" {
source = "../../"
project_id = var.project_id
network_name = "peer-network-1"
subnets = []
}

module "peer-network-2" {
source = "../../"
project_id = var.project_id
network_name = "peer-network-2"
subnets = []
}

module "peering-1" {
source = "../../modules/network-peering"

local_network = module.local-network.network_self_link
peer_network = module.peer-network-1.network_self_link
export_local_custom_routes = true
}

module "peering-2" {
source = "../../modules/network-peering"

local_network = module.local-network.network_self_link
peer_network = module.peer-network-2.network_self_link
export_local_custom_routes = true

module_depends_on = [module.peering-1.complete]
}
25 changes: 25 additions & 0 deletions examples/submodule_network_peering/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

output "peering1" {
description = "Peering1 module output."
value = module.peering-1
}

output "peering2" {
description = "Peering2 module output."
value = module.peering-2
}
20 changes: 20 additions & 0 deletions examples/submodule_network_peering/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

variable "project_id" {
description = "The project ID to put the resources in"
type = string
}
19 changes: 19 additions & 0 deletions examples/submodule_network_peering/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

terraform {
required_version = "~> 0.12.0"
}
66 changes: 66 additions & 0 deletions modules/network-peering/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Google Network Peering

This module allows creation of a [VPC Network Peering](https://cloud.google.com/vpc/docs/vpc-peering) between two networks.

The resources created/managed by this module are:

- one network peering from `local network` to `peer network`
- one network peering from `peer network` to `local network`

## Usage

Basic usage of this module is as follows:

```hcl
module "peering" {
source = "terraform-google-modules/terraform-google-network/google//modules/network-peering"
prefix = "name-prefix"
local_network = "<FIRST NETWORK SELF LINK>"
peer_network = "<SECOND NETWORK SELF LINK>"
}
```

If you need to create more than one peering for the same VPC Network `(A -> B, A -> C)` you have to use output from the first module as a dependency for the second one to keep order of peering creation (It is not currently possible to create more than one peering connection for a VPC Network at the same time).

```hcl
module "peering-a-b" {
source = "terraform-google-modules/terraform-google-network/google//modules/network-peering"
prefix = "name-prefix"
local_network = "<A NETWORK SELF LINK>"
peer_network = "<B NETWORK SELF LINK>"
}
module "peering-a-c" {
source = "terraform-google-modules/terraform-google-network/google//modules/network-peering"
prefix = "name-prefix"
local_network = "<A NETWORK SELF LINK>"
peer_network = "<C NETWORK SELF LINK>"
module_depends_on = module.peering-a-b.complete
}
```

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| export\_local\_custom\_routes | Export custom routes to peer network from local network. | bool | `"false"` | no |
| export\_peer\_custom\_routes | Export custom routes to local network from peer network. | bool | `"false"` | no |
| local\_network | Resource link of the network to add a peering to. | string | n/a | yes |
| module\_depends\_on | List of modules or resources this module depends on. | list | `<list>` | no |
| peer\_network | Resource link of the peer network. | string | n/a | yes |
| prefix | Name prefix for the network peerings | string | `"network-peering"` | no |

## Outputs

| Name | Description |
|------|-------------|
| complete | Output to be used as a module dependency. |
| local\_network\_peering | Network peering resource. |
| peer\_network\_peering | Peer network peering resource. |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
52 changes: 52 additions & 0 deletions modules/network-peering/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

locals {
local_network_name = element(reverse(split("/", var.local_network)), 0)
peer_network_name = element(reverse(split("/", var.peer_network)), 0)
}

resource "google_compute_network_peering" "local_network_peering" {
provider = "google-beta"
name = "${var.prefix}-${local.local_network_name}-${local.peer_network_name}"
network = var.local_network
peer_network = var.peer_network
export_custom_routes = var.export_local_custom_routes
import_custom_routes = var.export_peer_custom_routes

depends_on = ["null_resource.module_depends_on"]
}

resource "google_compute_network_peering" "peer_network_peering" {
provider = "google-beta"
name = "${var.prefix}-${local.peer_network_name}-${local.local_network_name}"
network = var.peer_network
peer_network = var.local_network
export_custom_routes = var.export_peer_custom_routes
import_custom_routes = var.export_local_custom_routes

depends_on = ["null_resource.module_depends_on", "google_compute_network_peering.local_network_peering"]
}

resource "null_resource" "module_depends_on" {
triggers = {
value = length(var.module_depends_on)
}
}

resource "null_resource" "complete" {
depends_on = ["google_compute_network_peering.local_network_peering", "google_compute_network_peering.peer_network_peering"]
}
30 changes: 30 additions & 0 deletions modules/network-peering/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

output "local_network_peering" {
description = "Network peering resource."
value = google_compute_network_peering.local_network_peering
}

output "peer_network_peering" {
description = "Peer network peering resource."
value = google_compute_network_peering.peer_network_peering
}

output "complete" {
description = "Output to be used as a module dependency."
value = null_resource.complete.id
}
19 changes: 19 additions & 0 deletions modules/network-peering/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

provider "google-beta" {
version = "~> 2.8"
}
Loading

0 comments on commit 8368373

Please sign in to comment.