<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Anattapol Limopasit</title>
    <description>The latest articles on DEV Community by Anattapol Limopasit (@anattapol).</description>
    <link>https://dev.to/anattapol</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F358886%2Fb94fb3fe-b85c-4573-9333-5413a31f3dc2.jpeg</url>
      <title>DEV Community: Anattapol Limopasit</title>
      <link>https://dev.to/anattapol</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anattapol"/>
    <language>en</language>
    <item>
      <title>I cannot destroy resources from my terraform </title>
      <dc:creator>Anattapol Limopasit</dc:creator>
      <pubDate>Sun, 06 Jun 2021 13:18:07 +0000</pubDate>
      <link>https://dev.to/anattapol/i-cannot-destroy-resources-from-my-terraform-fc</link>
      <guid>https://dev.to/anattapol/i-cannot-destroy-resources-from-my-terraform-fc</guid>
      <description>&lt;p&gt;I am learning the well-known infrastructure as code from Hashicorp. You know it is terraform. &lt;br&gt;
I applied the IaC now I want to destroy it but I couldn't. It said the resources not found.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;➜  02_01_variables git:&lt;span class="o"&gt;(&lt;/span&gt;master&lt;span class="o"&gt;)&lt;/span&gt; ✗ tf apply &lt;span class="nt"&gt;-destroy&lt;/span&gt;
aws_vpc.vpc1: Refreshing state... &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;vpc-00ff6b23017c33b36]
aws_internet_gateway.gateway1: Refreshing state... &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;igw-048ff50b04984c8c9]
aws_subnet.subnet1: Refreshing state... &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;subnet-092c7562b5217f94b]
aws_security_group.sg-nodejs-instance: Refreshing state... &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;sg-016d21995017adf82]
aws_route_table.route_table1: Refreshing state... &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;rtb-05e51e942674c90b0]
aws_instance.nodejs1: Refreshing state... &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;i-089b073c3bbbfeaa1]
aws_route_table_association.route-subnet1: Refreshing state... &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;rtbassoc-0f0ae78f78ee34ae2]
^C
Interrupt received.
Please &lt;span class="nb"&gt;wait &lt;/span&gt;&lt;span class="k"&gt;for &lt;/span&gt;Terraform to &lt;span class="nb"&gt;exit &lt;/span&gt;or data loss may occur.
Gracefully shutting down...

^C
Two interrupts received. Exiting immediately. Note that data loss may have occurred.

╷
│ Error: operation canceled
│
│
╵
╷
│ Error: Plugin did not respond
│
│   with aws_route_table_association.route-subnet1,
│   on main.tf line 113, &lt;span class="k"&gt;in &lt;/span&gt;resource &lt;span class="s2"&gt;"aws_route_table_association"&lt;/span&gt; &lt;span class="s2"&gt;"route-subnet1"&lt;/span&gt;:
│  113: resource &lt;span class="s2"&gt;"aws_route_table_association"&lt;/span&gt; &lt;span class="s2"&gt;"route-subnet1"&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
│
│ The plugin encountered an error, and failed to respond to the plugin.&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;*&lt;/span&gt;GRPCProvider&lt;span class="o"&gt;)&lt;/span&gt;.ReadResource call. The plugin logs may contain more details.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It looked like hang unexpectedly to me. I got nothing from the CLI. Oh, OK I did enable the log here.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;TF_LOG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;TRACE
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;TF_LOG_PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;tf.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OK, let me check the log quickly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP/1.1 400 Bad Request
...
2021-06-06T19:57:32.393+0700 [INFO]  provider.terraform-provider-aws_v3.44.0_x5: 2021/06/06 19:57:32 [DEBUG] [aws-sdk-go] &amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;Response&amp;gt;&amp;lt;Errors&amp;gt;&amp;lt;Error&amp;gt;&amp;lt;Code&amp;gt;InvalidRouteTableID.NotFound&amp;lt;/Code&amp;gt;&amp;lt;Message&amp;gt;The routeTable ID 'rtb-05e51e942674c90b0' does not exist&amp;lt;/Message&amp;gt;&amp;lt;/Error&amp;gt;&amp;lt;/Errors&amp;gt;&amp;lt;RequestID&amp;gt;5b99646a-0e04-4f87-85aa-708e4a537852&amp;lt;/RequestID&amp;gt;&amp;lt;/Response&amp;gt;: timestamp=2021-06-06T19:57:32.393+0700
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;InvalidRouteTableID.NotFound&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I then checked my resource.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;➜  02_01_variables git:&lt;span class="o"&gt;(&lt;/span&gt;master&lt;span class="o"&gt;)&lt;/span&gt; ✗ tf state list
data.aws_ami.aws-linux
data.aws_availability_zones.available
aws_instance.nodejs1
aws_internet_gateway.gateway1
aws_route_table.route_table1
aws_route_table_association.route-subnet1
aws_security_group.sg-nodejs-instance
aws_subnet.subnet1
aws_vpc.vpc1
➜  02_01_variables git:&lt;span class="o"&gt;(&lt;/span&gt;master&lt;span class="o"&gt;)&lt;/span&gt; ✗ tf state show &lt;span class="nt"&gt;-state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;terraform.tfstate aws_route_table.route_table1
&lt;span class="c"&gt;# aws_route_table.route_table1:&lt;/span&gt;
resource &lt;span class="s2"&gt;"aws_route_table"&lt;/span&gt; &lt;span class="s2"&gt;"route_table1"&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    arn              &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"arn:aws:ec2:ap-southeast-1:624836204311:route-table/rtb-05e51e942674c90b0"&lt;/span&gt;
    &lt;span class="nb"&gt;id&lt;/span&gt;               &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"rtb-05e51e942674c90b0"&lt;/span&gt;
    owner_id         &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"624836204311"&lt;/span&gt;
    propagating_vgws &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[]&lt;/span&gt;
    route            &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
        &lt;span class="o"&gt;{&lt;/span&gt;
            carrier_gateway_id         &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
            cidr_block                 &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"0.0.0.0/0"&lt;/span&gt;
            destination_prefix_list_id &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
            egress_only_gateway_id     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
            gateway_id                 &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"igw-048ff50b04984c8c9"&lt;/span&gt;
            instance_id                &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
            ipv6_cidr_block            &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
            local_gateway_id           &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
            nat_gateway_id             &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
            network_interface_id       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
            transit_gateway_id         &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
            vpc_endpoint_id            &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
            vpc_peering_connection_id  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;,
    &lt;span class="o"&gt;]&lt;/span&gt;
    tags             &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{}&lt;/span&gt;
    tags_all         &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{}&lt;/span&gt;
    vpc_id           &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"vpc-00ff6b23017c33b36"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I checked it, and found it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ec2 describe-route-tables &lt;span class="nt"&gt;--route-table-ids&lt;/span&gt; rtb-05e51e942674c90b0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I went away with my dog, dog walking. That helped.&lt;br&gt;
