MCPcopy Create free account
hub / github.com/Pluralith/pluralith-cli / LoadBackendConfig

Function LoadBackendConfig

app/pkg/backends/LoadBackend.go:34–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32}
33
34func LoadBackendConfig() (TerraformState, error) {
35 functionName := "LoadBackendConfig"
36 tfState := TerraformState{}
37 tfStatePath := filepath.Join(auxiliary.StateInstance.WorkingPath, ".terraform", "terraform.tfstate")
38
39 // Check if backend config exists
40 if _, err := os.Stat(tfStatePath); errors.Is(err, os.ErrNotExist) {
41 ux.PrintFormatted(" ✘", []string{"yellow", "bold"})
42 fmt.Println(" Couldn't sync diagram to remote backend. No remote backend detected.")
43 return tfState, nil
44 }
45
46 // Read terraform state for backend information
47 tfStateByte, configErr := os.ReadFile(tfStatePath)
48 if configErr != nil {
49 return tfState, fmt.Errorf("failed to read working directory config -> %v: %w", functionName, configErr)
50 }
51
52 // Parse terraform state
53 jsonErr := json.Unmarshal(tfStateByte, &tfState)
54 if jsonErr != nil {
55 return tfState, fmt.Errorf("failed to unmarshal terraform state information -> %v: %w", functionName, jsonErr)
56 }
57
58 return tfState, nil
59}

Callers 1

SyncToBackendFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected