AZURE HEROES
  • Home-Updates
  • Blog
    • Azure Blog
    • Azure Heroes Events >
      • Azure Heroes Sessions #1
      • Azure Heroes Sessions #2
      • Azure Heroes Sessions #3
      • Azure Heroes Sessions #4
      • Azure Heroes Sessions #5
      • Azure Heroes Sessions #6
      • Azure Heroes Sessions #7
  • Who We Are!
  • eBooks
  • Azure All In One!
    • Azure Disk & Storage
    • Azure Network
    • Azure VPN
    • Azure VMs
  • Free Azure Support!
  • Contact Us
  • Events
    • Beginners Event
    • Developers Event
    • Special Event
    • Azure Workshop #4
    • Azure Workshop #5
    • Azure Workshop #6
    • Azure Workshop #7
    • Azure Workshop #8
    • Upcoming Events
  • Registration Form
  • Privacy Policy
  • Home-Updates
  • Blog
    • Azure Blog
    • Azure Heroes Events >
      • Azure Heroes Sessions #1
      • Azure Heroes Sessions #2
      • Azure Heroes Sessions #3
      • Azure Heroes Sessions #4
      • Azure Heroes Sessions #5
      • Azure Heroes Sessions #6
      • Azure Heroes Sessions #7
  • Who We Are!
  • eBooks
  • Azure All In One!
    • Azure Disk & Storage
    • Azure Network
    • Azure VPN
    • Azure VMs
  • Free Azure Support!
  • Contact Us
  • Events
    • Beginners Event
    • Developers Event
    • Special Event
    • Azure Workshop #4
    • Azure Workshop #5
    • Azure Workshop #6
    • Azure Workshop #7
    • Azure Workshop #8
    • Upcoming Events
  • Registration Form
  • Privacy Policy

Terraform Specific Kind Of Resources You Should Know!

2/6/2022

2 Comments

 
In this post, I will attempt to explain what the some usefull resources and how they can be used with an examples.
Picture
Generate Random String
# Generate a random string name
resource "random_string" "name" {
  length = 8
  upper = false
  number = true
  lower = true
  special = false
}
You can use random resource in order to create a unique name for some resources where you can't use the same name i.g creating resource group

you can use this resource as below:
 name = "${random_string.name.result}"
Wait Resource:
this resource is very helpful if you want for sometime to get the resource ready before creating or executing different operation. i.g wait till you get the VM up and running before you run Shell script on it.
resource "time_sleep" "wait_60_seconds" {
  depends_on = [XYZ]
  create_duration = "60s"
}
Null resource, which is very helpful if you want to run/execute command on remote machine as example
resource "null_resource" "configure_identity" {  
    triggers = {
        id = azurerm_network_interface.nic.id
    }    provisioner "local-exec" {
        # Run any command
    }    depends_on = [azurerm_signalr_service.signalr_service]
}
Dynamic Block,  You can dynamically construct repeatable nested blocks like setting using a special dynamic block type, which is supported inside resource, data, provider, and provisioner blocks:
resource "azurerm_network_security_group" "nsg" {
    name                = var.nsg_name
    location            = azurerm_resource_group.rg.location
    resource_group_name = azurerm_resource_group.rg.name
    dynamic "security_rule" {
        for_each = var.sec_rules
        content {
            name                       = security_rule.value["name"]
            priority                   = security_rule.value["priority"]
            direction                  = security_rule.value["direction"]
            access                     = security_rule.value["access"]
            protocol                   = security_rule.value["protocol"]
            source_port_range          = security_rule.value["source_port_range"]
            destination_port_range     = security_rule.value["destination_port_range"]
            source_address_prefix      = "*"
            destination_address_prefix = "*"
        }
    }
     tags  = merge(var.tags, {
          environment : "Prod"
          })
}
2 Comments
Jarrah
3/30/2022 01:47:15 am

Thanks for this post! Great info!

Reply
Azure Training in Chennai link
6/1/2022 06:11:47 pm

Hello Mohammad Al Rousan!! Am really impressed with this Azure blog because this blog is very easy to learn and understand clearly. am pretty much pleased with your good work. Thanks for sharing.

Reply



Leave a Reply.

    Author

    Mohammad Al Rousan is a Microsoft MVP (Azure), Microsoft Certified Solution Expert (MCSE) in Cloud Platform & Azure DevOps & Infrastructure, An active community blogger and speaker. Al Rousan has over 8 years of professional experience in IT Infrastructure and very passionate about Microsoft technologies and products.

    Picture
    Picture
    Top 10 Microsoft Azure Blogs

    Archives

    November 2022
    October 2022
    July 2022
    June 2022
    May 2022
    April 2022
    March 2022
    February 2022
    January 2022
    December 2021
    November 2021
    May 2021
    February 2021
    December 2020
    November 2020
    October 2020
    September 2020
    August 2020
    June 2020
    April 2020
    January 2020
    July 2019
    June 2019
    May 2019
    February 2019
    January 2019

    Categories

    All
    AKS
    Azure
    Beginner
    CDN
    DevOps
    End Of Support
    Fundamentals
    Guide
    Hybrid
    License
    Migration
    Network
    Security
    SQL
    Storage
    Virtual Machines
    WAF

    RSS Feed

    Follow
    Free counters!
Powered by Create your own unique website with customizable templates.