Someone wants a `remote-exec` provisioner to configure servers after creation. What's your advice?
BeginnerScenarioSecrets Provisioners and Policy as Code
Answer
Situation read → Provisioners are a last resort.
What I'd do →
- Prefer
user_data/cloud-init for first boot and baked AMIs (Packer) for software. - Use Ansible or SSM State Manager for configuration management.
- If you must use a provisioner, make it idempotent and set
on_failure.
Why → Provisioners don't appear in plan, aren't tracked by state, need network access to the host and fail halfway, leaving tainted resources. HashiCorp documents them as a last resort.
Interview tip → Know local-exec vs remote-exec and why neither is declarative.
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?AdvancedYou must run a one-off command after a resource is created, such as registering with an external system.IntermediateHow 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