func()

in pkg/ec2helper/ec2helper.go [915:984]


func (h *EC2Helper) ParseConfig(simpleConfig *config.SimpleInfo) (*config.DetailedInfo, error) {
	// If new VPC and subnets will be created, skip formatting subnet and vpc
	var subnet *ec2.Subnet
	var vpc *ec2.Vpc
	var securityGroups []*ec2.SecurityGroup
	var tagSpecs []*ec2.TagSpecification
	var err error
	if !simpleConfig.NewVPC {
		// Decide format of vpc and subnet
		subnet, err = h.GetSubnetById(simpleConfig.SubnetId)
		if err != nil {
			return nil, err
		}

		vpc, err = h.GetVpcById(*subnet.VpcId)
		if err != nil {
			return nil, err
		}

		securityGroups, err = h.GetSecurityGroupsByIds(simpleConfig.SecurityGroupIds)
		if err != nil {
			return nil, err
		}
	}

	// Add simple-ec2 tags to created resources
	resourceTags := getSimpleEc2Tags()
	if len(simpleConfig.UserTags) > 0 {
		for k, v := range simpleConfig.UserTags {
			resourceTags = append(resourceTags, &ec2.Tag{
				Key:   aws.String(k),
				Value: aws.String(v),
			})
		}
	}
	tagSpecs = []*ec2.TagSpecification{
		{
			ResourceType: aws.String("instance"),
			Tags:         resourceTags,
		},
	}
	image, err := h.GetImageById(simpleConfig.ImageId)
	if err != nil {
		return nil, err
	} else {
		if *image.RootDeviceType == "ebs" {
			tagSpecs = append(tagSpecs,
				&ec2.TagSpecification{
					ResourceType: aws.String("volume"),
					Tags:         resourceTags,
				})
		}
	}

	instanceTypeInfo, err := h.GetInstanceType(simpleConfig.InstanceType)
	if err != nil {
		return nil, err
	}

	detailedConfig := config.DetailedInfo{
		Image:            image,
		Vpc:              vpc,
		Subnet:           subnet,
		InstanceTypeInfo: instanceTypeInfo,
		SecurityGroups:   securityGroups,
		TagSpecs:         tagSpecs,
	}

	return &detailedConfig, nil
}