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.
More on Secrets Provisioners and Policy as Code
A developer hardcodes a DB password in `terraform.tfvars` and commits it. What do you do right now, and what's the long-term fix?BeginnerHow do you avoid Terraform persisting a secret in state when creating a secret in AWS Secrets Manager?AdvancedSomeone wants a `remote-exec` provisioner to configure servers after creation. What's your advice?BeginnerHow do you generate and manage the master password for a new RDS instance?IntermediateCompare Sentinel, OPA/Conftest and Checkov for policy as code.IntermediateHow do you prevent public S3 buckets from ever reaching production via Terraform?Intermediate