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

<pre><code>$ terraform state pull &gt; terraform.tfstate
$ vim terraform.tfstate # Carefully remove invalid entries.
$ python -mjson.tool terraform.tfstate # Validate JSON.
</code></pre>

<p><sup>Note: In Vim, placing cursor on the opening bracket, hitting <kbd>d%</kbd> will remove the whole group.</sup></p>

<p>Then plan and apply:</p>

<pre><code>$ terraform plan -state=terraform.tfstate -refresh=false
$ terraform apply -state=terraform.tfstate -refresh=false
</code></pre>

<hr>

<p>Alternatively, pull, edit and push your local state file into remote state:</p>

<pre><code>$ terraform state pull &gt; terraform.tfstate
$ vim terraform.tfstate # Remove invalid entries and increase the serial value.
$ terraform state push terraform.tfstate
</code></pre>

<hr>

<p>For Azure, it's better to use <a href="https://github.com/terraform-providers/terraform-provider-azurerm" rel="noreferrer"><code>terraform-provider-azurerm</code></a> instead of general DNS provider (<a href="https://github.com/terraform-providers/terraform-provider-dns" rel="noreferrer"><code>terraform-provider-dns</code></a>).</p>

CC BY-SA 4.0
2019-06-19T16:41:19.100Z
2019-06-19T17:03:11.150Z
2019-06-19T17:03:11.150Z
kenorb
<p>I've created few <a href="https://www.terraform.io/docs/providers/dns/r/dns_cname_record.html" rel="nofollow noreferrer"><code>dns_cname_record</code> resources</a>, however <a href="https://github.com/terraform-providers/terraform-provider-dns" rel="nofollow noreferrer">Terraform DNS provider</a> started to throw the errors like:</p>

<blockquote>
  <p>Error: update server is not set</p>
</blockquote>

<p>I've created the <a href="https://github.com/terraform-providers/terraform-provider-dns/issues/83" rel="nofollow noreferrer">bug report</a> for it, as it prevents me from running any Terraform command. The error is basically shown on every Terraform command, including <code>plan</code>.</p>

<p>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 <code>dns_cname_record</code> resources from all <code>.tf</code> files. However there are some still resources stored in a state file which I want to get rid of.</p>

<pre><code>$  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" {
</code></pre>

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

<pre><code>$ TF_LOG=trace terraform destroy -target=dns_cname_record.foo-example -force -refresh=false
...
[TRACE] &lt;root&gt;: eval: *terraform.EvalIf
[TRACE] &lt;root&gt;: eval: *terraform.EvalApplyProvisioners
[TRACE] &lt;root&gt;: eval: *terraform.EvalIf
[TRACE] &lt;root&gt;: eval: *terraform.EvalIf
[TRACE] &lt;root&gt;: 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] &lt;root&gt;: eval: *terraform.EvalWriteState
[TRACE] EvalWriteState: writing current state object for dns_cname_record.foo-example
[TRACE] &lt;root&gt;: eval: *terraform.EvalApplyPost
[ERROR] &lt;root&gt;: eval: *terraform.EvalApplyPost, err: update server is not set
[ERROR] &lt;root&gt;: eval: *terraform.EvalSequence, err: update server is not set
[ERROR] &lt;root&gt;: 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
</code></pre>

<p>and at the end, it doesn't remove invalid entry, because of <a href="https://github.com/terraform-providers/terraform-provider-dns/search?q=%22update+server+is+not+set%22&amp;unscoped_q=%22update+server+is+not+set%22" rel="nofollow noreferrer">the error</a>.</p>

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

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

<terraform><terraform-module>
How to forcibly remove the resource created by the broken module?
kenorb
# How to forcibly remove the resource created by the broken module?

(Asked by: username_0 on 2019-06-17)

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] : eval: *terraform.EvalIf
[TRACE] : eval: *terraform.EvalApplyProvisioners
[TRACE] : eval: *terraform.EvalIf
[TRACE] : eval: *terraform.EvalIf
[TRACE] : 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] : eval: *terraform.EvalWriteState
[TRACE] EvalWriteState: writing current state object for dns_cname_record.foo-example
[TRACE] : eval: *terraform.EvalApplyPost
[ERROR] : eval: *terraform.EvalApplyPost, err: update server is not set
[ERROR] : eval: *terraform.EvalSequence, err: update server is not set
[ERROR] : 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?

**Tags:** terraform, terraform-module


---

## 1 answers

### Answer by username_0 on 2019-06-19. Score: 6 | Accepted answer

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).


---

