awsclient

package
v0.0.0-...-b1d5767 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2016 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StackResourceRegion    = "AWSRegion"
	StackResourceAccountID = "AccountID"
)

Variables

View Source
var BaseStackTemplate = Template{
	AWSTemplateFormatVersion: "2010-09-09",
	Description:              "Infrastructure required to bootstrap a BOSH director",
	Parameters: map[string]Parameter{
		"KeyName": Parameter{
			Type:        "AWS::EC2::KeyPair::KeyName",
			Description: "Name of existing SSH Keypair to use for instances",
		},
		"NATInstanceAMI": Parameter{
			Type:        "AWS::EC2::Image::Id",
			Description: "AMI ID for NAT instance.  Use the get-nat-ami tool to find the current AMI ID",
		},
		"NATInstanceType": Parameter{
			Type:        "String",
			Default:     "t2.large",
			Description: "EC2 instance type for NAT instance",
		},
		"BOSHInboundCIDR": Parameter{
			Type:        "String",
			Default:     "0.0.0.0/0",
			Description: "CIDR to permit access to BOSH (e.g. 205.103.216.37/32 for your specific IP)",
		},
		"VPCCIDR": Parameter{
			Type:        "String",
			Default:     "10.0.0.0/16",
			Description: "CIDR block for the VPC.",
		},
		"BOSHSubnetCIDR": Parameter{
			Type:        "String",
			Default:     "10.0.0.0/24",
			Description: "CIDR block for the BOSH subnet.",
		},
		"PrivateSubnetCIDR": Parameter{
			Type:        "String",
			Default:     "10.0.1.0/24",
			Description: "CIDR block for the private subnet.",
		},
	},
	Resources: map[string]Resource{
		"BOSHDirectorUser": {
			Type: "AWS::IAM::User",
			Properties: map[string]interface{}{
				"ManagedPolicyArns": []string{"arn:aws:iam::aws:policy/AdministratorAccess"},
			},
		},
		"NATSecurityGroup": {
			Type: "AWS::EC2::SecurityGroup",
			Properties: map[string]interface{}{
				"SecurityGroupIngress": []Rule{
					{
						ToPort:     65535,
						FromPort:   0,
						IpProtocol: "-1",
						CidrIp:     Ref("VPCCIDR"),
					},
					{
						ToPort:     22,
						FromPort:   22,
						IpProtocol: "tcp",
						CidrIp:     Ref("BOSHInboundCIDR"),
					},
				},
				"VpcId":               Ref("VPC"),
				"GroupDescription":    "NAT",
				"SecurityGroupEgress": []interface{}{},
			},
		},
		"BOSHSecurityGroup": {
			Type: "AWS::EC2::SecurityGroup",
			Properties: map[string]interface{}{
				"SecurityGroupIngress": []Rule{
					{
						ToPort:     22,
						FromPort:   22,
						IpProtocol: "tcp",
						CidrIp:     Ref("BOSHInboundCIDR"),
					},
					{
						ToPort:     6868,
						FromPort:   6868,
						IpProtocol: "tcp",
						CidrIp:     Ref("BOSHInboundCIDR"),
					},
					{
						ToPort:     25555,
						FromPort:   25555,
						IpProtocol: "tcp",
						CidrIp:     Ref("BOSHInboundCIDR"),
					},
					{
						ToPort:     65535,
						FromPort:   0,
						IpProtocol: "-1",
						CidrIp:     Ref("VPCCIDR"),
					},
				},
				"VpcId":               Ref("VPC"),
				"GroupDescription":    "BOSH",
				"SecurityGroupEgress": []interface{}{},
			},
		},
		"NATEIP": {
			Type: "AWS::EC2::EIP",
			Properties: map[string]interface{}{
				"InstanceId": Ref("NATInstance"),
				"Domain":     "vpc",
			},
		},
		"VPC": {
			Type: "AWS::EC2::VPC",
			Properties: map[string]interface{}{
				"CidrBlock": Ref("VPCCIDR"),
			},
		},
		"PrivateSubnetRouteTableAssociation": {
			Type: "AWS::EC2::SubnetRouteTableAssociation",
			Properties: map[string]interface{}{
				"SubnetId":     Ref("PrivateSubnet"),
				"RouteTableId": Ref("PrivateRouteTable"),
			},
		},
		"PrivateSubnet": {
			Type: "AWS::EC2::Subnet",
			Properties: map[string]interface{}{
				"VpcId":     Ref("VPC"),
				"CidrBlock": Ref("PrivateSubnetCIDR"),
				"Tags":      []Tag{{Key: "Name", Value: "Private"}},
			},
		},
		"VPCGatewayAttachment": {
			Type: "AWS::EC2::VPCGatewayAttachment",
			Properties: map[string]interface{}{
				"VpcId":             Ref("VPC"),
				"InternetGatewayId": Ref("VPCGatewayInternetGateway"),
			},
		},
		"NATInstance": {
			Type: "AWS::EC2::Instance",
			Properties: map[string]interface{}{
				"SourceDestCheck":  false,
				"Tags":             []Tag{{Key: "Name", Value: "NAT"}},
				"SecurityGroupIds": []interface{}{Ref("NATSecurityGroup")},
				"KeyName":          Ref("KeyName"),
				"SubnetId":         Ref("BOSHSubnet"),
				"ImageId":          Ref("NATInstanceAMI"),
				"InstanceType":     Ref("NATInstanceType"),
				"UserData": FnBase64(FnJoin("\n",
					"#!/bin/bash",
					"set -x -u -e",
					"sleep 30",
					"yum update -y",
					"yum install -y gcc gcc-c++ ruby ruby-devel mysql-devel postgresql-devel postgresql-libs sqlite-devel libxslt-devel libxml2-devel yajl-ruby patch",
					"mkdir -p /usr/local/bin",
					"curl -L -o /usr/local/bin/bosh-init https://s3.amazonaws.com/bosh-init-artifacts/bosh-init-0.0.81-linux-amd64",
					"chmod +x /usr/local/bin/bosh-init",
					"su -c 'gem install bosh_cli --no-ri --no-rdoc' ec2-user",
				)),
			},
		},
		"VPCGatewayInternetGateway": {
			Type: "AWS::EC2::InternetGateway",
		},
		"BOSHRouteTable": {
			Type: "AWS::EC2::RouteTable",
			Properties: map[string]interface{}{
				"VpcId": Ref("VPC"),
			},
		},
		"PrivateOutboundRoute": {
			Type: "AWS::EC2::Route",
			Properties: map[string]interface{}{
				"InstanceId":           Ref("NATInstance"),
				"DestinationCidrBlock": "0.0.0.0/0",
				"RouteTableId":         Ref("PrivateRouteTable"),
			},
			DependsOn: "NATInstance",
		},
		"PrivateRouteTable": {
			Type: "AWS::EC2::RouteTable",
			Properties: map[string]interface{}{
				"VpcId": Ref("VPC"),
			},
		},
		"BOSHRoute": {
			Type: "AWS::EC2::Route",
			Properties: map[string]interface{}{
				"GatewayId":            Ref("VPCGatewayInternetGateway"),
				"RouteTableId":         Ref("BOSHRouteTable"),
				"DestinationCidrBlock": "0.0.0.0/0",
			},
			DependsOn: "VPCGatewayInternetGateway",
		},
		"BOSHSubnetRouteTableAssociation": {
			Type: "AWS::EC2::SubnetRouteTableAssociation",
			Properties: map[string]interface{}{
				"SubnetId":     Ref("BOSHSubnet"),
				"RouteTableId": Ref("BOSHRouteTable"),
			},
		},
		"BOSHSubnet": {
			Type: "AWS::EC2::Subnet",
			Properties: map[string]interface{}{
				"VpcId":     Ref("VPC"),
				"CidrBlock": Ref("BOSHSubnetCIDR"),
				"Tags":      []Tag{{Key: "Name", Value: "BOSH"}},
			},
		},
		"BOSHDirectorIP": {
			Type: "AWS::EC2::EIP",
			Properties: map[string]interface{}{
				"Domain": "vpc",
			},
		},
	},
}
View Source
var ConcourseStackTemplate = Template{
	AWSTemplateFormatVersion: "2010-09-09",
	Description:              "Infrastructure required to bootstrap a Concourse deployment, on top of an existing Base Stack for BOSH",
	Parameters: map[string]Parameter{
		"VPCID": Parameter{
			Type:        "AWS::EC2::VPC::Id",
			Description: "VPC ID to create the subnet and security group inside of",
		},
		"VPCCIDR": Parameter{
			Type:        "String",
			Default:     "10.0.0.0/16",
			Description: "CIDR block of the parent VPC",
		},
		"NATInstance": Parameter{
			Type:        "AWS::EC2::Instance::Id",
			Description: "Instance ID of NAT box",
		},
		"ConcourseSubnetCIDR": Parameter{
			Type:        "String",
			Default:     "10.0.16.0/24",
			Description: "CIDR block for the Concourse subnet",
		},
		"PubliclyRoutableSubnetID": Parameter{
			Type:        "String",
			Description: "ID of a publicly routable subnet, usually the BOSH subnet from the base stack",
		},
		"AvailabilityZone": Parameter{
			Type:        "AWS::EC2::AvailabilityZone::Name",
			Description: "Availability zone for Concourse subnet",
		},
	},
	Resources: map[string]Resource{
		"ConcourseSecurityGroup": {
			Type: "AWS::EC2::SecurityGroup",
			Properties: map[string]interface{}{
				"SecurityGroupIngress": []Rule{
					{
						ToPort:     65535,
						FromPort:   0,
						IpProtocol: "-1",
						CidrIp:     Ref("VPCCIDR"),
					},
				},
				"VpcId":               Ref("VPCID"),
				"GroupDescription":    "Concourse",
				"SecurityGroupEgress": []interface{}{},
			},
		},
		"ConcourseSubnetRouteTableAssociation": {
			Type: "AWS::EC2::SubnetRouteTableAssociation",
			Properties: map[string]interface{}{
				"SubnetId":     Ref("ConcourseSubnet"),
				"RouteTableId": Ref("ConcourseRouteTable"),
			},
		},
		"ConcourseSubnet": {
			Type: "AWS::EC2::Subnet",
			Properties: map[string]interface{}{
				"VpcId":            Ref("VPCID"),
				"AvailabilityZone": Ref("AvailabilityZone"),
				"CidrBlock":        Ref("ConcourseSubnetCIDR"),
				"Tags":             []Tag{{Key: "Name", Value: "Concourse"}},
			},
		},
		"ConcourseOutboundRoute": {
			Type: "AWS::EC2::Route",
			Properties: map[string]interface{}{
				"InstanceId":           Ref("NATInstance"),
				"DestinationCidrBlock": "0.0.0.0/0",
				"RouteTableId":         Ref("ConcourseRouteTable"),
			},
		},
		"ConcourseRouteTable": {
			Type: "AWS::EC2::RouteTable",
			Properties: map[string]interface{}{
				"VpcId": Ref("VPCID"),
			},
		},
		"LoadBalancerSecurityGroup": {
			Type: "AWS::EC2::SecurityGroup",
			Properties: map[string]interface{}{
				"SecurityGroupIngress": []Rule{
					{
						ToPort:     80,
						FromPort:   80,
						IpProtocol: "tcp",
						CidrIp:     "0.0.0.0/0",
					},
					{
						ToPort:     2222,
						FromPort:   2222,
						IpProtocol: "tcp",
						CidrIp:     "0.0.0.0/0",
					},
					{
						ToPort:     443,
						FromPort:   443,
						IpProtocol: "tcp",
						CidrIp:     "0.0.0.0/0",
					},
				},
				"VpcId":               Ref("VPCID"),
				"GroupDescription":    "Concourse-LoadBalancer",
				"SecurityGroupEgress": []interface{}{},
			},
		},
		"LoadBalancer": {
			Type: "AWS::ElasticLoadBalancing::LoadBalancer",
			Properties: map[string]interface{}{
				"Subnets":        []interface{}{Ref("PubliclyRoutableSubnetID")},
				"SecurityGroups": []interface{}{Ref("LoadBalancerSecurityGroup")},
				"HealthCheck": map[string]string{
					"HealthyThreshold":   "2",
					"Interval":           "30",
					"Target":             "tcp:8080",
					"Timeout":            "5",
					"UnhealthyThreshold": "10",
				},
				"Listeners": []map[string]string{
					map[string]string{
						"Protocol":         "tcp",
						"LoadBalancerPort": "80",
						"InstanceProtocol": "tcp",
						"InstancePort":     "8080",
					},
					map[string]string{
						"Protocol":         "tcp",
						"LoadBalancerPort": "2222",
						"InstanceProtocol": "tcp",
						"InstancePort":     "2222",
					},
				},
			},
		},
	},
}

