Before creating git repo add some files to the .gitignore files. Check .gitignore files to see which files.
- Git init, create .gitignore file
- Create RG, run terraform init.
- Create Storage Account to store your state in remote location
main.tf >>> Main configuration files vars.tf >>> Variable declaring files terraform.tfvars or *.auto.tfvars >>> Terraform can populate variables using values from a file. Terraform automatically loads them from these files to populate variables
lookup >>> This introduces a built-in function call. The lookup function does a dynamic lookup in a map for a key
Terraform must authenticate to Azure to create infrastructure. In your terminal, use the Azure CLI tool to setup your account permissions locally.
$ az login
Your browser window will open and you will be prompted to enter your Azure login credentials. After successful authentication, your terminal will display your subscription information. You do not need to save this output as it is saved in your system for Terraform to use
To review the information in your state file, use the state command. If you have a long state file, you can see a list of the resources you created with Terraform by using the list subcommand. $ terraform state list
variable "myvar" { type = "string" # Define type of the variable default = "Salam aleykum Hagrid" }
variable "mymap" {
type = map(string)
default = "my value"
}
variable "mylist" {
type = list
default = [1,2,3]
}
variable "filename" { type = string default = "" }
resource "azurerm_storage_blob" "training-file" {
name = var.filename != "" ? var.filename : "trainingfile.txt" storage_account_name = azurerm_storage_account.trainingsa.name storage_container_name = azurerm_storage_container.trainingco.name type = "Block"
source = var.filename != "" ? var.filename : "trainingfile.txt" # IF VARIABLE FILE NAME IS NOT EMPTY USE VALUE FROM VARIABLE ITSELF OTHERWISE ASSIGN VALUE FROM THIS EXPRESSION }