infrastructure

package
v0.0.0-...-6c4a0e2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InstanceSSHPort  = 22
	InstanceRootUser = "ubuntu"
)
View Source
const (
	InstanceTypeArchArm64 = "arm64"
	InstanceTypeArchX8664 = "x86_64"
)
View Source
const (
	UbuntuAMIRootUser         = "ubuntu"
	UbuntuAMINamePatternAmd64 = "ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"
	UbuntuAMINamePatternArm64 = "ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-arm64-server-*"
)
View Source
const DynamoDBYoloConfigTableName = "yolo-configuration-dynamodb-table"
View Source
const (
	InstanceRootDeviceSizeGb = 16
)

Variables

View Source
var (
	ErrNoYoloConfigFound       = errors.New("ErrNoYoloConfigFound")
	ErrMultipleYoloConfigFound = errors.New("ErrMultipleYoloConfigFound")
)
View Source
var (
	ErrInvalidInstanceType     = errors.New("ErrInvalidInstanceType")
	ErrInvalidInstanceTypeArch = errors.New("ErrInvalidInstanceTypeArch")

	SupportedInstanceTypeArchs = []string{
		string(InstanceTypeArchArm64),
		string(InstanceTypeArchX8664),
	}
)
View Source
var (
	ErrInstanceNotFound = errors.New("ErrInstanceNotFound")
)
View Source
var (
	ErrYoloConfigTableAlreadyExists = errors.New("ErrYoloConfigTableAlreadyExists")
)

Functions

func AssociateRouteTable

func AssociateRouteTable(
	ec2Client *ec2.Client,
	subnetID string,
	routeTableID string,
) error

func AttachElasticIPToInstance

func AttachElasticIPToInstance(
	ec2Client *ec2.Client,
	elasticIPId string,
	instanceId string,
) (string, error)

func AttachInternetGatewayToVPC

func AttachInternetGatewayToVPC(
	ec2Client *ec2.Client,
	internetGatewayId string,
	VPCID string,
) error

func CloseInstancePort

func CloseInstancePort(
	ec2Client *ec2.Client,
	securityGroupID string,
	portToClose string,
) error

func CreateDynamoDBTableForYoloConfig

func CreateDynamoDBTableForYoloConfig(
	dynamoDBClient *dynamodb.Client,
) error

func DetachElasticIPFromInstance

func DetachElasticIPFromInstance(
	ec2Client *ec2.Client,
	elasticIPAssociationId string,
) error

func DetachInternetGatewayFromVPC

func DetachInternetGatewayFromVPC(
	ec2Client *ec2.Client,
	internetGatewayId string,
	VPCID string,
) error

func LookupYoloConfigInDynamoDBTable

func LookupYoloConfigInDynamoDBTable(
	dynamoDBClient *dynamodb.Client,
) (returnedConfigJSON string, returnedError error)

func OpenInstancePort

func OpenInstancePort(
	ec2Client *ec2.Client,
	securityGroupID string,
	portToOpen string,
) error

func RemoveDynamoDBTableForYoloConfig

func RemoveDynamoDBTableForYoloConfig(
	dynamoDBClient *dynamodb.Client,
) error

func RemoveElasticIP

func RemoveElasticIP(
	ec2Client *ec2.Client,
	elasticIPId string,
) error

func RemoveInternetGateway

func RemoveInternetGateway(
	ec2Client *ec2.Client,
	internetGatewayId string,
) error

func RemoveKeyPair

func RemoveKeyPair(
	ec2Client *ec2.Client,
	keyPairID string,
) error

func RemoveNetworkInterface

func RemoveNetworkInterface(
	ec2Client *ec2.Client,
	networkInterfaceID string,
) error

func RemoveRouteTable

func RemoveRouteTable(
	ec2Client *ec2.Client,
	routeTableID string,
) error

func RemoveSecurityGroup

func RemoveSecurityGroup(
	ec2Client *ec2.Client,
	securityGroupID string,
) error

func RemoveSubnet

