// CreateSecurityGroup creates a new Security Group based on the provided class, region, and VPC ID func CreateSecurityGroup(class, region, vpcID string, dryRun bool) error { // --dry-run flag if dryRun { terminal.Information("--dry-run flag is set, not making any actual changes!") } // Validate the region if !regions.ValidRegion(region) { return errors.New("Region [" + region + "] is Invalid!") } // Verify the security group class input cfg, err := config.LoadSecurityGroupClass(class) if err != nil { return err } terminal.Information("Found Security Group class configuration for [" + class + "]") svc := ec2.New(session.New(&aws.Config{Region: aws.String(region)})) // Create the security group params := &ec2.CreateSecurityGroupInput{ Description: aws.String(cfg.Description), GroupName: aws.String(class), DryRun: aws.Bool(dryRun), VpcId: aws.String(vpcID), } _, err = svc.CreateSecurityGroup(params) if err != nil { if awsErr, ok := err.(awserr.Error); ok { return errors.New(awsErr.Message()) } return err } return nil }
// private function without terminal prompts func updateSecurityGroups(secGrpList *SecurityGroups, dryRun bool) error { for _, secGrp := range *secGrpList { // Verify the security group class input cfg, err := config.LoadSecurityGroupClass(secGrp.Class) if err != nil { terminal.Information("Skipping Security Group [" + secGrp.Name + "]") terminal.ErrorLine(err.Error()) continue } else { terminal.Information("Found Security Group class configuration for [" + secGrp.Class + "]") } // TODO fmt.Println("\n\n") fmt.Println("aws\n") fmt.Println(secGrp.SecurityGroupGrants) fmt.Println("awsm\n") fmt.Println(cfg.SecurityGroupGrants) fmt.Println("\n\n") hash1, err := hashstructure.Hash(secGrp.SecurityGroupGrants, nil) if err != nil { panic(err) } fmt.Printf("\n\n%d\n\n", hash1) hash2, err := hashstructure.Hash(cfg.SecurityGroupGrants, nil) if err != nil { panic(err) } fmt.Printf("\n\n%d\n\n", hash2) } return nil }