Skip to content

Commit 7a42ddd

Browse files
Add open tofu configuration base
1 parent 72c0575 commit 7a42ddd

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

infrastructure/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.terraform
2+
*.tfstate*
3+
*.tfvars

infrastructure/.terraform.lock.hcl

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infrastructure/main.tf

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
terraform {
2+
required_providers {
3+
google = {
4+
source = "hashicorp/google"
5+
version = "~> 4.0"
6+
}
7+
}
8+
}
9+
10+
# GCP provider configuration
11+
provider "google" {
12+
credentials = file(var.gcp_service_key_path)
13+
project = var.project_id
14+
zone = var.zone
15+
}
16+
17+
# Variables
18+
variable "project_id" {
19+
description = "GCP Project ID"
20+
type = string
21+
}
22+
23+
variable "zone" {
24+
description = "GCP Zone"
25+
type = string
26+
default = "europe-west4-a"
27+
}
28+
29+
variable "gcp_service_key_path" {
30+
description = "Path to the GCP credentials JSON file"
31+
type = string
32+
}
33+
34+
variable "ssh_user" {
35+
description = "SSH username"
36+
type = string
37+
default = ""
38+
}
39+
40+
variable "ssh_key_path" {
41+
description = "Path to SSH public key file"
42+
type = string
43+
default = ""
44+
}
45+
46+
variable "instance_name" {
47+
description = "Name of the instance"
48+
type = string
49+
default = "benchmark-instance"
50+
}
51+
52+
# Test Instance
53+
resource "google_compute_instance" "c4_instance" {
54+
name = var.instance_name
55+
machine_type = "c4-standard-2"
56+
zone = var.zone
57+
58+
boot_disk {
59+
initialize_params {
60+
image = "debian-cloud/debian-11"
61+
size = 50 # Size in GB
62+
}
63+
}
64+
65+
network_interface {
66+
network = "default"
67+
access_config {
68+
// Ephemeral public IP
69+
}
70+
}
71+
72+
# Only set SSH keys if variables are provided
73+
metadata = {
74+
ssh-keys = var.ssh_user != "" && var.ssh_key_path != "" ? "${var.ssh_user}:${file(var.ssh_key_path)}" : null
75+
}
76+
77+
service_account {
78+
scopes = ["cloud-platform"]
79+
}
80+
81+
}
82+
83+
# Outputs
84+
output "instance_ip" {
85+
value = google_compute_instance.c4_instance.network_interface[0].access_config[0].nat_ip
86+
}
87+
output "instance_id" {
88+
value = google_compute_instance.c4_instance.id
89+
}

0 commit comments

Comments
 (0)