func RemoveSubnet(
	ec2Client *ec2.Client,
	subnetID string,
) error

func RemoveVPC

func RemoveVPC(
	ec2Client *ec2.Client,
	VPCID string,
) error

func TerminateInstance

func TerminateInstance(
	ec2Client *ec2.Client,
	instanceID string,
) error

func UpdateYoloConfigInDynamoDBTable

func UpdateYoloConfigInDynamoDBTable(
	dynamoDBClient *dynamodb.Client,
	configID string,
	configJSON string,
) error

func WaitForSSHAvailableInInstance

func WaitForSSHAvailableInInstance(
	ec2Client *ec2.Client,
	instancePublicIPAddress string,
	instanceSSHPort string,
) (returnedError error)

Types

type AMI

type AMI struct {
	ID             string `json:"id"`
	RootUser       string `json:"root_user"`
	RootDeviceName string `json:"root_device_name"`
}

func LookupUbuntuAMIForArch

func LookupUbuntuAMIForArch(
	ec2Client *ec2.Client,
	arch InstanceTypeArch,
) (returnedAMI *AMI, returnedError error)

type AttachVolumeResp

type AttachVolumeResp struct {
	Err error
}

func AttachVolume

func AttachVolume(
	ec2Client *ec2.Client,
	instanceID string,
	volumeID string,
	deviceName string,
) (resp AttachVolumeResp)

type CreateSnapshotForVolumeResp

type CreateSnapshotForVolumeResp struct {
	Err        error
	SnapshotID string
}

func CreateSnapshotForVolume

func CreateSnapshotForVolume(
	ec2Client *ec2.Client,
	name string,
	volumeID string,
) (resp CreateSnapshotForVolumeResp)

type CreateVolumeFromSnapshotResp

type CreateVolumeFromSnapshotResp struct {
	Err      error
	VolumeID string
}

func CreateVolumeFromSnapshot

func CreateVolumeFromSnapshot(
	ec2Client *ec2.Client,
	name string,
	availabilityZone string,
	snapshotID string,
) (resp CreateVolumeFromSnapshotResp)

type DetachVolumeResp

type DetachVolumeResp struct {
	Err error
}

func DetachVolume

func DetachVolume(
	ec2Client *ec2.Client,
	instanceID string,
	volumeID string,
	deviceName string,
) (resp DetachVolumeResp)

type DynamoDBYoloConfigTableRecord

type DynamoDBYoloConfigTableRecord struct {
	ID         string
	ConfigJSON string
}

type ElasticIP

type ElasticIP struct {
	ID                   string `json:"id"`
	Address              string `json:"address"`
	IsAttachedToInstance bool   `json:"is_attached_to_instance"`
	AssociationID        string `json:"association_id"`
}

func CreateElasticIP

func CreateElasticIP(
	ec2Client *ec2.Client,
	name string,
) (returnedElasticIP *ElasticIP, returnedError error)

type InitInstanceScriptResults

type InitInstanceScriptResults struct {
	ExitCode    string                   `json:"exit_code"`
	SSHHostKeys []entities.EnvSSHHostKey `json:"ssh_host_keys"`
}

func LookupInitInstanceScriptResults

func LookupInitInstanceScriptResults(
	ec2Client *ec2.Client,
	instancePublicIPAddress string,
	instanceSSHPort string,
	instanceLoginUser string,
	sshPrivateKeyContent string,
) (returnedInitScriptResults *InitInstanceScriptResults, returnedError error)

type Instance

type Instance struct {
	ID                 string                     `json:"id"`
	Type               string                     `json:"type"`
	TmpPublicIPAddress string                     `json:"tmp_public_ip_address"`
	Volumes            []InstanceVolume           `json:"volumes"`
	InitScriptResults  *InitInstanceScriptResults `json:"init_script_results"`
}

func CreateInstance

func CreateInstance(
	ec2Client *ec2.Client,
	name string,
	AMIID string,
	rootDeviceName string,
	instanceType string,
	networkInterfaceID string,
	keyName string,
) (returnedInstance *Instance, returnedError error)

