Class: Formatron::CloudFormation::Template::VPC::Subnet::Instance::SecurityGroup
- Inherits:
-
Object
- Object
- Formatron::CloudFormation::Template::VPC::Subnet::Instance::SecurityGroup
- Defined in:
- lib/formatron/cloud_formation/template/vpc/subnet/instance/security_group.rb
Overview
generates CloudFormation security group resource rubocop:disable Metrics/ClassLength
Constant Summary collapse
- SECURITY_GROUP_PREFIX =
'securityGroup'
Instance Method Summary collapse
-
#initialize(os:, security_group:, instance_guid:, vpc_guid:, vpc_cidr:) ⇒ SecurityGroup
constructor
rubocop:disable Metrics/MethodLength.
-
#merge(resources:) ⇒ Object
rubocop:disable Metrics/MethodLength.
Constructor Details
#initialize(os:, security_group:, instance_guid:, vpc_guid:, vpc_cidr:) ⇒ SecurityGroup
rubocop:disable Metrics/MethodLength
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/formatron/cloud_formation/template/vpc/subnet/instance/security_group.rb', line 15 def initialize( os:, security_group:, instance_guid:, vpc_guid:, vpc_cidr: ) @os = os @security_group = security_group @vpc_guid = vpc_guid @cidr = vpc_cidr @guid = instance_guid @security_group_id = "#{SECURITY_GROUP_PREFIX}#{@guid}" @vpc_id = "#{VPC::VPC_PREFIX}#{@vpc_guid}" @open_tcp_ports = @security_group.open_tcp_port unless @security_group.nil? @open_udp_ports = @security_group.open_udp_port unless @security_group.nil? end |
Instance Method Details
#merge(resources:) ⇒ Object
rubocop:disable Metrics/MethodLength
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 |
# File 'lib/formatron/cloud_formation/template/vpc/subnet/instance/security_group.rb', line 37 def merge(resources:) if @os.eql? 'windows' ingress_rules = _base_windows_ingress_rules else ingress_rules = _base_ingress_rules end ingress_rules.concat( @open_tcp_ports.collect do |port| { cidr: '0.0.0.0/0', protocol: 'tcp', from_port: port, to_port: port } end ) unless @open_tcp_ports.nil? ingress_rules.concat( @open_udp_ports.collect do |port| { cidr: '0.0.0.0/0', protocol: 'udp', from_port: port, to_port: port } end ) unless @open_udp_ports.nil? resources[@security_group_id] = Resources::EC2.security_group( group_description: 'Formatron instance security group', vpc: @vpc_id, egress: _base_egress_rules, ingress: ingress_rules ) end |