You must install and configure Terraform before you can use a Terraform configuration file to define, preview, and deploy cloud infrastructure.
Install Terraform
This topic describes how to install Terraform from a package on a Linux or Windows operating system. For more information about other installation methods, see Provider installation.
Go to the official Terraform website to download the package for your operating system.
Configure the Terraform runtime environment.
Linux
Run the following command to decompress the package to /usr/local/bin.
# Replace /terraform_1.9.5_linux_amd64.zip with the path where the package is stored. sudo unzip /terraform_1.9.5_linux_amd64.zip -d /usr/local/bin
Windows
After the package is decompressed, assume that the directory is D:\tool\terraform.
On the desktop, right-click This PC and select Properties > Advanced system settings > Environment Variables > System variables/User variables.
In the System variables or User variables section, select Path, click Edit, and then click New. Enter the directory where you decompressed Terraform, such as D:\tool\terraform, and then click OK to complete the configuration.
Run
terraform
to verify the path configuration.terraform
After you run the command, a list of available Terraform options appears, as shown in the following figure. This indicates that the installation is complete.
Configure Terraform identity authentication
Terraform identity authentication is the process of verifying the identity of the Alibaba Cloud Terraform Provider before you use Terraform to perform operations on Alibaba Cloud infrastructure. After successful identity authentication, you can communicate with Alibaba Cloud APIs to create and manage Alibaba Cloud infrastructure resources. The Alibaba Cloud Terraform Provider offers multiple identity authentication methods. For more information about identity authentication, see Terraform identity authentication.
This topic provides an example of how to configure identity authentication using the AccessKey pair of a RAM user in environment variables:
An Alibaba Cloud account has full permissions for its resources. Leaking the AccessKey pair of the account poses a high security threat. Therefore, we recommend that you use the AccessKey pair of a RAM user that is granted the minimum required permissions. For more information about how to create an AccessKey pair, see Create an AccessKey pair.
Grant the RAM user the minimum required permissions. For more information, see Create custom policies.
Create environment variables to store the identity authentication information.
Linux
ImportantEnvironment variables that are configured using the export command are temporary and valid only for the current session. When the session is closed, the configured environment variables are lost. To make the environment variables persistent, you can add the export command to the startup configuration file of the operating system.
# AccessKey ID export ALICLOUD_ACCESS_KEY="<yourAccessKeyID>" # AccessKey secret export ALICLOUD_SECRET_KEY="<yourAccessKeySecret>" # The region where the resources are to be deployed export ALICLOUD_REGION="cn-beijing"
Windows
On the desktop, right-click This PC and select Properties > Advanced system settings > Environment Variables > System variables/User variables.
In the System variables or User variables section, click New to create the following environment variables.
Variable name
Variable description
Variable value
ALICLOUD_ACCESS_KEY
AccessKey ID
Example: yourAccessKeyID
ALICLOUD_SECRET_KEY
AccessKey secret
Example: yourAccessKeySecret
ALICLOUD_REGION
The region where the resources are to be deployed
0