terraform/configs/configupgrade/test-fixtures/valid
Martin Atkins fa0d6484df configs/configupgrade: Detect and fix element(...) usage with sets
Although sets do not have indexed elements, in Terraform 0.11 and earlier
element(...) would work with sets because we'd automatically convert them
to lists on entry to HIL -- with an arbitrary-but-consistent ordering --
and this return an arbitrary-but-consistent element from the list.

The element(...) function in Terraform 0.12 does not allow this because it
is not safe in general, but there was an existing pattern relying on this
in Terraform 0.11 configs which this upgrade rule is intended to preserve:

    resource "example" "example" {
      count = "${length(any_set_attribute)}"

      foo = "${element(any_set_attribute, count.index}"
    }

The above works because the exact indices assigned in the conversion are
irrelevant: we're just asking Terraform to create one resource for each
distinct element in the set.

This upgrade rule therefore inserts an explicit conversion to list if it
is able to successfully provide that the given expression will return a
set type:

    foo = "${element(tolist(any_set_attribute), count.index}"

This makes the conversion explicit, allowing users to decide if it is
safe and rework the configuration if not. Since our static type analysis
functionality focuses mainly on resource type attributes, in practice this
rule will only apply when the given expression is a statically-checkable
resource reference. Since sets are an SDK-only concept in Terraform 0.11
and earlier anyway, in practice that works out just right: it's not
possible for sets to appear anywhere else in older versions anyway.
2019-02-21 09:39:55 -08:00
..
argument-commas configs/configupgrade: Test for removing commas between block arguments 2019-02-20 16:11:14 -08:00
block-as-list-attr configs/configupgrade: Upgrading of simple nested blocks 2018-12-04 11:37:39 -08:00
block-as-list-dynamic configs/configupgrade: Convert block-as-attr to dynamic blocks 2018-12-04 11:37:39 -08:00
block-as-list-dynamic-item configs/configupgrade: Convert block-as-attr to dynamic blocks 2018-12-04 11:37:39 -08:00
block-as-list-dynamic-nested configs/configupgrade: Convert block-as-attr to dynamic blocks 2018-12-04 11:37:39 -08:00
block-as-map-attr configs/configupgrade: Upgrading of simple nested blocks 2018-12-04 11:37:39 -08:00
depends-on configs/configupgrade: Upgrade depends_on in resources and outputs 2018-12-05 10:25:01 -08:00
element-of-set configs/configupgrade: Detect and fix element(...) usage with sets 2019-02-21 09:39:55 -08:00
funcs-replaced configs/configupgrade: Fix up internal HIL conversion functions 2019-02-20 14:01:53 -08:00
hash-of-file lang: New file-hashing functions 2019-01-25 10:18:44 -08:00
heredoc-flush configs/configupgrade: upgrade expressions inside heredocs 2019-02-20 12:56:44 -08:00
heredoc-no-interp configs/configupgrade: upgrade expressions inside heredocs 2019-02-20 12:56:44 -08:00
heredoc-sameline configs/configupgrade: upgrade expressions inside heredocs 2019-02-20 12:56:44 -08:00
heredoc-standard configs/configupgrade: upgrade expressions inside heredocs 2019-02-20 12:56:44 -08:00
ignore-changes-flatmap-colls configs/configupgrade: Silently ignore and trim .% .# in ignore_changes 2019-02-20 15:58:44 -08:00
interp-naked configupgrade: Basic expression formatting 2018-10-16 18:50:29 -07:00
lifecycle configs/configupgrade: Upgrade the resource "lifecycle" nested block 2018-12-05 10:25:01 -08:00
map-attr-as-block configs/configupgrade: Test that map attrs as blocks are fixed 2018-12-04 11:37:39 -08:00
nested-exprs-in-hcl configs/configupgrade: Upgrade expressions nested in HCL list/object 2018-12-04 11:37:39 -08:00
noop configs/configupgrade: Pass through connection and provisioner blocks 2018-12-05 10:25:01 -08:00
noop-exprs configupgrade: Basic expression formatting 2018-10-16 18:50:29 -07:00
provider-addrs configs/configupgrade: Upgrade provider addresses 2018-12-05 10:25:01 -08:00
redundant-list configs/configupgrade: Remove redundant list brackets 2018-12-07 17:05:36 -08:00
rename-json configupgrade: Basic expression formatting 2018-10-16 18:50:29 -07:00
rename-json-conflict configupgrade: Basic expression formatting 2018-10-16 18:50:29 -07:00
traversals configs/configupgrade: Fix up references to counted/uncounted resources 2018-12-04 11:37:39 -08:00
variable-type configupgrade: Basic expression formatting 2018-10-16 18:50:29 -07:00