Implement simple deletion functions
This commit is contained in:
parent
0efb8bdd69
commit
60a51f1222
3 changed files with 21 additions and 6 deletions
|
@ -19,6 +19,7 @@ export class Instance
|
|||
constructor(args: InstanceProperties) {
|
||||
super({
|
||||
resource: "AWS::EC2::Instance",
|
||||
properties: args,
|
||||
});
|
||||
this.imageId = args.imageId;
|
||||
this.instanceType = args.instanceType;
|
||||
|
|
|
@ -35,6 +35,7 @@ func (p *instanceProvider) Create(ctx context.Context, req *murpc.CreateRequest)
|
|||
props := resource.UnmarshalProperties(req.GetProperties())
|
||||
|
||||
// Read in the properties given by the request, validating as we go; if any fail, reject the request.
|
||||
// TODO: validate additional properties (e.g., that AMI exists in this region).
|
||||
// TODO: this is a good example of a "benign" (StateOK) error; handle it accordingly.
|
||||
inst, err := newInstance(props, true)
|
||||
if err != nil {
|
||||
|
@ -44,12 +45,10 @@ func (p *instanceProvider) Create(ctx context.Context, req *murpc.CreateRequest)
|
|||
// Create the create instances request object.
|
||||
var secgrpIDs []*string
|
||||
if inst.SecurityGroupIDs != nil {
|
||||
for _, sid := range *inst.SecurityGroupIDs {
|
||||
secgrpIDs = append(secgrpIDs, &sid)
|
||||
}
|
||||
secgrpIDs = aws.StringSlice(*inst.SecurityGroupIDs)
|
||||
}
|
||||
create := &ec2.RunInstancesInput{
|
||||
ImageId: &inst.ImageID,
|
||||
ImageId: aws.String(inst.ImageID),
|
||||
InstanceType: inst.InstanceType,
|
||||
SecurityGroupIds: secgrpIDs,
|
||||
KeyName: inst.KeyName,
|
||||
|
@ -91,7 +90,14 @@ func (p *instanceProvider) Update(ctx context.Context, req *murpc.UpdateRequest)
|
|||
// Delete tears down an existing resource with the given ID. If it fails, the resource is assumed to still exist.
|
||||
func (p *instanceProvider) Delete(ctx context.Context, req *murpc.DeleteRequest) (*pbempty.Empty, error) {
|
||||
contract.Assert(req.GetType() == string(Instance))
|
||||
return nil, errors.New("Not yet implemented")
|
||||
delete := &ec2.TerminateInstancesInput{
|
||||
InstanceIds: []*string{aws.String(req.GetId())},
|
||||
}
|
||||
if _, err := p.ctx.EC2().TerminateInstances(delete); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// TODO: wait for termination to complete.
|
||||
return &pbempty.Empty{}, nil
|
||||
}
|
||||
|
||||
// instance represents the state associated with an instance.
|
||||
|
|
|
@ -5,6 +5,7 @@ package ec2
|
|||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
pbempty "github.com/golang/protobuf/ptypes/empty"
|
||||
"github.com/marapongo/mu/pkg/resource"
|
||||
|
@ -82,7 +83,14 @@ func (p *securityGroupProvider) Update(ctx context.Context, req *murpc.UpdateReq
|
|||
// Delete tears down an existing resource with the given ID. If it fails, the resource is assumed to still exist.
|
||||
func (p *securityGroupProvider) Delete(ctx context.Context, req *murpc.DeleteRequest) (*pbempty.Empty, error) {
|
||||
contract.Assert(req.GetType() == string(SecurityGroup))
|
||||
return nil, errors.New("Not yet implemented")
|
||||
delete := &ec2.DeleteSecurityGroupInput{
|
||||
GroupId: aws.String(req.GetId()),
|
||||
}
|
||||
if _, err := p.ctx.EC2().DeleteSecurityGroup(delete); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// TODO: wait for termination to complete.
|
||||
return &pbempty.Empty{}, nil
|
||||
}
|
||||
|
||||
// securityGroup represents the state associated with a security group.
|
||||
|
|
Loading…
Reference in a new issue