-
Notifications
You must be signed in to change notification settings - Fork 910
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 blocks inside child modules #1914
Comments
Hello and thank you for this issue! The core team regularly reviews new issues and discusses them, but this can take a little time. Please bear with us while we get to your issue. If you're interested, the contribution guide has a section about the decision-making process. |
Hi @rdash99 , |
I feel like the use-case is under-specified. It sounds like you're trying to create HCL that matches existing resources, then import the state for those existing resources. Yes? And the issue is too many top-level files? |
Hi, I can provide some background on our use case.
Yes, that is correct. In our case, we have a terraform module that encapsulates the creation of an AWS RDS instance together with other terraform resources. One of the options there is to export the logs to AWS Cloudwatch with this option. When used AWS creates a log group and send the logs there. The same situation happens when using AWS Lambda functions. resource "terraform_data" "log_group_retention" {
for_each = toset(data.aws_cloudwatch_log_groups.this.log_group_names)
triggers_replace = [var.retention_in_days]
provisioner "local-exec" {
command = <<EOT
aws logs put-retention-policy --log-group-name ${each.key} --retention-in-days ${var.retention_in_days}
EOT
}
provisioner "local-exec" {
when = destroy
command = "aws logs delete-log-group --log-group-name ${each.key}"
}
}
resource "terraform_data" "log_group_tags" {
for_each = toset(data.aws_cloudwatch_log_groups.this.arns)
triggers_replace = [aws_db_instance.this.tags_all]
provisioner "local-exec" {
command = "aws logs tag-resource --resource-arn ${each.key} --tags '${local.cli_tag_string}'"
}
}
No, the issue is that the functionality is encapsulated in a module and OpenTofu doesn't allow importing inside a module only at the root level. We could ask everyone using our modules to "just import" the resources but that defeats the purpose of encapsulating the functionality inside a module. Hope it helps :) |
see same terraform issue and discussion: hashicorp/terraform#33474 |
Hi, I can add some extra context from my case too. I'm using Gitops like repository, which calls local submodule ( But I also need to
Having to move the |
Hey folks, I've moved this back to the queue for the core team to discuss. |
OpenTofu Version
Use Cases
We are defining a lot of GitHub infrastructure into terraform files and want to be able to organize it into folders but also keep things tidy by having the import blocks live alongside the rest of the resource definitions rather than filling up the top level main file or adding many files in the top level directory.
Attempted Solutions
We have attempted to do this and upon running tofu init get the following:
The text was updated successfully, but these errors were encountered: