PIGSTY

Terraform

Provision cloud VM with terraform

Terraform is a popular IaC tool. You can create VMs on public cloud with one command.

Aliyun & AWS templates are used as example providers. You can take terraform.tf as an example.


Get Started

You can install terraform with homebrew on MacOS

install homebrew and terraform
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install terraform

Then init terraform cloud provider, adjust the terraform.tf config file and apply it:

cd ~/pigsty/terraform
terraform init
terraform apply #-auto-approve

Print public IP Address:

terraform output | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'

AWS Setup

You have to set up aws config & credential to use AWS provider.

# ~/.aws

# ~/.aws/config
[default]
region = cn-northwest-1

# ~/.aws/credentials
[default]
aws_access_key_id = <YOUR_AWS_ACCESS_KEY>
aws_secret_access_key =  <AWS_ACCESS_SECRET>

# ~/.aws/pigsty-key
# ~/.aws/pigsty-key.pub

There's a contrib example for AWS (Amazon Web Services), but it's not actively maintained.


Aliyun Setup

You can add your aliyun credentials to the environment file, such as ~/.bash_profile

export ALICLOUD_ACCESS_KEY="<your_access_key>"
export ALICLOUD_SECRET_KEY="<your_secret_key>"
export ALICLOUD_REGION="cn-beijing"

Example config files:

Here's example ECS OS images used in Aliyun:

DistributionImage Prefix
CentOS 7.9centos_7_9_x64_20G_alibase_20240628.vhd
Rocky 8.10rockylinux_8_10_x64_20G_alibase_20240923.vhd
Rocky 9.5rockylinux_9_5_x64_20G_alibase_20240925.vhd
Ubuntu 20.04ubuntu_20_04_x64_20G_alibase_20240925.vhd
Ubuntu 22.04ubuntu_22_04_x64_20G_alibase_20240926.vhd
Ubuntu 24.04ubuntu_24_04_x64_20G_alibase_20240923.vhd
Debian 11.11debian_11_11_x64_20G_alibase_20240923.vhd
Debian 12.7debian_12_7_x64_20G_alibase_20240927.vhd
Anolis 8.8anolisos_8_9_x64_20G_rhck_alibase_20240724.vhd

QCloud Setup

There's a contrib example for QCloud (Tencent Cloud), but it's not actively maintained.