Skip to content

Conversation

@gui-wf
Copy link

@gui-wf gui-wf commented Mar 20, 2025

Summary

Simplify the documentation about using cf-terraforming to generate and import some resources.

Why

With this changes, I hope to make the documentation easier to follow, more compact and to bring a bit more knowledge to the reader - simple use case for a bit of shell scripting to automate things.

How/What was done

This PR changes the explanation of importing resources to the TF state:

  • From a very repetitive and dull manual process of running multiple by-hand terraform import ... commands to saving the newline-separated output of cf-terraforming import into a file.
  • Then we instruct the reader to run the file as a shell script.

Simplify the documentation about using cf-terraforming to generate and import some resources.

With this changes, I hope to make the documentation easier to follow, more compact and to bring a bit more knowledge to the reader - simple use case for a bit of shell scripting to automate things.
@gui-wf gui-wf requested review from a team and ranbel as code owners March 20, 2025 12:49
@hyperlint-ai
Copy link
Contributor

hyperlint-ai bot commented Mar 20, 2025

Howdy and thanks for contributing to our repo. The Cloudflare team reviews new, external PRs within two (2) weeks. If it's been two weeks or longer without any movement, please tag the PR Assignees in a comment.

We review internal PRs within 1 week. If it's something urgent or has been sitting without a comment, start a thread in the Developer Docs space internally.


PR Change Summary

Improved the documentation for using cf-terraforming to streamline the process of importing resources into Terraform state.

  • Simplified the explanation of importing resources into Terraform state.
  • Introduced a method to save import commands into a shell script for easier execution.
  • Removed repetitive manual steps for importing resources.

Modified Files

  • src/content/docs/terraform/advanced-topics/import-cloudflare-resources.mdx

How can I customize these reviews?

Check out the Hyperlint AI Reviewer docs for more information on how to customize the review.

If you just want to ignore it on this PR, you can add the hyperlint-ignore label to the PR. Future changes won't trigger a Hyperlint review.

Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add hyperlint-ignore to the PR to ignore the link check for this PR.

What is Hyperlint?

Hyperlint is an AI agent that helps you write, edit, and maintain your documentation.

Learn more about the Hyperlint AI reviewer and the checks that we can run on your documentation.

@github-actions github-actions bot added the product:terraform Related to Terraform product label Mar 20, 2025
@ranbel ranbel requested a review from jacobbednarz March 20, 2025 22:09
One way to ease the process of executing all the `terraform import`, is saving the result from `cf-terraforming import ...` into a shell script file.

> **NOTE**
> You can also just let cf-terraforming output directly to stdout (standard output, your terminal) and copy and run each of the command lines that `cf-terraforming import ...` generates for you
Copy link
Contributor

Choose a reason for hiding this comment

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

there is an alternative here with --modern-import-block with will output the idempotent import blocks instead which can then live alongside your side. they look like:

import {
  to = "cloudflare_record.terraform_managed_resource_3c0b456bc2aa443089c5f40f45f51b31"
  id = "1109d899a5ff5fd74bc01e581693685b/3c0b456bc2aa443089c5f40f45f51b31"
}

full docs: https://developer.hashicorp.com/terraform/language/import

Copy link
Author

@gui-wf gui-wf Mar 21, 2025

Choose a reason for hiding this comment

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

@jacobbednarz yeah, it is an alternative. But depending on what people want to do, it might be less clean.
For the purpose of having a backup of the cloudflare settings for example.

Can I add as an alternative? And not replace entirely?

One way to ease the process of executing all the `terraform import`, is saving the result from `cf-terraforming import ...` into a shell script file.

> **NOTE**
> You can also just let cf-terraforming output directly to stdout (standard output, your terminal) and copy and run each of the command lines that `cf-terraforming import ...` generates for you
Copy link
Contributor

Choose a reason for hiding this comment

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

we should avoid words like "just" and shortened words where we can be more explicit.

Suggested change
> You can also just let cf-terraforming output directly to stdout (standard output, your terminal) and copy and run each of the command lines that `cf-terraforming import ...` generates for you
> You can also let cf-terraforming output directly to standard output in your terminal and copy and run each of the command lines that `cf-terraforming import ...` generates for you

Copy link
Author

Choose a reason for hiding this comment

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

@jacobbednarz
My intention with stdout is because it's also a word that is widely used in tools, compilers, code and Linux.
What if I flip that into "standard output (stdout)"?

```
2. Copy each `terraform import ...` command included in the output and run it. Terraform will import each resource individually into Terraform state.
This new file - `to-import.sh` - will have valid the necessary commands `terraform import ...` to import into the TF. state all the previously generated resources.
Copy link
Contributor

Choose a reason for hiding this comment

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

this sentence doesn't really read well for me. couple of stand outs:

  • don't shorten to "TF", let's use the correct names
  • we should clean up the usages of - and the period in the middle of the sentence.


When you run `cf-terraforming import ...`, you will obtain a list of `terraform import ...` commands that you must run manually afterward to import those resources into Terraform state. This is currently a manual process, but it may be automated in the future.

One way to ease the process of executing all the `terraform import`, is saving the result from `cf-terraforming import ...` into a shell script file.
Copy link
Contributor

Choose a reason for hiding this comment

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

we're getting ready to revamp this entire tutorial with the goal of less bash. i don't think we really want to be adding more right now. cc @jhutchings1

Copy link
Author

@gui-wf gui-wf Mar 21, 2025

Choose a reason for hiding this comment

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

@jacobbednarz From my recent use of cf-terraforming, I haven't found a way to not script the use of it. There is currently no way to generate all the resources with the tool in just one command. There was before an all argument that you could give to it but there is not now.
So I believe that scripting with shell script is a well known and widely accepted way of scripting simple small things vs using something like Python or other scripting languages.

Also, I think that we should have a reference to the Terraform tool's -generate-config-out argument since that also has a somewhat similar result to cf-terraforming. What do you think?

Related to this: Ruleset can't be fully generated as of yet as per this issue. The fix a person found was to import the ruleset before generating the rest of it (with the rules). So both ways, with the modern import block or the command way can be acceptable for different use cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

@gui-baeta Thanks for all your work here! We've been working on a bunch of changes around cf-terraforming recently, so this is timely. My broader question on this is whether we think there's a good reason not to default our guidance to focus on the --modern-import-block options? Asking folks to run so many bash commands seems like it adds a bit of complexity. I know I struggled with this step in my own testing.

Copy link
Author

Choose a reason for hiding this comment

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

@jhutchings1 Yeah, it can get really convoluted and confusing really quickly.
I agree.

I have been testing more throughout the day and I guess that the problem I and others detected on that cf-terraforming issue I reference, should be fixed in cf-terraforming and/or the terraform provider.
The use of shell commands, even if they are only to interact with terraform with its basic commands (in this case the import via commandline), depending on the context it can be a dirty fix to the end goal which is to be able to use cf-terraforming directly and arrive at a just works tool solution.

So, for this PR, documenting the use of --modern-import-block would be the best approach? I can do that, if that sounds good to you guys.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think documenting --modern-import-block is the most sensible approach, yes. Thank you for leaning in like you have. Really appreciate the effort you've put in here! cc: @dcpena

@ranbel ranbel removed their assignment Oct 7, 2025
@dcpena
Copy link
Collaborator

dcpena commented Oct 7, 2025

Will be closing this due to inactivity. If this work still needs to be done, I'd recommend opening a new PR to be better in sync with production.

@dcpena dcpena closed this Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:terraform Related to Terraform product size/s

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants