mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
fixing context apply tests
This commit is contained in:
parent
3bd2293152
commit
07042a95fa
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/config/configschema"
|
||||||
"github.com/hashicorp/terraform/configs"
|
"github.com/hashicorp/terraform/configs"
|
||||||
|
"github.com/zclconf/go-cty/cty"
|
||||||
|
|
||||||
"github.com/hashicorp/go-version"
|
"github.com/hashicorp/go-version"
|
||||||
"github.com/hashicorp/terraform/flatmap"
|
"github.com/hashicorp/terraform/flatmap"
|
||||||
@ -156,9 +158,9 @@ func testContext2(t *testing.T, opts *ContextOpts) *Context {
|
|||||||
// Enable the shadow graph
|
// Enable the shadow graph
|
||||||
opts.Shadow = true
|
opts.Shadow = true
|
||||||
|
|
||||||
ctx, err := NewContext(opts)
|
ctx, diags := NewContext(opts)
|
||||||
if err != nil {
|
if diags.HasErrors() {
|
||||||
t.Fatalf("failed to create test context\n\n%s\n", err)
|
t.Fatalf("failed to create test context\n\n%s\n", diags.Err())
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx
|
return ctx
|
||||||
@ -357,11 +359,21 @@ func testProvider(prefix string) *MockResourceProvider {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.GetSchemaReturn = testProviderSchema(prefix)
|
||||||
|
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func testProvisioner() *MockResourceProvisioner {
|
func testProvisioner() *MockResourceProvisioner {
|
||||||
p := new(MockResourceProvisioner)
|
p := new(MockResourceProvisioner)
|
||||||
|
p.GetConfigSchemaReturnSchema = &configschema.Block{
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"command": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,6 +388,7 @@ func checkStateString(t *testing.T, state *State, expected string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resourceState(resourceType, resourceID string) *ResourceState {
|
func resourceState(resourceType, resourceID string) *ResourceState {
|
||||||
|
providerResource := strings.Split(resourceType, "_")
|
||||||
return &ResourceState{
|
return &ResourceState{
|
||||||
Type: resourceType,
|
Type: resourceType,
|
||||||
Primary: &InstanceState{
|
Primary: &InstanceState{
|
||||||
@ -384,6 +397,7 @@ func resourceState(resourceType, resourceID string) *ResourceState {
|
|||||||
"id": resourceID,
|
"id": resourceID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Provider: "provider." + providerResource[0],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -409,6 +423,198 @@ func testCheckDeadlock(t *testing.T, f func()) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testProviderSchema(name string) *ProviderSchema {
|
||||||
|
return &ProviderSchema{
|
||||||
|
Provider: &configschema.Block{
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"region": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"foo": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ResourceTypes: map[string]*configschema.Block{
|
||||||
|
name + "_instance": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"ami": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"dep": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"num": {
|
||||||
|
Type: cty.Number,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"require_new": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"var": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"foo": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"bar": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"compute": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"compute_value": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"value": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"output": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"write": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"instance": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"vpc_id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
name + "_eip": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"instance": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
name + "_resource": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"value": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"random": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
name + "_ami_list": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"ids": {
|
||||||
|
Type: cty.List(cty.String),
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
name + "_remote_state": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"foo": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"output": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
name + "_file": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"template": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DataSources: map[string]*configschema.Block{
|
||||||
|
name + "_data_source": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"foo": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
name + "_remote_state": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"foo": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
name + "_file": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"template": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
const testContextGraph = `
|
const testContextGraph = `
|
||||||
root: root
|
root: root
|
||||||
aws_instance.bar
|
aws_instance.bar
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
resource "null_resource" "write" {
|
resource "null_instance" "write" {
|
||||||
foo = "attribute"
|
foo = "attribute"
|
||||||
}
|
}
|
||||||
|
|
||||||
data "null_data_source" "read" {
|
data "null_data_source" "read" {
|
||||||
foo = ""
|
foo = ""
|
||||||
depends_on = ["null_resource.write"]
|
depends_on = ["null_instance.write"]
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
resource "aws_instance" "foo" {
|
resource "aws_instance" "foo" {
|
||||||
id = "foo"
|
|
||||||
num = "2"
|
num = "2"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_instance" "bar" {
|
resource "aws_instance" "bar" {
|
||||||
id = "bar"
|
|
||||||
foo = "{aws_instance.foo.num}"
|
foo = "{aws_instance.foo.num}"
|
||||||
dep = "foo"
|
dep = "foo"
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
resource "aws_instance" "foo" {
|
resource "aws_instance" "foo" {
|
||||||
id = "foo"
|
|
||||||
|
|
||||||
provisioner "shell" {}
|
provisioner "shell" {}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
resource "aws_instance" "foo" {
|
resource "aws_instance" "foo" {
|
||||||
id = "foo"
|
|
||||||
num = "2"
|
num = "2"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_instance" "bar" {
|
resource "aws_instance" "bar" {
|
||||||
id = "bar"
|
|
||||||
foo = "${aws_instance.foo.num}"
|
foo = "${aws_instance.foo.num}"
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
resource "aws_instance" "foo" {
|
resource "aws_instance" "foo" {
|
||||||
num = "2"
|
value = "2"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_instance" "bar" {
|
resource "aws_instance" "bar" {
|
||||||
foo = "${aws_instance.foo.num}"
|
foo = "${aws_instance.foo.value}"
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,6 @@ resource "aws_instance" "bar" {
|
|||||||
num = "2"
|
num = "2"
|
||||||
|
|
||||||
provisioner "shell" {
|
provisioner "shell" {
|
||||||
foo = "${aws_instance.bar.num}"
|
command = "${aws_instance.bar.num}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
resource "aws_instance" "foo" {
|
resource "aws_instance" "foo" {
|
||||||
id = "foo"
|
|
||||||
num = "2"
|
num = "2"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_instance" "bar" {
|
resource "aws_instance" "bar" {
|
||||||
id = "bar"
|
|
||||||
foo = "${aws_instance.foo.id}"
|
foo = "${aws_instance.foo.id}"
|
||||||
require_new = "yes"
|
require_new = "yes"
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
resource "aws_instance" "foo" {
|
resource "aws_instance" "foo" {
|
||||||
id = "foo"
|
|
||||||
num = "2"
|
num = "2"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_instance" "bar" {
|
resource "aws_instance" "bar" {
|
||||||
id = "bar"
|
|
||||||
num = "2"
|
num = "2"
|
||||||
foo = "${aws_instance.foo.id}"
|
foo = "${aws_instance.foo.id}"
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
resource "aws_instance" "bar" {
|
resource "aws_instance" "bar" {
|
||||||
id = "foo"
|
|
||||||
num = "2"
|
num = "2"
|
||||||
}
|
}
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
output "output" {
|
|
||||||
value = "${terraform.env}"
|
|
||||||
}
|
|
@ -0,0 +1,3 @@
|
|||||||
|
output "output" {
|
||||||
|
value = "${terraform.workspace}"
|
||||||
|
}
|
@ -6,6 +6,6 @@ provider "aws" {
|
|||||||
module "mod" {
|
module "mod" {
|
||||||
source = "./mod"
|
source = "./mod"
|
||||||
providers = {
|
providers = {
|
||||||
"aws.foo" = "aws.bar"
|
aws.foo = "aws.bar"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
resource "aws_instance" "foo" {
|
resource "aws_instance" "foo" {
|
||||||
id = "bar"
|
|
||||||
user_data = "x"
|
user_data = "x"
|
||||||
require_new = "yes"
|
require_new = "yes"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user