Skip to Content
Dismiss
創新
專為 AI 打造的平台

整合式、自動化、可將資料轉化為高效情報。

深入了解
Dismiss
拉斯維加斯,6 月 16-18 日
Pure//Accelerate® 2026

探索如何完整釋放資料價值。 

立即報名

什麼是 Terraform Refresh?

由於基礎架構是程式碼(IaC),企業組織可以進行擴展,並持續自動化與管理其 IT 基礎架構。由於大型科技公司和雲端供應商提供不同的 IaC 工具,HashiCorp 的 Terraform 以其配置和管理雲端資源的明確方法而脫穎而出。Terraform 命令套件中的一項有趣功能是更新 Terraform,這在確保基礎架構的狀態與配置檔案一致方面扮演關鍵角色。 

本文深入探討了更新更新模式、基礎架構管理的重要性,以及如何有效運用。

了解 Terraform Refresh

Terraform 更新功能可將您的 Terraform 狀態檔案與 Terraform 所管理的基礎架構的目前狀態同步。想像一下,您的 Terraform 狀態檔案是概述基礎架構所需配置的藍圖。然而,隨著時間的推移,Terraform 無法控制的基礎架構可能會直接進行手動變更。Terraform 更新更新透過更新狀態檔案來反映這些真實世界的修改,從而彌補了這一差距。

terraform refresh 的主要目的是偵測資源的實際狀態與所需狀態之間的任何漂移,如組態檔中所定義。由於對 Terraform 外部的基礎設施進行手動變更,或基礎設施環境本身發生變更,可能會發生這種漂移。

如何使用 Terraform Refresh

使用 terraform refresh 非常簡單。指令語法如下:

$ terraform refresh

此命令會指示 Terraform 重新整理目前在 Terraform 設定中管理的所有資源的狀態檔案。值得注意的是,terraform refresh 只會更新狀態檔案,不會修改您實際的基礎架構。

假設您有一個 Terraform 配置,其中配置了 AWS S3 貯體實例。以下是範例組態檔案(main.tf):

provider "aws" {
 region = "us-west-2"
 }
 
 resource "aws_s3_bucket" "example" {
 bucket = "my-unique-bucket-name"
 acl    = "private"
 }

若要套用此設定並建立 S3 儲存區,請執行以下操作:

$ terraform init
 $ terraform apply

如果直接透過 AWS 控制台或 API 對 S3 儲存區進行任何變更,執行 terraform 更新將更新狀態檔案,以反映這些變更:

$ terraform refresh

其他選項和旗標

  • 輸入:如果設定為假,當 Terraform 需要使用者輸入時,停用互動輸入
  • 狀態:指定用於作業的自訂狀態檔案

以下是他們的使用範例:

$ terraform refresh -input=false -state="custom_state.tfstate"

Terraform Refresh 的優勢

在基礎架構管理工作流程中整合terraform refresh有幾個優點,其中一些有:

  • 提高計劃準確度:透過更新狀態檔案,terraform 更新可確保您的 terraform 計畫輸出準確反映所需的變更,讓您的基礎架構與 Terraform 配置保持一致。這樣可以消除根據過時的州資訊提出不必要的修改的風險。
  • 強化基礎架構能見度:Terraform 更新可讓您清楚了解基礎架構的目前狀態。這種透明度可讓您識別程式碼與實際基礎架構之間的任何差異,並在必要時採取糾正措施。
  • 簡化基礎架構管理:Terraform 更新功能可讓您的 Terraform 狀態檔案維持在最新狀態,進而簡化基礎架構管理。您可以自信地套用設定變更,因為狀態檔案能準確反映基礎基礎架構。

使用 Terraform Refresh 的最佳做法

使用更新表格時,請牢記以下最佳做法:

  • Terraform v0.15.4 之前:在舊版中,terraform 更新會直接更新您的狀態檔案。然而,由於潛在的安全顧慮,這種行為現在被視為過時。建議採用 terraform-僅更新。此方法的優點是在完成更新之前提示您進行確認,讓您可以在變更套用到狀態檔案之前先檢閱變更。
  • -自動核准:雖然有些文件可能參考 -自動核准的旗標與更新錯誤,但此旗標也已過時,應避免使用。它繞過確認,並可能導致意外後果。
  • 預定使用量:通常建議策略性地使用 terraform 更新,特別是在執行 terraform 計畫或 terraform 套用命令之前。如此可確保您的計劃能反映最新的基礎架構狀態。
  • 版本控制整合:考慮將您的 Terraform 配置與 Git 等版本控制系統整合。這可讓您追蹤 Terraform 程式碼的變更,並在必要時還原為舊版。如果出現異常的更新,這就變得特別重要。
  • 有限範圍更新:如果您只想重新整理 Terraform 配置中的特定資源或模組,您可以利用目標 - 標記進行 terraform 重新整理。這種針對性的方法有助於管理大型和複雜的基礎架構部署。
  • 了解潛在影響:雖然 terraform refresh 會更新狀態檔案,但不會修改您的基礎架構。然而,更新狀態可能會顯示所需狀態(定義於 Terraform 組態中)與基礎架構實際狀態的差異。準備好解決更新狀態檔案後出現的任何差異。

結論

