You must install and configure Terraform before you can use its simple template language to define, preview, and deploy cloud infrastructure.

Procedure

  1. Download the appropriate software package for your operating system from the official website of Terraform.
  2. Decompress the package to an on-premises path, such as a /usr/local/bin.
    If you decompress the executable file to another directory, you must specify a global path for the file by using one of the following methods:
  3. Run the terraform command to verify the path.
    If a list that is similar to the following list of available Terraform options is displayed, the installation is complete:
    username:~$ terraform
    Usage: terraform [-version] [-help] <command> [args]
  4. For higher flexibility and security in permission management, we recommend that you create a RAM user and grant the required permissions to the RAM user.
    1. Log on to the Resource Access Management (RAM) console by using an Alibaba Cloud account.
    2. Create a RAM user named Terraform and create an AccessKey pair for the RAM user. For more information, see Create a RAM user.
    3. Grant the required permissions to the RAM user. In this example, the AliyunEDASFullAccess and AliyunVPCFullAccess permissions are granted to the Terraform RAM user. For more information, see Grant permissions to a RAM user.
  5. Create a test directory.
    You must create a separate working directory for each Terraform project. In this example, create a test directory named terraform-test.
    [root@test bin]#mkdir terraform-test
  6. Go to the terraform-test directory.
    [root@test bin]#cd terraform-test
    [root@test terraform-test]#
  7. Create configuration files.
    Terraform reads all the *.tf and *.tfvars files in the directory when Terraform is running. You can write configuration information to different files based on your business needs. The following list describes the frequently used configuration 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 outputs
    For example, when you create the provider.tf file, you can configure your authentication information in the following format:
    [root@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.

  8. Initialize your working directory.
    [root@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.                        
    Notice After you create a working directory and configuration files for a Terraform project, you must initialize the working directory.