I did the variable default to us-east-2 but I did apply them with ap-southeast-1. Let me try it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"region"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;default&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"us-east-2"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the log, us-east-2 everywhere&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;DEBUG: Request ec2/DescribeAccountAttributes Details:
&lt;span class="nt"&gt;---&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt; REQUEST POST-SIGN &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="nt"&gt;-----------------------------&lt;/span&gt;
POST / HTTP/1.1
Host: ec2.us-east-2.amazonaws.com
...
2021-06-06T19:57:16.084+0700 &lt;span class="o"&gt;[&lt;/span&gt;WARN]  Provider &lt;span class="s2"&gt;"provider[&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;registry.terraform.io/hashicorp/aws&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;]"&lt;/span&gt; produced an unexpected new value &lt;span class="k"&gt;for &lt;/span&gt;data.aws_availability_zones.available.
      - .zone_ids[0]: was cty.StringVal&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"apse1-az1"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;, but now cty.StringVal&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"use2-az1"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
      - .zone_ids[1]: was cty.StringVal&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"apse1-az2"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;, but now cty.StringVal&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"use2-az2"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
      - .zone_ids[2]: was cty.StringVal&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"apse1-az3"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;, but now cty.StringVal&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"use2-az3"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
      - .group_names: planned &lt;span class="nb"&gt;set &lt;/span&gt;element cty.StringVal&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"ap-southeast-1"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; does not correlate with any element &lt;span class="k"&gt;in &lt;/span&gt;actual
      - .id: was cty.StringVal&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"ap-southeast-1"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;, but now cty.StringVal&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"us-east-2"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
      - .names[0]: was cty.StringVal&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"ap-southeast-1a"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;, but now cty.StringVal&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"us-east-2a"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
      - .names[1]: was cty.StringVal&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"ap-southeast-1b"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;, but now cty.StringVal&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"us-east-2b"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
      - .names[2]: was cty.StringVal&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"ap-southeast-1c"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;, but now cty.StringVal&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"us-east-2c"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One that obviously seen is that &lt;code&gt;[WARN]  Provider "provider[\"registry.terraform.io/hashicorp/aws\"]" produced an unexpected new value for data&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and this one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;2021-06-06T19:57:09.758+0700 &lt;span class="o"&gt;[&lt;/span&gt;DEBUG] ReferenceTransformer: &lt;span class="s2"&gt;"provider[&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;registry.terraform.io/hashicorp/aws&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;]"&lt;/span&gt; references: &lt;span class="o"&gt;[&lt;/span&gt;var.region]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So I have had to supply the &lt;code&gt;-var region=ap-southeast-1&lt;/code&gt; to the cli. &lt;code&gt;tf apply -destroy -var region=ap-southeast-1&lt;/code&gt;  and all gone.&lt;/p&gt;

</description>
      <category>terraform</category>
      <category>aws</category>
      <category>errors</category>
      <category>study</category>
    </item>
  </channel>
</rss>
