Puppet Class: psick::aws::puppet::ec2

Defined in:
manifests/aws/puppet/ec2.pp

Overview

Setup ec2 instances and related stuff Important Params: region On which AWS region operate (mandatory) ensure Valid values: present, absent, running, stopped create_defaults Boolean to define it to automatically create a set of

default resources

ec2_instances An hash of (extra) ec2_instances to create ec2_launchconfigurations An hash of (extra) ec2_launchconfigurations create ec2_autoscalinggroups An hash of (extra) ec2_autoscalinggroups to create

A list of parameters setting the default values for default and extra ec2_instance resources. You can override them either setting the default value via the parameters, or in the $ec2_instances hash for each extra instance default_instance_type , default_image_id , default_ebs_optimized, default_monitoring, default_vpc_name

A similar list of parameters for the defaults of ec2_launchconfigurations default_autoscaling_instance_type , default_autoscaling_image_id

Parameters:

  • default_key_name (String)
  • ensure (String) (defaults to: 'present')
  • region (String) (defaults to: $psick::aws::region)
  • default_vpc_name (String) (defaults to: $psick::aws::default_vpc_name)
  • create_defaults (Boolean) (defaults to: $psick::aws::create_defaults)
  • ec2_instances (Hash) (defaults to: {})
  • ec2_launchconfigurations (Hash) (defaults to: {})
  • ec2_autoscalinggroups (Hash) (defaults to: {})
  • default_instance_type (String) (defaults to: 't2.nano')
  • default_autoscaling_instance_type (String) (defaults to: 't2.nano')
  • default_autoscaling_max_size (Integer) (defaults to: 2)
  • default_autoscaling_min_size (Integer) (defaults to: 1)
  • default_image_id (Variant[Undef,String]) (defaults to: undef)
  • default_autoscaling_image_id (Variant[Undef,String]) (defaults to: undef)
  • default_os (String) (defaults to: 'centos7')
  • default_autoscaling_os (String) (defaults to: 'amazon4')
  • default_ebs_optimized (Boolean) (defaults to: false)
  • default_monitoring (Boolean) (defaults to: false)
  • manage (Boolean) (defaults to: $psick::manage)
  • noop_manage (Boolean) (defaults to: $psick::noop_manage)
  • noop_value (Boolean) (defaults to: $psick::noop_value)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'manifests/aws/puppet/ec2.pp', line 20

class psick::aws::puppet::ec2 (
  String  $default_key_name,
  String  $ensure                  = 'present',

  String $region                    = $psick::aws::region,
  String $default_vpc_name          = $psick::aws::default_vpc_name,
  Boolean $create_defaults          = $psick::aws::create_defaults,

  # Hashes of resources to create
  Hash    $ec2_instances           = {},
  Hash    $ec2_launchconfigurations   = {},
  Hash    $ec2_autoscalinggroups = {},

  # Default settings
  String  $default_instance_type              = 't2.nano',
  String  $default_autoscaling_instance_type  = 't2.nano',
  Integer $default_autoscaling_max_size       = 2,
  Integer $default_autoscaling_min_size       = 1,

  Variant[Undef,String] $default_image_id = undef,
  Variant[Undef,String] $default_autoscaling_image_id = undef,

  String $default_os                   = 'centos7',
  String $default_autoscaling_os       = 'amazon4',

  Boolean $default_ebs_optimized       = false,
  Boolean $default_monitoring          = false,

  Boolean          $manage               = $psick::manage,
  Boolean          $noop_manage          = $psick::noop_manage,
  Boolean          $noop_value           = $psick::noop_value,
) {
  if $manage {
    if $noop_manage {
      noop($noop_value)
    }

    # Find the AMI to use if none specified
    contain psick::aws::ami
    $calculated_image_id = getvar("::psick::aws::ami::calculated_image_id_${default_os}")
    $calculated_autoscaling_image_id =
      getvar("::psick::aws::ami::calculated_autoscaling_image_id_${default_autoscaling_os}")

    $plain_ensure = $ensure ? {
      'absent' => 'absent',
      default  => 'present',
    }
    if $ensure == 'absent' {
      # Rds_db_securitygroup<|name == $title|> ->
      Rds_instance<|name == $title|>
    }

    # Default resources, if enabled
    # These default resources can be customised here.
    if $create_defaults {
      $default_ec2_instances = {
        "${default_vpc_name}-bastion" => {
          subnet                      => "${default_vpc_name}_dmz_a",
          associate_public_ip_address => true,
          security_groups             => ['public-ssh'],
        },
        "${default_vpc_name}-ci" => {
          subnet          => "${default_vpc_name}_mgmt_a",
          security_groups => ['private-ssh' , 'private-ci'],
        },
        "${default_vpc_name}-mon" => {
          subnet          => "${default_vpc_name}_mgmt_a",
          security_groups => ['private-ssh' , 'public-http'],
        },
      }
      $default_ec2_launchconfigurations = {
        "${default_vpc_name}-ecs" => {
          security_groups => ['private-ssh' , 'public-http'],
        },
      }
      $default_ec2_autoscalinggroups = {
        # TODO: Creation of this doesn't seem to work
        "${default_vpc_name}-ecs-a" => {
          subnets              => ["${default_vpc_name}_dmz_a","${default_vpc_name}_dmz_b"],
          availability_zones   => ["${region}a","${region}b"],
          launch_configuration => "${default_vpc_name}-ecs",
        },
      }
    } else {
      $default_ec2_instances = {}
      $default_ec2_launchconfigurations = {}
      $default_ec2_autoscalinggroups = {}
    }
    $all_ec2_instances = $ec2_instances+$default_ec2_instances
    $all_ec2_launchconfigurations = $ec2_launchconfigurations+$default_ec2_launchconfigurations
    $all_ec2_autoscalinggroups = $ec2_autoscalinggroups+$default_ec2_autoscalinggroups

    # EC2 INSTANCES
    $ec2_instances_defaults = {
      ensure               => $ensure,
      region               => $region,
      availability_zone    => "${region}a",
      image_id             => pick($default_image_id,$calculated_image_id),
      instance_type        => $default_instance_type,
      ebs_optimized        => $default_ebs_optimized,
      monitoring           => $default_monitoring,
      key_name             => $default_key_name,
    }

    if $all_ec2_instances != {} {
      create_resources('ec2_instance',$all_ec2_instances,$ec2_instances_defaults)
    }

    # EC2 AUTOSCALING
    $ec2_launchconfigurations_defaults = {
      ensure        => $plain_ensure,
      region        => $region,
      image_id      => pick($default_autoscaling_image_id,$calculated_autoscaling_image_id),
      instance_type => $default_autoscaling_instance_type,
      key_name      => $default_key_name,
    }
    if $all_ec2_launchconfigurations != {} {
      create_resources('ec2_launchconfiguration',$all_ec2_launchconfigurations,$ec2_launchconfigurations_defaults)
    }

    $ec2_autoscalinggroups_defaults = {
      ensure   => $plain_ensure,
      region   => $region,
      max_size => $default_autoscaling_max_size,
      min_size => $default_autoscaling_min_size,
    }
    if $all_ec2_autoscalinggroups != {} {
      create_resources('ec2_autoscalinggroup',$all_ec2_autoscalinggroups,$ec2_autoscalinggroups_defaults)
    }
  }
}