Skip to content

Commit

Permalink
test(hcl2cdk): document unsupported case of [] property access
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMSchmidt committed Jul 7, 2021
1 parent 5864857 commit d1dbf7b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
6 changes: 6 additions & 0 deletions packages/@cdktf/hcl2cdk/lib/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ export function extractReferencesFromExpression(
return carry;
}

// unsupported references
if (spot.includes("[")) {
throw new Error(
`Unsupported Terraform feature found: property access through foo.bar["xyz"] is not yet supported`
);
}
const referenceParts = spot.split(".");

const corespondingNodeId = nodeIds.find((id) => {
Expand Down
24 changes: 20 additions & 4 deletions packages/@cdktf/hcl2cdk/test/__snapshots__/hcl2cdk.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,14 @@ new DockerProvider(this, \\"docker\\", new Struct { });"

exports[`convert csharp errors on count loops 1`] = `"Unsupported Terraform feature found: for-each loops are not yet supported: {\\"count\\":\\"\${length(var.users)}\\",\\"name\\":\\"\${element(var.users, count.index)}\\",\\"path\\":\\"/system/\\",\\"tags\\":{\\"tag-key\\":\\"tag-value\\"}}"`;

exports[`convert csharp errors on dynamic blocks 1`] = `"Found a reference that is unknown: \${setting.value[\\"name\\"]} was not found in [\\"var.settings\\",\\"aws_elastic_beanstalk_environment.tfenvtest\\"]"`;
exports[`convert csharp errors on dynamic blocks 1`] = `"Unsupported Terraform feature found: property access through foo.bar[\\"xyz\\"] is not yet supported"`;

exports[`convert csharp errors on for_each loops 1`] = `"Unsupported Terraform feature found: for-each loops are not yet supported: {\\"for_each\\":\\"\${var.users}\\",\\"name\\":\\"\${each.key}\\",\\"path\\":\\"/system/\\",\\"tags\\":{\\"tag-key\\":\\"tag-value\\"}}"`;

exports[`convert csharp errors on list access through [] 1`] = `"Unsupported Terraform feature found: property access through foo.bar[\\"xyz\\"] is not yet supported"`;

exports[`convert csharp errors on property access through [] 1`] = `"Unsupported Terraform feature found: property access through foo.bar[\\"xyz\\"] is not yet supported"`;

exports[`convert csharp errors on provider alias 1`] = `"Unsupported Terraform feature found at \\"aws2\\": provider alias are not yet supported"`;

exports[`convert csharp errors on resource references with lists 1`] = `"Unsupported Terraform feature found: Splat operations (resource.name.*.property) are not yet supported: \${aws_s3_bucket.examplebucket.*.id}"`;
Expand Down Expand Up @@ -455,10 +459,14 @@ DockerProvider.Builder.create(this, \\"docker\\").build();"

exports[`convert java errors on count loops 1`] = `"Unsupported Terraform feature found: for-each loops are not yet supported: {\\"count\\":\\"\${length(var.users)}\\",\\"name\\":\\"\${element(var.users, count.index)}\\",\\"path\\":\\"/system/\\",\\"tags\\":{\\"tag-key\\":\\"tag-value\\"}}"`;

exports[`convert java errors on dynamic blocks 1`] = `"Found a reference that is unknown: \${setting.value[\\"name\\"]} was not found in [\\"var.settings\\",\\"aws_elastic_beanstalk_environment.tfenvtest\\"]"`;
exports[`convert java errors on dynamic blocks 1`] = `"Unsupported Terraform feature found: property access through foo.bar[\\"xyz\\"] is not yet supported"`;

exports[`convert java errors on for_each loops 1`] = `"Unsupported Terraform feature found: for-each loops are not yet supported: {\\"for_each\\":\\"\${var.users}\\",\\"name\\":\\"\${each.key}\\",\\"path\\":\\"/system/\\",\\"tags\\":{\\"tag-key\\":\\"tag-value\\"}}"`;

exports[`convert java errors on list access through [] 1`] = `"Unsupported Terraform feature found: property access through foo.bar[\\"xyz\\"] is not yet supported"`;

exports[`convert java errors on property access through [] 1`] = `"Unsupported Terraform feature found: property access through foo.bar[\\"xyz\\"] is not yet supported"`;

exports[`convert java errors on provider alias 1`] = `"Unsupported Terraform feature found at \\"aws2\\": provider alias are not yet supported"`;

exports[`convert java errors on resource references with lists 1`] = `"Unsupported Terraform feature found: Splat operations (resource.name.*.property) are not yet supported: \${aws_s3_bucket.examplebucket.*.id}"`;
Expand Down Expand Up @@ -797,10 +805,14 @@ docker.DockerProvider(self, \\"docker\\")"

exports[`convert python errors on count loops 1`] = `"Unsupported Terraform feature found: for-each loops are not yet supported: {\\"count\\":\\"\${length(var.users)}\\",\\"name\\":\\"\${element(var.users, count.index)}\\",\\"path\\":\\"/system/\\",\\"tags\\":{\\"tag-key\\":\\"tag-value\\"}}"`;

exports[`convert python errors on dynamic blocks 1`] = `"Found a reference that is unknown: \${setting.value[\\"name\\"]} was not found in [\\"var.settings\\",\\"aws_elastic_beanstalk_environment.tfenvtest\\"]"`;
exports[`convert python errors on dynamic blocks 1`] = `"Unsupported Terraform feature found: property access through foo.bar[\\"xyz\\"] is not yet supported"`;

exports[`convert python errors on for_each loops 1`] = `"Unsupported Terraform feature found: for-each loops are not yet supported: {\\"for_each\\":\\"\${var.users}\\",\\"name\\":\\"\${each.key}\\",\\"path\\":\\"/system/\\",\\"tags\\":{\\"tag-key\\":\\"tag-value\\"}}"`;

exports[`convert python errors on list access through [] 1`] = `"Unsupported Terraform feature found: property access through foo.bar[\\"xyz\\"] is not yet supported"`;

exports[`convert python errors on property access through [] 1`] = `"Unsupported Terraform feature found: property access through foo.bar[\\"xyz\\"] is not yet supported"`;

exports[`convert python errors on provider alias 1`] = `"Unsupported Terraform feature found at \\"aws2\\": provider alias are not yet supported"`;

exports[`convert python errors on resource references with lists 1`] = `"Unsupported Terraform feature found: Splat operations (resource.name.*.property) are not yet supported: \${aws_s3_bucket.examplebucket.*.id}"`;
Expand Down Expand Up @@ -1172,10 +1184,14 @@ new docker.DockerProvider(this, \\"docker\\", {});
exports[`convert typescript errors on count loops 1`] = `"Unsupported Terraform feature found: for-each loops are not yet supported: {\\"count\\":\\"\${length(var.users)}\\",\\"name\\":\\"\${element(var.users, count.index)}\\",\\"path\\":\\"/system/\\",\\"tags\\":{\\"tag-key\\":\\"tag-value\\"}}"`;
exports[`convert typescript errors on dynamic blocks 1`] = `"Found a reference that is unknown: \${setting.value[\\"name\\"]} was not found in [\\"var.settings\\",\\"aws_elastic_beanstalk_environment.tfenvtest\\"]"`;
exports[`convert typescript errors on dynamic blocks 1`] = `"Unsupported Terraform feature found: property access through foo.bar[\\"xyz\\"] is not yet supported"`;
exports[`convert typescript errors on for_each loops 1`] = `"Unsupported Terraform feature found: for-each loops are not yet supported: {\\"for_each\\":\\"\${var.users}\\",\\"name\\":\\"\${each.key}\\",\\"path\\":\\"/system/\\",\\"tags\\":{\\"tag-key\\":\\"tag-value\\"}}"`;
exports[`convert typescript errors on list access through [] 1`] = `"Unsupported Terraform feature found: property access through foo.bar[\\"xyz\\"] is not yet supported"`;
exports[`convert typescript errors on property access through [] 1`] = `"Unsupported Terraform feature found: property access through foo.bar[\\"xyz\\"] is not yet supported"`;
exports[`convert typescript errors on provider alias 1`] = `"Unsupported Terraform feature found at \\"aws2\\": provider alias are not yet supported"`;
exports[`convert typescript errors on resource references with lists 1`] = `"Unsupported Terraform feature found: Splat operations (resource.name.*.property) are not yet supported: \${aws_s3_bucket.examplebucket.*.id}"`;
Expand Down
26 changes: 26 additions & 0 deletions packages/@cdktf/hcl2cdk/test/hcl2cdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,32 @@ describe("convert", () => {
}
`,
],
[
"property access through []",
`
variable "settings" {
type = map(string)
}
resource "aws_s3_bucket" "examplebucket" {
bucket = var.settings["bucket_name"]
acl = "private"
}
`,
],
[
"list access through []",
`
variable "settings" {
type = list(map(string))
}
resource "aws_s3_bucket" "examplebucket" {
bucket = var.settings[0]["bucket_name"]
acl = "private"
}
`,
],
])("%s", async (_name, hcl) => {
expect(
convert(`file.hcl`, hcl, {
Expand Down

0 comments on commit d1dbf7b

Please sign in to comment.