Commit d35397b9 authored by Santan Thottempudi's avatar Santan Thottempudi

Initial commit

parents
File added
#!/bin/bash
sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get -y install apache2 && sudo apt-get -y install php libapache2-mod-php &&
echo '<!doctype html><html><body><h1>Hello World!</h1><p><?php echo "hostname is:".gethostname(); ?></p></body></html>
' | sudo tee /var/www/html/index.php && sudo rm -rf /var/www/html/index.html
terraform {
backend "gcs" {
bucket = "bucket-tfstate-finalproject"
prefix = "terraform/state"
}
}
\ No newline at end of file
module "gce-lb-http" {
source = "GoogleCloudPlatform/lb-http/google"
version = "~> 5.1"
name = google_compute_network.vpc_network.name
project = var.projectId
target_tags = [
"group1",
module.cloud-nat-group1.router_name,
module.cloud-nat-group2.router_name,
"group2",
]
firewall_networks = [google_compute_network.vpc_network.name]
backends = {
default = {
description = null
protocol = "HTTP"
port = 80
port_name = "http"
timeout_sec = 10
connection_draining_timeout_sec = null
enable_cdn = false
security_policy = null
session_affinity = null
affinity_cookie_ttl_sec = null
custom_request_headers = null
custom_response_headers = null
health_check = {
check_interval_sec = null
timeout_sec = null
healthy_threshold = null
unhealthy_threshold = null
request_path = "/"
port = 80
host = null
logging = null
}
log_config = {
enable = true
sample_rate = 1.0
}
groups = [
{
group = google_compute_region_instance_group_manager.mig1.instance_group
balancing_mode = null
capacity_scaler = null
description = null
max_connections = null
max_connections_per_instance = null
max_connections_per_endpoint = null
max_rate = null
max_rate_per_instance = null
max_rate_per_endpoint = null
max_utilization = null
},
{
group = google_compute_region_instance_group_manager.mig2.instance_group
balancing_mode = null
capacity_scaler = null
description = null
max_connections = null
max_connections_per_instance = null
max_connections_per_endpoint = null
max_rate = null
max_rate_per_instance = null
max_rate_per_endpoint = null
max_utilization = null
},
]
iap_config = {
enable = false
oauth2_client_id = ""
oauth2_client_secret = ""
}
}
}
}
\ No newline at end of file
# Define Terraform Provider
terraform {
required_version = "~> 1.0"
required_providers {
google = {
source = "hashicorp/google"
version = "~> 3.53" # pinning version
}
google-beta = {
source = "hashicorp/google-beta"
version = "~> 3.53"
}
template = {
source = "hashicorp/template"
}
}
}
# Credentials
provider "google" {
credentials = file(var.google_credentials)
project = var.projectId
}
# Credentials
provider "google-beta" {
credentials = file(var.google_credentials)
project = var.projectId
}
\ No newline at end of file
#VM template 1
resource "google_compute_instance_template" "vmtemp1" {
name = "${var.projectId}-vm"
description = "This template is used to create app server instances."
tags = [ "group1", module.cloud-nat-group1.router_name,]
instance_description = "description assigned to instances"
machine_type = var.vm_type
can_ip_forward = false
scheduling {
automatic_restart = true
on_host_maintenance = "MIGRATE"
}
// Create a new boot disk from an image
disk {
source_image = var.source_image
auto_delete = true
boot = true
disk_size_gb = "10"
disk_type = "pd-balanced"
}
network_interface {
network = google_compute_network.vpc_network.name
subnetwork = google_compute_subnetwork.subnet1.self_link
}
metadata_startup_script = file(var.startup_script)
}
# Regional Managed Instance Group 1
resource "google_compute_region_instance_group_manager" "mig1" {
name = "${var.projectId}-mig1"
base_instance_name = "apache"
region = var.region_1
distribution_policy_zones = [var.zone_1, var.zone_2, var.zone_3]
version {
instance_template = google_compute_instance_template.vmtemp1.self_link
}
target_size = 3
named_port {
name = "http"
port = 80
}
}
#VM template 2
resource "google_compute_instance_template" "vmtemp2" {
name = "${var.projectId}-vm2"
description = "This template is used to create app server instances."
tags = [ "group2", module.cloud-nat-group2.router_name,]
instance_description = "description assigned to instances"
machine_type = var.vm_type
can_ip_forward = false
scheduling {
automatic_restart = true
on_host_maintenance = "MIGRATE"
}
// Create a new boot disk from an image
disk {
source_image = var.source_image
auto_delete = true
boot = true
disk_size_gb = "10"
disk_type = "pd-balanced"
}
network_interface {
network = google_compute_network.vpc_network.name
subnetwork = google_compute_subnetwork.subnet2.self_link
}
metadata_startup_script = file(var.startup_script)
}
#Regional Mangaged Instance Group 2
resource "google_compute_region_instance_group_manager" "mig2" {
name = "${var.projectId}-mig2"
base_instance_name = "apache2"
region = var.region_2
distribution_policy_zones = [var.zone_4, var.zone_5, var.zone_6]
version {
instance_template = google_compute_instance_template.vmtemp2.self_link
}
target_size = 3
named_port {
name = "http"
port = 80
}
}
#VPC Network
resource "google_compute_network" "vpc_network" {
project = var.projectId
name = "${var.projectId}-vpc"
auto_create_subnetworks = false
}
#Subnet
resource "google_compute_subnetwork" "subnet1" {
name = "${var.projectId}-subnet1"
ip_cidr_range = var.ip_cidr_range_1
region = var.region_1
network = google_compute_network.vpc_network.self_link
}
resource "google_compute_subnetwork" "subnet2" {
name = "${var.projectId}-subnet2"
ip_cidr_range = var.ip_cidr_range_2
region = var.region_2
network = google_compute_network.vpc_network.self_link
}
resource "google_compute_router" "router1" {
name = "${var.projectId}-gw-router1"
network = google_compute_network.vpc_network.self_link
region = var.region_1
}
module "cloud-nat-group1" {
source = "terraform-google-modules/cloud-nat/google"
version = "1.4.0"
router = google_compute_router.router1.name
project_id = var.projectId
region = var.region_1
name = "${var.projectId}-vpc-cloud-nat-1"
}
resource "google_compute_router" "router2" {
name = "${var.projectId}-gw-router2"
network = google_compute_network.vpc_network.self_link
region = var.region_2
}
module "cloud-nat-group2" {
source = "terraform-google-modules/cloud-nat/google"
version = "1.4.0"
router = google_compute_router.router2.name
project_id = var.projectId
region = var.region_2
name = "${var.projectId}-vpc-cloud-nat-2"
}
{
"type": "service_account",
"project_id": "nisum-finalproject",
"private_key_id": "3af1abb2313d16656bb7710460fd16d5d2b0e0d8",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCtIZKwnQPQgpGG\nZ+2RAUKXgbEsPn8xiYUxHKLiwIK2rBuHawzaVnIvdjf8XK1aIaEFtbPYjSlb5tgn\nx7YIa8xA4z61XwY05lK4eC6x83Ei/epSMJoScs2XK4abrstVcDM/O8YQm+9TW5ys\nZ1qcyJ/UJkxo30qd0bPOatBxs4GtvspCd3az3iESqgVn03U8TR+KcIkrpNV+Chm4\nGDUHbIAt4f2PBzMex51Y/1LG6oTC1wFgf9s5YAY/cRA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pT5XgMvgEMWHZ\n5VswWrl3cTVj5bQYemCGWX8fQF+hbBOmwOyUju3oI98C0M4ygwrTZ/M915cOosQb\nG1S58L99gkO1lbcOf9W9sgmahC42m67lvjTIogECgYB1RndspRbe1oeFSTZQsWn7\n3tKftt+1/FG0K5m4NlZbBgfRH/ZeJHnEzp6Pb0nybdOh2g/lgzQb0H/FpdgENjev\n0+Gz+/bWReCt5gyfXCqorJVN2E8McZaiuUevJItdPtZIEBsKMDefWjaQeh8TY0Yc\nfsAv/xi1lNwPVq3B5CW9iA==\n-----END PRIVATE KEY-----\n",
"client_email": "nisum-finalproject-sa@nisum-finalproject.iam.gserviceaccount.com",
"client_id": "103032064498352301647",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/nisum-finalproject-sa%40nisum-finalproject.iam.gserviceaccount.com"
}
output "load-balancer-ip" {
value = module.gce-lb-http.external_ip
}
#GCP Config
variable projectId {
description = "The project ID for the gcp resources to be created in"
}
variable google_credentials{
description = "absolute path to json gcp service account cred key"
}
#Regions & Zones
variable region_1 {
description = "Region where resources are created"
}
variable region_2{
description = "secondary region where resources are created"
}
variable zone_1 {
description = "Name of the zone where resources are created"
}
variable zone_2{
description = "Name of zone where resources are created"
}
variable zone_3 {
description = "name of zone where resources are created"
}
variable zone_4 {
description = "name of zone where resources are created"
}
variable zone_5 {
description = "name of zone where resources are created"
}
variable zone_6 {
description = "name of zone where resources are created"
}
#Networking IP Range
variable ip_cidr_range_1{
description = "subnet ip cidr range"
}
variable ip_cidr_range_2{
description = "subnet 2 ip cidr range"
}
#MIG-VM Config
variable vm_type{
description = "size of the vm instance to be created"
}
variable source_image{
description = "source image for vm to be created"
}
variable startup_script{
description = "path to startup script "
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment