Cloud altyapısını tanımlamak, önizlemek ve dağıtmak için kullanmadan önce Terraform'ı yükleyin ve yapılandırın.
Yordam
İşletim sisteminize uygun paketi Terraform adresinden indirin.
Paketi /usr/local/bin dizinine çıkarın.
-
Kurulumu doğrulamak için
terraformkomutunu çalıştırın.Aşağıdakine benzer bir çıktı görürsünüz:
username:~$ terraform Usage: terraform [-version] [-help] <command> [args] -
Güvenliği artırmak için bir RAM kullanıcısı oluşturun.
Bir Alibaba Cloud hesabı kullanarak Resource Access Management (RAM) konsolunda oturum açın.
Terraform adlı bir RAM kullanıcısı oluşturun ve bir AccessKey çifti oluşturun. Daha fazla bilgi için bkz. RAM kullanıcı oluşturma.
RAM kullanıcısına izinler atayın. Bu örnekte,
Terraformkullanıcısına AliyunEDASFullAccess veAliyunVPCFullAccessizinleri verilir. Daha fazla bilgi için bkz. RAM kullanıcı izinlerini yönetme.
-
Bir test dizini oluşturun.
Her Terraform projesinin kendi çalışma dizinine ihtiyacı vardır. terraform-test adlı bir test dizini oluşturun:
[user@test bin]#mkdir terraform-test -
terraform-test dizinine gidin.
[user@test bin]#cd terraform-test [user@test terraform-test]# -
Yapılandırma dosyaları oluşturun.
Terraform, dizindeki tüm *.tf ve *.tfvars dosyalarını okur. Yapılandırmanızı birden çok dosyada düzenleyebilirsiniz:
provider.tf -- used to configure providers terraform.tfvars -- used to configure the variables that are required to configure providers varable.tf -- used to configure universal variables resource.tf -- used to define resources data.tf -- used to define package files output.tf -- used to configure outputsÖrneğin, kimlik bilgilerinizle provider.tf dosyasını oluşturun:
[user@test terraform-test]# vim provider.tf provider "alicloud" { region = "cn-beijing" access_key = "LTA**********NO2" secret_key = "MOk8x0*********************wwff" }Yapılandırma hakkında daha fazla bilgi için bkz. alicloud_edas_application.
-
Çalışma dizinini başlatın.
[user@test terraform-test]#terraform init Initializing provider plugins... - Checking for available provider plugins on https://releases.hashicorp.com... - Downloading plugin for provider "alicloud" (1.25.0)... The following providers do not have any version constraints in configuration, so the latest version was installed. To prevent automatic upgrades to new major versions that may contain breaking changes, it is recommended to add version = "..." constraints to the corresponding provider blocks in configuration, with the constraint strings suggested below. * provider.alicloud: version = "~> 1.25" Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work. If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary.ÖnemliBir çalışma dizini ve yapılandırma dosyaları oluşturduktan sonra
terraform initkomutunu çalıştırmanız gerekir.