Skip to content

Commit

Permalink
Fixed happy path flow now SG gets created in default VPC. Also fixed …
Browse files Browse the repository at this point in the history
…389. (nanovms#670)
  • Loading branch information
chaitanya-baraskar authored Oct 7, 2020
1 parent b235d66 commit 282745e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func instanceCreateCommandHandler(cmd *cobra.Command, args []string) {
}

zone, _ := cmd.Flags().GetString("zone")
if zone == "" && (provider == "gcp" || provider == "aws") {
if zone != "" && (provider == "gcp" || provider == "aws") {
c.CloudConfig.Zone = zone
}

Expand Down
14 changes: 11 additions & 3 deletions lepton/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func (p *AWS) SyncImage(config *Config, target Provider, image string) error {
func (p *AWS) CreateInstance(ctx *Context) error {
result, err := getAWSImages(ctx.config.CloudConfig.Zone)
if err != nil {
return err
exitWithError("Invalid zone")
}

imgName := ctx.config.CloudConfig.ImageName
Expand Down Expand Up @@ -493,7 +493,15 @@ func (p *AWS) CreateSG(ctx *Context, svc *ec2.EC2, imgName string) (string, erro
if len(result.Vpcs) == 0 {
fmt.Println("No VPCs found to associate security group with.")
}
vpcID := aws.StringValue(result.Vpcs[0].VpcId)

var vpcID string
//TODO: This will fail if there is no default VPC. Need to implement feature where user should be able to mention VPC
for i, s := range result.Vpcs {
isDefault := *s.IsDefault
if isDefault == true {
vpcID = aws.StringValue(result.Vpcs[i].VpcId)
}
}

t := time.Now().UnixNano()
s := strconv.FormatInt(t, 10)
Expand Down Expand Up @@ -525,7 +533,7 @@ func (p *AWS) CreateSG(ctx *Context, svc *ec2.EC2, imgName string) (string, erro

// maybe have these ports specified from config.json in near future
_, err = svc.AuthorizeSecurityGroupIngress(&ec2.AuthorizeSecurityGroupIngressInput{
GroupName: aws.String(sgName),
GroupId: createRes.GroupId,
IpPermissions: []*ec2.IpPermission{
(&ec2.IpPermission{}).
SetIpProtocol("tcp").
Expand Down
11 changes: 11 additions & 0 deletions lepton/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package lepton

import (
"fmt"
"os"
)

func exitWithError(errs string) {
fmt.Println(fmt.Sprintf(ErrorColor, errs))
os.Exit(1)
}

0 comments on commit 282745e

Please sign in to comment.