Terraform 更新在保持 Terraform 配置與實際基礎架構之間的一致性上扮演了關鍵角色。透過保持狀態檔案同步,您可以確保計畫準確無誤,並簡化基礎架構管理。

對於 Terraform 管理基礎架構的進階儲存解決方案,請考慮使用 Pure Storage 產品,如 KubernetesPortworx® 和各種容器工作負載Pure Cloud Block Store。這些解決方案提供強大的資料管理功能,可進一步提升雲端基礎架構的可靠性和效率。

04/2026
The CIO Playbook for Running VMs on Kubernetes
A strategic guide for CIOs redefining modern virtualization by running enterprise VMs on Kubernetes with Portworx®—securely, at scale, and across hybrid environments.
電子書
15 頁

查看重要資訊與活動

商展
Pure//Accelerate® 2026
June 16-18, 2026 | Resorts World Las Vegas

準備好參加今年度為您帶來最大價值的活動了嗎?

立即報名
PURE360 示範
探索、認識、體驗 Everpure。

存取隨取隨用影片與示範,了解 Everpure 的強大功效。

觀賞示範影片
影片
觀看影片:企業級資料雲端的價值。

Charlie Giancarlo 討論管理為何管理資料才是未來趨勢,而非儲存設備。發掘整合式做法如何革新企業級 IT 作業。

立即觀看
資源
傳統儲存裝置無法驅動未來。

現代化工作負載需求必須達到 AI 級速度、安全性與規模。您的技術棧準備好了嗎?

進行評估
您的瀏覽器已不受支援!

較舊版的瀏覽器通常存在安全風險。為讓您使用我們網站時得到最佳體驗,請更新為這些最新瀏覽器其中一個。

Personalize for Me
Steps Complete!
1
2
3
Personalize your Everpure experience
Select a challenge, or skip and build your own use case.
迎向未來的虛擬化策略

因應所有需求的儲存方案

任意規模皆可實行 AI 專案

資料管道、訓練、推論專用的高效能儲存裝置

防護資料遺失問題

保衛資料的網路彈性解決方案

降低雲端作業成本

Azure、AWS 與私有雲專用的高成本效益儲存裝置

加速應用程式與資料庫效能

低延遲儲存裝置,達成應用程式高效能

降低資料中心耗能與空間使用

高效資源運用的儲存裝置,改善資料中心運用率

Confirm your outcome priorities
Your scenario prioritizes the selected outcomes. You can modify or choose next to confirm.
Primary
Reduce My Storage Costs
Lower hardware and operational spend.
Primary
Strengthen Cyber Resilience
Detect, protect against, and recover from ransomware.
Primary
Simplify Governance and Compliance
Easy-to-use policy rules, settings, and templates.
Primary
Deliver Workflow Automation
Eliminate error-prone manual tasks.
Primary
Use Less Power and Space
Smaller footprint, lower power consumption.
Primary
Boost Performance and Scale
Predictability and low latency at any size.
What’s your role and industry?
We've inferred your role based on your scenario. Modify or confirm and select your industry.
Select your industry
Financial services
Government
Healthcare
Education
Telecommunications
Automotive
Hyperscaler
Electronic design automation
Retail
Service provider
Transportation
Which team are you on?
Technical leadership team
Defines the strategy and the decision making process
Infrastructure and Ops team
Manages IT infrastructure operations and the technical evaluations
Business leadership team
Responsible for achieving business outcomes
Security team
Owns the policies for security, incident management, and recovery
Application team
Owns the business applications and application SLAs
Describe your ideal environment
Tell us about your infrastructure and workload needs. We chose a few based on your scenario.
Select your preferred deployment
Hosted
Dedicated off-prem
On-prem
Your data center + edge
Public cloud
Public cloud only
Hybrid
Mix of on-prem and cloud
Select the workloads you need
Databases
Oracle, SQL Server, SAP HANA, open-source

Key benefits:

  • Instant, space-efficient snapshots

  • Near-zero-RPO protection and rapid restore

  • Consistent, low-latency performance

 

AI/ML and analytics
Training, inference, data lakes, HPC

Key benefits:

  • Predictable throughput for faster training and ingest

  • One data layer for pipelines from ingest to serve

  • Optimized GPU utilization and scale
Data protection and recovery
Backups, disaster recovery, and ransomware-safe restore

Key benefits:

  • Immutable snapshots and isolated recovery points

  • Clean, rapid restore with SafeMode™

  • Detection and policy-driven response

 

Containers and Kubernetes
Kubernetes, containers, microservices

Key benefits:

  • Reliable, persistent volumes for stateful apps

  • Fast, space-efficient clones for CI/CD

  • Multi-cloud portability and consistent ops
Cloud
AWS, Azure

Key benefits:

  • Consistent data services across clouds

  • Simple mobility for apps and datasets

  • Flexible, pay-as-you-use economics

 

Virtualization
VMs, vSphere, VCF, vSAN replacement

Key benefits:

  • Higher VM density with predictable latency

  • Non-disruptive, always-on upgrades

  • Fast ransomware recovery with SafeMode™

 

Data storage
Block, file, and object

Key benefits:

  • Consolidate workloads on one platform

  • Unified services, policy, and governance

  • Eliminate silos and redundant copies

 

What other vendors are you considering or using?
Thinking...
Your personalized, guided path
Get started with resources based on your selections.