mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-16 02:23:39 -06:00
Merge pull request #13110 from hashicorp/jbardin/apply-plan
Don't Validate if we have an execution plan
This commit is contained in:
commit
9eb6faa679
@ -802,6 +802,39 @@ func TestApply_planVars(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we should be able to apply a plan file with no other file dependencies
|
||||||
|
func TestApply_planNoModuleFiles(t *testing.T) {
|
||||||
|
// temprary data directory which we can remove between commands
|
||||||
|
td, err := ioutil.TempDir("", "tf")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(td)
|
||||||
|
|
||||||
|
defer testChdir(t, td)()
|
||||||
|
|
||||||
|
p := testProvider()
|
||||||
|
planFile := testPlanFile(t, &terraform.Plan{
|
||||||
|
Module: testModule(t, "apply-plan-no-module"),
|
||||||
|
})
|
||||||
|
|
||||||
|
contextOpts := testCtxConfig(p)
|
||||||
|
|
||||||
|
apply := &ApplyCommand{
|
||||||
|
Meta: Meta{
|
||||||
|
ContextOpts: contextOpts,
|
||||||
|
Ui: new(cli.MockUi),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
args := []string{
|
||||||
|
planFile,
|
||||||
|
}
|
||||||
|
apply.Run(args)
|
||||||
|
if p.ValidateCalled {
|
||||||
|
t.Fatal("Validate should not be called with a plan")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestApply_refresh(t *testing.T) {
|
func TestApply_refresh(t *testing.T) {
|
||||||
originalState := &terraform.State{
|
originalState := &terraform.State{
|
||||||
Modules: []*terraform.ModuleState{
|
Modules: []*terraform.ModuleState{
|
||||||
|
@ -104,9 +104,13 @@ func (m *Meta) Backend(opts *BackendOpts) (backend.Enhanced, error) {
|
|||||||
StateBackupPath: m.backupPath,
|
StateBackupPath: m.backupPath,
|
||||||
ContextOpts: m.contextOpts(),
|
ContextOpts: m.contextOpts(),
|
||||||
Input: m.Input(),
|
Input: m.Input(),
|
||||||
Validation: true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't validate if we have a plan. Validation is normally harmless here,
|
||||||
|
// but validation requires interpolation, and `file()` function calls may
|
||||||
|
// not have the original files in the current execution context.
|
||||||
|
cliOpts.Validation = opts.Plan == nil
|
||||||
|
|
||||||
// If the backend supports CLI initialization, do it.
|
// If the backend supports CLI initialization, do it.
|
||||||
if cli, ok := b.(backend.CLI); ok {
|
if cli, ok := b.(backend.CLI); ok {
|
||||||
if err := cli.CLIInit(cliOpts); err != nil {
|
if err := cli.CLIInit(cliOpts); err != nil {
|
||||||
|
7
command/test-fixtures/apply-plan-no-module/main.tf
Normal file
7
command/test-fixtures/apply-plan-no-module/main.tf
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
resource "test_instance" "tmpl" {
|
||||||
|
foo = "${file("${path.module}/template.txt")}"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "template" {
|
||||||
|
value = "${test_instance.tmpl.foo}"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user