type InstanceTypeArch

type InstanceTypeArch string

type InstanceTypeInfos

type InstanceTypeInfos struct {
	Type string           `json:"type"`
	Arch InstanceTypeArch `json:"arch"`
}

func LookupInstanceTypeInfos

func LookupInstanceTypeInfos(
	ec2Client *ec2.Client,
	instanceType string,
) (returnedInstanceTypeInfos *InstanceTypeInfos, returnedError error)

type InstanceVolume

type InstanceVolume struct {
	ID           string `json:"id"`
	DeviceName   string `json:"device_name"`
	SnapshotID   string `json:"snapshot_id"`
	IsRootVolume bool   `json:"is_root_volume"`
}

type InternetGateway

type InternetGateway struct {
	ID              string `json:"id"`
	IsAttachedToVPC bool   `json:"is_attached_to_vpc"`
}

func CreateInternetGateway

func CreateInternetGateway(
	ec2Client *ec2.Client,
	name string,
) (returnedIG *InternetGateway, returnedError error)

type KeyPair

type KeyPair struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	PEMContent string `json:"pem_content"`
}

func CreateKeyPair

func CreateKeyPair(
	ec2Client *ec2.Client,
	keyPairName string,
) (returnedKeyPair *KeyPair, returnedError error)

type NetworkInterface

type NetworkInterface struct {
	ID string `json:"id"`
}

func CreateNetworkInterface

func CreateNetworkInterface(
	ec2Client *ec2.Client,
	name string,
	description string,
	subnetID string,
	securityGroupIDs []string,
) (returnedNetworkInterface *NetworkInterface, returnedError error)

type RawInitInstanceScriptResults

type RawInitInstanceScriptResults struct {
	ExitCode      string `json:"exit_code"`
	SSHHostKeys   string `json:"ssh_host_keys"`
	CloudInitLogs string `json:"cloud_init_logs"`
}

type RemoveVolumeResp

type RemoveVolumeResp struct {
	Err error
}

func RemoveVolume

func RemoveVolume(
	ec2Client *ec2.Client,
	volumeID string,
) (resp RemoveVolumeResp)

type RemoveVolumeSnapshotResp

type RemoveVolumeSnapshotResp struct {
	Err error
}

func RemoveVolumeSnapshot

func RemoveVolumeSnapshot(
	ec2Client *ec2.Client,
	snapshotID string,
) (resp RemoveVolumeSnapshotResp)

type Route

type Route struct{}

func CreateRoute

func CreateRoute(
	ec2Client *ec2.Client,
	internetGatewayID string,
	routeTableID string,
) (returnedRoute *Route, returnedError error)

type RouteTable

type RouteTable struct {
	ID                   string `json:"id"`
	IsAssociatedToSubnet bool   `json:"is_associated_to_subnet"`
}

func CreateRouteTable

func CreateRouteTable(
	ec2Client *ec2.Client,
	name string,
	VPCID string,
) (returnedRouteTable *RouteTable, returnedError error)

type SecurityGroup

type SecurityGroup struct {
	ID string `json:"id"`
}

func CreateSecurityGroup

func CreateSecurityGroup(
	ec2Client *ec2.Client,
	name string,
	description string,
	VPCID string,
	ingressPorts []types.IpPermission,
) (returnedSecurityGroup *SecurityGroup, returnedError error)

type Subnet

type Subnet struct {
	ID               string `json:"id"`
	AvailabilityZone string `json:"availability_zone"`
}

func CreateSubnet

func CreateSubnet(
	ec2Client *ec2.Client,
	name string,
	cidrBlock string,
	VPCID string,
) (returnedSubnet *Subnet, returnedError error)

type VPC

type VPC struct {
	ID string `json:"id"`
}

func CreateVPC

func CreateVPC(
	ec2Client *ec2.Client,
	VPCName string,
	CIDRBlock string,
) (returnedVPC *VPC, returnedError error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL