From ebe3754fe6a19c1c6754bde608bc946fc1eee5aa Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 21 Sep 2018 17:00:30 -0400 Subject: [PATCH] validate test updates Remove a test that is no longer needed, since provider must be explicitly defined for orphaned modules, and is covered in other context tests. Udpate a test fixture to better represent the origianl missing map issue, since the ability to detect nil now made the old test invalid. --- terraform/context_validate_test.go | 58 ------------------- terraform/test-fixtures/issue-9549/main.tf | 9 ++- .../test-fixtures/issue-9549/mod/main.tf | 5 +- 3 files changed, 7 insertions(+), 65 deletions(-) diff --git a/terraform/context_validate_test.go b/terraform/context_validate_test.go index de470e4f5..a2b902b53 100644 --- a/terraform/context_validate_test.go +++ b/terraform/context_validate_test.go @@ -407,64 +407,6 @@ func TestContext2Validate_moduleDepsShouldNotCycle(t *testing.T) { } } -func TestContext2Validate_moduleProviderInheritOrphan(t *testing.T) { - m := testModule(t, "validate-module-pc-inherit-orphan") - p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - Provider: &configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "set": {Type: cty.String, Optional: true}, - }, - }, - ResourceTypes: map[string]*configschema.Block{ - "aws_instance": { - Attributes: map[string]*configschema.Attribute{}, - }, - }, - } - - c := testContext2(t, &ContextOpts{ - Config: m, - ProviderResolver: providers.ResolverFixed( - map[string]providers.Factory{ - "aws": testProviderFuncFixed(p), - }, - ), - State: mustShimLegacyState(&State{ - Modules: []*ModuleState{ - &ModuleState{ - Path: []string{"root", "child"}, - Resources: map[string]*ResourceState{ - "aws_instance.bar": &ResourceState{ - Type: "aws_instance", - Primary: &InstanceState{ - ID: "bar", - }, - }, - }, - }, - }, - }), - }) - - p.ValidateFn = func(c *ResourceConfig) ([]string, []error) { - v, ok := c.Get("set") - if !ok { - return nil, []error{fmt.Errorf("not set")} - } - if v != "bar" { - return nil, []error{fmt.Errorf("bad: %#v", v)} - } - - return nil, nil - } - - diags := c.Validate() - if diags.HasErrors() { - t.Fatalf("unexpected error: %s", diags.Err()) - } -} - func TestContext2Validate_moduleProviderVar(t *testing.T) { m := testModule(t, "validate-module-pc-vars") p := testProvider("aws") diff --git a/terraform/test-fixtures/issue-9549/main.tf b/terraform/test-fixtures/issue-9549/main.tf index 25452930d..5bf28c66d 100644 --- a/terraform/test-fixtures/issue-9549/main.tf +++ b/terraform/test-fixtures/issue-9549/main.tf @@ -2,7 +2,10 @@ module "mod" { source = "./mod" } -resource "template_instance" "root_template" { - compute_value = "ext: ${module.mod.base_config["base_template"]}" - compute = "value" +output "out" { + value = module.mod.base_config["base_template"] +} + +resource "template_instance" "root_template" { + foo = module.mod.base_config["base_template"] } diff --git a/terraform/test-fixtures/issue-9549/mod/main.tf b/terraform/test-fixtures/issue-9549/mod/main.tf index 1121564dc..aedf9f003 100644 --- a/terraform/test-fixtures/issue-9549/mod/main.tf +++ b/terraform/test-fixtures/issue-9549/mod/main.tf @@ -5,9 +5,6 @@ resource "template_instance" "example" { output "base_config" { value = { - base_template = "${template_instance.example.value}" - - # without this we fail with no entries - extra = "value" + base_template = template_instance.example.value } }