Functions

This section is empty.

Types

type ARN

type ARN struct {
	Partition string
	Service   string
	Region    string
	AccountID string
	Resource  string
}

ARN represents an Amazon Resource Name http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html

type BaseStackResources

type BaseStackResources struct {
	AvailabilityZone  string
	BOSHSubnetCIDR    string
	BOSHSubnetID      string
	BOSHElasticIP     string
	BOSHSecurityGroup string
	AccountID         string
	BOSHUser          string
	AWSRegion         string
	NATInstanceID     string
	NATElasticIP      string
	VPCID             string
}

type Client

type Client struct {
	EC2                       ec2Client
	CloudFormation            cloudformationClient
	IAM                       iamClient
	Clock                     clock
	CloudFormationWaitTimeout time.Duration
}

func New

func New(config Config) (*Client, error)

func (*Client) CreateAccessKey

func (c *Client) CreateAccessKey(userName string) (string, string, error)

func (*Client) CreateKeyPair

func (c *Client) CreateKeyPair(keyName string) (string, error)

func (*Client) DeleteAccessKey

func (c *Client) DeleteAccessKey(userName, accessKeyID string) error

func (*Client) DeleteKeyPair

func (c *Client) DeleteKeyPair(keyName string) error

func (*Client) DeleteStack

