Interview Prep/Terraform/Secrets Provisioners and Policy as Code

You must run a one-off command after a resource is created, such as registering with an external system.

IntermediateScenarioSecrets Provisioners and Policy as Code
Answer

Situation read → No provider support; a hook is needed.

What I'd do → Use terraform_data with local-exec and triggers.

resource "terraform_data" "register" {
  triggers_replace = [aws_instance.app.id]
  provisioner "local-exec" {
    command = "./scripts/register.sh ${aws_instance.app.private_ip}"
  }
  provisioner "local-exec" {
    when    = destroy
    command = "./scripts/deregister.sh"
  }
}

Why → triggers_replace re-runs it when the instance changes, and destroy-time provisioners handle cleanup. Destroy-time provisioners can only reference self, so pass values via triggers/input.

Interview tip → Say you'd replace it with a proper provider if one exists.

All Terraform questions

More on Secrets Provisioners and Policy as Code