This repository has been archived by the owner on Apr 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
info.go
70 lines (58 loc) · 2.11 KB
/
info.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package concourse
import (
"fmt"
"strings"
"github.com/EngineerBetter/concourse-up/bosh"
"github.com/EngineerBetter/concourse-up/config"
"github.com/EngineerBetter/concourse-up/terraform"
)
// Info represents the terraform output and concourse-up config files
type Info struct {
Terraform *terraform.Metadata `json:"terraform"`
Config *config.Config `json:"config"`
Instances []bosh.Instance `json:"instances"`
}
// FetchInfo fetches and builds the info
func (client *Client) FetchInfo() (*Info, error) {
config, err := client.configClient.Load()
if err != nil {
return nil, err
}
terraformClient, err := client.buildTerraformClient(config)
if err != nil {
return nil, err
}
metadata, err := terraformClient.Output()
if err != nil {
return nil, err
}
defer terraformClient.Cleanup()
boshClient, err := client.buildBoshClient(config, metadata)
if err != nil {
return nil, err
}
defer boshClient.Cleanup()
instances, err := boshClient.Instances()
if err != nil {
return nil, err
}
return &Info{
Terraform: metadata,
Config: config,
Instances: instances,
}, nil
}
func (info *Info) String() string {
boshCACert := strings.Join(strings.Split(info.Config.DirectorCACert, "\n"), "\n\t\t")
str := "\n"
str += fmt.Sprintf("Deployment:\n\tIAAS: aws\n\tRegion: %s\n\n", info.Config.Region)
str += fmt.Sprintf("Workers:\n\tCount: %d\n\tSize: %s\n\tOutbound Public IP: %s\n\n", info.Config.ConcourseWorkerCount, info.Config.ConcourseWorkerSize, info.Terraform.NatGatewayIP.Value)
str += "Instances:"
for _, instance := range info.Instances {
str += fmt.Sprintf("\n\t%s\t%s\t%s", instance.Name, instance.IP, instance.State)
}
str += "\n\n"
str += fmt.Sprintf("Concourse credentials:\n\tusername: %s\n\tpassword: %s\n\tURL: https://%s\n\n", info.Config.ConcourseUsername, info.Config.ConcoursePassword, info.Config.Domain)
str += fmt.Sprintf("Bosh credentials:\n\tusername: %s\n\tpassword: %s\n\tIP: %s\n\tCA Cert:\n\t\t%s\n", info.Config.DirectorUsername, info.Config.DirectorPassword, info.Terraform.DirectorPublicIP.Value, boshCACert)
return str
}