<p>I am installing CNI using null_resource in terraform. Now if the CNI is already installed the terraform script fails with error:
<code>exit status 254. Output: │ An error occurred (ResourceInUseException) when calling the CreateAddon │ operation: Addon already exists.</code>
How can I make terraform continue with execution if the CNI is already installed, rather than failing.</p>
<p>Below is my Configuration for installing CNI:</p>
<pre><code>### Installing CNI Addon ###
resource &quot;null_resource&quot; &quot;install-CNI&quot; {
  provisioner &quot;local-exec&quot; {
    when = create
    interpreter = [&quot;bash&quot;, &quot;-c&quot;]
    command = &lt;&lt;EOT
        aws eks create-addon  \
            --cluster-name ${data.aws_eks_cluster.Custom_Dev-cluster-deploy.name} \
            --addon-name vpc-cni \
            --addon-version v1.11.2-eksbuild.1 \
            --service-account-role-arn ${aws_iam_role.Custom_Dev-cluster.arn} \
            --resolve-conflicts OVERWRITE
    EOT
  }
  triggers = {
    &quot;before&quot; = null_resource.eks-config-file.id
  }
}

</code></pre>

curiousgeek
<p>you can handle the error base on the response. if the command response contains <code>Addon already exists</code> you can <code>exit 0</code> and return an error if something else, it can be <code>aws cli</code> permission or wrong command.</p>
<pre><code>resource &quot;null_resource&quot; &quot;install-CNI&quot; {
  provisioner &quot;local-exec&quot; {
    when = create
    interpreter = [&quot;bash&quot;, &quot;-c&quot;]
    command = &lt;&lt;EOT
        RESULT=$(aws eks create-addon --cluster-name ${data.aws_eks_cluster.Custom_Dev-cluster-deploy.name} --addon-name vpc-cni --addon-version v1.11.2-eksbuild.1 --service-account-role-arn ${aws_iam_role.Custom_Dev-cluster.arn} --resolve-conflicts OVERWRITE 2&gt;&amp;1)
        if [ $? -eq 0 ]
        then
        echo &quot;Addon installed successfully $RESULT&quot;
        exit 0
        elif [[ &quot;$RESULT&quot; =~ .*&quot;Addon already exists&quot;.* ]] 
        then
        echo &quot;Plugin already exists $RESULT&quot; &gt;&amp;2
        exit 0
        else 
        echo &quot;Encounter error $RESULT&quot; &gt;&amp;2
        exit 1
        fi
    EOT
    
  }
  triggers = {
    &quot;before&quot; = null_resource.eks-config-file.id
  }
}
</code></pre>
