Terraform

 

Terraform

Featured snippet from the web

HashiCorp Terraform is an infrastructure as code tool that lets you define both cloud and on-prem resources in human-readable configuration files that you can version, reuse, and share. You can then use a consistent workflow to provision and manage all of your infrastructure throughout its lifecycle.

How does Terraform work?

Terraform creates and manages resources on cloud platforms and other services through their application programming interfaces (APIs). Providers enable Terraform to work with virtually any platform or service with an accessible API.


Advantages of Terraform

  • It supports multiple providers
  • it is idempodent
  • can split configuration into multiple files within working directory
  • manually created existing resources can be able to import to terraform
  • can perform dryrun (plan)

Important Commands of Terraform

Terraform init: It starts the working directory consisting of Terraform configuration files, that can be checked from source control.  

Terraform version: It tells which Terraform version is currently installed on your system. 

Terraform fmt: It rewrites the terraform configuration files into canonical style and format

Terraform providers: Highlights the providers' requirements in the working directory. 

Terraform destroy: It allows you to destroy all of the remote objects managed by a particular configuration of terraforming. 

Terraform import: This command is used to import resources created under some other means under the umbrella of Terraform arrangement.  

Terraform validate: With this command, you can check whether a configuration is internally consistent and syntactically valid. 

Terraform apply: Apply all the actions proposed under Terraform plan. 

Terraform show: This command offers a human-readable output from a plan file. This can either be used to inspect the current state or to be sure of what planned operations are expected. 

Infrastructure as Code - Tools Overview
There are a lot of tools that allow you to deploy infrastructure as code:
  • Terraform
  • CloudFormation
  • Heat
  • Ansible
  • SaltStack
Chef, Puppet, Others

Not all of these tools are targeted for the same purpose. It is important to understand the difference between Configuration Management and Infrastructure Orchestration:
  • Ansible, Chef and Puppet are configuration management tools which means they are primarily designed to install and manage software on existing servers
  • Terraform and CloudFormation are infrastructure orchestration tools which are designed to provision servers and infrastructure themselves.

Provider block with service principal authentication

provider "azurerm" {
    features {}
  # Configuration options
 subscription_id = "00000000-0000-0000-0000-000000000000"
  client_id       = "00000000-0000-0000-0000-000000000000"
  client_secret   = var.client_secret
  tenant_id       = "00000000-0000-0000-0000-000000000000"
}



Creating Resource group

resource "azurerm_resource_group" "rg_name" {
       name = var.rg_01
       location = var.loc-name
 
}

Creating Virtual Network
resource "azurerm_virtual_network" "vnet" {
  name                = "Intenral-network"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  address_space       = ["10.0.0.0/16"]
 }

















































































































































































Comments

Popular posts from this blog

Azure Site Recovery

Azure Storage Accounts

Application Gateway