Commit Graph

22782 Commits

Author SHA1 Message Date
Sander van Harmelen
48ef7ecfa6 Updates after running make fmt with Go v1.11.1 2018-10-17 14:11:08 -07:00
Brian Flad
02e135bac8
Merge pull request #19102 from hashicorp/v-helper-validation-All-IntInSlice
helper/validation: Add All() and IntInSlice() SchemaValidateFunc
2018-10-17 14:39:03 -04:00
Brian Flad
17ac9a5756
helper/validation: Add All() and IntInSlice() SchemaValidateFunc
`All()` combines the outputs of multiple `SchemaValidateFunc`, to reduce the usage of custom validation functions that implement standard validation functions.

Example provider usage:

```go
ValidateFunc: validation.All(
  StringLenBetween(5, 42),
  StringMatch(regexp.MustCompile(`[a-zA-Z0-9]+`), "value must be alphanumeric"),
),
```

`IntInSlice()` is the `int` equivalent of `StringInSlice()`

Example provider usage:

```go
ValidateFunc: validation.IntInSlice([]int{30, 60, 120})
```

Output from unit testing:

```
$ make test TEST=./helper/validation
==> Checking that code complies with gofmt requirements...
go generate ./...
2018/10/17 14:16:03 Generated command/internal_plugin_list.go
go list ./helper/validation | xargs -t -n4 go test  -timeout=2m -parallel=4
go test -timeout=2m -parallel=4 github.com/hashicorp/terraform/helper/validation
ok  	github.com/hashicorp/terraform/helper/validation	1.106s
```
2018-10-17 14:22:29 -04:00
James Bardin
9143cb5b49
Merge pull request #19101 from hashicorp/jbardin/resource-tests
helper/resource tests
2018-10-17 13:10:38 -04:00
James Bardin
9c2f3ebe17
Merge pull request #19100 from hashicorp/jbardin/command-tests
Backend config and command tests
2018-10-17 13:10:21 -04:00
James Bardin
1ab96f42b7 fail nonfunctional resource tests
The helper/resource unit tests will panic, because they were using the
legacy terraform.MockResourceProvider, which doesn't have the same
internals required by the new GRPC shims.

Fail these tests for now, and a new test provider will need to be made
out of a schema.Provider instance.
2018-10-17 12:51:07 -04:00
James Bardin
3a0c2f1b67 close grpc TestListener 2018-10-17 12:13:59 -04:00
James Bardin
fe9ed37dfc minor fixes for command Apply tests 2018-10-17 09:42:15 -04:00
James Bardin
d707049f72 don't make a backup of a nil state
This makes sure we don't create a backup of an intermediate state if the
first read state was empty.
2018-10-17 09:42:08 -04:00
James Bardin
0a0eece15c add backend cli options after configuration
The cli should override the config
2018-10-17 09:41:58 -04:00
Radek Simko
edaa4bbc82
lang: Add fileexists function 2018-10-17 10:18:07 +01:00
Martin Atkins
86e6481cc6 Merge v0.12 development so far
The master branch is now tracking towards the v0.12 release.
2018-10-16 19:52:24 -07:00
Martin Atkins
541952bb8f Revert some work that happened since v0.12-dev branched
This work was done against APIs that were already changed in the branch
before work began, and so it doesn't apply to the v0.12 development work.

To allow v0.12 to merge down to master, we'll revert this work out for now
and then re-introduce equivalent functionality in later commits that works
against the new APIs.
2018-10-16 19:48:28 -07:00
Martin Atkins
fd77765154 vendor: make some transitive dependencies line up better
After a bunch of recent changes/rebasing our vendored dependencies got a
little out of sync w.r.t transitive dependencies through codebases that
are not themselves Go Modules yet.
2018-10-16 19:14:54 -07:00
Martin Atkins
e25f79ed28 plugin/convert: Show approximate location context for all provider errors
Even if a provider doesn't indicate a specific attribute as the cause of
a resource operation error, we know the error relates to some aspect of
the resource, so we'll include that approximate information in the result
so that we don't produce user-hostile error messages with no context
whatsoever.

