@@ -994,6 +994,64 @@ func TestApply_planUndeclaredVars(t *testing.T) {
994994 }
995995}
996996
997+ func TestApply_planWithEnvVars (t * testing.T ) {
998+ _ , snap := testModuleWithSnapshot (t , "apply-output-only" )
999+ plan := testPlan (t )
1000+
1001+ addr , diags := addrs .ParseAbsOutputValueStr ("output.shadow" )
1002+ if diags .HasErrors () {
1003+ t .Fatal (diags .Err ())
1004+ }
1005+
1006+ shadowVal := mustNewDynamicValue ("noot" , cty .DynamicPseudoType )
1007+ plan .VariableValues = map [string ]plans.DynamicValue {
1008+ "shadow" : shadowVal ,
1009+ }
1010+ plan .Changes .Outputs = append (plan .Changes .Outputs , & plans.OutputChangeSrc {
1011+ Addr : addr ,
1012+ ChangeSrc : plans.ChangeSrc {
1013+ Action : plans .Create ,
1014+ After : shadowVal ,
1015+ },
1016+ })
1017+ planPath := testPlanFileMatchState (
1018+ t ,
1019+ snap ,
1020+ states .NewState (),
1021+ plan ,
1022+ statemgr.SnapshotMeta {},
1023+ )
1024+
1025+ statePath := testTempFile (t )
1026+
1027+ p := applyFixtureProvider ()
1028+ view , done := testView (t )
1029+ c := & ApplyCommand {
1030+ Meta : Meta {
1031+ testingOverrides : metaOverridesForProvider (p ),
1032+ View : view ,
1033+ },
1034+ }
1035+
1036+ t .Setenv ("TF_VAR_shadow" , "env" )
1037+
1038+ args := []string {
1039+ "-state" , statePath ,
1040+ "-no-color" ,
1041+ planPath ,
1042+ }
1043+ code := c .Run (args )
1044+ output := done (t )
1045+ if code != 0 {
1046+ t .Fatal ("unexpected failure: " , output .All ())
1047+ }
1048+
1049+ expectedWarn := "Warning: Ignoring variable when applying a saved plan\n "
1050+ if ! strings .Contains (output .Stdout (), expectedWarn ) {
1051+ t .Fatalf ("expected warning in output, given: %q" , output .Stdout ())
1052+ }
1053+ }
1054+
9971055// A saved plan includes a list of "apply-time variables", i.e. ephemeral
9981056// input variables that were set during the plan, and must therefore be set
9991057// during apply. No other variables may be set during apply.
0 commit comments