Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform module gcp compute engine #33

Merged
merged 8 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ This are various examples build using the above modules.
[Cloud Function v2 - GCP](/terraform/gcp/modules/cloud_function_v2/function_v2.tf)

This module will create a simple cloud function with an http trigger via Terraform.

### 5. Compute Engine - GCP
[Compute Engine -GCP](/terraform/gcp/modules/compute_engine/compute_engine.tf)

This module will create a VM instance with the image chosen by the user (defaults to Ubuntu 22.04)
13 changes: 13 additions & 0 deletions terraform/gcp/examples/compute_engine/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module "compute_engine" {
source = "/../../gcp/modules/compute_engine"
name = "Qburst-DevOps"
machine_type = "e2-medium"
image = "ubuntu-os-cloud/ubuntu-2204-lts"
zone = "us-central1-a"
network = "10.1.1.0"

}

output "computeengine_module_outputs" {
value = module.compute_engine
}
9 changes: 9 additions & 0 deletions terraform/gcp/examples/compute_engine/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
provider "google" {
project = "qburst-devops-automation"
region = "us-central1"
credentials = file("credentials.json")

}
terraform {
required_version = "1.5.0"
}
22 changes: 22 additions & 0 deletions terraform/gcp/modules/compute_engine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Compute Engine Module
This module will create a simple compute engine. As a part of the module it will generate the following

- 1 Compute Engine with specified image .
- 2 Service account created for compute engine


## Inputs
**Important**
All inputs :heavy_check_mark: must be configured.
Any with :x: can be ignored, but can be configurd if you want.

| Name | Description | Required | Type | Default |
| ----------- | ----------- | -------- | ---- | ------- |
| name | The name of the compute engine being created | :heavy_check_mark: | string | "" |
| machine_type | The machine type required | :heavy_check_mark:| string | "e2-medium" |
| zone | The zone where the engine will be created | :heavy_check_mark: | string | If it is not provided, the provider zone is used.|
| image | Image to be used for the engine | :heavy_check_mark: | string | "ubuntu-2204-lts" |
| network | VPC where compute engine needs to be created | :heavy_check_mark:| string | "" |



30 changes: 30 additions & 0 deletions terraform/gcp/modules/compute_engine/compute_engine.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
resource "google_compute_instance" "compute_engine" {
name = var.name
machine_type = var.machine_type
zone = var.zone

tags = ["QBurst"]

boot_disk {
initialize_params {
image = var.image
labels = {
my_label = "QBurst"
}
}
}
network_interface {
network = var.network

}
service_account {
email = google_service_account.computeengine_sa.email
#The scope can be changed based on requirement.By using cloud-platform,it has full access to all APIs.In ideal case, restrict the scope
scopes = ["cloud-platform"]
}
}

resource "google_service_account" "computeengine_sa" {
account_id = "compute-engine-sa"
display_name = "Service Account"
}
4 changes: 4 additions & 0 deletions terraform/gcp/modules/compute_engine/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "instance_id" {
value = google_compute_instance.compute_engine.id
description = "The ID of the Instance created"
}
22 changes: 22 additions & 0 deletions terraform/gcp/modules/compute_engine/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

variable "name" {
type = string
default = ""
}
variable "machine_type" {
type = string
default = "e2-medium"
}
variable "zone" {
type = string
default = "us-central1-a"
}
variable "image" {
type = string
default = "ubuntu-os-cloud/ubuntu-2204-lts"
}
variable "network" {
type = string
default=""

}