Later we can hopefully refine this to place the source range on the header
of the configuration block rather than on an empty part of the body, but
that'll require some more complex rework here and so for now we'll just
accept this as an interim state so that the user can at least figure out
which resource block the error is coming from.
2018-10-16 19:14:54 -07:00
Kristin Laemmert
fd77e56fd6 lookup will return a tuple type when passed an object 2018-10-16 19:14:54 -07:00
Kristin Laemmert
f54ee830d3 lang/funcs: update values to accept object types 2018-10-16 19:14:54 -07:00
Kristin Laemmert
4ec904bca7 funcs/lang lookup: validate that argument is map or object type 2018-10-16 19:14:54 -07:00
Martin Atkins
c06f24b323 core: Use hcl2shimConfigValueFromHCL2Block when shimming ResourceConfig
This ensures more HCL1/HIL-like behaviors when dealing with nested blocks
that are not set in the configuration, which is important for
compatibility with helper/schema's validation logic.
2018-10-16 19:14:54 -07:00
Kristin Laemmert
d1d0ede069 lang/funcs: return default value if provided when object lookup fails to find attr 2018-10-16 19:14:54 -07:00
Martin Atkins
93630cf95f config/hcl2shim: ConfigValueFromHCL2Block function
This is a more specialized version of ConfigValueFromHCL2 which is
specifically for config values that represent the content of a block
body in the configuration.

By using the schema of that block we can more precisely emulate the old
HCL1/HIL behaviors by distinguishing attributes from blocks and applying
some slightly different behaviors for the handling of null values and
of empty collections that are representing the absense of blocks of a
particular type.
2018-10-16 19:14:54 -07:00
Kristin Laemmert
46e168a682 lang/funcs: update lookup() to accept object-typed values for "map" arg 2018-10-16 19:14:54 -07:00
James Bardin
5303137b8c udpate test configs to work with hcl2
The last 2 broken tests will be hanlded later
2018-10-16 19:14:54 -07:00
James Bardin
38163f2b37 use SimpleDiff and set "id" as RequiresReplace
Use the new SimpleDiff method of the provider so that the diff isn't
altered by ForceNew attributes.

Always set an "id" as RequiresReplace so core knows an instance will be
replaced, even if all ForceNew attributes are filtered out due to
ignore_changes.
2018-10-16 19:14:54 -07:00
Martin Atkins
72a7947cb7 state/remote: Un-stub TestStateRace
The underlying bug that was causing this test to hang has since been
fixed.
2018-10-16 19:14:54 -07:00
Martin Atkins
3eaf2c308d plugin/discovery: Use mockos_mockarch when testing installation
If we don't override these then the tests can only pass on one platform.
2018-10-16 19:14:54 -07:00
Martin Atkins
8e51363f04 command: Don't allow -var and -var-file when applying saved plan
This reinstates an old behavior that was lost in the reorganization of how
we deal with the -var and -var-file options.

This fix is verified by TestApply_planVars now passing.
2018-10-16 19:14:11 -07:00
Martin Atkins
7abf81d8da command: Restore support for terraform.tfvars.json
In the new implementation of collecting variables I initially forgot the
JSON variant of terraform.tfvars.

