How to run terraform output command on same terraform script

Hi All,

after creating aws resources using terrafom i am unable to executing get terraform from null_resource.


 resource "null_resource" "next" {
        provisioner "local-exec" {
         command = "sleep 600"
         }
       }

   resource "null_resource" "delay" {
        provisioner "local-exec" {

            command = "terraform output|sed 's/[][]//g'|sed 's/\"//g'|sed 's/\,//g'|grep -v private|sed '/^[[:space:]]*$/d'|sed -e 's/[\t ]//g;/^$/d'  > list_privateips.txt"
         }
        triggers = {
            "before" = null_resource.next.id
         }
        }

above script is not working.
could you please help us.

Hi @sharathmankala,

The state may not be written out in its entirety until the current operation completes, so calling terraform output from a provisioner is always likely to show stale information.

It’s hard to say else you could do without a complete example, but having a resource to impose a delay like this is usually not a reliable technique for getting the information you want. I would make sure the outputs are correctly configured in the config, and retrieve the data in a post-processing step.