Skip to content

Commit cf7a315

Browse files
committed
provider eval scope test
1 parent 099cca3 commit cf7a315

File tree

5 files changed

+83
-0
lines changed

5 files changed

+83
-0
lines changed

internal/command/apply_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2901,3 +2901,72 @@ func mustNewDynamicValue(val string, ty cty.Type) plans.DynamicValue {
29012901
}
29022902
return ret
29032903
}
2904+
2905+
func TestProviderInconsistentFileFunc(t *testing.T) {
2906+
// Verify that providers can still accept inconsistent results from
2907+
// filesystem functions. We allow this for backwards compatibility, but
2908+
// ephemeral values should be used in the long-term to allow for controlled
2909+
// changes in values between plan and apply.
2910+
td := t.TempDir()
2911+
planDir := filepath.Join(td, "plan")
2912+
applyDir := filepath.Join(td, "apply")
2913+
testCopyDir(t, testFixturePath("changed-file-func-plan"), planDir)
2914+
testCopyDir(t, testFixturePath("changed-file-func-apply"), applyDir)
2915+
t.Chdir(planDir)
2916+
2917+
p := planVarsFixtureProvider()
2918+
p.GetProviderSchemaResponse = &providers.GetProviderSchemaResponse{
2919+
Provider: providers.Schema{
2920+
Body: &configschema.Block{
2921+
Attributes: map[string]*configschema.Attribute{
2922+
"foo": {Type: cty.String, Optional: true},
2923+
},
2924+
},
2925+
},
2926+
ResourceTypes: map[string]providers.Schema{
2927+
"test_instance": {
2928+
Body: &configschema.Block{
2929+
Attributes: map[string]*configschema.Attribute{
2930+
"id": {Type: cty.String, Optional: true, Computed: true},
2931+
},
2932+
},
2933+
},
2934+
},
2935+
}
2936+
2937+
view, done := testView(t)
2938+
c := &PlanCommand{
2939+
Meta: Meta{
2940+
testingOverrides: metaOverridesForProvider(p),
2941+
View: view,
2942+
},
2943+
}
2944+
2945+
args := []string{
2946+
"-out", filepath.Join(applyDir, "planfile"),
2947+
}
2948+
code := c.Run(args)
2949+
output := done(t)
2950+
if code != 0 {
2951+
t.Fatalf("non-zero exit %d\n\n%s", code, output.Stderr())
2952+
}
2953+
2954+
t.Chdir(applyDir)
2955+
2956+
view, done = testView(t)
2957+
apply := &ApplyCommand{
2958+
Meta: Meta{
2959+
testingOverrides: metaOverridesForProvider(p),
2960+
Ui: new(cli.MockUi),
2961+
View: view,
2962+
},
2963+
}
2964+
args = []string{
2965+
"planfile",
2966+
}
2967+
code = apply.Run(args)
2968+
output = done(t)
2969+
if code != 0 {
2970+
t.Fatalf("non-zero exit %d\n\n%s", code, output.Stderr())
2971+
}
2972+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
apply
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
provider "test" {
2+
foo = file("./data")
3+
}
4+
5+
resource "test_instance" "foo" {
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
plan
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
provider "test" {
2+
foo = file("./data")
3+
}
4+
5+
resource "test_instance" "foo" {
6+
}

0 commit comments

Comments
 (0)