Skip to content

Commit

Permalink
Add logic to import subnets by IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Nov 6, 2018
1 parent 33d350d commit a2668d4
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pkg/eks/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package eks

import (
"fmt"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"

"github.com/kubicorn/kubicorn/pkg/logger"
"github.com/weaveworks/eksctl/pkg/eks/api"
Expand Down Expand Up @@ -48,3 +52,30 @@ func (c *ClusterProvider) SetSubnets() error {

return nil
}

// UseSubnets imports
func (c *ClusterProvider) UseSubnets(topology api.SubnetTopology, subnetIDs []string) error {
if len(subnetIDs) == 0 {
return nil
}
input := &ec2.DescribeSubnetsInput{
SubnetIds: aws.StringSlice(subnetIDs),
}
output, err := c.Provider.EC2().DescribeSubnets(input)
if err != nil {
return err
}

for _, subnet := range output.Subnets {
if c.Spec.VPC.ID == "" {
c.Spec.VPC.ID = *subnet.VpcId
} else if c.Spec.VPC.ID != *subnet.VpcId {
return fmt.Errorf("given subnets (%s) are not in the same VPC", strings.Join(subnetIDs, ", "))
}

c.Spec.ImportSubnet(topology, *subnet.AvailabilityZone, *subnet.SubnetId)
c.Spec.AppendAvailabilityZone(*subnet.AvailabilityZone)
}

return nil
}

0 comments on commit a2668d4

Please sign in to comment.