Class: Aws::RailsProvisioner::Vpc

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-rails-provisioner/vpc.rb

Defined Under Namespace

Classes: Subnet

Constant Summary collapse

SUBNETS_DEFAULTS =
{
  application: {
    cidr_mask: 24,
    type: 'private'
  },
  ingress: {
    cidr_mask: 24,
    type: 'public'
  },
  database: {
    cidr_mask: 28,
    type: 'isolated'
  }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Vpc

Configuration value under :vpc

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :max_azs (Integer)

    maximum number of AZs to use in this region, default to 3

  • :cidr (String)

    CIDR range to use for the VPC, default to '10.0.0.0/21'

  • :subnets (Hash)

    subnets configuration to build for each AZ, default to following example:

    @example: at `aws-rails-provisioner.yml`
      subnets:
        application:
          cidr_mask: 24
          type: private
        ingress:
          cidr_mask: 24
          type: public
        database:
          cidr_mask: 28
          type: isolate
    
  • :enable_dns (Boolean)

    whether the DNS resolution is supported for the VPC, default to `true`

  • :nat_gateways (Integer)

    number of NAT Gateways to create, default to :maxAz value

  • :nat_gateway_subnets (Hash)

    choose the subnets that will have NAT Gateway attached, default to public:

    @example: at `aws-rails-provisioner.yml`
      nat_gateway_subnets:
        type: public
    

    Note: Either subnet `:type` or `:name` can be provided @see SubnetSelection

See Also:

  • CDK VpcNetworkProps


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/aws-rails-provisioner/vpc.rb', line 60

def initialize(options = {})
  @max_azs = options[:max_azs] || 3
  @cidr = options[:cidr] || '10.0.0.0/21'
  subnets_config = options[:subnets] || SUBNETS_DEFAULTS
  @subnets = subnets_config.map do |name, config|
    Subnet.new(
      cidr_mask: config[:cidr_mask],
      subnet_name: name,
      type: config[:type]
    )
  end
  @enable_dns = options[:enable_dns].nil? ? true : !!options[:enable_dns]
  @nat_gateways = options[:nat_gateways] || @max_azs
  @nat_gateway_subnets = Aws::RailsProvisioner::SubnetSelection.new(options[:nat_gateway_subnets]) if options[:nat_gateway_subnets]
end

Instance Attribute Details

#cidrString (readonly)

Returns:

  • (String)


86
87
88
# File 'lib/aws-rails-provisioner/vpc.rb', line 86

def cidr
  @cidr
end

#enable_dnsBoolean (readonly)

Returns:

  • (Boolean)


89
90
91
# File 'lib/aws-rails-provisioner/vpc.rb', line 89

def enable_dns
  @enable_dns
end

#max_azsInteger (readonly)

Returns:

  • (Integer)


77
78
79
# File 'lib/aws-rails-provisioner/vpc.rb', line 77

def max_azs
  @max_azs
end

#nat_gateway_subnetsAws::RailsProvisioner::SubnetSelection | nil (readonly)



83
84
85
# File 'lib/aws-rails-provisioner/vpc.rb', line 83

def nat_gateway_subnets
  @nat_gateway_subnets
end

#nat_gatewaysInteger (readonly)

Returns:

  • (Integer)


80
81
82
# File 'lib/aws-rails-provisioner/vpc.rb', line 80

def nat_gateways
  @nat_gateways
end

#subnetsArray|nil (readonly)

Returns:

  • (Array|nil)


92
93
94
# File 'lib/aws-rails-provisioner/vpc.rb', line 92

def subnets
  @subnets
end