mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-10 23:55:34 -06:00
terraform: State.IsRemote
This commit is contained in:
parent
3550f7ac3a
commit
6cd5c894e8
@ -125,6 +125,22 @@ func (s *State) ModuleOrphans(path []string, c *config.Config) [][]string {
|
||||
return orphans
|
||||
}
|
||||
|
||||
// IsRemote returns true if State represents a state that exists and is
|
||||
// remote.
|
||||
func (s *State) IsRemote() bool {
|
||||
if s == nil {
|
||||
return false
|
||||
}
|
||||
if s.Remote == nil {
|
||||
return false
|
||||
}
|
||||
if s.Remote.Type == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// RootModule returns the ModuleState for the root module
|
||||
func (s *State) RootModule() *ModuleState {
|
||||
root := s.ModuleByPath(rootModulePath)
|
||||
|
@ -312,6 +312,34 @@ func TestInstanceStateEqual(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStateIsRemote(t *testing.T) {
|
||||
cases := []struct {
|
||||
In *State
|
||||
Result bool
|
||||
}{
|
||||
{
|
||||
nil,
|
||||
false,
|
||||
},
|
||||
{
|
||||
&State{},
|
||||
false,
|
||||
},
|
||||
{
|
||||
&State{
|
||||
Remote: &RemoteState{Type: "foo"},
|
||||
},
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
if tc.In.IsRemote() != tc.Result {
|
||||
t.Fatalf("bad %d %#v:\n\n%#v", i, tc.Result, tc.In)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInstanceState_MergeDiff(t *testing.T) {
|
||||
is := InstanceState{
|
||||
ID: "foo",
|
||||
|
Loading…
Reference in New Issue
Block a user