LoginSignup
0
0

Terraform 環境構築

Last updated at Posted at 2024-06-24

環境

% sw_vers                                                               
ProductName:		macOS
ProductVersion:		14.5
BuildVersion:		23F79

AWS-CLIのインストール

% brew install awscli
% aws --version
aws-cli/2.16.9 Python/3.11.8 Darwin/23.5.0 exe/x86_64

IAMユーザー作成

AWS-CLI用ユーザー(既存ユーザーと同じであれば再利用する)
Terraform用ユーザー

AWS-CLI初期設定

AWS-CLI用のユーザーでアクセスキーを作成して値をメモする。

% aws configure
AWS Access Key ID [None]: アクセスキー ID
AWS Secret Access Key [None]: シークレットアクセスキー
Default region name [None]: ap-northeast-1
Default output format [None]: json

認証情報にTerraformユーザー情報を追加

% aws configure --profile terraform
AWS Access Key ID [None]: アクセスキー ID
AWS Secret Access Key [None]: シークレットアクセスキー
Default region name [None]: ap-northeast-1
Default output format [None]: json

credentialファイル確認

% cat ~/user/aws/credentials
CLI用とTerraform用で2つの設定が入っていること

Terraformインストール

% cd ~
% git clone https://github.com/tfutils/tfenv.git .tfenv

% export PATH=$PATH:~/.packer/bin

% tfenv list-remote
% tfenv install [version]
% tfenv use[version]
% terraform version
Terraform v1.8.5
on darwin_arm64

エイリアス設定 ※入れなくてもOK

% cd ~

% vi .zshrc
alias tf='terraform'
alias tfmt='terraform fmt -recursive'

% cat .zshrc
alias tf='terraform'
alias tfmt='terraform fmt'

読み込み
% source ~/.zshrc

動作確認
% tf version
% cd [Terraformのソースコードがある場所]
% tfmt ./ 

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0