-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from averbuks/averbuks-network-peering
network-peering submodule
- Loading branch information
Showing
21 changed files
with
575 additions
and
2 deletions.
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
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
Validating CODEOWNERS rules …
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
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 @@ | ||
.tfvars |
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,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 --> |
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,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] | ||
} |
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,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 | ||
} |
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,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 | ||
} |
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,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" | ||
} |
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,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 --> |
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,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"] | ||
} |
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,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 | ||
} |
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,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" | ||
} |
Oops, something went wrong.