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

Attempting conversion containing for_each with primitives fails #228

Open
smithrobs opened this issue Nov 26, 2024 · 0 comments
Open

Attempting conversion containing for_each with primitives fails #228

smithrobs opened this issue Nov 26, 2024 · 0 comments
Labels
kind/bug Some behavior is incorrect or out of spec

Comments

@smithrobs
Copy link

What happened?

The pulumi convert --from terraform --language python command does not work for terraform for-loops that have primitives. For example for_each = var.enable ? [1] : [] which we typically do for dynamic blocks such as S3 lifecycle rules which has to be defined in a single resource (ref). The error message is:

error: main.pp:7,40-75: cannot traverse value of type number;
error: main.pp:7,40-75: cannot traverse value of type union(cty.NumberIntVal(1), none);
error: could not generate output program

Example

resource "aws_s3_bucket_lifecycle_configuration" "this" {
  count  = length(var.expirations) > 0 || length(var.transitions) > 0 || length(var.noncurrent_version_transitions) > 0 ? 1 : 0
  bucket = aws_s3_bucket.this.id
  
  # There are some other dynamic rule blocks i have omitted

  dynamic "rule" {
    for_each = var.transitions
    content {
      status = try(rule.value.enabled, true) ? "Enabled" : "Disabled"
      id     = try(rule.value.id, md5("transitions${jsonencode(rule.value)}"))
      dynamic "abort_incomplete_multipart_upload" {
        # following line will fail to convert
        for_each = try(rule.value.abort_incomplete_multipart_upload_days, null) != null ? [1] : []
        content {
          days_after_initiation = rule.value.abort_incomplete_multipart_upload_days
        }
      }
      filter {
        prefix = try(rule.value.prefix, "")
        dynamic "tag" {
          for_each = try(jsondecode(rule.value.tags), [])
          content {
            key   = try(tag.key, null)
            value = try(tag.value, null)
          }
        }
      }
      transition {
        date          = try(rule.value.date, null)
        days          = try(rule.value.days, null)
        storage_class = rule.value.storage_class
      }
    }
  }
}

Output of pulumi about

Not available; assume v3.141.0

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@smithrobs smithrobs added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Nov 26, 2024
@justinvp justinvp removed the needs-triage Needs attention from the triage team label Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Some behavior is incorrect or out of spec
Projects
None yet
Development

No branches or pull requests

2 participants