如果不导入/刷新,“terraform apply”会破坏正在运行的集群吗?

问题描述 投票:0回答:1

我有一个客户正在运行 PREPROD k8s 集群,现在他需要我使用调整后的 IP 范围对其进行正确的克隆,例如 PROD 集群。

不幸的是,我们编写 terraform 代码的人要到今年年底才能上班,现在我正在尝试自己解决这个问题。

首先我遇到了这个问题:https://github.com/ansible/terraform-provider-ansible/issues/126 我在'providers.tf'中将ansible版本从1.1.0更新到1.3.0

我编辑了“nutanix_karbon_clusters.auto.tfvars”中需要编辑的所有内容,我真的认为我已经弄清楚了所有这些,所以我保存了一些细节。

我现在做了一个地形计划,上面写着:

...
Plan: 4 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + cluster_status = [
      + (known after apply),
      + (known after apply),
      + (known after apply),
    ]
╷
│ Warning: Disabled Providers: foundation_central, ndb, prism_central, karbon, foundation. Please provide required fields in provider configuration to enable them. Refer docs.
│
│   with provider["registry.terraform.io/nutanix/nutanix"],
│   on provider.tf line 33, in provider "nutanix":
│   33: provider "nutanix" {
│
╵

我认为禁用的提供程序可以忽略,因为它是在 nutanix 上运行的。

“4 to add”,因为它似乎没有正在运行的集群的实际状态。地形刷新:

terraform refresh
╷
│ Warning: Empty or non-existent state
│
│ There are currently no remote objects tracked in the state, so there is nothing to refresh.
╵
Outputs:

cluster_names = [
  "CLUSTER1",
  "CLUSTER2",

我正在考虑简单地应用火地形,但想知道这是否会破坏当前正在运行的集群,这是我需要避免的(我猜)

尝试 terraform 刷新,但集群似乎未导入该州,因此 terraform 希望部署 4 个新集群。不知道如果我应用地形,它是否会被摧毁并重新部署

terraform nutanix
1个回答
0
投票

不会,不会破坏现有资源。 Terraform 只是无法应用它们。

解决方案是将这些现有资源导入 terraform 状态。

terraform import module.resouce.resource_name existing_resource_id 

至于另一个问题,要对现有资源进行完整克隆,可以使用

terraform workspace
。将工作区名称与存储库分支名称相匹配,因此原始 PREPROD 配置变量保留在其自己的分支中

© www.soinside.com 2019 - 2024. All rights reserved.