
[英]Terraform issues with waiting for GCP infrastructure changes to propagate
[英]Trying to Reconcile/refresh terraform infrastructure drift
我有一個使用以下模塊創建的 Terraform GCE 資源:
resource "google_compute_address" "gke_proxy1" {
...
}
resource "google_compute_disk" "gke_proxy1" {
...
}
resource "google_compute_instance" "gke_proxy1" {
...
}
但是在某些時候,在 Terraform 腳本之外,已經為特定的 GCE 創建了 google_compute_address,因此當我嘗試應用 TF 腳本時,它會嘗試創建我不想要的計算地址。 例如使用:
terraform plan -var "env=dev" -target module.gke-proxy-primary;
如果我運行以下命令來顯示真實世界的 state:
terraform state show module.gke-proxy-primary.google_compute_instance.gke_proxy1
Output 顯示預期的compute_address state 地址如預期:
network_interface {
name = "nic0"
...
}
network_interface {
name = "nic1"
...
}
所以我想我需要從現實世界的基礎設施重建 TF state 所以我嘗試了以下方法,因為 state 和現實世界之間存在偏差:運行:
terraform refresh -var "env=dev" -target module.gke-proxy-primary;
給我:
module.gke-proxy-primary.google_compute_disk.gke_proxy1: Refreshing state... [id=projects/proj1/zones/europe-west2-a/disks/gke-proxy1]
module.gke-proxy-primary.google_compute_instance.gke_proxy1: Refreshing state... [id=projects/proj1/zones/europe-west2-a/instances/gke-proxy1]
因此,它不會像現實世界中預期的那樣為資源刷新 compute_address.gke_proxy1 遠程存儲桶 state。 任何想法我做錯了什么?
使用以下命令將缺少的依賴項 compute_address 導入到主資源 gce 的 state:
terraform 導入 -var "env=dev" -var "primary_cluster_suffix=1" module.gke-proxy-primary.google_compute_address.gke_proxy1 hsbc-10723777-safe-dev/europe-west2/gke-proxy1
然后驗證資源是否在本地 state 中:
terraform state 顯示 module.gke-proxy-primary.google_compute_address.gke_proxy1 現在應該顯示。
運行計划,它應該按預期進行協調。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.