« ^ »

terraformの使い方

所要時間: 約 1分

インストール

macOS (Homebrewを使う場合)

brew install terraform

バージョンの確認

terraform version
Terraform v0.11.13

初期化

terraform init を使って初期化します。

terraform init
Terraform initialized in an empty directory!

The directory has no Terraform configuration files. You may begin working
with Terraform immediately by creating Terraform configuration files.

planを実行

terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


------------------------------------------------------------------------

No changes. Infrastructure is up-to-date.

This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, no
actions need to be performed.

適応する

applyコマンドを使って

terraform apply -input=false

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

tfstateファイルができる

terraformはリソースの状態を terraform.tfstate というファイルの中に記述することで管理をしています。 中身はこのようなjsonファイルです。

{
    "version": 3,
    "terraform_version": "0.11.13",
    "serial": 1,
    "lineage": "4c522adb-b827-5753-c96b-6cc88a640a13",
    "modules": [
        {
            "path": [
                "root"
            ],
            "outputs": {},
            "resources": {},
            "depends_on": []
        }
    ]
}