terraform plan
plan 用於執行前進行差異比對,透過 plan 來檢查更新是否符合需求,確保 terraform 按計畫進行更新。
terraform 會拿現有的 state 與目前定義的 resource 進行比對,
執行流程
$ terraform planplan 會檢查可以 refresh 的資源,像是 data 就會每次都檢查。
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.
data.aws_ami.ubuntu: Refreshing state...接下來
plan會印出這次執行會有的動作
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
- destroy
-/+ destroy and the create replacment
-> change to data resource新增 resource 顯示
+修改 resource 顯示
~(僅異動 resource 內參數)刪除 resource 顯示
-先刪除後新增 resource 顯示
-/+異動 data 顯示
->
再來就是詳細資源
異動清單
最後是此次異動的總結
使用 -out 避免 apply 與 plan 的差異
-out 避免 apply 與 plan 的差異使用自動化執行 terraform 時 -out 可以匯出這次 plan 的 異動清單,讓 apply 執行時按照這個 異動清單 執行更新,確保 plan 和 apply 執行時是相同的結果。
Last updated
Was this helpful?