hashicorp / hcl2

Former temporary home for experimental new version of HCL
https://github.com/hashicorp/hcl
Mozilla Public License 2.0
373 stars 66 forks source link

Legacy numeric index syntax #17

Closed apparentlymart closed 6 years ago

apparentlymart commented 6 years ago

Due to limitations of HIL, Terraform has for a long time been supporting a weird index syntax using numeric "attributes", like data.alicloud_zones.default.zones.0.id. From HIL's perspective, that all just one long variable name with dots and digits in it.

Our expression parser currently rejects this because 0 is not a valid attribute name. Since identifiers cannot start with zero, it's safe for us to accept this as an alias for data.alicloud_zones.default.zones[0].id, though we may generate a warning in this case because that odd old form is deprecated now that we support proper attribute and index operators.

Error: Invalid attribute name

  on .terraform/init-from-module/root/alibaba-terraform-alicloud-ecs-instance-063c382/main.tf line 33:
  33:   instance_type = "${var.instance_type == "" ? data.alicloud_instance_types.default.instance_types.0.id : var.instance_type}"

An attribute name is required after a dot.
apparentlymart commented 6 years ago

This is added in 074b73b8b58cbec2cde9e8d95c38101687ea016a.

Decided not to generate a warning after all, since we're already supporting the legacy splat syntax and its associated legacy index form and this is really just a logical extension of that. It's sad to have these weird forms in the language forever, but doesn't hurt too much in practice.