1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Terraformのよく使うコマンド(作業用)

Posted at

はじめに

自分が良く使うTerraformコマンドを作業用にまとめておきます。
良かったら使ってください。

目次

  1. はじめに
  2. Terraformの基本的なコマンド
    1. terraform init
    2. terraform plan
    3. terraform apply
    4. terraform destroy
    5. terraform show
    6. terraform output
  3. まとめ

はじめに

Terraformは、インフラの構成管理をコードとして記述するためのツールです。AWS、GCP、Azure、さらにはオンプレミス環境まで、さまざまなクラウドプロバイダーに対応しています。Terraformを使うことで、インフラの構成をコードで管理し、再現性のあるインフラ環境を作成できます。

この記事では、Terraformを使用する上でよく使う基本的なコマンドを紹介します。ぜひ参考にしてください。


Terraformの基本的なコマンド

1. terraform init

terraform initは、Terraformの作業ディレクトリを初期化するコマンドです。このコマンドを実行すると、必要なプロバイダーのプラグインをインストールしたり、バックエンドの設定を行ったりします。作業を始める前に最初に実行するコマンドです。

terraform init

2 . terraform plan

terraform planは、現在の設定がどのように適用されるかをプランニングするコマンドです。このコマンドを実行すると、変更点が表示され、実際にインフラに適用する前にどのリソースが作成・変更・削除されるかを確認できます。

terraform plan

3 . terraform apply

terraform applyは、terraform planで確認した内容を実際にインフラに適用するコマンドです。このコマンドを実行すると、プラン通りにリソースが作成・変更・削除されます。

terraform apply

実行後、変更内容を確認するプロンプトが表示されるので、yesと入力して実行を確定します。

4 . terraform destroy

terraform destroyは、Terraformで管理しているリソースを全て削除するコマンドです。このコマンドを使用すると、指定されたインフラ全体を削除できます。

terraform destroy

削除の確認を求められるので、yesと入力して削除を実行します。

5 . terraform show

terraform showは、現在の状態(状態ファイル)を人間が読める形式で表示するコマンドです。これにより、現在管理しているインフラの状態を確認できます。

terraform show

6 . terraform output

terraform outputは、Terraformで定義した出力値を表示するコマンドです。これにより、例えば作成されたリソースの情報(例えばIPアドレスやURLなど)を取得できます。

terraform output

まとめ

Terraformは、インフラの管理をコードで行う強力なツールです。基本的なコマンドを理解しておくことで、より効率的にインフラの構築や管理を行うことができます。今回紹介したコマンドは、Terraformを使う上で最も基本的なコマンドですが、実際に使いながらさらに深い知識を身につけていきましょう。

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?