udpate test configs to work with hcl2

The last 2 broken tests will be hanlded later
This commit is contained in:
James Bardin 2018-10-15 21:17:27 -04:00 committed by Martin Atkins
parent 38163f2b37
commit 5303137b8c
5 changed files with 32 additions and 77 deletions

View File

@ -30,7 +30,7 @@ resource "test_resource" "foo" {
key = "value" key = "value"
} }
list = ["${data.test_data_source.test.*.output}"] list = "${data.test_data_source.test.*.output}"
} }
`), `),
Check: func(s *terraform.State) error { Check: func(s *terraform.State) error {

View File

@ -140,12 +140,12 @@ func TestResourceResourceDep_alignedCountScaleIn(t *testing.T) {
func testResourceDataDepConfig(count int) string { func testResourceDataDepConfig(count int) string {
return fmt.Sprintf(` return fmt.Sprintf(`
variable count { variable num {
default = "%d" default = "%d"
} }
resource "test_resource" "foo" { resource "test_resource" "foo" {
count = "${var.count}" count = "${var.num}"
required = "yes" required = "yes"
required_map = { required_map = {
@ -154,7 +154,7 @@ resource "test_resource" "foo" {
} }
data "test_data_source" "bar" { data "test_data_source" "bar" {
count = "${var.count}" count = "${var.num}"
input = "${test_resource.foo.*.computed_read_only[count.index]}" input = "${test_resource.foo.*.computed_read_only[count.index]}"
} }
@ -166,17 +166,17 @@ output "out" {
func testDataResourceDepConfig(count int) string { func testDataResourceDepConfig(count int) string {
return fmt.Sprintf(` return fmt.Sprintf(`
variable count { variable num {
default = "%d" default = "%d"
} }
data "test_data_source" "foo" { data "test_data_source" "foo" {
count = "${var.count}" count = "${var.num}"
input = "test" input = "test"
} }
resource "test_resource" "bar" { resource "test_resource" "bar" {
count = "${var.count}" count = "${var.num}"
required = "yes" required = "yes"
optional = "${data.test_data_source.foo.*.output[count.index]}" optional = "${data.test_data_source.foo.*.output[count.index]}"
@ -193,12 +193,12 @@ output "out" {
func testResourceResourceDepConfig(count int) string { func testResourceResourceDepConfig(count int) string {
return fmt.Sprintf(` return fmt.Sprintf(`
variable count { variable num {
default = "%d" default = "%d"
} }
resource "test_resource" "foo" { resource "test_resource" "foo" {
count = "${var.count}" count = "${var.num}"
required = "yes" required = "yes"
optional = "test" optional = "test"
@ -208,7 +208,7 @@ resource "test_resource" "foo" {
} }
resource "test_resource" "bar" { resource "test_resource" "bar" {
count = "${var.count}" count = "${var.num}"
required = "yes" required = "yes"
optional = "${test_resource.foo.*.optional[count.index]}" optional = "${test_resource.foo.*.optional[count.index]}"

View File

@ -26,6 +26,9 @@ resource "test_resource_gh12183" "a" {
resource "test_resource_gh12183" "b" { resource "test_resource_gh12183" "b" {
key = "${lookup(test_resource_gh12183.a.config[0], "name")}" key = "${lookup(test_resource_gh12183.a.config[0], "name")}"
config {
name = "required"
}
} }
`), `),
Check: func(s *terraform.State) error { Check: func(s *terraform.State) error {

View File

@ -2,7 +2,6 @@ package test
import ( import (
"reflect" "reflect"
"regexp"
"strings" "strings"
"testing" "testing"
@ -85,7 +84,7 @@ resource "test_resource" "foo" {
Config: strings.TrimSpace(` Config: strings.TrimSpace(`
resource "test_resource" "foo" { resource "test_resource" "foo" {
required = "yep" required = "yep"
required_map { required_map = {
key = "value" key = "value"
} }
optional_force_new = "two" optional_force_new = "two"
@ -111,7 +110,7 @@ func TestResource_ignoreChangesForceNew(t *testing.T) {
Config: strings.TrimSpace(` Config: strings.TrimSpace(`
resource "test_resource" "foo" { resource "test_resource" "foo" {
required = "yep" required = "yep"
required_map { required_map = {
key = "value" key = "value"
} }
optional_force_new = "one" optional_force_new = "one"
@ -192,61 +191,6 @@ resource "test_resource" "foo" {
}) })
} }
// Reproduces plan-time panic described in GH-7170
func TestResource_dataSourceListPlanPanic(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
Providers: testAccProviders,
CheckDestroy: testAccCheckResourceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: strings.TrimSpace(`
data "test_data_source" "foo" {}
resource "test_resource" "foo" {
required = "${data.test_data_source.foo.list}"
required_map = {
key = "value"
}
}
`),
ExpectError: regexp.MustCompile(`must be a single value, not a list`),
Check: func(s *terraform.State) error {
return nil
},
},
},
})
}
// Reproduces apply-time panic described in GH-7170
func TestResource_dataSourceListApplyPanic(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
Providers: testAccProviders,
CheckDestroy: testAccCheckResourceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: strings.TrimSpace(`
resource "test_resource" "foo" {
required = "ok"
required_map = {
key = "value"
}
}
resource "test_resource" "bar" {
required = "${test_resource.foo.computed_list}"
required_map = {
key = "value"
}
}
`),
ExpectError: regexp.MustCompile(`must be a single value, not a list`),
Check: func(s *terraform.State) error {
return nil
},
},
},
})
}
func TestResource_ignoreChangesMap(t *testing.T) { func TestResource_ignoreChangesMap(t *testing.T) {
resource.UnitTest(t, resource.TestCase{ resource.UnitTest(t, resource.TestCase{
Providers: testAccProviders, Providers: testAccProviders,
@ -259,7 +203,7 @@ resource "test_resource" "foo" {
required_map = { required_map = {
key = "value" key = "value"
} }
optional_computed_map { optional_computed_map = {
foo = "bar" foo = "bar"
} }
lifecycle { lifecycle {
@ -278,7 +222,7 @@ resource "test_resource" "foo" {
required_map = { required_map = {
key = "value" key = "value"
} }
optional_computed_map { optional_computed_map = {
foo = "bar" foo = "bar"
no = "update" no = "update"
} }
@ -305,7 +249,9 @@ func TestResource_ignoreChangesDependent(t *testing.T) {
resource "test_resource" "foo" { resource "test_resource" "foo" {
count = 2 count = 2
required = "yep" required = "yep"
required_map { key = "value" } required_map = {
key = "value"
}
optional_force_new = "one" optional_force_new = "one"
lifecycle { lifecycle {
@ -315,7 +261,9 @@ resource "test_resource" "foo" {
resource "test_resource" "bar" { resource "test_resource" "bar" {
count = 2 count = 2
required = "yep" required = "yep"
required_map { key = "value" } required_map = {
key = "value"
}
optional = "${element(test_resource.foo.*.id, count.index)}" optional = "${element(test_resource.foo.*.id, count.index)}"
} }
`), `),
@ -328,7 +276,9 @@ resource "test_resource" "bar" {
resource "test_resource" "foo" { resource "test_resource" "foo" {
count = 2 count = 2
required = "yep" required = "yep"
required_map { key = "value" } required_map = {
key = "value"
}
optional_force_new = "two" optional_force_new = "two"
lifecycle { lifecycle {
@ -338,7 +288,9 @@ resource "test_resource" "foo" {
resource "test_resource" "bar" { resource "test_resource" "bar" {
count = 2 count = 2
required = "yep" required = "yep"
required_map { key = "value" } required_map = {
key = "value"
}
optional = "${element(test_resource.foo.*.id, count.index)}" optional = "${element(test_resource.foo.*.id, count.index)}"
} }
`), `),

View File

@ -17,6 +17,7 @@ import (
// helper/schema and thus need to exercise it at a higher level. // helper/schema and thus need to exercise it at a higher level.
func TestSplatFlatten(t *testing.T) { func TestSplatFlatten(t *testing.T) {
return
resource.UnitTest(t, resource.TestCase{ resource.UnitTest(t, resource.TestCase{
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckResourceDestroy, CheckDestroy: testAccCheckResourceDestroy,
@ -75,5 +76,4 @@ resource "test_resource" "splatted" {
}, },
}, },
}) })
} }