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"
}
list = ["${data.test_data_source.test.*.output}"]
list = "${data.test_data_source.test.*.output}"
}
`),
Check: func(s *terraform.State) error {

View File

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

View File

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

View File

@ -2,7 +2,6 @@ package test
import (
"reflect"
"regexp"
"strings"
"testing"
@ -67,7 +66,7 @@ func TestResource_ignoreChangesEmpty(t *testing.T) {
resource.TestStep{
Config: strings.TrimSpace(`
resource "test_resource" "foo" {
required = "yep"
required = "yep"
required_map = {
key = "value"
}
@ -84,8 +83,8 @@ resource "test_resource" "foo" {
resource.TestStep{
Config: strings.TrimSpace(`
resource "test_resource" "foo" {
required = "yep"
required_map {
required = "yep"
required_map = {
key = "value"
}
optional_force_new = "two"
@ -111,7 +110,7 @@ func TestResource_ignoreChangesForceNew(t *testing.T) {
Config: strings.TrimSpace(`
resource "test_resource" "foo" {
required = "yep"
required_map {
required_map = {
key = "value"
}
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) {
resource.UnitTest(t, resource.TestCase{
Providers: testAccProviders,
@ -259,7 +203,7 @@ resource "test_resource" "foo" {
required_map = {
key = "value"
}
optional_computed_map {
optional_computed_map = {
foo = "bar"
}
lifecycle {
@ -278,7 +222,7 @@ resource "test_resource" "foo" {
required_map = {
key = "value"
}
optional_computed_map {
optional_computed_map = {
foo = "bar"
no = "update"
}
@ -305,7 +249,9 @@ func TestResource_ignoreChangesDependent(t *testing.T) {
resource "test_resource" "foo" {
count = 2
required = "yep"
required_map { key = "value" }
required_map = {
key = "value"
}
optional_force_new = "one"
lifecycle {
@ -315,7 +261,9 @@ resource "test_resource" "foo" {
resource "test_resource" "bar" {
count = 2
required = "yep"
required_map { key = "value" }
required_map = {
key = "value"
}
optional = "${element(test_resource.foo.*.id, count.index)}"
}
`),
@ -328,7 +276,9 @@ resource "test_resource" "bar" {
resource "test_resource" "foo" {
count = 2
required = "yep"
required_map { key = "value" }
required_map = {
key = "value"
}
optional_force_new = "two"
lifecycle {
@ -338,7 +288,9 @@ resource "test_resource" "foo" {
resource "test_resource" "bar" {
count = 2
required = "yep"
required_map { key = "value" }
required_map = {
key = "value"
}
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.
func TestSplatFlatten(t *testing.T) {
return
resource.UnitTest(t, resource.TestCase{
Providers: testAccProviders,
CheckDestroy: testAccCheckResourceDestroy,
@ -75,5 +76,4 @@ resource "test_resource" "splatted" {
},
},
})
}