Skip to content

Commit 85bfb4a

Browse files
chore: Added example for creating a VM with multiple interfaces (#175)
* Added example for creating a VM with multiple interfaces * Deleted white space * fixed region tag
1 parent d82fde9 commit 85bfb4a

File tree

5 files changed

+157
-0
lines changed

5 files changed

+157
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Instance with multiple interfaces
2+
3+
This example creates a VM instance with multiple network interfaces.
4+
The subnets must be in the same region as the VM.
5+
6+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
7+
## Inputs
8+
9+
| Name | Description | Type | Default | Required |
10+
|------|-------------|------|---------|:--------:|
11+
| project\_id | The Google Cloud project ID | `string` | n/a | yes |
12+
| subnet\_1 | Self link to a subnetwork in the same region as the VM. | `string` | n/a | yes |
13+
| subnet\_2 | Self link to a subnetwork in the same region as the VM. | `string` | n/a | yes |
14+
15+
## Outputs
16+
17+
| Name | Description |
18+
|------|-------------|
19+
| instance\_self\_link | The URI of the instance rule being created |
20+
| network\_name\_1 | The name of the VPC network where the VM's first network interface is created |
21+
| network\_name\_2 | The name of the VPC network where the VM's second network interface is created |
22+
| project\_id | Google Cloud project ID |
23+
24+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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_providers {
19+
google = {
20+
version = ">= 3.45.0"
21+
}
22+
null = {
23+
version = ">= 2.1.0"
24+
}
25+
}
26+
}
27+
28+
# [START compute_vm_with_multiple_interface]
29+
resource "google_compute_instance" "default" {
30+
project = var.project_id # Replace with your project ID in quotes
31+
zone = "us-central1-b"
32+
name = "backend-instance"
33+
machine_type = "e2-medium"
34+
boot_disk {
35+
initialize_params {
36+
image = "debian-cloud/debian-9"
37+
}
38+
}
39+
network_interface {
40+
subnetwork = var.subnet_1 # Replace with self link to a subnetwork in quotes
41+
network_ip = "10.0.0.14"
42+
}
43+
network_interface {
44+
subnetwork = var.subnet_2 # Replace with self link to a subnetwork in quotes
45+
network_ip = "10.10.20.14"
46+
}
47+
}
48+
# [END compute_vm_with_multiple_interface]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 "project_id" {
19+
value = google_compute_instance.default.project
20+
description = "Google Cloud project ID"
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 "network_name_1" {
29+
value = google_compute_instance.default.network_interface[0].network
30+
description = "The name of the VPC network where the VM's first network interface is created"
31+
}
32+
33+
output "network_name_2" {
34+
value = google_compute_instance.default.network_interface[1].network
35+
description = "The name of the VPC network where the VM's second network interface is created"
36+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
variable "project_id" {
18+
description = "The Google Cloud project ID"
19+
type = string
20+
}
21+
22+
variable "subnet_1" {
23+
description = "Self link to a subnetwork in the same region as the VM."
24+
type = string
25+
}
26+
27+
variable "subnet_2" {
28+
description = "Self link to a subnetwork in the same region as the VM."
29+
type = string
30+
}
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)