このステップでは、まず Terraform プロジェクトを初期化し、次に terraform plan コマンドを実行して実行計画(execution plan)を作成します。
変更を計画する前に、プロジェクトを初期化する必要があります。terraform init コマンドは、設定ファイルをスキャンし、必要なプロバイダ(この場合は local_file 用)をダウンロードし、バックエンドを設定します。
ターミナルで、まず terraform init を実行します。
terraform init
初期化が成功したら、terraform plan を実行します。このコマンドは、変更の「ドライラン」を提供するため、Terraform ワークフローの重要な部分です。これは、実際に変更を加えずに Terraform がインフラストラクチャに対して何を行うかを示します。これにより、適用前に意図されたアクションを確認および検証できます。
terraform plan
Terraform は設定ファイルを読み込み、インフラストラクチャの現在の状態(現時点では空)と比較します。その後、アクションの計画が表示されます。リソースが 1 つ作成されることを示す、以下に類似した出力が表示されるはずです。
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
## local_file.example will be created
+ resource "local_file" "example" {
+ content = "Hello, Terraform!"
+ content_base64sha256 = (known after apply)
+ content_base64sha512 = (known after apply)
+ content_md5 = (known after apply)
+ content_sha1 = (known after apply)
+ content_sha256 = (known after apply)
+ content_sha512 = (known after apply)
+ directory_permission = "0777"
+ file_permission = "0777"
+ filename = "./hello.txt"
+ id = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
resource "local_file" "example" の隣にある + 記号は、このリソースが作成されることを示しています。出力には、新しいファイルに設定されるすべての属性が詳細に示されています。