Skip to content

show relevant expression rather than (source code not available) for CLI argument diagnostics #36853

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

Open
EugenKon opened this issue Apr 4, 2025 · 3 comments
Labels
enhancement new new issue not yet triaged

Comments

@EugenKon
Copy link

EugenKon commented Apr 4, 2025

Terraform Version

v1.11.3

Use Cases

moving resources between different names

Attempted Solutions


  # module.private-cloud.aws_acm_certificate.acm-ssl will be destroyed
  # module.private-cloud.aws_acm_certificate_validation.acm-ssl will be destroyed
  # module.private-cloud.aws_route53_record.acm-ssl-validation["sandbox"] will be destroyed
  # module.private-cloud.module.ssl[0].aws_acm_certificate.acm-ssl will be created
  # module.private-cloud.module.ssl[0].aws_acm_certificate_validation.acm-ssl will be created
  # module.private-cloud.module.ssl[0].aws_route53_record.acm-ssl-validation["sandbox"] will be created

ek-mac@job sandbox $ terraform state mv -state=./state.d/terraform.tfstate module.private-cloud.aws_acm_certificate.acm-ssl module.private-cloud.module.ssl[0].aws_acm_certificate.acm-ssl
Move "module.private-cloud.aws_acm_certificate.acm-ssl" to "module.private-cloud.module.ssl[0].aws_acm_certificate.acm-ssl"
Successfully moved 1 object(s).

ek-mac@job sandbox $ terraform state mv -state=./state.d/terraform.tfstate  module.private-cloud.aws_acm_certificate_validation.acm-ssl module.private-cloud.module.ssl[0].aws_acm_certificate_validation.acm-ssl
Move "module.private-cloud.aws_acm_certificate_validation.acm-ssl" to "module.private-cloud.module.ssl[0].aws_acm_certificate_validation.acm-ssl"
Successfully moved 1 object(s).

ek-mac@job sandbox $ terraform state mv -state=./state.d/terraform.tfstate  module.private-cloud.aws_route53_record.acm-ssl-validation["sandbox"] module.private-cloud.module.ssl[0].aws_route53_record.acm-ssl-validation["sandbox"]
╷
│ Error: Index value required
│
│   on  line 1:
│   (source code not available)
│
│ Index brackets must contain either a literal number or a literal string.
╵

╷
│ Error: Index value required
│
│   on  line 1:
│   (source code not available)
│
│ Index brackets must contain either a literal number or a literal string.
╵

Configuration:

resource "aws_route53_record" "acm-ssl-validation" {
  for_each = {
    for dvo in aws_acm_certificate.acm-ssl.domain_validation_options : dvo.domain_name => {
      zone_id = lookup(local.hostedzone_ids, dvo.domain_name, data.aws_route53_zone.zones[0].zone_id)
      name    = dvo.resource_record_name
      type    = dvo.resource_record_type
      record  = dvo.resource_record_value
    }
    if !startswith(dvo.domain_name, "*.")
  }

  zone_id = each.value.zone_id
  name    = each.value.name
  type    = each.value.type
  records = [each.value.record]
  ttl     = 60
}

resource "aws_acm_certificate_validation" "acm-ssl" {
  certificate_arn         = aws_acm_certificate.acm-ssl.arn
  validation_record_fqdns = [for record in aws_route53_record.acm-ssl-validation : record.fqdn]
}

Proposal

It is not clear what is going on from the first sight. Probably terraform should not require ".

Here the problem was that bash eats ". When I put my resource name into 'xxx["yyyy"]' then it works well.

as source TF could display this module.private-cloud.module.ssl[0].aws_route53_record.acm-ssl-validation[sandbox]

References

No response

@EugenKon EugenKon added enhancement new new issue not yet triaged labels Apr 4, 2025
@jbardin
Copy link
Member

jbardin commented Apr 4, 2025

You are not quoting your command line arguments properly. The error from terraform is going to be confusing, because you are passing confusing data into terraform.

Here the problem was that bash eats ". When I put my resource name into 'xxx["yyyy"]' then it works well.

Yes, those quotes are an important part of the syntax, and you need to escape them on the command line, though how you do that is dependent on the shell you are using.

@jbardin jbardin closed this as not planned Won't fix, can't repro, duplicate, stale Apr 4, 2025
@EugenKon
Copy link
Author

EugenKon commented Apr 4, 2025

@jbardin Please look at it more carefully.

TF displayes:

│   (source code not available)

My proposition:

as source TF could display this module.private-cloud.module.ssl[0].aws_route53_record.acm-ssl-validation[sandbox]

As far as I can see this would be not so complex to display what TF received on its command arguments.

@jbardin jbardin changed the title Improve error message: show relevant expression rather than (source code not available) for CLI argument diagnostics Apr 4, 2025
@jbardin
Copy link
Member

jbardin commented Apr 4, 2025

I have an issue, somewhere, to work on improving the (source code not available) situation, but we can use this issue to represent that change for now. It's not quite as easy as it seems, because the HCL language which the resource address is a part of is not defined or parsed by Terraform, so the error is generated in a context outside of our control. I think it may be possible to create a "fake source code" body which would get returned in that diagnostic.

@jbardin jbardin reopened this Apr 4, 2025
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

2 participants