3

I've created few dns_cname_record resources, however Terraform DNS provider started to throw the errors like:

Error: update server is not set

I've created the bug report for it, as it prevents me from running any Terraform command. The error is basically shown on every Terraform command, including plan.

Now I want to clean up and get rid of this DNS module completely, and all references to it. So I've removed all my dns_cname_record resources from all .tf files. However there are some still resources stored in a state file which I want to get rid of.

$  terraform show | grep -w dns_cname_record
# dns_cname_record.foo-example: 
resource "dns_cname_record" "foo-example" {
# dns_cname_record.bar-example: 
resource "dns_cname_record" "bar-example" {

So I've tried to destroy it with force without refreshing state, but it failed as well:

$ TF_LOG=trace terraform destroy -target=dns_cname_record.foo-example -force -refresh=false
...
[TRACE] <root>: eval: *terraform.EvalIf
[TRACE] <root>: eval: *terraform.EvalApplyProvisioners
[TRACE] <root>: eval: *terraform.EvalIf
[TRACE] <root>: eval: *terraform.EvalIf
[TRACE] <root>: eval: *terraform.EvalApply
[DEBUG] dns_cname_record.foo-example: applying the planned Delete change
[TRACE] GRPCProvider: ApplyResourceChange
[DEBUG] dns_cname_record.foo-example: apply errored, but we're indicating that via the Error pointer rather than returning it: update server is not set
[TRACE] <root>: eval: *terraform.EvalWriteState
[TRACE] EvalWriteState: writing current state object for dns_cname_record.foo-example
[TRACE] <root>: eval: *terraform.EvalApplyPost
[ERROR] <root>: eval: *terraform.EvalApplyPost, err: update server is not set
[ERROR] <root>: eval: *terraform.EvalSequence, err: update server is not set
[ERROR] <root>: eval: *terraform.EvalOpFilter, err: update server is not set
[TRACE] [walkDestroy] Exiting eval tree: dns_cname_record.foo-example (destroy)
[TRACE] vertex "dns_cname_record.foo-example (destroy)": visit complete
[TRACE] dag/walk: upstream of "dns_cname_record.foo-example (clean up state)" errored, so skipping
[TRACE] dag/walk: upstream of "provider.dns (close)" errored, so skipping
[TRACE] dag/walk: upstream of "meta.count-boundary (EachMode fixup)" errored, so skipping
[TRACE] dag/walk: upstream of "root" errored, so skipping

Error: update server is not set

Releasing state lock. This may take a few moments...
[DEBUG] plugin: plugin process exited: path=~/.terraform/plugins/darwin_amd64/terraform-provider-dns_v2.1.1_x4 pid=76229
[DEBUG] plugin: plugin exited

and at the end, it doesn't remove invalid entry, because of the error.

I've also tried to remove terraform-provider-dns_v2.1.1_x4 binary module file, but teraform plan complains about it, and terraform init downloads it again, and the problem repeats.

Is there any higher power command than destroy -force -refresh=false to get rid of the invalid entries from the state file which breaking local setup? Or I need to edit the state file manually?

1 Answer 1

6

The workaround is to pull the current state file, edit it and use it as a base line. For example:

$ terraform state pull > terraform.tfstate
$ vim terraform.tfstate # Carefully remove invalid entries.
$ python -mjson.tool terraform.tfstate # Validate JSON.

Note: In Vim, placing cursor on the opening bracket, hitting d% will remove the whole group.

Then plan and apply:

$ terraform plan -state=terraform.tfstate -refresh=false
$ terraform apply -state=terraform.tfstate -refresh=false

Alternatively, pull, edit and push your local state file into remote state:

$ terraform state pull > terraform.tfstate
$ vim terraform.tfstate # Remove invalid entries and increase the serial value.
$ terraform state push terraform.tfstate

For Azure, it's better to use terraform-provider-azurerm instead of general DNS provider (terraform-provider-dns).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.