-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.tf
69 lines (55 loc) · 1.29 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
## terraform & providers
terraform {
required_version = ">= 1.5.7"
backend "local" {
path = "terraform.tfstate"
}
required_providers {
google = {
source = "hashicorp/google"
version = "~> 5.0"
}
}
}
provider "google" {
# Configuration options
project = var.project_id
region = var.region
}
## variaveis locais
locals {
prefix = var.prefix
}
## referenciar um recurso já existente
## ref: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/google_project
data "google_project" "this" {
project_id = var.project_id
}
## Recursos locais
resource "random_pet" "this" {
length = 2
prefix = local.prefix
separator = "-"
}
#### Instância de VM e respetiva subnet
# referenciar a subnet já existente
data "google_compute_subnetwork" "default" {
name = "subnetwork-default"
region = var.region
}
# criar uma VM
resource "google_compute_instance" "default" {
name = "${random_pet.this.id}-vm"
machine_type = "g1-small"
zone = "${var.region}-b"
## 2.1 - Descomentar apenas quando for pedido
#tags = [ "allow-iap" ]
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
}
}
network_interface {
subnetwork = data.google_compute_subnetwork.default.self_link
}
}