-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
52 lines (43 loc) · 1.13 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
# Define Terraform provider
terraform {
required_version = "~> 1.2.5"
required_providers {
google = {
source = "hashicorp/google"
version = "4.31.0" # pinning version
}
}
}
provider "google" {
credentials = file(var.credentials_file)
project = var.project_name
zone = var.zone_free_south_carolina
}
# Create a single Compute Engine instance
resource "google_compute_instance" "default" {
name = var.instance_name
machine_type = var.machine_type_free
zone = var.zone_free_south_carolina
metadata = {
ssh-keys = join("\n", [for acc in var.ssh_keys : "${acc.user}:${acc.key}"])
}
boot_disk {
auto_delete = true
initialize_params {
image = var.ubuntu_min_2204
size = var.disk_size_free
type = var.disk_type_free
}
}
# Install Swap Space
metadata_startup_script = file("swapfile.sh")
network_interface {
network = "default"
access_config {
# Include this section to give the VM an external IP address
}
}
}
output "external_ip" {
value = google_compute_instance.default.network_interface.0.access_config.0.nat_ip
}