Skip to content

Commit

Permalink
Output the port number.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Nov 25, 2017
1 parent c2165cb commit d6048f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions data_source_ssh_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func dataSourceSSHTunnel() *schema.Resource {
Required: true,
Description: "The remote bind address (e.g. localhost:8500)",
},
"port": {
Type: schema.TypeString,
Computed: true,
},
"tunnel_established": {
// Probably not the proper way to store this
Type: schema.TypeBool,
Expand Down Expand Up @@ -118,6 +122,11 @@ func dataSourceSSHTunnelRead(d *schema.ResourceData, meta interface{}) error {
d.Set("local_address", effectiveAddress)
}

lastColon := strings.LastIndex(effectiveAddress, ":")
port := effectiveAddress[lastColon+1 : len(effectiveAddress)]
log.Printf("[DEBUG] port: %v", port)
d.Set("port", port)

go func() {
sshClientConn, err := ssh.Dial("tcp", host, sshConf)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ data "consul_keys" "keys" {
output "local_address" {
value = "${data.ssh_tunnel.consul.local_address}"
}
output "random_port" {
value = "${data.ssh_tunnel.consul.port}"
}
output "revision" {
value = "${data.consul_keys.keys.var.revision}"
}

0 comments on commit d6048f9

Please sign in to comment.