Git Product home page Git Product logo

deploy-web-server-in-azure's Introduction

Azure Infrastructure Operations Project: Deploying a scalable IaaS web server in Azure

Introduction

The infrastructure as code gives us a huge advantage in defining, deploying, updating and destroying our infrastructure. So to set up an image which contains our application for repeatable deployments, we will use packer to create the virtual machine images(in JSON format).

Terraform also expands on this by not only deploying virtual machines but also storage, networking and security entities across multiple infrastructures, clouds and vendors.

Based on these, this project will use a Packer template and a Terraform template to deploy a customizable, scalable web server in Azure.

Getting Started

  1. Clone this repository
  2. Create your infrastructure as code
  3. Create your tagging-policy in Azure
  4. Create your resource group in Azure

Dependencies

  1. Create an Azure Account
  2. Install the Azure command line interface
  3. Install Packer
  4. Install Terraform

Instructions

Once you've collected your dependencies, to deploy the scalable web server in Azure we need:

  1. Deploy the packer image
  2. Deploy the infrastructure with Terraform template

πŸ“Œ Deploy the Packer Image

Packer is a server templating software. It will deploy virtual machines images. After deploying the virtual machines with the help of packer template, make sure to delete the packer images as it does not maintain the state.

πŸ”· Config Environment Variables πŸ”·

Go to the terminal and export the environment variables like below.

export ARM_CLIENT_ID=4685768f-1912-4c9a-8226-b670918xxxxfakeclientid
export ARM_CLIENT_SECRET=6GNB5c5p_5H.-odi_zffakesecret
export ARM_SUBSCRIPTION_ID=59ce2236-a139-4c5fakesubsribtionid

βœ”οΈ Get Subscription ID

  • Login into your azure account
  • Search and click "Subscriptions"
  • Select whichever subscriptions are needed
  • Click on the overview
  • Copy the Subscription Id

βœ”οΈ Get Client ID

  • Login into your azure account
  • Search and click "Azure Active Directory"
  • Click "App registrations" under the Manage tab
  • Click the application that you own
  • Copy the client ID

βœ”οΈ Get Client Secret

  • Login into your azure account
  • Search and click "Azure Active Directory"
  • Click "App registrations" under the Manage tab
  • Click the application that you own
  • Click the "Certificates & Secrets" under the Manage tab
  • Create a client secret as you need.

Once you have exported and config the environment variable, use printenv to check whether they are configured properly.

printenv

πŸ”· Deploy the Packer Image πŸ”·

Run the following command to deploy the packer image.

packer build server.json

packer output

πŸ“ŒCreate and Update Azure Resouces with Terraform Template

πŸ”· Specify the Variables πŸ”·

To use variables for your main.tf, you can specify your variables like below in your vars.tf file.

variable "environment"{
  description = "The environment should be used for all resources in this example"
  default = "test"
}

And in your main.tf, you can call the variables like

var.environment

πŸ”· Deploy the Infrastructure Using Terraform πŸ”·

Now we come to deploy the resources using the Terraform template. One thing worth mentioning is that we have already created the resources group for our PackerImage, so we can't deploy the resource group with the same name. Instead, we need to import the existing resource group and then it will know which resource group to deploy. The similar command will be like:

terraform import azurerm_resource_group.main /subscriptions/{subsriptionId}/resourceGroups/{resourceGroupName}

In main.tf: The az availability set, platform_fault_domain_count = 2 has default value 5, so we need to specify it to 2. Run the following commands to deploy the infrastructure.

az login

az login output

Remember to copy the tenant id and export it to the environment like the last step. Then run the following to deploy the terraform template.

terraform plan -out solution.plan

terraform plan output

terraform apply

Once you have deployed the infrastructure. You can go to the Azure portal to check the resources. Once you have finished, remember to destroy these resources.

terraform destroy

Output

If you succeeded in deploying the resources, it will looks like below

terraform output

You can also check whether these resources are deployed by looking at the Azure portal. The results will look like this.

azure portal

In the terminal, type terraform show to check the resources

terraform show

After the deployment, remember to destroy the resources.

terraform destroy

deploy-web-server-in-azure's People

Contributors

wujenny15 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.