Skip to content

Commit 613764f

Browse files
authored
Merge pull request #1 from umairidris/impl
Initial implementation
2 parents 2380723 + 131ac9e commit 613764f

File tree

17 files changed

+516
-65
lines changed

17 files changed

+516
-65
lines changed

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# terraform-google-cloud-router
22

3-
This module was generated from [terraform-google-module-template](https://github.com/terraform-google-modules/terraform-google-module-template/), which by default generates a module that simply creates a GCS bucket. As the module develops, this README should be updated.
4-
5-
The resources/services/activations/deletions that this module will create/trigger are:
6-
7-
- Create a GCS bucket with the provided name
3+
This module handles opinionated Google Cloud Platform routing.
84

95
## Usage
106

@@ -15,8 +11,10 @@ module "cloud_router" {
1511
source = "terraform-google-modules/cloud-router/google"
1612
version = "~> 0.1"
1713
18-
project_id = "<PROJECT ID>"
19-
bucket_name = "gcs-test-bucket"
14+
name = "example-router"
15+
project = "<PROJECT ID>"
16+
region = "us-central1"
17+
network = "default"
2018
}
2119
```
2220

@@ -28,14 +26,18 @@ Functional examples are included in the
2826

2927
| Name | Description | Type | Default | Required |
3028
|------|-------------|:----:|:-----:|:-----:|
31-
| bucket\_name | The name of the bucket to create | string | n/a | yes |
32-
| project\_id | The project ID to deploy to | string | n/a | yes |
29+
| bgp | BGP information specific to this router. | any | `"null"` | no |
30+
| name | Name of the router | string | n/a | yes |
31+
| nats | NATs to deploy on this router. | any | `<list>` | no |
32+
| network | A reference to the network to which this router belongs | string | n/a | yes |
33+
| project | The project ID to deploy to | string | n/a | yes |
34+
| region | Region where the router resides | string | n/a | yes |
3335

3436
## Outputs
3537

3638
| Name | Description |
3739
|------|-------------|
38-
| bucket\_name | |
40+
| router | The created router |
3941

4042
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
4143

@@ -55,7 +57,7 @@ The following dependencies must be available:
5557
A service account with the following roles must be used to provision
5658
the resources of this module:
5759

58-
- Storage Admin: `roles/storage.admin`
60+
- Network Admin: `roles/compute.networkAdmin`
5961

6062
The [Project Factory module][project-factory-module] and the
6163
[IAM module][iam-module] may be used in combination to provision a
@@ -66,7 +68,7 @@ service account with the necessary roles applied.
6668
A project with the following APIs enabled must be used to host the
6769
resources of this module:
6870

69-
- Google Cloud Storage JSON API: `storage-api.googleapis.com`
71+
- Google Cloud Compute Engine API: `compute.googleapis.com`
7072

7173
The [Project Factory module][project-factory-module] can be used to
7274
provision a project with the necessary APIs enabled.
@@ -76,7 +78,6 @@ provision a project with the necessary APIs enabled.
7678
Refer to the [contribution guidelines](./CONTRIBUTING.md) for
7779
information on contributing to this module.
7880

79-
[iam-module]: https://registry.terraform.io/modules/terraform-google-modules/iam/google
8081
[project-factory-module]: https://registry.terraform.io/modules/terraform-google-modules/project-factory/google
8182
[terraform-provider-gcp]: https://www.terraform.io/docs/providers/google/index.html
8283
[terraform]: https://www.terraform.io/downloads.html
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
provider "google" {
18+
version = "~> 3.0"
19+
}
20+
21+
module "cloud_router" {
22+
source = "../../"
23+
24+
name = "example-router"
25+
project = "example-project"
26+
network = "default"
27+
region = "us-central1"
28+
29+
bgp = {
30+
asn = 65000
31+
advertised_groups = ["ALL_SUBNETS"]
32+
}
33+
}
34+
35+
module "interconnect_attachment" {
36+
source = "../../modules/interconnect_attachment"
37+
name = "example-attachment"
38+
project = "example-project"
39+
region = "us-central1"
40+
router = module.cloud_router.router.name
41+
42+
interconnect = "https://googleapis.com/interconnects/example-interconnect"
43+
44+
interface = {
45+
name = "example-interface"
46+
}
47+
48+
peer = {
49+
name = "example-peer"
50+
peer_ip_address = "169.254.1.2"
51+
peer_asn = 65001
52+
advertised_groups = ["ALL_SUBNETS"]
53+
}
54+
}
File renamed without changes.

examples/nat/main.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
provider "google" {
18+
version = "~> 3.0"
19+
}
20+
21+
module "cloud_router" {
22+
source = "../../"
23+
24+
name = "example-router"
25+
project = "example-project"
26+
network = "default"
27+
region = "us-central1"
28+
29+
nats = [{
30+
name = "example-nat"
31+
}]
32+
}

examples/simple_example/variables.tf renamed to examples/nat/versions.tf

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
variable "project_id" {
18-
description = "The ID of the project in which to provision resources."
19-
type = string
20-
}
21-
22-
variable "bucket_name" {
23-
description = "The name of the bucket to create."
24-
type = string
17+
terraform {
18+
required_version = ">= 0.12"
2519
}

examples/simple_example/main.tf renamed to examples/simple/main.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
*/
1616

1717
provider "google" {
18-
version = "~> 2.0"
18+
version = "~> 3.0"
1919
}
2020

2121
module "cloud_router" {
22-
source = "../.."
22+
source = "../../"
2323

24-
project_id = var.project_id
25-
bucket_name = var.bucket_name
24+
name = "example-router"
25+
project = "example-project"
26+
network = "default"
27+
region = "us-central1"
2628
}

examples/simple/versions.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
terraform {
18+
required_version = ">= 0.12"
19+
}

examples/simple_example/README.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

main.tf

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018 Google LLC
2+
* Copyright 2020 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,7 +14,30 @@
1414
* limitations under the License.
1515
*/
1616

17-
resource "google_storage_bucket" "main" {
18-
project = var.project_id
19-
name = var.bucket_name
17+
resource "google_compute_router" "router" {
18+
name = var.name
19+
network = var.network
20+
region = var.region
21+
project = var.project
22+
dynamic "bgp" {
23+
for_each = var.bgp != null ? [var.bgp] : []
24+
content {
25+
asn = var.bgp.asn
26+
27+
# advertise_mode is intentionally set to CUSTOM to not allow "DEFAULT".
28+
# This forces the config to explicitly state what subnets and ip ranges
29+
# to advertise. To advertise the same range as DEFAULT, set
30+
# `advertise_groups = ["ALL_SUBNETS"]`.
31+
advertise_mode = "CUSTOM"
32+
advertised_groups = lookup(var.bgp, "advertised_groups", null)
33+
34+
dynamic "advertised_ip_ranges" {
35+
for_each = lookup(var.bgp, "advertised_ip_ranges", [])
36+
content {
37+
range = advertised_ip_ranges.value.range
38+
description = lookup(advertised_ip_ranges.value, "description", null)
39+
}
40+
}
41+
}
42+
}
2043
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
resource "google_compute_interconnect_attachment" "attachment" {
18+
name = var.name
19+
router = var.router
20+
project = var.project
21+
region = var.region
22+
interconnect = var.interconnect
23+
admin_enabled = var.admin_enabled
24+
type = var.type
25+
description = var.description
26+
bandwidth = var.bandwidth
27+
vlan_tag8021q = var.vlan_tag8021q
28+
}
29+
30+
module "interface" {
31+
source = "../interface"
32+
name = var.interface.name
33+
project = var.project
34+
router = var.router
35+
region = var.region
36+
ip_range = google_compute_interconnect_attachment.attachment.cloud_router_ip_address
37+
interconnect_attachment = google_compute_interconnect_attachment.attachment.self_link
38+
peers = [{
39+
name = var.peer.name
40+
peer_ip_address = var.peer.peer_ip_address
41+
peer_asn = var.peer.peer_asn
42+
advertised_route_priority = lookup(var.peer, "advertised_route_priority", null)
43+
advertised_groups = var.peer.advertised_groups
44+
}]
45+
}

0 commit comments

Comments
 (0)