0
0

More than 1 year has passed since last update.

terraformが実行可能か速攻で実験したい場合の手順

Posted at

概要

時々、localでterraformの動きを確認したいことがあります。
その時に早く実験を開始できる方法を書いておきます

AWSの設定をする。

ターミナルでterraformは実行すると思いますが、ターミナル上でのAWSの設定がそのままterraformのデプロイ先になります。
~/.aws/configや環境変数を利用してaws cliが叩けるようにしておきます。

そこで、以下のコマンドで現在のユーザーを確認しておきます。

aws sts get-caller-identity

ユーザーを間違えて、商用アカウントなどにデプロイしないように注意しましょう

terraformのファイルを記述

適当な場所にディレクトリを作ります。
その中にファイルを作っていきます。

必要なのは2つのファイルです

provider.tf
provider "aws" {
    region = "ap-northeast-1"
}
iam.tf
resource "aws_iam_group" "test" {
  name = "testgroup"
}

IAM User Groupの作成で動作確認するのがおすすめ。

terraform init

terraform initで初期設定をおこないます。aws providerなど勝手に設定してくれます。

適用

以下の順番で

  • terraform fmtでフォーマットを整える
  • terraform validで変なとこがないか見ておく
  • terraform planで適用内容を確認
  • terraform applyで適用し、実行できたことをaws consoleなどで確認する。

後片付け

  • terraform plan --destroyで適用内容を確認
  • terraform destroyで適用し、リソースがなくなったことをaws consoleなどで確認する。
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