コンテンツにスキップ

Install

tfenvをインストール

1
2
3
4
5
6
7
git clone https://github.com/tfutils/tfenv.git ~/.tfenv
touch .bash_profile
echo export PATH='$HOME/.tfenv/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile
tfenv -v
sudo apt-get install zip
tfenv list-remote

terraformをインストール

1
2
3
tfenv install 1.9.2
tfenv use 1.9.2
terraform -v

動作確認

1
2
3
4
5
6
7
mkdir terraform
cd terraform
touch main.tf
terraform init
terraform plan
terraform apply
terraform destroy

AWSにリソース作成時に必要な環境変数を設定

1
2
3
export AWS_ACCESS_KEY_ID="XXXXXXXX"
export AWS_SECRET_ACCESS_KEY="XXXXXXXX"
export AWS_DEFAULT_REGION="ap-northeast-1"

GCPにリソース作成時に必要な環境変数を設定

1
2
3
4
export GOOGLE_CLOUD_KEYFILE_JSON="XXXXXXXX.json"
export GOOGLE_PROJECT="XXXXXXXX"
export GOOGLE_REGION="asia-northeast1"
export GOOGLE_ZONE="asia-northeast1-a"

Azureにリソース作成時に必要な環境変数を設定

1
2
3
4
5
export ARM_CLIENT_ID="XXXXXXXX"
export ARM_CLIENT_SECRET="XXXXXXXX"
export ARM_SUBSCRIPTION_ID="XXXXXXXX"
export ARM_TENANT_ID="XXXXXXXX"
export ARM_ENVIRONMENT="public"

その他

1
2
3
4
5
6
7
terraform fmt
terraform validate
terraform show
terraform graph
terraform plan -out=planfile
terraform apply planfile
terraform destroy

コメント