Florian Kaute
Florian Kaute

Reputation: 1

Will 'terraform apply' destroy running cluster if not imported/refreshed?

I have a customer with a running PREPROD k8s cluster and now he needs me to do a proper clone of it with adjusted IP ranges and such for a PROD cluster.

Unfortunately our guy who wrote the terraform code is unavailable until the end of the year and now Im trying to figure it out by myself.

First I had this problem: https://github.com/ansible/terraform-provider-ansible/issues/126 I updated ansible version from 1.1.0 in 1.3.0 in the 'providers.tf'

I edited everything that need to be edited int 'nutanix_karbon_clusters.auto.tfvars' and I really think I figured all that out so I save some details on these.

I did a terraform plan now and it says:

...
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" {
│
╵

I think disabled providers can be ignored since this is running on nutanix.

'4 to add' because it seems like it does not have an actual state of the running clusters. terraform refresh:

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",

Im thinking about simply fire terraform apply but wonder if this will destroy current running clusters which is what I need to avoid (I guess)

Tried to terraform refresh but it seems like clusters are notimported into the state and therefore terraform wants to deploy 4 new clusters. wonder if it will be destroyed and redeployed if I terraform apply

Upvotes: 0

Views: 48

Answers (1)

Friedec
Friedec

Reputation: 23

No, it won't destroy the existing resources. Terraform just fail to apply them.

The solution is to import these existing resources into terraform state.

terraform import module.resouce.resource_name existing_resource_id 

As for the other question, to make a complete clone of the existing resource, you can use terraform workspace. Match the workspace name with the repository branch name, so the original PREPROD configuration variables stays in its own branch

Upvotes: 0

Related Questions