Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ismoilovdevml committed Sep 27, 2024
1 parent 654f16a commit 78338b1
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 136 deletions.
36 changes: 36 additions & 0 deletions Terraform/GCP/vm-template/README.md
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
```
34 changes: 34 additions & 0 deletions Terraform/GCP/vm-template/main.tf
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
}
9 changes: 9 additions & 0 deletions Terraform/GCP/vm-template/terraform.tfvars
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"
46 changes: 46 additions & 0 deletions Terraform/GCP/vm-template/variables.tf
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"
}
82 changes: 0 additions & 82 deletions Terraform/GCP/vm-template/vm-template.tf

This file was deleted.

54 changes: 0 additions & 54 deletions Terraform/create-vm.tf

This file was deleted.

0 comments on commit 78338b1

Please sign in to comment.