~egtann/terrafirma

af343e5c8f8f0b335ee06d95ffb8eb85f5e401a0 — Evan Tann 4 months ago 8b32101 external
add both internal and external ips to inventory
1 files changed, 11 insertions(+), 12 deletions(-)

M cmd/terrafirma/main.go
M cmd/terrafirma/main.go => cmd/terrafirma/main.go +11 -12
@@ 37,7 37,6 @@ func run() error {
		planFile      = flag.String("p", defaultPlanFile, "plan file")
		bins          = flag.String("b", "", "bins")
		timeout       = flag.Duration("t", 5*time.Minute, "timeout")
		external      = flag.Bool("x", false, "show external ips (inventory only)")
		ignoreDestroy = flag.Bool("i", false, "ignore servers to be destroyed")
	)
	flag.Parse()


@@ 116,22 115,22 @@ func run() error {
			destroy[vm.Name] = struct{}{}
		}

		// TODO(egtann) allow each service to configure whether
		// inventory should include external or internal IPs?
		inv := map[string][]string{}
		inv := struct {
			Internal map[string][]string `json:"internal"`
			External map[string][]string `json:"external"`
		}{
			Internal: map[string][]string{},
			External: map[string][]string{},
		}
		for _, vm := range vms {
			if _, ok := destroy[vm.Name]; ok && *ignoreDestroy {
				continue
			}
			for _, ip := range vm.IPs {
				if *external {
					if ip.Type == tf.IPExternal {
						inv[ip.Addr] = vm.Tags
					}
					continue
				}
				if ip.Type == tf.IPInternal {
					inv[ip.Addr] = vm.Tags
				if ip.Type == tf.IPExternal {
					inv.External[ip.Addr] = vm.Tags
				} else {
					inv.Internal[ip.Addr] = vm.Tags
				}
			}
		}