Skip to content

Commit

Permalink
chore: Created example for VM with IP forwarding enabled (#171)
Browse files Browse the repository at this point in the history
* Created example for VM with IP forwarding enabled

* Generated README
  • Loading branch information
betsy-lichtenberg authored Apr 28, 2021
1 parent 7a78bdf commit cd4294c
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 0 deletions.
27 changes: 27 additions & 0 deletions examples/compute_instance/next_hop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Instance as next hop for a route

This example creates a VM instance with IP forwarding enabled so that the
VM can forward a packet originated by another VM.

To use a VM as a next hop for a route, the VM needs to receive packets that have
destinations other than itself. Because it forwards those packets, the packet
sources are different from its own internal IP address. To accomplish this, you
must enable IP forwarding for the VM. When IP forwarding is enabled, Google
Cloud does not enforce packet source and destination checking.

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

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| project\_id | The Google Cloud project ID | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| instance\_self\_link | The URI of the instance rule being created |
| network\_name | The name of the VPC network where the VM instance is created |
| project\_id | Google Cloud project ID |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
38 changes: 38 additions & 0 deletions examples/compute_instance/next_hop/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright 2018 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" {

version = "~> 3.0"
}

# [START compute_vm_as_next_hop_create]
resource "google_compute_instance" "default" {
project = var.project_id # Replace this with your project ID in quotes
zone = "southamerica-east1-b"
name = "instance-next-hop"
machine_type = "e2-medium"
boot_disk {
initialize_params {
image = "debian-cloud/debian-9"
}
}
network_interface {
network = "default"
}
can_ip_forward = true
}
# [END compute_vm_as_next_hop_create]
31 changes: 31 additions & 0 deletions examples/compute_instance/next_hop/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright 2018 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 "network_name" {
value = google_compute_instance.default.network_interface[0].network
description = "The name of the VPC network where the VM instance is created"
}

output "instance_self_link" {
value = google_compute_instance.default.self_link
description = "The URI of the instance rule being created"
}

output "project_id" {
value = google_compute_instance.default.project
description = "Google Cloud project ID"
}
22 changes: 22 additions & 0 deletions examples/compute_instance/next_hop/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* 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 Google Cloud project ID"
type = string
}
19 changes: 19 additions & 0 deletions examples/compute_instance/next_hop/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright 2018 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.6"
}

0 comments on commit cd4294c

Please sign in to comment.