How to work IaaC with Terraform integration Azure

How to work IaaC  with Terraform integration Azure

Login in azure and go to Azure CLI and create a service principle:

az account list --query "[].{name:name, subscriptionId:id, tenantId:tenantId}"

set subscription in case you have many: az account set --subscription="${SUBSCRIPTION_ID}"


Now you can create a service principal for use with Terraform:
az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${SUBSCRIPTION_ID}"

These values map to the Terraform variables like so:
appId is the client_id defined above.
password is the client_secret defined above.
tenant is the tenant_id defined above.

Now you can use local Terraform Client with below template:

# Configure the Microsoft Azure Provider
provider "azurerm" {
  # The "feature" block is required for AzureRM provider 2.x.
  # If you're using version 1.x, the "features" block is not allowed.
  version = "~>2.0"
  features {}
 
  subscription_id = "3d68f630-6550-4991-bacdsfdsc-7d04933a8974"
  client_id       = "472ecef0-0ddfdsfds41-4e94-883e-0c3ec2c5db46"
  client_secret   = "8db189dsfdsf31-0c6b-4927-a901-488c2db4e0fc"
  tenant_id       = "003a0efe-32ad-4da9-8037-030dfdfkd40db05c75"
}

# Create a resource group
resource "azurerm_resource_group" "example" {
  name     = "production-resources"
  location = "West US"
}

# Create a virtual network in the production-resources resource group
resource "azurerm_virtual_network" "test" {
  name                = "production-network"
  resource_group_name = "${azurerm_resource_group.example.name}"
  location            = "${azurerm_resource_group.example.location}"
  address_space       = ["10.0.0.0/16"]
}

Comments

Popular posts from this blog

Cloud Computing in simple

How to Write an Effective Design Document

Bookmark