-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
654f16a
commit 78338b1
Showing
6 changed files
with
125 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# GCP VM Terraform Template | ||
|
||
This repository contains a Terraform template to create 3 Virtual Machines (VMs) on Google Cloud Platform (GCP). | ||
|
||
## Features 🌟 | ||
|
||
- **Creates 3 VMs** - Dynamically assigns names, disk sizes, and machine types to each VM. | ||
- **Ubuntu OS** - Uses Ubuntu 20.04 Focal OS image for the VMs. | ||
- **Auto Disk Delete** - Disks are automatically deleted when the VM is deleted. | ||
- **SSH Keys** - Connect to the VMs via SSH keys. | ||
|
||
## Usage 📘 | ||
|
||
Follow these steps to use this template in your project: | ||
|
||
**Initialize Terraform:** | ||
|
||
```bash | ||
terraform init | ||
``` | ||
**Review the Terraform plan:** | ||
|
||
```bash | ||
terraform plan | ||
``` | ||
Apply the Terraform configuration to create the resources: | ||
|
||
```bash | ||
terraform apply | ||
``` | ||
|
||
Destroy | ||
|
||
```bash | ||
terraform destroy | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
provider "google" { | ||
project = var.project | ||
region = var.region | ||
} | ||
|
||
resource "google_compute_instance" "custom-vm" { | ||
count = 3 | ||
name = var.vm_names[count.index] | ||
|
||
machine_type = var.machine_types[count.index] | ||
|
||
boot_disk { | ||
auto_delete = true | ||
initialize_params { | ||
image = var.os_image | ||
size = var.disk_size[count.index] | ||
type = "pd-balanced" | ||
} | ||
} | ||
|
||
network_interface { | ||
access_config { | ||
network_tier = "PREMIUM" | ||
} | ||
|
||
subnetwork = var.subnetwork | ||
} | ||
|
||
metadata = { | ||
ssh-keys = var.ssh_keys | ||
} | ||
|
||
zone = var.zone | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
project = "labaratoriya" | ||
region = "us-central1" | ||
vm_names = ["config-server1", "config-server2", "config-server3"] | ||
machine_types = ["e2-medium", "e2-medium", "e2-medium"] | ||
disk_size = [50, 50, 50] | ||
zone = "us-central1-a" | ||
subnetwork = "projects/labaratoriya/regions/us-central1/subnetworks/default" | ||
ssh_keys = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOsX4I3rwJr+/NL3aPA7rIS/4/XtlnJRIpn/0C9T3os0 ismoilovdev@vivobook" | ||
os_image = "projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20240830" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
variable "project" { | ||
type = string | ||
default = "labaratoriya" | ||
} | ||
|
||
variable "region" { | ||
type = string | ||
default = "us-central1" | ||
} | ||
|
||
variable "vm_names" { | ||
type = list(string) | ||
default = ["config-server1", "config-server2", "config-server3"] | ||
} | ||
|
||
variable "machine_types" { | ||
type = list(string) | ||
default = ["e2-medium", "e2-medium", "e2-medium"] | ||
} | ||
|
||
variable "disk_size" { | ||
type = list(number) | ||
default = [50, 50, 50] | ||
} | ||
|
||
variable "zone" { | ||
type = string | ||
default = "us-central1-a" | ||
} | ||
|
||
variable "subnetwork" { | ||
type = string | ||
default = "projects/labaratoriya/regions/us-central1/subnetworks/default" | ||
} | ||
|
||
variable "ssh_keys" { | ||
type = string | ||
description = "SSH public key for accessing VMs" | ||
default = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOsX4I3rwJr+/NL3aPA7rIS/4/XtlnJRIpn/0C9T3os0 ismoilovdev@vivobook" | ||
} | ||
|
||
variable "os_image" { | ||
type = string | ||
description = "The OS image to use for the VMs" | ||
default = "projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20240830" | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.