Hi@akhtar,
You can use a local-exec provisioner to do this task. The local-exec provisioner invokes a local executable after a resource is created. This invokes a process on the machine running the Terraform, not on the resource. You can see the remote-exec provisioned to run commands on the resource. I have attached one example below for your reference.
resource "aws_instance" "web" {
provisioner "local-exec" {
command = "echo ${aws_instance.web.private_ip} >> private_ips.txt"
}
}