Module: Enscalator::Core::CfParameters

Included in:
RichTemplateDSL
Defined in:
lib/enscalator/core/cf_parameters.rb

Overview

Parameters for cloudformation template dsl

Instance Method Summary collapse

Instance Method Details

#parameter_allocated_storage(instance_name, default: 5, min: 5, max: 1024) ⇒ Object

Allocated storage parameter

Parameters:

  • instance_name (String)

    instance name

  • default (String) (defaults to: 5)

    size of instance primary storage

  • min (Integer) (defaults to: 5)

    minimal allowed value

  • max (Integer) (defaults to: 1024)

    maximum allowed value



77
78
79
80
81
82
83
84
85
# File 'lib/enscalator/core/cf_parameters.rb', line 77

def parameter_allocated_storage(instance_name, default: 5, min: 5, max: 1024)
  parameter "#{instance_name}AllocatedStorage",
            Default: default.to_s,
            Description: "The size of the #{instance_name} (Gb)",
            Type: 'Number',
            MinValue: min.to_s,
            MaxValue: max.to_s,
            ConstraintDescription: "must be between #{min} and #{max}Gb."
end

#parameter_ami(name, ami_id) ⇒ String

Ami image parameter

Parameters:

  • name (String)

    ami of the ami

  • ami_id (String)

    id of the ami

Returns:

  • (String)

    parameter name



92
93
94
95
96
97
98
99
100
101
# File 'lib/enscalator/core/cf_parameters.rb', line 92

def parameter_ami(name, ami_id)
  parameter_name = "#{name}AMIId"
  parameter parameter_name,
            Default: ami_id,
            Description: "The #{name} AMI id",
            Type: 'String',
            AllowedPattern: 'ami-[a-zA-Z0-9]*',
            ConstraintDescription: 'must be valid AMI id (ami-*).'
  parameter_name
end

#parameter_ec2_instance_type(instance_name, type: InstanceType.ec2_instance_type.current_generation[:general_purpose].first) ⇒ Object

EC2 Instance type parameter

Parameters:

  • instance_name (String)

    name of the instance

  • type (String) (defaults to: InstanceType.ec2_instance_type.current_generation[:general_purpose].first)

    instance type



127
128
129
130
131
132
# File 'lib/enscalator/core/cf_parameters.rb', line 127

def parameter_ec2_instance_type(instance_name,
                                type: InstanceType.ec2_instance_type.current_generation[:general_purpose].first)
  fail("Not supported instance type: #{type}") unless InstanceType.ec2_instance_type.supported?(type)
  warn("Using obsolete instance type: #{type}") if InstanceType.ec2_instance_type.obsolete?(type)
  parameter_instance_type(instance_name, type, allowed_values: InstanceType.ec2_instance_type.allowed_values(type))
end

#parameter_instance_type(instance_name, type, allowed_values: []) ⇒ Object

Instance type parameter

Parameters:

  • instance_name (String)

    instance name

  • type (String)

    instance type (default: t2.micro)

  • allowed_values (Array) (defaults to: [])

    list used to override built-in instance types



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/enscalator/core/cf_parameters.rb', line 108

def parameter_instance_type(instance_name, type, allowed_values: [])
  # check if given type is included in allowed_values and fails if none matched
  unless allowed_values.any? { |v| v == type }
    fail("Instance type \"#{type}\" is not in allowed values: #{allowed_values.join(' ')}")
  end
  name = "#{instance_name}InstanceType"
  parameter name,
            Default: type,
            Description: "The #{instance_name} instance type",
            Type: 'String',
            AllowedValues: allowed_values,
            ConstraintDescription: 'must be valid EC2 instance type.'
  name
end

#parameter_key_name(instance_name) ⇒ Object

Key name parameter

Parameters:

  • instance_name (String)

    for which ssh key was created



8
9
10
11
12
13
14
15
16
# File 'lib/enscalator/core/cf_parameters.rb', line 8

