iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 3
0
DevOps

今晚我想來點 Terraform 佐 AWS系列 第 3

今晚我想安裝 Terraform

目前的 Terraform 版本是 0.13.2 (2020-09-02 發佈)

下載

你可以到官方下載頁: https://www.terraform.io/downloads.html 直接下載適合你使用的作業系統的執行檔

我的目前所使用的作業系統是 Mac OS X

可以透過 homebrew 這個套件管理工具安裝執行檔:

$ brew install terraform

安裝完成之後,敲下 terraform 指令,你就可以看到 terraform 裡面的所有子指令了:

$ terraform
Usage: terraform [-version] [-help] <command> [args]

The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
...

自動補齊指令

啟用終端機上的 Tab 自動補齊指令功能,執行以下指令,再重新開啟你的終端機,就會有了:

$ terraform -install-autocomplete

如果要解除自動補齊,執行以下指令:

$ terraform -uninstall-autocomplete

Hello World

建立 main.tf 檔案,內容如下:

output "hello_world" {
  value = "Hello, World!"
}

敲下執行的指令:

$ terraform apply

在看到 Enter a value: 時,鍵入 yes,你就會看到:

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

Outputs:

hello_world = Hello, World!

.gitignore

在執行 terraform 的過程中,會產生一個 .terraform 的資料夾放下載的外掛,以及 terraform.tfstate 的狀態檔。

這些檔案都不需要 commit 到 git repository 裡面,所以需要在 .gitignore 加入下面這段設定:

# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

上一篇
今晚我想認識 Terraform
下一篇
今晚我想來點快速生產的伺服器
系列文
今晚我想來點 Terraform 佐 AWS30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言