HashiCorp Terraform is a declarative Infrastructure-as-Code (IaC) tool that allows you to define public cloud and on-premises resources using human-readable configuration files. These files can be written in HashiCorps proprietary language called Hashicorp Configuration Language (HCL) or JSON. Terraform employs a state-driven resource model to define the desired state of infrastructure components and services. It is used to automate the provisioning and management of a company's cloud and on-premises resources in a declarative and consistent manner, all in an agentless architecture. A notable difference between Terraform and Ansible is that Terraform is written in GO. Terraform was first released in 2014 as an open-source tool but later moved away from its longstanding open-source licensing and is now under the Business Source License (BSL) 1.1 which is more restrictive in terms of commercial use.
HashiCorp Terraform 是一套宣告式的基礎架構即程式碼(Infrastructure-as-Code,IaC)工具,可讓你使用人類可讀的設定檔來定義公有雲與地端資源。這些檔案可以用 HashiCorp 專有的 HashiCorp Configuration Language(HCL)或 JSON 撰寫。Terraform 採用狀態驅動的資源模型,來定義基礎架構元件與服務的期望狀態。它以宣告式且一致的方式,用來自動化公司雲端與地端資源的佈建與管理,且整體架構為無代理程式(agentless)。Terraform 與 Ansible 之間一個顯著差異是,Terraform 以 GO 語言撰寫。Terraform 於 2014 年首次以開放原始碼工具發行,但後來脫離其長期採用的開放原始碼授權,目前採用 Business Source License(BSL)1.1,在商業使用方面限制較多。
Terraform's agentless architecture simplifies the adoption of infrastructure automation. Since Terraform is agentless, integrations can use REST APIs, NETCONF, SSH, or even SNMP, if desired. This allows for seamless integration with a wide range of cloud services, on-premises solutions, and SaaS platforms, enabling consistent and scalable infrastructure management.
Terraform 無代理程式的架構簡化了基礎架構自動化的導入。由於 Terraform 是無代理程式的,整合可使用 REST API、NETCONF、SSH,甚至 SNMP,視需求而定。這使其能與各種雲端服務、地端解決方案及 SaaS 平台無縫整合,實現一致且可擴充的基礎架構管理。
How Terraform Works
Terraform 的運作方式
A DevOps or network engineer—Terraform administrator—typically defines the configuration files on a Terraform controller, a machine where Terraform is installed. A Terraform workflow consists of plan and apply phases, both triggered by an administrator manually or by an automated pipeline on the Terraform controller. During the planning phase, Terraform calculates the differences between the current state (defined in the state file) and the desired state (defined in the configuration files) and determines the necessary actions to achieve the desired state. The apply phase is triggered once the intended changes are verified. During this phase, Terraform executes the required actions to align the infrastructure with the desired state specified in the configuration files. Once the changes are applied, the state and configuration files are consolidated (state file is updated to reflect the current state of the infrastructure).
DevOps 或網路工程師——即 Terraform 管理員——通常會在 Terraform 控制器(安裝 Terraform 的機器)上定義設定檔。Terraform 的工作流程包含 plan(規劃)與 apply(套用)兩個階段,兩者都由管理員在 Terraform 控制器上手動觸發,或由自動化管線觸發。在規劃階段,Terraform 會計算目前狀態(定義於狀態檔)與期望狀態(定義於設定檔)之間的差異,並決定達成期望狀態所需的動作。一旦驗證了預期變更,就會觸發套用階段。在此階段,Terraform 會執行必要的動作,使基礎架構與設定檔中指定的期望狀態一致。變更套用後,狀態檔與設定檔會被整合(更新狀態檔以反映基礎架構的目前狀態)。

