Skip to content

Commit cd4294c

Browse files
chore: Created example for VM with IP forwarding enabled (#171)
* Created example for VM with IP forwarding enabled * Generated README
1 parent 7a78bdf commit cd4294c

File tree

5 files changed

+137
-0
lines changed

5 files changed

+137
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Instance as next hop for a route
2+
3+
This example creates a VM instance with IP forwarding enabled so that the
4+
VM can forward a packet originated by another VM.
5+
6+
To use a VM as a next hop for a route, the VM needs to receive packets that have
7+
destinations other than itself. Because it forwards those packets, the packet
8+
sources are different from its own internal IP address. To accomplish this, you
9+
must enable IP forwarding for the VM. When IP forwarding is enabled, Google
10+
Cloud does not enforce packet source and destination checking.
11+
12+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
13+
## Inputs
14+
15+
| Name | Description | Type | Default | Required |
16+
|------|-------------|------|---------|:--------:|
17+
| project\_id | The Google Cloud project ID | `string` | n/a | yes |
18+
19+
## Outputs
20+
21+
| Name | Description |
22+
|------|-------------|
23+
| instance\_self\_link | The URI of the instance rule being created |
24+
| network\_name | The name of the VPC network where the VM instance is created |
25+
| project\_id | Google Cloud project ID |
26+
27+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
19+
version = "~> 3.0"
20+
}
21+
22+
# [START compute_vm_as_next_hop_create]
23+
resource "google_compute_instance" "default" {
24+
project = var.project_id # Replace this with your project ID in quotes
25+
zone = "southamerica-east1-b"
26+
name = "instance-next-hop"
27+
machine_type = "e2-medium"
28+
boot_disk {
29+
initialize_params {
30+
image = "debian-cloud/debian-9"
31+
}
32+
}
33+
network_interface {
34+
network = "default"
35+
}
36+
can_ip_forward = true
37+
}
38+
# [END compute_vm_as_next_hop_create]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
18+
output "network_name" {
19+
value = google_compute_instance.default.network_interface[0].network
20+
description = "The name of the VPC network where the VM instance is created"
21+
}
22+
23+
output "instance_self_link" {
24+
value = google_compute_instance.default.self_link
25+
description = "The URI of the instance rule being created"
26+
}
27+
28+
output "project_id" {
29+
value = google_compute_instance.default.project
30+
description = "Google Cloud project ID"
31+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright 2019 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+
18+
19+
variable "project_id" {
20+
description = "The Google Cloud project ID"
21+
type = string
22+
}
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.6"
19+
}

0 commit comments

Comments
 (0)