-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathterraform_env.go
49 lines (40 loc) · 1.3 KB
/
terraform_env.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.
package servicedeployer
import (
"errors"
"fmt"
"strings"
"github.com/elastic/elastic-package/internal/compose"
)
const (
tfDir = "TF_DIR"
tfTestRunID = "TF_VAR_TEST_RUN_ID"
envYmlFile = "env.yml"
)
func (tsd TerraformServiceDeployer) buildTerraformExecutorEnvironment(ctxt ServiceContext) []string {
vars := map[string]string{}
vars[serviceLogsDirEnv] = ctxt.Logs.Folder.Local
vars[tfTestRunID] = ctxt.Test.RunID
vars[tfDir] = tsd.definitionsDir
var pairs []string
for k, v := range vars {
pairs = append(pairs, fmt.Sprintf("%s=%s", k, v))
}
return pairs
}
func buildTerraformAliases(serviceComposeConfig *compose.Config) (map[string]interface{}, error) {
terraformService, found := serviceComposeConfig.Services["terraform"]
if !found {
return nil, errors.New("missing config section for terraform service")
}
m := map[string]interface{}{}
for name, value := range terraformService.Environment {
// skip empty values and internal Terraform variables
if value != "" && !strings.HasPrefix(name, "TF_VAR_") {
m[name] = value
}
}
return m, nil
}