opentofu/internal/command/meta_new.go
Martin Atkins 034e944070 Move plans/ to internal/plans/
This is part of a general effort to move all of Terraform's non-library
package surface under internal in order to reinforce that these are for
internal use within Terraform only.

If you were previously importing packages under this prefix into an
external codebase, you could pin to an earlier release tag as an interim
solution until you've make a plan to achieve the same functionality some
other way.
2021-05-17 14:09:07 -07:00

47 lines
1000 B
Go

package command
import (
"os"
"strconv"
"github.com/hashicorp/terraform/internal/plans/planfile"
)
// NOTE: Temporary file until this branch is cleaned up.
// Input returns whether or not input asking is enabled.
func (m *Meta) Input() bool {
if test || !m.input {
return false
}
if envVar := os.Getenv(InputModeEnvVar); envVar != "" {
if v, err := strconv.ParseBool(envVar); err == nil && !v {
return false
}
}
return true
}
// PlanFile returns a reader for the plan file at the given path.
//
// If the return value and error are both nil, the given path exists but seems
// to be a configuration directory instead.
//
// Error will be non-nil if path refers to something which looks like a plan
// file and loading the file fails.
func (m *Meta) PlanFile(path string) (*planfile.Reader, error) {
fi, err := os.Stat(path)
if err != nil {
return nil, err
}
if fi.IsDir() {
// Looks like a configuration directory.
return nil, nil
}
return planfile.Open(path)
}