This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add EC2InstanceConnectEndpoint resource (#1087)
- Loading branch information
1 parent
a3fa4aa
commit a552489
Showing
1 changed file
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package resources | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/ec2" | ||
"github.com/rebuy-de/aws-nuke/v2/pkg/types" | ||
) | ||
|
||
type EC2InstanceConnectEndpoint struct { | ||
svc *ec2.EC2 | ||
az *string | ||
createdAt *time.Time | ||
dnsName *string | ||
fipsDNSName *string | ||
id *string | ||
ownerID *string | ||
state *string | ||
subnetID *string | ||
tags []*ec2.Tag | ||
vpcID *string | ||
} | ||
|
||
func init() { | ||
register("EC2InstanceConnectEndpoint", ListEC2InstanceConnectEndpoints) | ||
} | ||
|
||
func ListEC2InstanceConnectEndpoints(sess *session.Session) ([]Resource, error) { | ||
svc := ec2.New(sess) | ||
params := &ec2.DescribeInstanceConnectEndpointsInput{} | ||
resources := make([]Resource, 0) | ||
for { | ||
resp, err := svc.DescribeInstanceConnectEndpoints(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, endpoint := range resp.InstanceConnectEndpoints { | ||
resources = append(resources, &EC2InstanceConnectEndpoint{ | ||
svc: svc, | ||
az: endpoint.AvailabilityZone, | ||
createdAt: endpoint.CreatedAt, | ||
dnsName: endpoint.DnsName, | ||
fipsDNSName: endpoint.FipsDnsName, | ||
id: endpoint.InstanceConnectEndpointId, | ||
ownerID: endpoint.OwnerId, | ||
state: endpoint.State, | ||
subnetID: endpoint.SubnetId, | ||
tags: endpoint.Tags, | ||
vpcID: endpoint.VpcId, | ||
}) | ||
} | ||
|
||
if resp.NextToken == nil { | ||
break | ||
} | ||
|
||
params.NextToken = resp.NextToken | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (i *EC2InstanceConnectEndpoint) Remove() error { | ||
params := &ec2.DeleteInstanceConnectEndpointInput{ | ||
InstanceConnectEndpointId: i.id, | ||
} | ||
|
||
_, err := i.svc.DeleteInstanceConnectEndpoint(params) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (i *EC2InstanceConnectEndpoint) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties.Set("ID", i.id) | ||
properties.Set("AZ", i.az) | ||
properties.Set("CreatedAt", i.createdAt.Format(time.RFC3339)) | ||
properties.Set("DNSName", i.dnsName) | ||
properties.Set("FIPSDNSName", i.fipsDNSName) | ||
properties.Set("OwnerID", i.ownerID) | ||
properties.Set("State", i.state) | ||
properties.Set("SubnetID", i.subnetID) | ||
properties.Set("VPCID", i.vpcID) | ||
|
||
for _, tagValue := range i.tags { | ||
properties.SetTag(tagValue.Key, tagValue.Value) | ||
} | ||
|
||
return properties | ||
} | ||
|
||
func (i *EC2InstanceConnectEndpoint) String() string { | ||
return *i.id | ||
} |