Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace null_resource with terraform_data #1548

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

janfrederik
Copy link
Contributor

@janfrederik janfrederik commented Nov 15, 2024

As from Terraform 1.4, the doc suggests to use terraform_data instead of null_resource. See https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource.

To avoid destroy and recreation of these resources, terraform>=1.9 allows the moved statement to do exactly this refactoring. Works like a charm :-)

For details, see https://registry.terraform.io/providers/hashicorp/null/latest/docs/guides/terraform-migration#migrating-existing-configurations.

@janfrederik janfrederik marked this pull request as ready for review November 15, 2024 15:26
@janfrederik janfrederik marked this pull request as draft November 27, 2024 15:39
@mysticaltech
Copy link
Collaborator

@janfrederik Your issue has been accepted last week, so great job! Going to review in-depth.

@mysticaltech mysticaltech marked this pull request as ready for review February 16, 2025 08:22
@mysticaltech mysticaltech self-requested a review February 16, 2025 08:22
mysticaltech
mysticaltech previously approved these changes Feb 16, 2025
Copy link
Collaborator

@mysticaltech mysticaltech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

Overall, this PR cleanly replaces null_resource with the new terraform_data resource. The approach is consistent throughout, using triggers_replace to force a new evaluation when relevant data changes. The added moved blocks ensure a smooth migration of state, and the mapping from null_resource to terraform_data looks thoughtfully handled.

Key Observations

  1. terraform_data Resource Semantics: The terraform_data resource is designed for ephemeral data or orchestration placeholders. Using it as a direct replacement for null_resource is valid, and the usage looks consistent with typical patterns of triggers and provisioning logic.
  2. State & Orchestration: You are storing some relatively large sets of triggers (like checksums) in yamlencode(...). That is typical for null_resource migrations but keep in mind that changes in large dynamic strings can lead to more frequent replacements. This is expected, but be sure that is the intended orchestration flow.
  3. Use of Moved Blocks: Excellent approach to preserve state (moved { from = null_resource.foo to = terraform_data.foo }) so existing resources do not get recreated inadvertently.
  4. No Obvious Performance or Security Gaps: The code remains consistent with prior state. The references to sets, triggers, and inline provisioning look properly aligned.

Recommendation: The changes look good overall. Great work on systematically replacing these resources!

@mysticaltech
Copy link
Collaborator

I'm ready to merge when you are, let me know @janfrederik

@janfrederik
Copy link
Contributor Author

I'm ready to merge when you are, let me know @janfrederik

Hi @mysticaltech
I just updated with the latest code from main and fixed a null_resource that I had forgotten.

Still waiting for the release of opentofu 1.10 with the support for moving null_resource to terraform_data. The code has already been committed to opentofu's main branch (see PR opentofu/opentofu#2481), so now we just need a little patience for the release.

@mysticaltech
Copy link
Collaborator

Ok wonderful, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants