Coder Social home page Coder Social logo

gcp-wordpress-application's Introduction

GCP-Wordpress-Application

Befor you start

Please make sure you enabled all GCP api's you needed.

Run bash enableapis.sh command to enable them

#!/bin/bash
gcloud services enable compute.googleapis.com
gcloud services enable dns.googleapis.com
gcloud services enable storage-api.googleapis.com
gcloud services enable container.googleapis.com

VPC module

In this project, we used regional VPC, because it provided us managed in specific virtual network of our Gcloud resources through subnets.

Steps:

  1. Create vpc.tf file in folder with .gitignore and README.md files
  2. Use google_compute_network resource to create the vpc
resource "google_compute_network" "vpc_network" {
   name = "vpc-network"
   auto_create_subnetworks = "true"
   routing_mode = "Regional"
}
  1. Open integrated terminal for this folder

  2. DO NOT FORGET to set the project first, otherwise your resources won't be created under your project in GCP

  3. Command for setting the project: gcloud config set project [PROJECT_ID]

  4. Run terraform init command to initialize it

  5. Run terraform plan and see if you have any syntax error

  6. Run terraform apply to apply your changes

  7. Go to Google Console and check if your VPC is created under the name of vpc-network

Note: there is also Default VPC in GCP. Please find your newly created VPC

Database

Google Cloud SQL is managed database service and it allows us to run MySQL, PosgreSQL on GCloud.

  1. In Cloud Shell under your repo folder, create a folder DB and add terraform files in it - dbinstance.tf, variables.tf and provider.tf

  2. In dbinstance.tf add your resources to create your database instance. Use google_sql_database_instance resource for this:

    resource "google_sql_database_instance" "instance" {
	name = var.db_name
	region = var.db_region
	# private_network 	= "CHANGEME"								# Give one of the VPC's Private IPv4	private_network - (Optional) The VPC network from which the Cloud SQL instance is accessible for private IP. For example, projects/myProject/global/networks/default. Specifying a network enables private IP. At least ipv4_enabled must be enabled or a private_network must be configured. This setting can be updated, but it cannot be removed after it is set.
	# zone  			= "ChangeMeIfNecessaryIfItsNotGlobal" 		# (Optional) The preferred compute engine zone.

	database_version = var.db_database_version
	settings {
		tier = var.db_tier
	}
	deletion_protection = var.db_deletion_protection
}

    In dbinstance.tf file add your resource to create your database inside db instance

resource "google_sql_database" "database" {
	name = var.db_name
	instance = google_sql_database_instance.instance.name
}
  1. In variables.tf add your variables to make your resources more dynamic
  2. Run terraform init, terraform apply to apply your changes
  3. Check Gcloud and make sure your resources are created under instance
  4. In Google Console, you will be able to find your db instance's Public IP address and also Connection name
  5. From SQL service, add a user to your database instance
  6. You can connect to your db instance from Cloud Shell by using gcloud sql connect 'mysql -h instance --user=team3 --quiet command'
  7. Connect to your database instance, use show databases; query and make sure your db is created. this db will be used for wordpress connection
  8. If you see your db inside your db instance, you should be good. Move on

Autoscaling

For handling increasings in traffic dynamically we used Autoscaling. It's adding/reducing capacity.

  1. Create asg.tf file and add google_compute_autoscaler resource inside the file. Use gcloud compute images list command to list of available images in GCloud. For ex: we used centos-cloud/centos-7

    1. Add google_compute_instance_template resource in asg.tf file. No matter how many instances are in your instance group, they will be created from this template. Use gcloud compute machine-types list command to list all available machine types in GCloud.

    2. Also add your google_compute_instance_group_manager, google_compute_target_pool, resource in asg.tf file and targets groups.

    3. Add variables.tf file inside your ASG folder. Variables file will allow you to have your scripts more dynamic. Instead of hardcoding the data inside your resources, variables.tf file will give you opportunity to keep your data inside it and fetch from another file as long as the files share same root.

    4. Add startup.sh file for bootstrapping. It means whatever command like you in this file, it will be launching during the instance provisioning. Please see metadata_startup_script = file("startup.sh") line under google_compute_instance_template

gcp-wordpress-application's People

Contributors

nazcona avatar oykueskici avatar ibeisheev avatar ucanozyurteri avatar fadimecanoglu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.