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 block: generate config within local modules #35596

Open
vazome opened this issue Aug 16, 2024 · 3 comments
Open

import block: generate config within local modules #35596

vazome opened this issue Aug 16, 2024 · 3 comments
Labels
enhancement new new issue not yet triaged

Comments

@vazome
Copy link

vazome commented Aug 16, 2024

Terraform Version

Terraform v1.9.4
on darwin_arm64
+ provider registry.terraform.io/hashicorp/azurerm v3.116.0

Terraform Configuration Files

module "azure-rg" {
  source = "./modules/azure-rg"
}

provider "azurerm" {
  features {}
  tenant_id = var.tenant_id
  subscription_id = var.subscription_id
}

import {
  to = module.azure-rg.azurerm_resource_group.rg-databricks
  id = "/../resourcegroup../"
}

Debug Output

https://gist.github.com/vazome/d639adc98c0999d0edae4abf80f4a816

Expected Behavior

Terraform creates resource configuration file for the given import

Actual Behavior

│ Error: Configuration for import target does not exist

│ on main.tf line 15, in import:
│ 15: to = module.azure-rg.azurerm_resource_group.rg-databricks

│ The configuration for the given import target module.azure-rg.azurerm_resource_group.rg-databricks does not exist. All target
│ instances must have an associated configuration to be imported.

Steps to Reproduce

terraform plan -generate-config-out=generated_resources.tf

Additional Context

This issue seems to be covered in this Japanese blog

References

No response

@vazome vazome added bug new new issue not yet triaged labels Aug 16, 2024
@vazome vazome changed the title Terraform -generate-config-out does not with modules Terraform -generate-config-out does not work with modules Aug 16, 2024
@crw
Copy link
Collaborator

crw commented Aug 16, 2024

Thanks for this report! If you are viewing this issue and would like to indicate your interest, please use the 👍 reaction on the issue description to upvote this issue. We also welcome additional use case descriptions. Thanks again!

@liamcervante liamcervante changed the title Terraform -generate-config-out does not work with modules import block: generate config within local modules Aug 19, 2024
@liamcervante
Copy link
Member

Related to #33376

@liamcervante
Copy link
Member

I've relabelled this as an enhancement instead of a bug.

There are three kinds of modules: local, registry and remote. Generating configuration for registry and remote based modules from the root module is not something that will ever be possible. It does seem possible that we could add support for generating configuration within local modules.

It's worth noting there are considerable complications with this given the -generate-config-out command points to a single file location. We'd need to update that to allow specifying the file within the local module, and then also make sure there aren't import blocks requesting configuration generation across multiple modules as the file will only be written to a single module. Potentially, the flag could support multiple file locations with a requirement that every module that wants to generate config needs to have a file included.

A workaround here would be to generate the configuration at the root level, and then move the generated configuration into the local module, before rerunning the plan command to connect the import block up to the correct module.

If you're interested in this as a feature, please give a 👍 reaction to the original comment!

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

No branches or pull requests

3 participants