# Terraform

(If Time Permits)

Infrastructure as a Code.

Its Cloud agnostic - Open Source provisioning tool

Written in Go language.

* Speed and Simplicity
* Team Collaboration
* Error Reduction
* Disaster Recovery
* Enhanced Security

<https://developer.hashicorp.com/terraform/downloads>\ <br>

main.tf

```
terraform {
  required_version = ">=1.0"

  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~>3.0"
    }
    random = {
      source  = "hashicorp/random"
      version = "~>3.0"
    }
  }
}

provider "azurerm" {
  features {}

  subscription_id = "88ed8ca7d72f0589"
  client_id       = "30174d17-b192-30806a9b50ee"
  client_secret   = "e4H8Q~UOKvXS-q6VN7Jj9K~tic88"
  tenant_id       = "27e52f18-4-c8781beadaad"
}

resource "azurerm_resource_group" "bigdataclass" {
  name     = "bigdataclass-resources"
  location = "East US"
}

resource "azurerm_virtual_network" "bigdataclass" {
  name                = "bigdataclass-network"
  address_space       = ["10.0.0.0/16"]
  location            = azurerm_resource_group.bigdataclass.location
  resource_group_name = azurerm_resource_group.bigdataclass.name
}

resource "azurerm_subnet" "bigdataclass" {
  name                 = "internal"
  resource_group_name  = azurerm_resource_group.bigdataclass.name
  virtual_network_name = azurerm_virtual_network.bigdataclass.name
  address_prefixes     = ["10.0.2.0/24"]
}

resource "azurerm_public_ip" "bigdataclass" {
  name                = "bigdataclass-publicip"
  location            = azurerm_resource_group.bigdataclass.location
  resource_group_name = azurerm_resource_group.bigdataclass.name
  allocation_method   = "Dynamic"
  sku                 = "Basic"
}


resource "azurerm_network_interface" "bigdataclass" {
  name                = "bigdataclass-nic"
  location            = azurerm_resource_group.bigdataclass.location
  resource_group_name = azurerm_resource_group.bigdataclass.name

  ip_configuration {
    name                          = "internal"
    subnet_id                     = azurerm_subnet.bigdataclass.id
    private_ip_address_allocation = "Dynamic"
    public_ip_address_id          = azurerm_public_ip.bigdataclass.id
  }
}


resource "azurerm_linux_virtual_machine" "bigdataclass" {
  name                = "bigdataclass-vm"
  resource_group_name = azurerm_resource_group.bigdataclass.name
  location            = azurerm_resource_group.bigdataclass.location
  size                = "Standard_DS1_v2"
  admin_username      = "adminuser"
  admin_password      = "B1GD@t@Tu3"
  disable_password_authentication = false

  network_interface_ids = [
    azurerm_network_interface.bigdataclass.id,
  ]

  /*
  admin_ssh_key {
    username   = "adminuser"
    public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC..."
  }
  */

  os_disk {
    caching              = "ReadWrite"
    storage_account_type = "Standard_LRS"
  }

  source_image_reference {
    publisher = "Canonical"
    offer     = "UbuntuServer"  
    sku       = "19.04"
    version   = "latest"
  }
}

```

terraform init

terraform plan

terraform apply

terraform destroy