This fix is verified by TestApply_varFileDefaultJSON now passing.
2018-10-16 19:14:11 -07:00
James Bardin
46b4c27dbe create a SimpleDiff for the new provider shims
Terraform now handles any actual "diffing" of resource, and the existing
Diff functions are only used to shim the schema.Provider to the new
methods. Since terraform is handling what used to be the Diff, the
provider now should not modify the diff based on RequiresNew due to it
interfering with the ignore_changes handling.
2018-10-16 19:14:11 -07:00
James Bardin
0d4d572c39 start work on helper/resource test fixtures
The helper resource tests won't pass for now, as they use a
terraform.MockProvider which can't be used in the schema.Provider shims.
2018-10-16 19:14:11 -07:00
James Bardin
f8b1a3c7a4 make sure apply can properly destroy
We need to ensure that a destroyed value is returned as such from apply
2018-10-16 19:14:11 -07:00
James Bardin
3b6deef296 reset plan changes every call to Plan.
Tests often call Plan multiple times on the same context to verify there
are no changes, so we need to make sure changes don't accumulate.
2018-10-16 19:14:11 -07:00
James Bardin
b3fed27dbf export MustShimLegacyState for resource tests
We also need to convert legacy states for helper resource tests.
2018-10-16 19:14:11 -07:00
Martin Atkins
c990c9f36d lang/funcs: Don't panic if coalescelist gets an unknown list 2018-10-16 19:14:11 -07:00
Martin Atkins
db58b88c2d lang/funcs: short-circuit with unknown index and tuple collection
Since we need to know the index to know the result type for a tuple, we
need a special case here to deal with that situation and return
cty.DynamicVal; we can't predict the result type exactly until we know the
element type.
2018-10-16 19:14:11 -07:00
Martin Atkins
d5d8596bb1 vendor: update google.golang.org/api 2018-10-16 19:14:11 -07:00
Martin Atkins
66f96cf842 command: Un-stub and reimplement "terraform state rm"
This was previously targeting the old state manager and state types, so it
needed some considerable rework to get it working again with the new state
types.

Since our new resource address syntax lacks the weird extra .deposed
special case we had before, we instead interpret addresses as
whole-instance addresses here and remove the deposed objects along with
the current one (if present), since this is more likely to match with
user expectations because we don't consider deposed objects to be
independently addressable in any other situation.

With that said, to be more explicit about what is going on we do now have
a -dry-run mode and maintain separate counts of current and deposed
instances so that we can expose that in the UI where relevant.
2018-10-16 19:14:11 -07:00
Martin Atkins
40eda180d6 command: go fmt in import_test.go and refresh_test.go 2018-10-16 19:14:11 -07:00
Martin Atkins
1a654e9e1c configs/configupgrade: Disable the tests for now
The tests in here are illustrating that this package is not yet finished,
but we plan to run a release before we finish this and so we'll skip those
tests for now with the intent of reinstating this again once we return
to finish this up.
2018-10-16 19:14:11 -07:00
Martin Atkins
8b466811d2 command: Fix a few tests from meta_backend_test.go 2018-10-16 19:14:11 -07:00
Martin Atkins
86b7963bba command: Fix tests for "terraform providers" 2018-10-16 19:14:11 -07:00
Martin Atkins
5b61cc919b command: Fix "terraform import" tests 2018-10-16 19:14:11 -07:00
Martin Atkins
7b77e20bdc command: Fix several "terraform init" tests 2018-10-16 19:14:11 -07:00
Martin Atkins
89d0944e5b command: Fix even more of the "terraform refresh" tests 2018-10-16 19:14:11 -07:00
Martin Atkins
5d1d6a95f9 command: "go fmt" of plan_test.go 2018-10-16 19:14:11 -07:00
Martin Atkins
e54848b86f command: Fix many (but not all) "terraform refresh" tests 2018-10-16 19:14:11 -07:00
Martin Atkins
73abb6e8f4 command: Re-enable showing outputs after successful "apply"
We temporarily disabled this because it needed some further work to update
it for the new state models, which has now been done.

We no longer need the configuration objects for the outputs because the
state itself contains all of the information needed for displaying these.
2018-10-16 19:14:11 -07:00
Martin Atkins
98bbd560b5 command: Fix most (but not all) "terraform plan" tests 2018-10-16 19:14:11 -07:00
Martin Atkins
ca314afc0d command: Make suitable provider schemas available for all "plan" tests 2018-10-16 19:14:11 -07:00
Martin Atkins
73318a436b command: go fmt 2018-10-16 19:14:11 -07:00