Practice repo for MLOps on Azure using terraform.
Basic commands:
terraform init
terraform plan
terraform apply
terraform destroy
Resources:
resource "<type>: "<name>" {
...
}
resource "azurerm_resource_group" "rg" {
name = "${var.resource_group_name}_${var.environment}"
location = var.location
}
resource "azurerm_virtual_network" "vnet" {
name = "vnet"
location = var.location
address_space = ["10.0.0.0/16"]
resource_group_name = azurerm_resource_group.rg.name
dns_servers = []
}
variables can be cross refences by resource_type.resource_name.key
pr resource_type.resource_name.id
(some use IDs)
Data blocks:
If a resource already exists in the statefile, or if you want to reference that exists but your didn't create you can do that in a data block.
Providers:
providers.tf
Helper functions the terraform uses to interact with external sercices/resouces. IE: local docker server, Cloud provider (Azure).
provider "aws" {
alias = "west"
region = "us-west-2"
}
Variables: Variables are common values that can be declared and referenced elsewhere
variables.tf
variable "location" { }
terraform.tfvars: terraform.tfvars holds the common values, is referrenced in variables.tf
location = "centralus"
Statefile:
Terraform statefile only keeps readings of what it did last time.
terraform.tfstate
(Make sure it's kept in the .gitignore
)
terraform destroy
can only destroy resources it created, by looking in the statefile.
terraform.tfstate.backup
is a backup of the statefile, you can use this to undo a destroy
-
Terraform Modules:
module "name" {
source = "./some_path"
servers = 5
}
Terraform graph:
terraform graph | dot -Tsvg > graph.svg
Terraform Import:
terraform import
command can be used to import existing resources. az login --use-device-code
az account set --subscription ""
if on more than 1 subscriptionaz ad sp create-for-rbac --name aw-sp-1 --role Admin --scopes /subscriptions/df854c79-25cc-463f-9b9d-b5c918678a91
TF_API_TOKEN.
on
to workload_dispatch
terraform-docs markdown table --output-file terraform_docs.md --output-mode inject .
zip -r test_app.zip ./test_app/
az functionapp deployment source config-zip -g aw-rg-2-dev -n awazfunctionapp-dev --src ./test_app.zip