Install and configure Terraform before using it to define, preview, and deploy cloud infrastructure.
Procedure
Download the appropriate package for your operating system from the Terraform.
Extract the package to /usr/local/bin.
Run
terraformto verify the installation.You should see output similar to this:
username:~$ terraform Usage: terraform [-version] [-help] <command> [args]Create a RAM user for better security.
Log on to the Resource Access Management (RAM) console by using an Alibaba Cloud account.
Create a RAM user named Terraform and create an AccessKey pair. For more information, see Create a RAM user.
Grant permissions to the RAM user. In this example, grant AliyunEDASFullAccess and
AliyunVPCFullAccessto theTerraformuser. For more information, see Grant permissions to a RAM user.
Create a test directory.
Each Terraform project needs its own working directory. Create a test directory named terraform-test:
[user@test bin]#mkdir terraform-testNavigate to the terraform-test directory.
[user@test bin]#cd terraform-test [user@test terraform-test]#Create configuration files.
Terraform reads all *.tf and *.tfvars files in the directory. You can organize your configuration across multiple files:
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 outputsFor example, create provider.tf with your credentials:
[user@test terraform-test]# vim provider.tf provider "alicloud" { region = "cn-beijing" access_key = "LTA**********NO2" secret_key = "MOk8x0*********************wwff" }For more information about the configuration, see alicloud_edas_application.
Initialize the working directory.
[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.ImportantYou must run
terraform initafter creating a working directory and configuration files.