pulumi / pulumi-converter-terraform

Apache License 2.0
9 stars 3 forks source link

Cannot iterate over range of type number #200

Open brandonpollack23 opened 1 day ago

brandonpollack23 commented 1 day ago
resource "public" "aws:ec2/subnet:Subnet" {
  options {
    range = createPublicSubnets && (!oneNatGatewayPerAz || lenPublicSubnets >= length(azs)) ? lenPublicSubnets : 0

  }
  assignIpv6AddressOnCreation = enableIpv6 && publicSubnetIpv6Native ? true : publicSubnetAssignIpv6AddressOnCreation
  availabilityZone            = length(notImplemented("regexall(\"^[a-z]{2}-\",element(var.azs,count.index))")) > 0 ? element(azs, range.value) : null
  availabilityZoneId          = length(notImplemented("regexall(\"^[a-z]{2}-\",element(var.azs,count.index))")) == 0 ? element(azs, range.value) : null
  cidrBlock = publicSubnetIpv6Native ? null : element(invoke("std:index:concat", {
    input = [publicSubnets, [""]]
  }).result, range.value)
  enableDns64                             = enableIpv6 && publicSubnetEnableDns64
  enableResourceNameDnsAaaaRecordOnLaunch = enableIpv6 && publicSubnetEnableResourceNameDnsAaaaRecordOnLaunch
  enableResourceNameDnsARecordOnLaunch    = !publicSubnetIpv6Native && publicSubnetEnableResourceNameDnsARecordOnLaunch
  ipv6CidrBlock = enableIpv6 && length(publicSubnetIpv6Prefixes) > 0 ? invoke("std:index:cidrsubnet", {
    input   = this[0].ipv6CidrBlock
    newbits = 8
    netnum  = publicSubnetIpv6Prefixes[range.value]
  }).result : null
  ipv6Native                     = enableIpv6 && publicSubnetIpv6Native
  mapPublicIpOnLaunch            = mapPublicIpOnLaunch
  privateDnsHostnameTypeOnLaunch = publicSubnetPrivateDnsHostnameTypeOnLaunch
  vpcId                          = vpcId
  tags                           = notImplemented("merge(\n{\nName=try(\nvar.public_subnet_names[count.index],\nformat(\"$${var.name}-$${var.public_subnet_suffix}-%s\",element(var.azs,count.index))\n)\n},\nvar.tags,\nvar.public_subnet_tags,\nlookup(var.public_subnet_tags_per_az,element(var.azs,count.index),{})\n)")
}

When trying to convert VPC to PCL, the above code has the error:

vpc_5.13.0/main.pp:97,5-115: cannot iterate over a value of type number; , and 43 other diagnostic(s);

Upon a brief investigation of VPC terraform provider, we can observe that this section of the code maps to here

This code assigns to resource field "count" not "options.range" which may be the source of the trouble.

brandonpollack23 commented 1 day ago

tf.go#L2364 contains the code which generates this, worth looking at

brandonpollack23 commented 19 hours ago

When the line is hard coded as an integer it works so something is invalid about the syntax potentially.

It does reveal that this is still blocked by #202