core: update various context apply tests for schema/fixtures
Most of these changes are just adding schema to describe the expectations of the existing test fixtures. However, some of them require the fixtures themselves to be changed due to changing assumptions in the language.
This commit is contained in:
parent
8774c857f6
commit
1caffba0e6
|
@ -2012,6 +2012,20 @@ func TestContext2Apply_compute(t *testing.T) {
|
|||
p := testProvider("aws")
|
||||
p.ApplyFn = testApplyFn
|
||||
p.DiffFn = testDiffFn
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"num": {Type: cty.String, Optional: true},
|
||||
"compute": {Type: cty.String, Optional: true},
|
||||
"compute_value": {Type: cty.String, Optional: true},
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
"dynamical": {Type: cty.String, Computed: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
|
@ -3527,6 +3541,28 @@ func TestContext2Apply_multiVarComprehensive(t *testing.T) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test_thing": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"source_id": {Type: cty.String, Optional: true},
|
||||
"source_name": {Type: cty.String, Optional: true},
|
||||
"first_source_id": {Type: cty.String, Optional: true},
|
||||
"first_source_name": {Type: cty.String, Optional: true},
|
||||
"source_ids": {Type: cty.List(cty.String), Optional: true},
|
||||
"source_names": {Type: cty.List(cty.String), Optional: true},
|
||||
"source_ids_from_func": {Type: cty.List(cty.String), Optional: true},
|
||||
"source_names_from_func": {Type: cty.List(cty.String), Optional: true},
|
||||
"source_ids_wrapped": {Type: cty.List(cty.String), Optional: true},
|
||||
"source_names_wrapped": {Type: cty.List(cty.String), Optional: true},
|
||||
|
||||
"id": {Type: cty.String, Computed: true},
|
||||
"name": {Type: cty.String, Computed: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// First, apply with a count of 3
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
|
@ -4180,10 +4216,18 @@ func TestContext2Apply_providerConfigureDisabled(t *testing.T) {
|
|||
|
||||
func TestContext2Apply_provisionerModule(t *testing.T) {
|
||||
m := testModule(t, "apply-provisioner-module")
|
||||
|
||||
p := testProvider("aws")
|
||||
pr := testProvisioner()
|
||||
p.ApplyFn = testApplyFn
|
||||
p.DiffFn = testDiffFn
|
||||
|
||||
pr := testProvisioner()
|
||||
pr.GetConfigSchemaReturnSchema = &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
}
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
|
@ -5842,10 +5886,10 @@ func TestContext2Apply_Provisioner_ConnInfo(t *testing.T) {
|
|||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"num": {Type: cty.String, Optional: true},
|
||||
"compute": {Type: cty.String, Optional: true},
|
||||
"num": {Type: cty.String, Optional: true},
|
||||
"compute": {Type: cty.String, Optional: true},
|
||||
"compute_value": {Type: cty.String, Optional: true},
|
||||
"dynamical": {Type: cty.String, Computed: true},
|
||||
"dynamical": {Type: cty.String, Computed: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
variable "foo" {
|
||||
default = "2"
|
||||
default = "2"
|
||||
}
|
||||
|
||||
resource "aws_instance" "foo" {
|
||||
count = "${var.foo}"
|
||||
count = "${var.foo}"
|
||||
}
|
||||
|
||||
resource "aws_instance" "bar" {
|
||||
foo = "${aws_instance.foo.count}"
|
||||
foo = length(aws_instance.foo)
|
||||
}
|
||||
|
|
|
@ -12,29 +12,29 @@ resource "test_thing" "multi_count_var" {
|
|||
count = "${var.num}"
|
||||
|
||||
# Can pluck a single item out of a multi-var
|
||||
source_id = "${test_thing.source.*.id[count.index]}"
|
||||
source_id = "${test_thing.source.*.id[count.index]}"
|
||||
source_name = "${test_thing.source.*.name[count.index]}"
|
||||
}
|
||||
|
||||
resource "test_thing" "multi_count_derived" {
|
||||
# Can use the source to get the count
|
||||
count = "${test_thing.source.count}"
|
||||
count = "${length(test_thing.source)}"
|
||||
|
||||
source_id = "${test_thing.source.*.id[count.index]}"
|
||||
source_id = "${test_thing.source.*.id[count.index]}"
|
||||
source_name = "${test_thing.source.*.name[count.index]}"
|
||||
}
|
||||
|
||||
resource "test_thing" "whole_splat" {
|
||||
# Can "splat" the ids directly into an attribute of type list.
|
||||
source_ids = "${test_thing.source.*.id}"
|
||||
source_ids = "${test_thing.source.*.id}"
|
||||
source_names = "${test_thing.source.*.name}"
|
||||
|
||||
# Accessing through a function should work.
|
||||
source_ids_from_func = "${split(" ", join(" ", test_thing.source.*.id))}"
|
||||
source_ids_from_func = "${split(" ", join(" ", test_thing.source.*.id))}"
|
||||
source_names_from_func = "${split(" ", join(" ", test_thing.source.*.name))}"
|
||||
|
||||
# A common pattern of selecting with a default.
|
||||
first_source_id = "${element(concat(test_thing.source.*.id, list("default")), 0)}"
|
||||
first_source_id = "${element(concat(test_thing.source.*.id, list("default")), 0)}"
|
||||
first_source_name = "${element(concat(test_thing.source.*.name, list("default")), 0)}"
|
||||
|
||||
# Legacy form: Prior to Terraform having comprehensive list support,
|
||||
|
@ -44,7 +44,7 @@ resource "test_thing" "whole_splat" {
|
|||
#
|
||||
# This should result in exactly the same result as the above, even
|
||||
# though it looks like it would result in a list of lists.
|
||||
source_ids_wrapped = ["${test_thing.source.*.id}"]
|
||||
source_ids_wrapped = ["${test_thing.source.*.id}"]
|
||||
source_names_wrapped = ["${test_thing.source.*.name}"]
|
||||
|
||||
}
|
||||
|
@ -52,8 +52,8 @@ resource "test_thing" "whole_splat" {
|
|||
module "child" {
|
||||
source = "./child"
|
||||
|
||||
count = "${var.num}"
|
||||
source_ids = "${test_thing.source.*.id}"
|
||||
num = "${var.num}"
|
||||
source_ids = "${test_thing.source.*.id}"
|
||||
source_names = "${test_thing.source.*.name}"
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
resource "aws_instance" "foo" {
|
||||
count = 3
|
||||
count = 3
|
||||
}
|
||||
|
||||
resource "aws_instance" "bar" {
|
||||
foo = "${aws_instance.foo.count}"
|
||||
foo = length(aws_instance.foo)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue