Skip to main content

One post tagged with "Terraform"

View All Tags

· 24 min read
zaxro

使用 Terraform 首要注意事項

  1. apply 之後看到 destroy 有件數,請立刻停手,並按下中斷,然後去找其他人討論

What is Terraform?

HashiCorp 公司打造的 IaC 工具,使用者透過可閱讀的設定檔以達到版控,重複使用,共享設定,管理本地端(on-premises resources)跟雲端(cloud resources)由低階組件,例如:計算、存儲、網路資源,到高層級組件,例如 DNS record,SAAS 功能等的管理.

基本上,常用的雲服務,他都可以操作,地端機器也可以透過 terraform 管理!他有自己的 config 語言(*tf),透過 tf 檔跟各廠商的 api 做串接,也就是說原本你要創建 instance,要自己去翻 aws 的指令,現在只要知道怎麼設定 tf 檔就好,當 terraform 幫你把東西建立好,會把 response 的資訊寫在一隻 state 檔案!

installation

官網安裝cover 所有用例,以下提供我的 lab 環境的安裝方式,linux centos

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo yum -y install terraform

因為我這邊 lab 都會用 aws,所以要另外設定 IAM 的相關資訊,請人幫你把你的 key 生出來吧

  1. set the AWS_ACCESS_KEY_ID
export AWS_ACCESS_KEY_ID=
  1. set your secret key.
export AWS_SECRET_ACCESS_KEY=