Skip to content

Commit 3c09be1

Browse files
committed
added parameter to define output for conncetion details
1 parent 2039dac commit 3c09be1

File tree

4 files changed

+26
-36
lines changed

4 files changed

+26
-36
lines changed

cmd/cmd/constants.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package cmd
22

33
const (
4-
projectName string = "project-name"
5-
projectNameDesc string = "project name to identify the instance of the stack"
6-
backedURL string = "backed-url"
7-
backedURLDesc string = "backed for stack state. Can be a local path with format file:///path/subpath or s3 s3://existing-bucket"
8-
supportedHostID string = "host-id"
9-
supportedHostIDDesc string = "host id from supported hosts list"
10-
availabilityZones string = "availability-zones"
11-
availabilityZonesDesc string = "List of comma separated azs to check. If empty all will be searched"
4+
projectName string = "project-name"
5+
projectNameDesc string = "project name to identify the instance of the stack"
6+
backedURL string = "backed-url"
7+
backedURLDesc string = "backed for stack state. Can be a local path with format file:///path/subpath or s3 s3://existing-bucket"
8+
connectionDetailsOutput string = "conn-details-output"
9+
connectionDetailsOutputDesc string = "path to export host connection information. Here 3 files will be created holding: host, username and privateKey"
10+
supportedHostID string = "host-id"
11+
supportedHostIDDesc string = "host id from supported hosts list"
12+
availabilityZones string = "availability-zones"
13+
availabilityZonesDesc string = "List of comma separated azs to check. If empty all will be searched"
1214

1315
createCmdName string = "create"
1416
destroyCmdName string = "destroy"

cmd/cmd/host-create.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func init() {
1818
flagSet := pflag.NewFlagSet(createCmdName, pflag.ExitOnError)
1919
flagSet.StringP(projectName, "", "", projectNameDesc)
2020
flagSet.StringP(backedURL, "", "", backedURLDesc)
21+
flagSet.StringP(connectionDetailsOutput, "", "", connectionDetailsOutputDesc)
2122
flagSet.StringP(supportedHostID, "", "", supportedHostIDDesc)
2223
hostCreateCmd.Flags().AddFlagSet(flagSet)
2324
}
@@ -32,6 +33,7 @@ var hostCreateCmd = &cobra.Command{
3233
if err := environment.Create(
3334
viper.GetString(projectName),
3435
viper.GetString(backedURL),
36+
viper.GetString(connectionDetailsOutput),
3537
// fixed as public to ensure sync, when PR is merged we can offer as param
3638
// https://github.com/pulumi/pulumi-command/pull/132
3739
true,

cmd/cmd/host-destroy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ var hostDestroyCmd = &cobra.Command{
2929
return err
3030
}
3131
if err := environment.Destroy(
32-
"qenvs",
33-
"file:///tmp/qenvs"); err != nil {
32+
viper.GetString(projectName),
33+
viper.GetString(backedURL)); err != nil {
3434
logging.Error(err)
3535
}
3636
return nil

pkg/infra/aws/modules/environment/api.go

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/pulumi/pulumi/sdk/v3/go/auto"
1818
)
1919

20-
func Create(projectName, backedURL string, public bool, targetHostID string) (err error) {
20+
func Create(projectName, backedURL, connectionDetailsOutput string, public bool, targetHostID string) (err error) {
2121
// Check which supported host
2222
host, err := supportMatrix.GetHost(targetHostID)
2323
if err != nil {
@@ -56,7 +56,7 @@ func Create(projectName, backedURL string, public bool, targetHostID string) (er
5656
return err
5757
}
5858
// Write host access info to disk
59-
if err = manageResults(stackResult, host, public, "/tmp/qenvs"); err != nil {
59+
if err = manageResults(stackResult, host, public, connectionDetailsOutput); err != nil {
6060
return err
6161
}
6262
logging.Debug("Environment has been created")
@@ -125,32 +125,18 @@ func manageRequest(request *corporateEnvironmentRequest,
125125
func manageResults(stackResult auto.UpResult,
126126
host *supportMatrix.SupportedHost, public bool,
127127
destinationFolder string) error {
128+
// Currently support only one host on host operation
129+
// this should be change when create a environment with multiple hosts
130+
remoteHostID := host.ID
128131
if !public {
129-
if err := writeOutputs(stackResult, destinationFolder, map[string]string{
130-
fmt.Sprintf("%s-%s", compute.OutputPrivateKey, "bastion"): "bastion_id_rsa",
131-
fmt.Sprintf("%s-%s", compute.OutputHost, "bastion"): "bastion_host",
132-
fmt.Sprintf("%s-%s", compute.OutputUsername, "bastion"): "bastion_username",
133-
}); err != nil {
134-
return err
135-
}
132+
remoteHostID = supportMatrix.S_BASTION.ID
136133
}
137-
switch host.Type {
138-
case supportMatrix.RHEL:
139-
if err := writeOutputs(stackResult, destinationFolder, map[string]string{
140-
fmt.Sprintf("%s-%s", compute.OutputPrivateKey, supportMatrix.OL_RHEL.ID): "rhel_id_rsa",
141-
fmt.Sprintf("%s-%s", compute.OutputHost, supportMatrix.OL_RHEL.ID): "rhel_host",
142-
fmt.Sprintf("%s-%s", compute.OutputUsername, supportMatrix.OL_RHEL.ID): "rhel_username",
143-
}); err != nil {
144-
return err
145-
}
146-
case supportMatrix.MacM1:
147-
if err := writeOutputs(stackResult, destinationFolder, map[string]string{
148-
fmt.Sprintf("%s-%s", compute.OutputPrivateKey, supportMatrix.G_MAC_M1.ID): "macm1_id_rsa",
149-
fmt.Sprintf("%s-%s", compute.OutputHost, supportMatrix.G_MAC_M1.ID): "macm1_host",
150-
fmt.Sprintf("%s-%s", compute.OutputUsername, supportMatrix.G_MAC_M1.ID): "macm1_username",
151-
}); err != nil {
152-
return err
153-
}
134+
if err := writeOutputs(stackResult, destinationFolder, map[string]string{
135+
fmt.Sprintf("%s-%s", compute.OutputPrivateKey, remoteHostID): "id_rsa",
136+
fmt.Sprintf("%s-%s", compute.OutputHost, remoteHostID): "host",
137+
fmt.Sprintf("%s-%s", compute.OutputUsername, remoteHostID): "username",
138+
}); err != nil {
139+
return err
154140
}
155141
return nil
156142
}

0 commit comments

Comments
 (0)