Documentation
¶
Index ¶
- func SubnetCIDRWithinVPC(vpcCIDR, subnetCIDR string) bool
- func ValidateCIDR(cidr string) bool
- type EC2Service
- type ElasticIP
- type IGWAttachment
- type Instance
- type InternetGateway
- type NACLEntry
- type NatGateway
- type NetworkACL
- type NetworkInterface
- type Route
- type RouteTable
- type RouteTableAssociation
- type SGRule
- type SecurityGroup
- type Store
- func (s *Store) AcceptVPCPeeringConnection(pcxId string) (*VPCPeeringConnection, string)
- func (s *Store) AllocateAddress() *ElasticIP
- func (s *Store) AssociateAddress(allocationId, instanceId, networkInterfaceId string) (string, string)
- func (s *Store) AssociateRouteTable(rtbId, subnetId string) (string, string)
- func (s *Store) AttachInternetGateway(igwId, vpcId string) string
- func (s *Store) AuthorizeSecurityGroupEgress(groupId string, rules []SGRule) string
- func (s *Store) AuthorizeSecurityGroupIngress(groupId string, rules []SGRule) string
- func (s *Store) CreateInternetGateway() *InternetGateway
- func (s *Store) CreateNatGateway(subnetId, allocationId string) (*NatGateway, string)
- func (s *Store) CreateNetworkACL(vpcId string) (*NetworkACL, string)
- func (s *Store) CreateNetworkACLEntry(aclId string, entry NACLEntry) string
- func (s *Store) CreateNetworkInterface(subnetId string, sgIds []string) (*NetworkInterface, string)
- func (s *Store) CreateRoute(rtbId, destCidr, gatewayId, natGatewayId, vpcEndpointId string) string
- func (s *Store) CreateRouteTable(vpcId string) (*RouteTable, string)
- func (s *Store) CreateSecurityGroup(groupName, description, vpcId string) (*SecurityGroup, string)
- func (s *Store) CreateSubnet(vpcId, cidrBlock, availabilityZone string) (*Subnet, string)
- func (s *Store) CreateTags(resourceIds []string, tags map[string]string)
- func (s *Store) CreateVPC(cidrBlock string, enableDnsSupport, enableDnsHostnames bool) (*VPC, error)
- func (s *Store) CreateVPCEndpoint(vpcId, serviceName, epType string) (*VPCEndpoint, string)
- func (s *Store) CreateVPCPeeringConnection(requesterVpcId, accepterVpcId string) (*VPCPeeringConnection, string)
- func (s *Store) DeleteInternetGateway(igwId string) string
- func (s *Store) DeleteNatGateway(natGatewayId string) string
- func (s *Store) DeleteNetworkACL(aclId string) string
- func (s *Store) DeleteNetworkACLEntry(aclId string, ruleNumber int, egress bool) string
- func (s *Store) DeleteNetworkInterface(eniId string) string
- func (s *Store) DeleteRoute(rtbId, destCidr string) string
- func (s *Store) DeleteRouteTable(rtbId string) string
- func (s *Store) DeleteSecurityGroup(groupId string) string
- func (s *Store) DeleteSubnet(subnetId string) bool
- func (s *Store) DeleteTags(resourceIds []string, keys []string)
- func (s *Store) DeleteVPC(vpcId string) (string, bool)
- func (s *Store) DeleteVPCEndpoint(epId string) string
- func (s *Store) DeleteVPCPeeringConnection(pcxId string) string
- func (s *Store) DetachInternetGateway(igwId, vpcId string) string
- func (s *Store) DisassociateAddress(assocId string) string
- func (s *Store) DisassociateRouteTable(assocId string) string
- func (s *Store) GetSecurityGroup(groupId string) (*SecurityGroup, bool)
- func (s *Store) GetSubnet(subnetId string) (*Subnet, bool)
- func (s *Store) GetVPC(vpcId string) (*VPC, bool)
- func (s *Store) ListAddresses(ids []string) []*ElasticIP
- func (s *Store) ListInstances(ids []string, filters map[string][]string) []*Instance
- func (s *Store) ListInternetGateways(ids []string, filterVpcId string) []*InternetGateway
- func (s *Store) ListNatGateways(ids []string, filterSubnetId, filterVpcId, filterState string) []*NatGateway
- func (s *Store) ListNetworkACLs(ids []string, filterVpcId string) []*NetworkACL
- func (s *Store) ListNetworkInterfaces(ids []string, filterSubnetId string) []*NetworkInterface
- func (s *Store) ListRouteTableAssociations(rtbId string) []*RouteTableAssociation
- func (s *Store) ListRouteTables(ids []string, filterVpcId string) []*RouteTable
- func (s *Store) ListSecurityGroups(ids []string, vpcId, groupName string) []*SecurityGroup
- func (s *Store) ListSubnets(ids []string, vpcId string) []*Subnet
- func (s *Store) ListTags(filters map[string][]string) []TagEntry
- func (s *Store) ListVPCEndpoints(ids []string, filterVpcId string) []*VPCEndpoint
- func (s *Store) ListVPCs(ids []string) []*VPC
- func (s *Store) ModifyVPCAttribute(vpcId string, dnsSupport, dnsHostnames *bool) bool
- func (s *Store) ReleaseAddress(allocationId string) string
- func (s *Store) ReplaceRoute(rtbId, destCidr, gatewayId, natGatewayId, vpcEndpointId string) string
- func (s *Store) RevokeSecurityGroupEgress(groupId string, rules []SGRule) string
- func (s *Store) RevokeSecurityGroupIngress(groupId string, rules []SGRule) string
- func (s *Store) RunInstances(imageId, instanceType, subnetId, keyName string, sgIds []string, count int) ([]*Instance, string, string)
- func (s *Store) StartInstances(ids []string) map[string][2]string
- func (s *Store) StopInstances(ids []string) map[string][2]string
- func (s *Store) TerminateInstances(ids []string) map[string][2]string
- type Subnet
- type TagEntry
- type VPC
- type VPCEndpoint
- type VPCPeeringConnection
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SubnetCIDRWithinVPC ¶
SubnetCIDRWithinVPC returns true if the subnet CIDR block is fully contained within the VPC CIDR block.
func ValidateCIDR ¶
ValidateCIDR checks whether a CIDR string is syntactically valid.
Types ¶
type EC2Service ¶
type EC2Service struct {
// contains filtered or unexported fields
}
EC2Service is the cloudmock implementation of the AWS EC2 API.
func New ¶
func New(accountID, region string) *EC2Service
New returns a new EC2Service for the given AWS account ID and region. It automatically creates the default VPC (172.31.0.0/16) with 3 subnets, a default route table, security group, NACL, and an attached internet gateway.
func (*EC2Service) Actions ¶
func (s *EC2Service) Actions() []service.Action
Actions returns the list of EC2 API actions supported by this service.
func (*EC2Service) HandleRequest ¶
func (s *EC2Service) HandleRequest(ctx *service.RequestContext) (*service.Response, error)
HandleRequest routes an incoming EC2 request to the appropriate handler. EC2 uses form-encoded POST bodies; the Action may appear in the query string (already parsed into ctx.Params) or in the form-encoded body.
func (*EC2Service) HealthCheck ¶
func (s *EC2Service) HealthCheck() error
HealthCheck always returns nil (no external dependencies).
func (*EC2Service) Name ¶
func (s *EC2Service) Name() string
Name returns the AWS service name used for routing.
func (*EC2Service) ResourceSchemas ¶
func (s *EC2Service) ResourceSchemas() []schema.ResourceSchema
ResourceSchemas returns schemas for EC2 VPC, Subnet, SecurityGroup, and Instance resources.
type ElasticIP ¶
type ElasticIP struct {
AllocationId string
PublicIp string
AssociationId string
InstanceId string
NetworkInterfaceId string
Tags map[string]string
}
ElasticIP represents an allocated Elastic IP address.
type IGWAttachment ¶
IGWAttachment records a VPC attached to an internet gateway.
type Instance ¶
type Instance struct {
InstanceId string
ImageId string
InstanceType string
SubnetId string
VpcId string
SecurityGroupIds []string
KeyName string
State string // pending, running, stopping, stopped, shutting-down, terminated
LaunchTime time.Time
PrivateIpAddress string
Tags map[string]string
}
Instance represents an EC2 instance.
type InternetGateway ¶
type InternetGateway struct {
IgwId string
Attachments []IGWAttachment
Tags map[string]string
}
InternetGateway represents an EC2 internet gateway.
type NACLEntry ¶
type NACLEntry struct {
RuleNumber int
Protocol string
RuleAction string // allow, deny
Egress bool
CidrBlock string
}
NACLEntry represents a single rule in a Network ACL.
type NatGateway ¶
type NatGateway struct {
NatGatewayId string
SubnetId string
VpcId string
AllocationId string
State string // available, deleted
Tags map[string]string
}
NatGateway represents an EC2 NAT gateway.
type NetworkACL ¶
type NetworkACL struct {
NetworkAclId string
VpcId string
Entries []NACLEntry
IsDefault bool
Tags map[string]string
}
NetworkACL represents a VPC network ACL (auto-created with VPC).
type NetworkInterface ¶
type NetworkInterface struct {
NetworkInterfaceId string
SubnetId string
VpcId string
PrivateIpAddress string
SecurityGroupIds []string
Status string // available, in-use
Tags map[string]string
}
NetworkInterface represents an EC2 elastic network interface.
type Route ¶
type Route struct {
DestinationCidrBlock string
GatewayId string // igw-*, local, or vpce-*
NatGatewayId string
VpcEndpointId string
State string // active
Origin string // CreateRoute or CreateRouteTable
}
Route represents a single entry in a route table.
type RouteTable ¶
type RouteTable struct {
RouteTableId string
VpcId string
IsMain bool
Routes []Route
Tags map[string]string
}
RouteTable represents a VPC route table (auto-created with VPC).
type RouteTableAssociation ¶
type RouteTableAssociation struct {
AssociationId string
RouteTableId string
SubnetId string
Main bool
}
RouteTableAssociation links a subnet to a route table.
type SGRule ¶
type SGRule struct {
IpProtocol string // tcp, udp, icmp, -1 (all)
FromPort int
ToPort int
CidrBlocks []string // CIDR ranges (e.g. "0.0.0.0/0")
GroupIds []string // referenced security group IDs
}
SGRule represents a single inbound or outbound security group rule.
type SecurityGroup ¶
type SecurityGroup struct {
GroupId string
GroupName string
Description string
VpcId string
IngressRules []SGRule
EgressRules []SGRule
Tags map[string]string
}
SecurityGroup represents a VPC security group (auto-created with VPC).
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store manages all EC2 resources.
func (*Store) AcceptVPCPeeringConnection ¶
func (s *Store) AcceptVPCPeeringConnection(pcxId string) (*VPCPeeringConnection, string)
AcceptVPCPeeringConnection accepts a pending peering connection. Returns the updated connection and an error code string.
func (*Store) AllocateAddress ¶
AllocateAddress allocates a new Elastic IP in the vpc domain.
func (*Store) AssociateAddress ¶
func (s *Store) AssociateAddress(allocationId, instanceId, networkInterfaceId string) (string, string)
AssociateAddress associates an EIP with an instance or ENI. Returns the association ID and an error code string.
func (*Store) AssociateRouteTable ¶
AssociateRouteTable links a subnet to a route table. Returns the association ID and an error code string.
func (*Store) AttachInternetGateway ¶
AttachInternetGateway attaches an IGW to a VPC. Returns an error code string. Empty string means success.
func (*Store) AuthorizeSecurityGroupEgress ¶
AuthorizeSecurityGroupEgress adds egress rules to a security group.
func (*Store) AuthorizeSecurityGroupIngress ¶
AuthorizeSecurityGroupIngress adds ingress rules to a security group.
func (*Store) CreateInternetGateway ¶
func (s *Store) CreateInternetGateway() *InternetGateway
CreateInternetGateway creates a new detached internet gateway.
func (*Store) CreateNatGateway ¶
func (s *Store) CreateNatGateway(subnetId, allocationId string) (*NatGateway, string)
CreateNatGateway creates a new NAT gateway in the given subnet with the given EIP allocation ID. Returns the gateway and an error code string.
func (*Store) CreateNetworkACL ¶
func (s *Store) CreateNetworkACL(vpcId string) (*NetworkACL, string)
CreateNetworkACL creates a new (non-default) network ACL in the given VPC.
func (*Store) CreateNetworkACLEntry ¶
CreateNetworkACLEntry adds a rule to a NACL. Returns an error code string.
func (*Store) CreateNetworkInterface ¶
func (s *Store) CreateNetworkInterface(subnetId string, sgIds []string) (*NetworkInterface, string)
CreateNetworkInterface creates a new ENI in the given subnet. Assigns a private IP from the subnet's CIDR (10.0.x.x range).
func (*Store) CreateRoute ¶
CreateRoute adds a new route to a route table. Returns an error code string. Validates that the gateway/NAT GW target exists.
func (*Store) CreateRouteTable ¶
func (s *Store) CreateRouteTable(vpcId string) (*RouteTable, string)
CreateRouteTable creates a new route table in the given VPC with a local route.
func (*Store) CreateSecurityGroup ¶
func (s *Store) CreateSecurityGroup(groupName, description, vpcId string) (*SecurityGroup, string)
CreateSecurityGroup creates a new security group in the given VPC. Returns the new group and an error code string (empty on success).
func (*Store) CreateSubnet ¶
CreateSubnet creates a new subnet within a VPC. Validates that the subnet CIDR falls within the VPC CIDR.
func (*Store) CreateTags ¶
CreateTags applies tags to one or more resources.
func (*Store) CreateVPC ¶
func (s *Store) CreateVPC(cidrBlock string, enableDnsSupport, enableDnsHostnames bool) (*VPC, error)
CreateVPC creates a new VPC with the given CIDR block and also creates the default route table, security group, and network ACL for the VPC.
func (*Store) CreateVPCEndpoint ¶
func (s *Store) CreateVPCEndpoint(vpcId, serviceName, epType string) (*VPCEndpoint, string)
CreateVPCEndpoint creates a new VPC endpoint. Returns the endpoint and an error code string.
func (*Store) CreateVPCPeeringConnection ¶
func (s *Store) CreateVPCPeeringConnection(requesterVpcId, accepterVpcId string) (*VPCPeeringConnection, string)
CreateVPCPeeringConnection creates a new peering connection between two VPCs. Returns the connection and an error code string.
func (*Store) DeleteInternetGateway ¶
DeleteInternetGateway deletes an IGW. Fails if still attached to a VPC.
func (*Store) DeleteNatGateway ¶
DeleteNatGateway sets a NAT gateway's state to deleted. Returns an error code.
func (*Store) DeleteNetworkACL ¶
DeleteNetworkACL removes a non-default NACL. Returns an error code string.
func (*Store) DeleteNetworkACLEntry ¶
DeleteNetworkACLEntry removes a rule from a NACL. Returns an error code string.
func (*Store) DeleteNetworkInterface ¶
DeleteNetworkInterface removes an ENI. Returns an error code string.
func (*Store) DeleteRoute ¶
DeleteRoute removes a route by destination CIDR from a route table.
func (*Store) DeleteRouteTable ¶
DeleteRouteTable deletes a route table. Fails if it has subnet associations.
func (*Store) DeleteSecurityGroup ¶
DeleteSecurityGroup removes a security group. Returns an error code string or empty on success. Fails if any other security group references this one.
func (*Store) DeleteSubnet ¶
DeleteSubnet removes a subnet. Returns false if not found.
func (*Store) DeleteTags ¶
DeleteTags removes specific tag keys from one or more resources.
func (*Store) DeleteVPC ¶
DeleteVPC removes a VPC and its associated default resources. Returns an error string if the VPC has subnets (DependencyViolation) or is not found.
func (*Store) DeleteVPCEndpoint ¶
DeleteVPCEndpoint removes a VPC endpoint. Returns an error code string.
func (*Store) DeleteVPCPeeringConnection ¶
DeleteVPCPeeringConnection deletes a peering connection. Returns an error code.
func (*Store) DetachInternetGateway ¶
DetachInternetGateway detaches an IGW from a VPC. Returns an error code string.
func (*Store) DisassociateAddress ¶
DisassociateAddress removes an EIP association. Returns an error code string.
func (*Store) DisassociateRouteTable ¶
DisassociateRouteTable removes a subnet-to-route-table association.
func (*Store) GetSecurityGroup ¶
func (s *Store) GetSecurityGroup(groupId string) (*SecurityGroup, bool)
GetSecurityGroup returns a security group by ID.
func (*Store) ListAddresses ¶
ListAddresses returns EIPs, optionally filtered by allocation IDs.
func (*Store) ListInstances ¶
ListInstances returns instances filtered by IDs and/or filters. filters: map of filter-name -> values (any match).
func (*Store) ListInternetGateways ¶
func (s *Store) ListInternetGateways(ids []string, filterVpcId string) []*InternetGateway
ListInternetGateways returns IGWs filtered by IDs and/or attached VPC ID.
func (*Store) ListNatGateways ¶
func (s *Store) ListNatGateways(ids []string, filterSubnetId, filterVpcId, filterState string) []*NatGateway
ListNatGateways returns NAT gateways filtered by IDs, subnet ID, VPC ID, and/or state. Any empty filter is ignored.
func (*Store) ListNetworkACLs ¶
func (s *Store) ListNetworkACLs(ids []string, filterVpcId string) []*NetworkACL
ListNetworkACLs returns NACLs filtered by IDs and/or VPC ID.
func (*Store) ListNetworkInterfaces ¶
func (s *Store) ListNetworkInterfaces(ids []string, filterSubnetId string) []*NetworkInterface
ListNetworkInterfaces returns ENIs filtered by IDs and/or subnet ID.
func (*Store) ListRouteTableAssociations ¶
func (s *Store) ListRouteTableAssociations(rtbId string) []*RouteTableAssociation
ListRouteTableAssociations returns all associations for a given route table.
func (*Store) ListRouteTables ¶
func (s *Store) ListRouteTables(ids []string, filterVpcId string) []*RouteTable
ListRouteTables returns route tables filtered by IDs and/or VPC ID.
func (*Store) ListSecurityGroups ¶
func (s *Store) ListSecurityGroups(ids []string, vpcId, groupName string) []*SecurityGroup
ListSecurityGroups returns security groups filtered by IDs, VPC ID, and/or group name. Any filter that is empty / nil is ignored.
func (*Store) ListSubnets ¶
ListSubnets returns subnets, optionally filtered by subnet IDs and/or VPC ID.
func (*Store) ListTags ¶
ListTags returns all tags matching the provided filters. Supported filters: resource-id, resource-type, key, value.
func (*Store) ListVPCEndpoints ¶
func (s *Store) ListVPCEndpoints(ids []string, filterVpcId string) []*VPCEndpoint
ListVPCEndpoints returns endpoints filtered by IDs and/or VPC ID.
func (*Store) ModifyVPCAttribute ¶
ModifyVPCAttribute updates DNS support or DNS hostnames on a VPC.
func (*Store) ReleaseAddress ¶
ReleaseAddress releases an allocated Elastic IP. Returns an error code string.
func (*Store) ReplaceRoute ¶
ReplaceRoute updates the target for an existing route destination.
func (*Store) RevokeSecurityGroupEgress ¶
RevokeSecurityGroupEgress removes matching egress rules.
func (*Store) RevokeSecurityGroupIngress ¶
RevokeSecurityGroupIngress removes matching ingress rules.
func (*Store) RunInstances ¶
func (s *Store) RunInstances(imageId, instanceType, subnetId, keyName string, sgIds []string, count int) ([]*Instance, string, string)
RunInstances creates count instances. Returns the created instances and a reservation ID, or an error code.
func (*Store) StartInstances ¶
StartInstances sets state to running for the given instance IDs. Only instances in "stopped" state can be started.
func (*Store) StopInstances ¶
StopInstances sets state to stopped for the given instance IDs. Only instances in "running" state can be stopped.
type Subnet ¶
type Subnet struct {
SubnetId string
VpcId string
CidrBlock string
AvailabilityZone string
State string
AvailableIpAddressCount int
MapPublicIpOnLaunch bool
Tags map[string]string
}
Subnet represents an EC2 subnet within a VPC.
type VPC ¶
type VPC struct {
VpcId string
CidrBlock string
State string
IsDefault bool
OwnerId string
EnableDnsSupport bool
EnableDnsHostnames bool
DhcpOptionsId string
Tags map[string]string
}
VPC represents an EC2 Virtual Private Cloud.