Skip to content

Commit 7a78bdf

Browse files
chore: Added example that creates a VM with tags (#172)
1 parent 5ca905b commit 7a78bdf

File tree

5 files changed

+138
-0
lines changed

5 files changed

+138
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Instance with tags
2+
3+
This example creates a VM instance with network tags.
4+
Tags enable you to make firewall rules and routes applicable to
5+
specific VM instances.
6+
7+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
8+
## Inputs
9+
10+
| Name | Description | Type | Default | Required |
11+
|------|-------------|------|---------|:--------:|
12+
| project\_id | The Google Cloud project ID | `string` | n/a | yes |
13+
14+
## Outputs
15+
16+
| Name | Description |
17+
|------|-------------|
18+
| instance\_self\_link | The URI of the instance rule being created |
19+
| network\_name | The name of the VPC network where the VM instance is created |
20+
| project\_id | Google Cloud project ID |
21+
| tags | Tags added to VM instance |
22+
23+
<!-- 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_with_tags_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 = "backend-instance"
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+
tags = ["health-check", "ssh"]
37+
}
38+
# [END compute_vm_with_tags_create]
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 "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 "tags" {
29+
value = google_compute_instance.default.tags
30+
description = "Tags added to VM instance"
31+
}
32+
33+
output "project_id" {
34+
value = google_compute_instance.default.project
35+
description = "Google Cloud project ID"
36+
}
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)