Skip to content

Latest commit

 

History

History
172 lines (117 loc) · 6.14 KB

FIRST_STEPS.md

File metadata and controls

172 lines (117 loc) · 6.14 KB

👣 First Steps with Terraform and Huawei Cloud

🔙 Back to README.

🌐 Language: English | Português

💿 Terraform installation

Install Terraform: https://developer.hashicorp.com/terraform/install

Windows (simple)

  1. Download the zip file for Windows AMD64 (available in the link above);

  2. Extract file terraform.exe in the parent folder (that is, in the same folder as main.tf file);

  3. Open PowerShell in the parent folder and run ./terraform version to confirm it was installed successfully. You should see something like this:

    > ./terraform version
    Terraform v1.8.5
    on windows_amd64
    

Windows (advanced)

  1. Download the zip file for Windows AMD64 (available in the link above);

  2. Create folder C:\Programs\Terraform and extract file terraform.exe inside it;

  3. Open Windows Start menu, search for "system variables" and click on "Edit the system environment variables"

    "Edit the system environment variables" option in Start Menu

  4. Click on "Environment Variables..." button in the bottom right

    "Environment Variables..." button in System Properties dialog

  5. Select "Path" inside "System variables" and click on "Edit" in the bottom part:

    "Path" inside "System variables", and "Edit" button

  6. Click on "New" in the right side and add C:\Programs\Terraform. Then, click on "OK" on all windows.

    "New" button on the right side, add a line with "C:\Programs\Terraform" content

  7. Open Command Prompt or PowerShell and run terraform version to confirm it was installed successfully. You should see something like this:

    > terraform version
    Terraform v1.8.5
    on windows_amd64
    

Ubuntu/Debian

Run the following commands:

sudo apt update && sudo apt install -y gnupg software-properties-common

wget -O- https://apt.releases.hashicorp.com/gpg | \
  sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list

sudo apt update && sudo apt install -y terraform

Run command terraform version to confirm that Terraform is installed. You should see something like this:

$ terraform version
Terraform v.18.5
on linux_amd64

🔑 Creating an access key (AK and SK)

An access key comprises an access key ID (AK) and secret access key (SK), and is used as a long-term identity credential to sign your requests for Huawei Cloud APIs (made by Terraform provider). AK is used together with SK to sign requests cryptographically, ensuring that the requests are secret, complete, and correct. For more details, see Access Keys documentation

To create an access key for your Huawei Cloud account, first log in to Huawei Cloud Console.

  1. Put your mouse over your username in the top right corner (A) and click on "My Credentials" (B) in the dropdown menu;

    "My Credentials" option (B) under username (A)

  2. On the left side menu, click on "Access Keys" and then click on "Create Access Key";

    "Access Keys" (C) option in the left menu and "Create Access Key" (D) button

  3. Enter a description (optional) and then click on "OK";

    Enter a description (E) and click on "OK" (F)

  4. Click on "Download" (G) in the modal message. A file named credentials.csv will be saved;

    "Download" button (G) after creating the access key

  5. Open the credentials.csv file in Notepad. It should have the following layout:

    User Name,Access Key Id,Secret Access Key
    "username",**********,##########
    
  6. On the second line, the second part is the Access Key (AK), and the third part is the Secret Key (SK).

👩‍💻 Main Terraform commands

terraform init - Initializes Terraform provider and modules

terraform fmt - Formats the Terraform code automatically

terraform validate - Checks if code syntax is correct

terraform plan - Outputs what will be executed by Terraform

terraform apply - Executes the infrastructure changes

terraform graph > graph.txt - Generate a instructure description in a graph format (DOT language) and saves it to graph.txt file. You can use the https://dreampuf.github.io/GraphvizOnline/ website to view the graph.

😣 Troubleshooting

If you encounter an error message that is unclear, or if you identified a problem while using the provider, it is possible to configure Terraform to generates debug logs by configuring environment variables TF_LOG and TF_LOG_PATH.

If you are on Windows, run the following commands in PowerShell:

$Env:TF_LOG="DEBUG"
$Env:TF_LOG_PATH="tf_log.txt"

If you are on Linux, run the following commands in your shell:

export TF_LOG="DEBUG"
export TF_LOG_PATH="tf_log.txt"

Then run the Terraform command again. The debug logs will be saved in the tf_log.txt file. Please note that this debug configuration only applies to the same terminal where the environment variables were previously configured.