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

import: add support for import blocks in Terraform 1.5+ #623

Merged
merged 1 commit into from
Oct 26, 2023

Conversation

jacobbednarz
Copy link
Member

@jacobbednarz jacobbednarz commented Oct 26, 2023

In Terraform 1.5+, there is now the option to import resources using a HCL block alongside your resources code. This commit updates the import command to support that conditional generation if the —modern-import-block flag is used.

CLI compatible output

terraform import cloudflare_ruleset.terraform_managed_resource_c311c194ead8414c985c44eb4710d435 zone/0d555506aec9767e661a2e19e6d4e711/c311c194ead8414c985c44eb4710d435
terraform import cloudflare_ruleset.terraform_managed_resource_64a2203f3c0246bebc2f39b886d54982 zone/0d555506aec9767e661a2e19e6d4e711/64a2203f3c0246bebc2f39b886d54982

HCL block import output

import {
  to = cloudflare_ruleset.terraform_managed_resource_c311c194ead8414c985c44eb4710d435
  id = "zone/0d555506aec9767e661a2e19e6d4e711/c311c194ead8414c985c44eb4710d435"
}

import {
  to = cloudflare_ruleset.terraform_managed_resource_64a2203f3c0246bebc2f39b886d54982
  id = "zone/0d555506aec9767e661a2e19e6d4e711/64a2203f3c0246bebc2f39b886d54982"
}

In Terraform 1.5+, there is now the option to import resources using a
HCL block alongside your resources code[1]. This commit updates the
`import` command to support that conditional generation if the
`—modern-import-block` flag is used.

CLI compatible output

```
terraform import cloudflare_ruleset.terraform_managed_resource_c311c194ead8414c985c44eb4710d435 zone/0d555506aec9767e661a2e19e6d4e711/c311c194ead8414c985c44eb4710d435
terraform import cloudflare_ruleset.terraform_managed_resource_64a2203f3c0246bebc2f39b886d54982 zone/0d555506aec9767e661a2e19e6d4e711/64a2203f3c0246bebc2f39b886d54982
```

HCL block import output

```
import {
  to = cloudflare_ruleset.terraform_managed_resource_c311c194ead8414c985c44eb4710d435
  id = "zone/0d555506aec9767e661a2e19e6d4e711/c311c194ead8414c985c44eb4710d435"
}

import {
  to = cloudflare_ruleset.terraform_managed_resource_64a2203f3c0246bebc2f39b886d54982
  id = "zone/0d555506aec9767e661a2e19e6d4e711/64a2203f3c0246bebc2f39b886d54982"
}
```

[1]: https://developer.hashicorp.com/terraform/language/import
@jafowler jafowler self-requested a review October 26, 2023 14:58
@jacobbednarz jacobbednarz merged commit 86c85c7 into master Oct 26, 2023
6 checks passed
@jacobbednarz jacobbednarz deleted the support-tf-1.5-import-blocks branch October 26, 2023 18:59
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