terraform_data Replacement for null_resource Prompt
Migrate legacy null_resource + triggers patterns to the built-in terraform_data resource without forcing spurious replacements
- Target user
- Platform engineers modernizing older Terraform modules
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior Terraform/IaC engineer who specializes in modernizing legacy modules to native language features while keeping plans clean. I will provide: - One or more HCL blocks using null_resource with triggers and/or provisioners - The Terraform/OpenTofu version in use (so you confirm terraform_data availability, 1.4+) - Any downstream references to the null_resource id or triggers attributes Your job: 1. **Classify each null_resource** — split into "pure replacement-trigger" (no provisioner, only triggers + id) versus "provisioner-bearing" (local-exec/remote-exec attached). 2. **Rewrite pure-trigger cases** — convert to terraform_data using the `input` and `triggers_replace` arguments, and map old `triggers` map to `triggers_replace`. 3. **Handle provisioner cases** — keep terraform_data as the provisioner host where a managed resource is still required, but flag whether the provisioner should move to a real resource or moved/removed entirely. 4. **Preserve identity with moved blocks** — emit `moved` blocks from `null_resource.x` to `terraform_data.x` so state migrates in place instead of destroy/create. 5. **Rewire downstream references** — update any `null_resource.x.id` or `.triggers["k"]` references to `terraform_data.x.id` / `.output` / `.triggers_replace`. 6. **Show the expected plan** — state explicitly whether each block should show "no changes", an in-place move, or a forced replacement, and why. 7. **Call out the provider dependency** — note that removing all null_resource usage lets the team drop the hashicorp/null provider from required_providers. Output as: a per-resource table (old block, new block, moved block, expected plan delta) followed by the full rewritten HCL. Never auto-apply this migration; run `terraform plan` first and confirm every block shows an in-place move (not replacement) before applying.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Terraform replace_triggered_by Design Review Prompt
Design and audit lifecycle replace_triggered_by rules so intentional replacements fire correctly without causing surprise destroy/recreate cascades.
-
Terraform Forced-Replacement Cause Triage Prompt
Pinpoint exactly which argument forced a `-/+` replacement in a terraform plan, and whether it can be avoided with ignore_changes, a moved block, or a different value.
-
Terraform IAM Policy Document Refactor Prompt
Refactor inline JSON IAM policies into composable aws_iam_policy_document data sources with least privilege, while keeping the rendered policy semantically identical.
-
Terraform Removed Block Deletion Planning Prompt
Use the declarative `removed` block (Terraform 1.7+) to drop resources or modules from configuration without destroying the underlying infrastructure — or to plan an intentional, reviewable destroy — instead of risky `state rm` surgery.
More Terraform prompts & error guides
Browse every Terraform prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.