-
Notifications
You must be signed in to change notification settings - Fork 0
/
terraform.tf
68 lines (58 loc) · 1.31 KB
/
terraform.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
variable "ssh_public_key_file_path" {}
variable "gcp_project_id" {}
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 4.0"
}
}
}
provider "google" {
project = var.gcp_project_id
region = "europe-west1"
zone = "europe-west1-b"
}
resource "google_compute_firewall" "web-traffic" {
name = "web-traffic"
target_tags = ["web"]
network = "default"
source_ranges = ["0.0.0.0/0"]
allow {
protocol = "tcp"
ports = ["80", "443"]
}
}
resource "google_redis_instance" "redis-cache" {
name = "redis-cache"
memory_size_gb = 1
#lifecycle {
# prevent_destroy = true
#}
}
resource "google_compute_instance" "webserver-1" {
name = "webserver-1"
machine_type = "e2-micro"
metadata = {
ssh-keys = "user:${file(var.ssh_public_key_file_path)}"
}
tags = ["web"]
boot_disk {
initialize_params {
image = "debian-cloud/debian-12"
}
}
network_interface {
network = "default"
access_config {}
}
}
resource "local_file" "ansible-node-inventory" {
filename = "./ansible-node-inventory"
content = <<-EOF
[webservers]
${google_compute_instance.webserver-1.network_interface.0.access_config.0.nat_ip}
[redis_cache]
${google_redis_instance.redis-cache.host}
EOF
}