Terraform First Practice in Windows
In this practice guide you will learn how to use terraform to create an azure resource group.
First of all you need to download terraform command in this link, if you already have the file you can start create the terraform configuration
create main.tf for initial terraform configuration
# Configure the Azure Provider
provider "azurerm" {
version = "~>1.32.0"
}
# Configure a new resource group
resource "azurerm_resource_group" "rg" {
name = "ansible-lab"
location = "southeastasia"
}
make sure you already installed azure command line. to check if your azure command line was working, you can run command az --version
in your command prompt and you got this output. make sure you already logged in using az login
command you can see my other article how to setup az cli and logged in
now you can continue to the next step to initialize terraform configuration
run terraform init
to download file needed to run the configuration
this process will generate .terraform directory to save file or plugin required
terraform need to generate execution plan using terraform plan
run terraform plan
run terraform apply
to start apply your configuration into Azure
go to azure portal and check the resource group was created
when Terraform created the resource group it also wrote data into the terraform.tfstate file. State keeps track of the all managed resources and their associated properties with current value. This state file is extremely important
Terraform state is essential for managing changes to infrastructure over time. It is necessary to preserve the state file for the entire life cycle of the resources. For that reason (and others), it is recommended to use a remote backend to save state in centralized, secure storage.
inspect the current state using terraform show
Congratulations your first try using terraform was succeed, you can move to the next step
BAHASA INDONESIA
Pada pelatihan kali ini kita akan mempelajari cara menggunakan terraform untuk membuat azure resource group
Langkah pertama yang dibutuhkan yaitu membuat file untuk menyimpan konfigurasi terraform
buat file main.tf untuk awal konfigurasi terraform
# Configure the Azure Provider
provider "azurerm" {
version = "~>1.32.0"
}
# Configure a new resource group
resource "azurerm_resource_group" "rg" {
name = "ansible-lab"
location = "southeastasia"
}
jalankan command terraform init
untuk terraform mengunduh semua file yang diperlukan untuk menjalankan konfigurasi yang sudah kita buat
proses tersebut akan menghasilkan folder .terraform untuk menyimpan plugin yang dibutuhkan
terraform bisa menampilkan execution plan dengan menjalankan perintah terraform plan
jalankan terraform plan
jalankan terraform apply
untuk memulai pengaplikasian konfigurasi yang ada di terraform ke Azure
masuk ke portal azure untuk melakukan pengecekan apakah resource group sudah terbuat
ketika terraform membuat resource group, terraform akan menuliskan hasilnya pada file terraform.tfstate. File tersebut akan menyimpan semua resource dan properties yang diimplementasikan. File terraform.tfstate ini sangat penting.
Terraform state merupakan bagian penting untuk mengelola infrastruktur seiring berjalannya waktu. File ini digunakan untuk mengetahui kondisi dari keseluruhan resource. untuk alasan tersebut sehingga sangat direkomendasikan untuk menyimpan file tersebut di tempat penyimpanan lainnya maupun di remote backend
untuk melihat kondisi saat ini di state file jalankan perintah terraform show
Selamat!! kamu sudah menyelesaikan pelatihan pertama menggunakan terraform. Kamu bisa melanjutkan ke langkah berikutnya.