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
Interpolate locals, variables etc. into import block ids #1084
Comments
Hi @simoncrowe , Thanks for raising this! This feature was in 1.6.x of terraform but not 1.5.x, this is probably why you're noticing some differences here in the errors that are reported. This change was also included in opentofu in this commit because it was committed to the terraform repository before the license change occurred and, therefore, before the point that we forked. As for the errors you have received here
I think that this error message is acceptable. It is impossible to interpolate those variables in the expression without having those resources applied.
Would you be able to provide us with the full file or a cut down reproduction to help here? I'm going to attempt to reproduce this issue now but if you had a cut down reproduction that would be extremely helpful. Thanks! |
Thanks @Yantrio I was unable to work out whether that commit was included in OpenToFu. My That said, I here is the relevant code for the locals: aws_account_id = data.aws_caller_identity.current.account_id
...
colour = var.environment == "Staging" ? var.environment : trimprefix(var.environment, "Staging")
staging_colour = var.environment == "Staging" || var.environment == "Production" || var.environment == "Development" ? "" : lower(trimprefix(var.environment, "Staging"))
...
env_type_map = {
"Production" = "production"
"Staging" = "staging"
"Development" = "development"
}
env_type = local.staging_colour != "" ? "staging" : lookup(local.env_type_map, var.environment)
...
tasks_queue_name = "${local.env_type}-${lower(local.colour)}-tasks" And the module referenced in the module "tasks_queue" {
source = "git@<REDACTED>/tf-modules.git//aws/sqs/queue?ref=r327"
name = local.tasks_queue_name
sqs_policy_doc = templatefile("${path.module}/policies/task_queue_access_policy.json.tftpl", {
queue_arn = "arn:aws:sqs:eu-west-1:${data.aws_caller_identity.current.account_id}:${local.tasks_queue_name}"
})
} Please don't go to too much effort if this isn't enough information to work with. My team would need to properly migrate the codebsase to OpenToFu before I could be confident that the |
What happens when you plan with terraform 1.6? Also it looks like local.aws_account_id depends on data.aws_caller_identity.current.account_id which may not yet be accessible? |
@cam72cam I've run the same |
Reproduced with: provider "aws" {
region = "eu-west-1"
}
variable "environment" {
type = string
}
locals {
tasks_queue_name = "myqueuoe"
aws_account_id = data.aws_caller_identity.current.account_id
colour = var.environment == "Staging" ? var.environment : trimprefix(var.environment, "Staging")
staging_colour = var.environment == "Staging" || var.environment == "Production" || var.environment == "Development" ? "" : lower(trimprefix(var.environment, "Staging"))
env_type_map = {
"Production" = "production"
"Staging" = "staging"
"Development" = "development"
}
}
data "aws_caller_identity" "current" {
}
module "tasks_queue" {
source = "./mod"
#source = "git@<REDACTED>/tf-modules.git//aws/sqs/queue?ref=r327"
name = local.tasks_queue_name
sqs_policy_doc = "nop" /*templatefile("${path.module}/policies/task_queue_access_policy.json.tftpl", {
queue_arn = "arn:aws:sqs:eu-west-1:${data.aws_caller_identity.current.account_id}:${local.tasks_queue_name}"
})*/
}
import {
to = module.tasks_queue.aws_sqs_queue.this
id = "https://sqs.eu-west-1.amazonaws.com/${local.aws_account_id}/${local.tasks_queue_name}"
} mod/mod.tf variable "name" {
type = string
}
variable "sqs_policy_doc" {
type = string
}
resource "aws_sqs_queue" "this" {
} |
OpenTofu Version
Use Cases
I've been testing whether opentofu has the feature added to terraform in this PR.
Based on what I've attempted, although the error messages are different to those output by
terraform
1.5.6, it does not seem that interplating variables intoimport
block ids works inopentofu
.Here are few use cases I can think of:
Attempted Solutions
Terrafrom code
Output (to be clear, both
aws_account_id
andtasks_queue_name
are declared as locals in the same module as the code snippet above so maybe they are somehow not in scope).Proposal
Make it possible to interpolate variables, locals, outputs and data sources within
import
block ids so that they are dynamic.References
No response
The text was updated successfully, but these errors were encountered: