|
| 1 | +terraform { |
| 2 | + required_providers { |
| 3 | + google = { |
| 4 | + source = "hashicorp/google" |
| 5 | + version = "6.8.0" |
| 6 | + } |
| 7 | + } |
| 8 | +} |
| 9 | + |
| 10 | +provider "google" { |
| 11 | + #credentials = file(var.credentials_file) |
| 12 | + project = var.project |
| 13 | + region = var.region |
| 14 | +} |
| 15 | + |
| 16 | + |
| 17 | +resource "google_compute_network" "qdb-vpc" { |
| 18 | + name = "qdb-vpc" |
| 19 | + routing_mode = "REGIONAL" |
| 20 | + auto_create_subnetworks = false |
| 21 | + network_firewall_policy_enforcement_order = "AFTER_CLASSIC_FIREWALL" |
| 22 | +} |
| 23 | + |
| 24 | +resource "google_compute_subnetwork" "qdb-subnet-with-logging" { |
| 25 | + name = "qdb-subnet-with-logging" |
| 26 | + ip_cidr_range = "10.2.0.0/16" |
| 27 | + region = var.region |
| 28 | + network = google_compute_network.qdb-vpc.id |
| 29 | + stack_type = "IPV4_ONLY" |
| 30 | + |
| 31 | + log_config { |
| 32 | + aggregation_interval = "INTERVAL_10_MIN" |
| 33 | + flow_sampling = 0.5 |
| 34 | + metadata = "INCLUDE_ALL_METADATA" |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +resource "google_compute_route" "qdb-public-route" { |
| 39 | + name = "qdb-public-route" |
| 40 | + network = google_compute_network.qdb-vpc.id |
| 41 | + dest_range = "0.0.0.0/0" # Destination IP range |
| 42 | + priority = 1000 |
| 43 | + next_hop_gateway = "default-internet-gateway" # Specify the next hop |
| 44 | +} |
| 45 | + |
| 46 | + |
| 47 | +resource "google_compute_firewall" "qdb-firewall" { |
| 48 | + name = "qdb-firewall" |
| 49 | + description = "Creates firewall rule targeting tagged instances" |
| 50 | + network = google_compute_network.qdb-vpc.id |
| 51 | + |
| 52 | + allow { |
| 53 | + protocol = "all" |
| 54 | + } |
| 55 | + |
| 56 | + source_ranges = [var.my_ip] |
| 57 | + |
| 58 | + target_tags = ["qdb"] |
| 59 | +} |
| 60 | + |
| 61 | + |
| 62 | +resource "google_compute_instance" "qdb-ubuntu" { |
| 63 | + name = "qdb-ubuntu" |
| 64 | + machine_type = "n2d-standard-2" |
| 65 | + zone = "australia-southeast1-a" |
| 66 | + |
| 67 | + tags = ["qdb"] |
| 68 | + |
| 69 | + boot_disk { |
| 70 | + initialize_params { |
| 71 | + image = "ubuntu-2410-oracular-amd64-v20241021" |
| 72 | + size = 10 |
| 73 | + type = "pd-balanced" |
| 74 | + } |
| 75 | + auto_delete = true |
| 76 | + } |
| 77 | + |
| 78 | + attached_disk { |
| 79 | + source = google_compute_disk.persistent-data.id |
| 80 | + device_name = google_compute_disk.persistent-data.name |
| 81 | + } |
| 82 | + |
| 83 | + |
| 84 | + network_interface { |
| 85 | + network = google_compute_network.qdb-vpc.id |
| 86 | + subnetwork = google_compute_subnetwork.qdb-subnet-with-logging.id |
| 87 | + access_config { |
| 88 | + network_tier = "STANDARD" |
| 89 | + } |
| 90 | + |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +output "public-ipv4" { |
| 95 | + value = google_compute_instance.qdb-ubuntu.network_interface.0.access_config.0.nat_ip |
| 96 | +} |
| 97 | + |
| 98 | + |
| 99 | +resource "google_compute_disk" "persistent-data" { |
| 100 | + name = "persistent-data" |
| 101 | + type = "pd-balanced" |
| 102 | + zone = "australia-southeast1-a" |
| 103 | + size = "20" |
| 104 | +} |
| 105 | + |
0 commit comments