-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.tf
More file actions
83 lines (68 loc) · 1.92 KB
/
Copy pathmain.tf
File metadata and controls
83 lines (68 loc) · 1.92 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
provider "google" {
project = var.project_id
region = var.region
zone = var.zone
}
resource "google_compute_network" "vpc" {
name = "demo-vpc"
auto_create_subnetworks = false
}
resource "google_compute_subnetwork" "subnet" {
name = "demo-subnet"
ip_cidr_range = var.subnet_cidr
network = google_compute_network.vpc.self_link
}
resource "google_compute_firewall" "firewall" {
name = "demo-firewall"
network = google_compute_network.vpc.name
allow {
protocol = "icmp"
}
allow {
protocol = "tcp"
ports = ["22", "80", "443", "8080"]
}
source_ranges = ["0.0.0.0/0"]
}
resource "google_compute_address" "static_ip" {
count = var.instance_count
name = "demo-ip-${count.index}"
}
resource "google_compute_instance" "vm_instance" {
count = var.instance_count
name = "${var.instance_name_prefix}-${count.index}"
machine_type = var.machine_type
boot_disk {
initialize_params {
image = var.image
}
}
network_interface {
subnetwork = google_compute_subnetwork.subnet.self_link
access_config {
nat_ip = google_compute_address.static_ip[count.index].address
}
}
metadata_startup_script = <<-EOF
sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker $USER
sudo apt-get install docker-compose -y
sudo docker run -d -p 80:80 nginx
EOF
}
resource "google_storage_bucket" "bucket" {
name = "demo12-bucket23"
location = var.region
project = var.project_id
lifecycle_rule {
action {
type = "Delete"
}
condition {
age = 365
}
}
}