0
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 の 基本的なコマンド

Last updated at Posted at 2025-02-11

📌 はじめに

Terraform を使ってインフラを構築する際、基本となるコマンドの流れを解説します。この流れを理解することで、どの記事でもスムーズに Terraform を実行できるようになります。

📌 プロジェクトの初期化

Terraform を実行する前に、プロジェクトを初期化します。

terraform init

🔹 主な処理

  • プロバイダーのダウンロード(AWS などのクラウドと連携するためのプラグインを取得)
  • バックエンドの設定(S3 やローカルに状態管理ファイルを保存)※ terraform.tfstate
  • モジュールの取得(定義されたモジュールをダウンロード)

📌 実行プランの作成

Terraform が適用する変更内容を事前に確認します。

terraform plan

📌 インフラの適用

Terraform の設定に基づき、リソースを作成・更新します。

terraform apply

🔹 代表的なオプション

オプション 説明
-auto-approve 確認なしで適用
-target=module.モジュール名 指定したモジュールのみ適用 / 削除

📌 インフラの削除

作成したリソースを削除する場合は、以下のコマンドを実行。

terraform destroy

🔹 代表的なオプション

オプション 説明
-auto-approve 確認なしで適用
-target=module.モジュール名 指定したモジュールのみ適用 / 削除
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?