iann0036 / hcl2cdktf

Converts HCL to Terraform CDK
MIT License
40 stars 4 forks source link

Order resources by usage of references #7

Open skorfmann opened 4 years ago

skorfmann commented 4 years ago

When a resource A is referenced in another resource B, resource A should be rendered first.

That's how it's generated:

// ...
      origin: [{
          domainName: b.bucketRegionalDomainName!,
          originId: s3_origin_id!,
          s3OriginConfig: [{
              originAccessIdentity: "origin-access-identity/cloudfront/ABCDEFG1234567"
          }]
      }],

// ...

  const b = new S3Bucket(this, 'b', {
    acl: "private",
    bucket: "mybucket",
    tags: {
        Name: "My bucket"
    }
});

That's how it should be

  const b = new S3Bucket(this, 'b', {
    acl: "private",
    bucket: "mybucket",
    tags: {
        Name: "My bucket"
    }
});

// ...
      origin: [{
          domainName: b.bucketRegionalDomainName!,
          originId: s3_origin_id!,
          s3OriginConfig: [{
              originAccessIdentity: "origin-access-identity/cloudfront/ABCDEFG1234567"
          }]
      }],
iann0036 commented 4 years ago

A half-measure in place with d7bb111ef796705ee5adc23b6e81cfe415159f21 is that if the reference hasn't previously been seen, it'll fall back into "${}" syntax. There's some complexity around circular references that need to be thought through before fixing this perfectly (I ran into the same in Former2).