func (c *Client) DeleteStack(stackName string) error

func (*Client) GetBaseStackResources

func (c *Client) GetBaseStackResources(stackName string) (BaseStackResources, error)

func (*Client) GetLatestNATBoxAMIID

func (c *Client) GetLatestNATBoxAMIID() (string, error)

func (*Client) GetStackResources

func (c *Client) GetStackResources(stackName string) (map[string]string, error)

func (*Client) ListAccessKeys

func (c *Client) ListAccessKeys(userName string) ([]string, error)

func (Client) ParseARN

func (c Client) ParseARN(arn string) (ARN, error)

ParseARN parses an ARN string into its component fields

func (*Client) UpsertStack

func (c *Client) UpsertStack(stackName string, template string, parameters map[string]string) error

func (*Client) WaitForStack

func (c *Client) WaitForStack(stackName string, pundit CloudFormationStatusPundit) error

type CloudFormationDeletePundit

type CloudFormationDeletePundit struct{}

func (CloudFormationDeletePundit) IsComplete

func (p CloudFormationDeletePundit) IsComplete(statusString string) bool

func (CloudFormationDeletePundit) IsHealthy

func (p CloudFormationDeletePundit) IsHealthy(statusString string) bool

type CloudFormationStatusPundit

type CloudFormationStatusPundit interface {
	IsHealthy(statusString string) bool
	IsComplete(statusString string) bool
}

type CloudFormationUpsertPundit

type CloudFormationUpsertPundit struct{}

func (CloudFormationUpsertPundit) IsComplete

func (p CloudFormationUpsertPundit) IsComplete(statusString string) bool

func (CloudFormationUpsertPundit) IsHealthy

func (p CloudFormationUpsertPundit) IsHealthy(statusString string) bool

type Config

type Config struct {
	Region                    string
	AccessKey                 string
	SecretKey                 string
	CloudFormationWaitTimeout time.Duration
	EndpointOverrides         map[string]string
}

type Rule

type Rule struct {
	ToPort     int `json:",string"`
	FromPort   int `json:",string"`
	IpProtocol string
	CidrIp     interface{}
}

type Tag

type Tag struct {
	Key   string
	Value string
}

Jump to

Keyboard shortcuts

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