def parameter_key_name(instance_name)
  parameter "#{instance_name}KeyName",
            Description: "Name of the #{instance_name} ssh key pair",
            Type: 'String',
            MinLength: '1',
            MaxLength: '64',
            AllowedPattern: '[a-zA-Z][-_a-zA-Z0-9]*',
            ConstraintDescription: 'can contain only alphanumeric characters, dashes and underscores.'
end

#parameter_name(instance_name, default: nil, min_length: 1, max_length: 64) ⇒ Object

Name parameter

Parameters:

  • instance_name (String)

    instance name

  • default (String) (defaults to: nil)

    default name

  • min_length (Integer) (defaults to: 1)

    minimum length

  • max_length (Integer) (defaults to: 64)

    maximum length



24
25
26
27
28
29
30
31
32
33
# File 'lib/enscalator/core/cf_parameters.rb', line 24

def parameter_name(instance_name, default: nil, min_length: 1, max_length: 64)
  parameter "#{instance_name}Name",
            Default: default ? default.to_s : "#{instance_name}",
            Description: "#{instance_name} name",
            Type: 'String',
            MinLength: min_length,
            MaxLength: max_length,
            AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*',
            ConstraintDescription: 'must begin with a letter and contain only alphanumeric characters.'
end

#parameter_password(instance_name, default: 'password', min_length: 8, max_length: 41) ⇒ Object

Password parameter

Parameters:

  • instance_name (String)

    instance name

  • default (String) (defaults to: 'password')

    default value

  • min_length (Integer) (defaults to: 8)

    minimum length

  • max_length (Integer) (defaults to: 41)

    maximum length



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/enscalator/core/cf_parameters.rb', line 59

def parameter_password(instance_name, default: 'password', min_length: 8, max_length: 41)
  parameter "#{instance_name}Password",
            Default: default,
            NoEcho: 'true',
            Description: "Password for #{instance_name} access",
            Type: 'String',
            MinLength: min_length,
            MaxLength: max_length,
            AllowedPattern: '[a-zA-Z0-9]*',
            ConstraintDescription: 'must contain only alphanumeric characters.'
end

#parameter_rds_instance_type(instance_name, type: InstanceType.rds_instance_type.current_generation[:general_purpose].first) ⇒ Object

RDS Instance type parameter

Parameters:

  • instance_name (String)

    name of the instance

  • type (String) (defaults to: InstanceType.rds_instance_type.current_generation[:general_purpose].first)

    instance type



138
139
140
141
142
143
# File 'lib/enscalator/core/cf_parameters.rb', line 138

def parameter_rds_instance_type(instance_name,
                                type: InstanceType.rds_instance_type.current_generation[:general_purpose].first)
  fail("Not supported instance type: #{type}") unless InstanceType.rds_instance_type.supported?(type)
  warn("Using obsolete instance type: #{type}") if InstanceType.rds_instance_type.obsolete?(type)
  parameter_instance_type(instance_name, type, allowed_values: InstanceType.rds_instance_type.allowed_values(type))
end

#parameter_username(instance_name, default: 'root', min_length: 1, max_length: 16) ⇒ Object

Username parameter

Parameters:

  • instance_name (String)

    instance name

  • default (String) (defaults to: 'root')

    default username

  • min_length (Integer) (defaults to: 1)

    minimum length

  • max_length (Integer) (defaults to: 16)

    maximum length



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/enscalator/core/cf_parameters.rb', line 41

def parameter_username(instance_name, default: 'root', min_length: 1, max_length: 16)
  parameter "#{instance_name}Username",
            Default: default,
            NoEcho: 'true',
            Description: "Username for #{instance_name} access",
            Type: 'String',
            MinLength: min_length,
            MaxLength: max_length,
            AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*',
            ConstraintDescription: 'must begin with a letter and contain only alphanumeric characters.'
end