joselcaguilar / terraformHoL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Terraform Hands-On Lab 2019

Create and deploy your first template using Terraform

Overview

This lab will guide you through the creation of 3 resources using Terraform configuration files.

The following diagram depicts the final infrastructure that you will have to deploy:

alt text

Requirements: the following tools are needed

Exercise 0 - Generate Resource Group

As an example, we have provisioned a folder with all the configuration files for creating a Resource Group: Resource group.

You can use them as a template for the following exercises.

In order to try this module, follow these steps:

  1. Login to Azure CLI

    az login
    
  2. Select the Azure Subscription where you want to deploy

    az account set -s <subscription_id>
    
  3. Verify if it has been selected

    az account show
    
  4. Itialize the Terraform configuration directory

    terraform init
    
  5. Validate the code

    terraform validate
    
  6. Create an execution plan

    terraform plan
    
  7. Create the resource group

    terraform apply
    

Once deployed, the Resource Group should have been created in your subscription.

Exercise 1 - Generate Key Vault

In this exercise, we will create the configuration files needed to generate a Key Vault.

In the repository you will find a folder named kvt . Inside it, you will find all the files that Terraform needs for deploying a resource.

alt text

The key vault should have the following attributes:

  • Disk encryption should be enabled.
  • Template deployment should be enabled.
  • (Optional) Access Policy: at least one user should have these permissions:
    • Secret: get, list, set
    • Storage: get
  • Two tags:
    • environment: should be inherited from RG.
    • channel.

Moreover, your module should have the following outputs:

  • Key Vault ID
  • Key Vault name

How can you start?

  1. Main.tf: fill the block resource bearing in mind all the requirements.
  2. Variables.tf: define all the variables. Remember that you should have already defined them in Main file.
  3. Output.tf: add all the requested outputs. Take a look at RG outputs file.
  4. versions.tf: as you are using Terraform 12, you should constrain terraform to a specific version or a range of versions.

Exercise 2 - Generate Log Analytics workspace

In this exercise, we will create the configuration files needed to generate a Log Analytics Workspace. You will need to create all the configuration files from scratch.

The Log Analytics should have the following attributes:

  • Tags: should be inherited from RG.
  • Location: inherit from RG.

Moreover, your module should have the following outputs:

  • Log Analytics ID
  • Log Analytics name

How can you start?

  1. Create the file structure.
  2. Follow same steps explained above for exercise 2.

Exercise 3 (BONUS) - Create blueprint

If you have already finished the previous exercises, you are prepared to create your first blueprint, being blueprint a set of modules.

The goal of this exercise is to create a blueprint that generates a Resource Group, a Log Analytics Workspace and a Key Vault which sends its logs to the Log Analytics Workspace via diagnostic setting.

About

License:MIT License


Languages

Language:HCL 100.0%