Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/simulator/terraform_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type TerraformOutput struct {
BastionPublicIP StringOutput `json:"bastion_public_ip"`
ClusterNodesPrivateIP StringSliceOutput `json:"cluster_nodes_private_ip"`
MasterNodesPrivateIP StringSliceOutput `json:"master_nodes_private_ip"`
InternalNodePrivateIP StringOutput `json:"internal_host_private_ip"`
}

var bastionConfigTmplSrc = `Host bastion {{.Hostname}}
Expand Down Expand Up @@ -111,6 +112,18 @@ func (tfo *TerraformOutput) ToSSHConfig() (*string, error) {
}
}

c := SSHConfig{
Alias: "internal",
Hostname: tfo.InternalNodePrivateIP.Value,
KeyFilePath: ssh.PrivateKeyPath,
KnownHostsFilePath: ssh.KnownHostsPath,
BastionIP: tfo.BastionPublicIP.Value,
}
err = k8sConfigTmpl.Execute(&buf, c)
if err != nil {
return nil, errors.Wrapf(err, "Error populating ssh internal config template with %+v", c)
}

var output = buf.String()
return &output, nil
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/simulator/terraform_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ func Test_ToSSHConfig(t *testing.T) {
Type: []interface{}{},
Value: []string{"127.0.0.2", "127.0.0.3"},
},
InternalNodePrivateIP: simulator.StringOutput{
Sensitive: false,
Type: "string",
Value: "127.0.0.4",
},
}
expected := `Host bastion 8.8.8.8
Hostname 8.8.8.8
Expand Down Expand Up @@ -86,6 +91,13 @@ Host node-1 127.0.0.3
IdentityFile ~/.kubesim/cp_simulator_rsa
UserKnownHostsFile ~/.kubesim/cp_simulator_known_hosts
ProxyJump bastion
Host internal 127.0.0.4
Hostname 127.0.0.4
User root
RequestTTY force
IdentityFile ~/.kubesim/cp_simulator_rsa
UserKnownHostsFile ~/.kubesim/cp_simulator_known_hosts
ProxyJump bastion
`

out, err := tfo.ToSSHConfig()
Expand Down