Commit Graph

28 Commits

Author SHA1 Message Date
James Nugent 074545e536 core: Use .% instead of .# for maps in state
The flatmapped representation of state prior to this commit encoded maps
and lists (and therefore by extension, sets) with a key corresponding to
the number of elements, or the unknown variable indicator under a .# key
and then individual items. For example, the list ["a", "b", "c"] would
have been encoded as:

    listname.# = 3
    listname.0 = "a"
    listname.1 = "b"
    listname.2 = "c"

And the map {"key1": "value1", "key2", "value2"} would have been encoded
as:

    mapname.# = 2
    mapname.key1 = "value1"
    mapname.key2 = "value2"

Sets use the hash code as the key - for example a set with a (fictional)
hashcode calculation may look like:

    setname.# = 2
    setname.12312512 = "value1"
    setname.56345233 = "value2"

Prior to the work done to extend the type system, this was sufficient
since the internal representation of these was effectively the same.
However, following the separation of maps and lists into distinct
first-class types, this encoding presents a problem: given a state file,
it is impossible to tell the encoding of an empty list and an empty map
apart. This presents problems for the type checker during interpolation,
as many interpolation functions will operate on only one of these two
structures.

This commit therefore changes the representation in state of maps to use
a "%" as the key for the number of elements. Consequently the map above
will now be encoded as:

    mapname.% = 2
    mapname.key1 = "value1"
    mapname.key2 = "value2"

This has the effect of an empty list (or set) now being encoded as:

    listname.# = 0

And an empty map now being encoded as:

    mapname.% = 0

Therefore we can eliminate some nasty guessing logic from the resource
variable supplier for interpolation, at the cost of having to migrate
state up front (to follow in a subsequent commit).

In order to reduce the number of potential situations in which resources
would be "forced new", we continue to accept "#" as the count key when
reading maps via helper/schema. There is no situation under which we can
allow "#" as an actual map key in any case, as it would not be
distinguishable from a list or set in state.
2016-06-09 10:49:42 +01:00
Martin Atkins 6a468dcd83 helper/schema: Resource can be writable or not
In the "schema" layer a Resource is just any "thing" that has a schema
and supports some or all of the CRUD operations. Data sources introduce
a new use of Resource to represent read-only resources, which require
some different InternalValidate logic.
2016-05-14 08:26:36 -07:00
Mitchell Hashimoto b728e55861
helper/schema: Resource.Data should set latest schema version 2016-05-11 13:02:36 -07:00
Mitchell Hashimoto b8121ea63e
helper/schema: Resource.Data to return a ResourceData for a Resource 2016-05-11 13:02:30 -07:00
Radek Simko 4c6ceef9b8 helper/schema: Allow identification of a new resource in update func 2015-12-27 14:01:03 +01:00
Panagiotis Moustafellos e4845f75cc removed extra parentheses 2015-10-08 15:48:04 +03:00
Radek Simko 641b701830 schema: Make validation more strict 2015-10-03 14:29:19 -07:00
Paul Hinze 7eb72e7a12 helper/schema: record schema version when destroy fails
This was just a missed exit from the resource.Apply function -
subsequent refreshes would add the SchemaVersion back into the state,
but having the state recorded once without the meta information can
cause problems with Atlas's remote state checksumming.
2015-08-03 15:53:15 -05:00
Mitchell Hashimoto dd24ed4b76 helper/schema: blank ID refresh doesn't exist [GH-1905] 2015-05-13 20:15:13 -07:00
Justin Campbell bb14bfa657 helper/schema: call InternalValidate w/ schemaMap{} 2015-05-12 11:01:08 -04:00
Paul Hinze 3ba8ed536b helper/schema: record schema version on apply
We were previously only recording the schema version on refresh. This
caused the state to be incorrectly written after a `terraform apply`
causing subsequent commands to run the state through an unnecessary
migration.
2015-03-18 19:08:48 -05:00
Paul Hinze 3d4b55e557 helper/schema: schema versioning & migration
Providers get a per-resource SchemaVersion integer that they can bump
when a resource's schema changes format. Each InstanceState with an
older recorded SchemaVersion than the cureent one is yielded to a
`MigrateSchema` function to be transformed such that it can be addressed
by the current version of the resource's Schema.
2015-03-06 16:26:11 -06:00
Mitchell Hashimoto 466a54cfe4 Merge pull request #766 from hashicorp/f-exists-api
helper/schema: Exists API
2015-01-16 10:56:25 -08:00
Mitchell Hashimoto 448887f3c4 helper/schema: map counts in state 2015-01-15 14:12:24 -08:00
Mitchell Hashimoto 48b9614556 helper/schema: Exists API 2015-01-10 15:39:29 -08:00
Mitchell Hashimoto d0ce67a5b7 helper/schema: on destroy/create, reset state to be empty [GH-464] 2014-10-21 00:28:53 -07:00
Mitchell Hashimoto 9b2b3a963f ResourceDiff => InstanceDiff 2014-09-17 16:33:24 -07:00
Mitchell Hashimoto 81d9d70296 helper/schema: conforms to new API, tests pass 2014-09-16 17:07:13 -07:00
Mitchell Hashimoto 5fc41cc272 helper/schema: properly put "id" into attributes 2014-08-20 10:38:51 -07:00
Mitchell Hashimoto 021a23fe99 helper/schema: if update sets the ID to blank, it deletes the resource 2014-08-20 10:38:51 -07:00
Mitchell Hashimoto 2444986fe8 helper/schema: nice error if update isn't supported 2014-08-19 09:26:48 -07:00
Mitchell Hashimoto c418681cc3 helper/schema: create/update/delete should work for Resource 2014-08-17 20:20:11 -07:00
Mitchell Hashimoto 894187ec18 helper/schema: Resource.Refresh 2014-08-17 19:45:26 -07:00
Mitchell Hashimoto 51a44db6c2 helper/schema: move InternalValidate to schemaMap 2014-08-17 14:50:44 -07:00
Mitchell Hashimoto a33e4bcdf0 helper/schema: properly validate sub-resources 2014-08-17 14:33:54 -07:00
Mitchell Hashimoto 7bc0be4b81 helper/schema: couple more tests around Computed (+ fix) 2014-08-16 09:49:22 -07:00
Mitchell Hashimoto 7f14708e71 helper/schema: list ForceNew 2014-08-14 23:32:20 -07:00
Mitchell Hashimoto 01b6b5f48e helper/schema: initial work 2014-08-13 14:23:22 -07:00