formatron 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +12 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +3 -0
  6. data/.simplecov +7 -0
  7. data/.travis.yml +17 -0
  8. data/CODE_OF_CONDUCT.md +13 -0
  9. data/Gemfile +6 -0
  10. data/Guardfile +16 -0
  11. data/LICENSE.txt +21 -0
  12. data/README.md +93 -0
  13. data/Rakefile +16 -0
  14. data/bin/console +14 -0
  15. data/bin/setup +7 -0
  16. data/exe/formatron +20 -0
  17. data/formatron.gemspec +52 -0
  18. data/lib/formatron.rb +357 -0
  19. data/lib/formatron/aws.rb +197 -0
  20. data/lib/formatron/chef.rb +156 -0
  21. data/lib/formatron/chef/berkshelf.rb +55 -0
  22. data/lib/formatron/chef/keys.rb +48 -0
  23. data/lib/formatron/chef/knife.rb +169 -0
  24. data/lib/formatron/chef_clients.rb +73 -0
  25. data/lib/formatron/cli.rb +33 -0
  26. data/lib/formatron/cli/completion.rb +26 -0
  27. data/lib/formatron/cli/deploy.rb +57 -0
  28. data/lib/formatron/cli/destroy.rb +57 -0
  29. data/lib/formatron/cli/generators/bootstrap.rb +250 -0
  30. data/lib/formatron/cli/generators/credentials.rb +100 -0
  31. data/lib/formatron/cli/generators/instance.rb +118 -0
  32. data/lib/formatron/cli/provision.rb +59 -0
  33. data/lib/formatron/cloud_formation.rb +54 -0
  34. data/lib/formatron/cloud_formation/resources/cloud_formation.rb +27 -0
  35. data/lib/formatron/cloud_formation/resources/ec2.rb +336 -0
  36. data/lib/formatron/cloud_formation/resources/iam.rb +94 -0
  37. data/lib/formatron/cloud_formation/resources/route53.rb +54 -0
  38. data/lib/formatron/cloud_formation/scripts.rb +128 -0
  39. data/lib/formatron/cloud_formation/template.rb +114 -0
  40. data/lib/formatron/cloud_formation/template/parameters.rb +20 -0
  41. data/lib/formatron/cloud_formation/template/vpc.rb +181 -0
  42. data/lib/formatron/cloud_formation/template/vpc/subnet.rb +187 -0
  43. data/lib/formatron/cloud_formation/template/vpc/subnet/acl.rb +147 -0
  44. data/lib/formatron/cloud_formation/template/vpc/subnet/bastion.rb +66 -0
  45. data/lib/formatron/cloud_formation/template/vpc/subnet/chef_server.rb +205 -0
  46. data/lib/formatron/cloud_formation/template/vpc/subnet/instance.rb +162 -0
  47. data/lib/formatron/cloud_formation/template/vpc/subnet/instance/policy.rb +74 -0
  48. data/lib/formatron/cloud_formation/template/vpc/subnet/instance/security_group.rb +117 -0
  49. data/lib/formatron/cloud_formation/template/vpc/subnet/instance/setup.rb +68 -0
  50. data/lib/formatron/cloud_formation/template/vpc/subnet/nat.rb +94 -0
  51. data/lib/formatron/completion.rb +26 -0
  52. data/lib/formatron/completion/completion.sh.erb +35 -0
  53. data/lib/formatron/config.rb +31 -0
  54. data/lib/formatron/config/reader.rb +29 -0
  55. data/lib/formatron/dsl.rb +15 -0
  56. data/lib/formatron/dsl/formatron.rb +25 -0
  57. data/lib/formatron/dsl/formatron/global.rb +19 -0
  58. data/lib/formatron/dsl/formatron/global/ec2.rb +17 -0
  59. data/lib/formatron/dsl/formatron/vpc.rb +17 -0
  60. data/lib/formatron/dsl/formatron/vpc/subnet.rb +27 -0
  61. data/lib/formatron/dsl/formatron/vpc/subnet/acl.rb +18 -0
  62. data/lib/formatron/dsl/formatron/vpc/subnet/chef_server.rb +32 -0
  63. data/lib/formatron/dsl/formatron/vpc/subnet/chef_server/organization.rb +22 -0
  64. data/lib/formatron/dsl/formatron/vpc/subnet/instance.rb +29 -0
  65. data/lib/formatron/dsl/formatron/vpc/subnet/instance/chef.rb +22 -0
  66. data/lib/formatron/dsl/formatron/vpc/subnet/instance/policy.rb +21 -0
  67. data/lib/formatron/dsl/formatron/vpc/subnet/instance/policy/statement.rb +23 -0
  68. data/lib/formatron/dsl/formatron/vpc/subnet/instance/security_group.rb +21 -0
  69. data/lib/formatron/dsl/formatron/vpc/subnet/instance/setup.rb +22 -0
  70. data/lib/formatron/dsl/formatron/vpc/subnet/instance/setup/variable.rb +23 -0
  71. data/lib/formatron/external.rb +61 -0
  72. data/lib/formatron/external/dsl.rb +171 -0
  73. data/lib/formatron/external/outputs.rb +25 -0
  74. data/lib/formatron/generators/bootstrap.rb +90 -0
  75. data/lib/formatron/generators/bootstrap/config.rb +62 -0
  76. data/lib/formatron/generators/bootstrap/ec2.rb +17 -0
  77. data/lib/formatron/generators/bootstrap/formatronfile.rb +52 -0
  78. data/lib/formatron/generators/bootstrap/formatronfile/Formatronfile.erb +79 -0
  79. data/lib/formatron/generators/bootstrap/ssl.rb +35 -0
  80. data/lib/formatron/generators/credentials.rb +17 -0
  81. data/lib/formatron/generators/instance.rb +64 -0
  82. data/lib/formatron/generators/instance/config.rb +47 -0
  83. data/lib/formatron/generators/instance/formatronfile.rb +47 -0
  84. data/lib/formatron/generators/instance/formatronfile/Formatronfile.erb +16 -0
  85. data/lib/formatron/generators/util.rb +14 -0
  86. data/lib/formatron/generators/util/cookbook.rb +65 -0
  87. data/lib/formatron/generators/util/gitignore.rb +16 -0
  88. data/lib/formatron/generators/util/readme.rb +18 -0
  89. data/lib/formatron/logger.rb +8 -0
  90. data/lib/formatron/s3/chef_server_cert.rb +85 -0
  91. data/lib/formatron/s3/chef_server_keys.rb +103 -0
  92. data/lib/formatron/s3/cloud_formation_template.rb +61 -0
  93. data/lib/formatron/s3/configuration.rb +58 -0
  94. data/lib/formatron/s3/path.rb +30 -0
  95. data/lib/formatron/util/dsl.rb +107 -0
  96. data/lib/formatron/util/shell.rb +20 -0
  97. data/lib/formatron/util/vpc.rb +15 -0
  98. data/lib/formatron/version.rb +4 -0
  99. data/support/cloudformation_describe_stacks_response.rb +36 -0
  100. data/support/dsl_test.rb +123 -0
  101. data/support/route53_get_hosted_zone_response.rb +21 -0
  102. data/support/s3_get_object_response.rb +21 -0
  103. data/support/template_test.rb +41 -0
  104. metadata +414 -0
@@ -0,0 +1,162 @@
1
+ require 'formatron/cloud_formation/resources/iam'
2
+ require 'formatron/cloud_formation/resources/ec2'
3
+ require 'formatron/cloud_formation/resources/cloud_formation'
4
+ require 'formatron/cloud_formation/resources/route53'
5
+ require_relative 'instance/policy'
6
+ require_relative 'instance/security_group'
7
+ require_relative 'instance/setup'
8
+
9
+ class Formatron
10
+ module CloudFormation
11
+ class Template
12
+ class VPC
13
+ class Subnet
14
+ # generates CloudFormation instance resources
15
+ # rubocop:disable Metrics/ClassLength
16
+ class Instance
17
+ INSTANCE_PREFIX = 'instance'
18
+ ROLE_PREFIX = 'role'
19
+ INSTANCE_PROFILE_PREFIX = 'instanceProfile'
20
+ WAIT_CONDITION_HANDLE_PREFIX = 'waitConditionHandle'
21
+ WAIT_CONDITION_PREFIX = 'waitCondition'
22
+ PRIVATE_RECORD_SET_PREFIX = 'privateRecordSet'
23
+ PUBLIC_RECORD_SET_PREFIX = 'publicRecordSet'
24
+
25
+ # rubocop:disable Metrics/MethodLength
26
+ # rubocop:disable Metrics/AbcSize
27
+ # rubocop:disable Metrics/ParameterLists
28
+ def initialize(
29
+ instance:,
30
+ key_pair:,
31
+ availability_zone:,
32
+ subnet_guid:,
33
+ hosted_zone_name:,
34
+ vpc_guid:,
35
+ vpc_cidr:,
36
+ kms_key:,
37
+ private_hosted_zone_id:,
38
+ public_hosted_zone_id:,
39
+ bucket:,
40
+ name:,
41
+ target:
42
+ )
43
+ @instance = instance
44
+ @guid = @instance.guid
45
+ @setup = @instance.setup
46
+ @instance_id = "#{INSTANCE_PREFIX}#{@guid}"
47
+ @role_id = "#{ROLE_PREFIX}#{@guid}"
48
+ @instance_profile_id = "#{INSTANCE_PROFILE_PREFIX}#{@guid}"
49
+ @wait_condition_handle_id =
50
+ "#{WAIT_CONDITION_HANDLE_PREFIX}#{@guid}"
51
+ @wait_condition_id =
52
+ "#{WAIT_CONDITION_PREFIX}#{@guid}"
53
+ @policy = @instance.policy
54
+ @security_group = @instance.security_group
55
+ @security_group_id =
56
+ "#{SecurityGroup::SECURITY_GROUP_PREFIX}#{@guid}"
57
+ @availability_zone = availability_zone
58
+ @instance_type = @instance.instance_type || 't2.micro'
59
+ @key_pair = key_pair
60
+ @subnet_guid = subnet_guid
61
+ @subnet_id = "#{Subnet::SUBNET_PREFIX}#{@subnet_guid}"
62
+ @sub_domain = @instance.sub_domain
63
+ @hosted_zone_name = hosted_zone_name
64
+ @source_dest_check = @instance.source_dest_check
65
+ @source_dest_check =
66
+ @source_dest_check.nil? ? true : @source_dest_check
67
+ @vpc_guid = vpc_guid
68
+ @vpc_cidr = vpc_cidr
69
+ @kms_key = kms_key
70
+ @private_hosted_zone_id = private_hosted_zone_id
71
+ @public_hosted_zone_id = public_hosted_zone_id
72
+ @private_record_set_id =
73
+ "#{PRIVATE_RECORD_SET_PREFIX}#{@guid}"
74
+ @public_record_set_id =
75
+ "#{PUBLIC_RECORD_SET_PREFIX}#{@guid}"
76
+ @bucket = bucket
77
+ @name = name
78
+ @target = target
79
+ end
80
+ # rubocop:enable Metrics/ParameterLists
81
+ # rubocop:enable Metrics/AbcSize
82
+ # rubocop:enable Metrics/MethodLength
83
+
84
+ # rubocop:disable Metrics/MethodLength
85
+ # rubocop:disable Metrics/AbcSize
86
+ def merge(resources:, outputs:)
87
+ @outputs = outputs
88
+ resources[@role_id] = Resources::IAM.role
89
+ resources[@instance_profile_id] = Resources::IAM.instance_profile(
90
+ role: @role_id
91
+ )
92
+ policy = Policy.new(
93
+ policy: @policy,
94
+ instance_guid: @guid,
95
+ kms_key: @kms_key,
96
+ bucket: @bucket,
97
+ name: @name,
98
+ target: @target
99
+ )
100
+ policy.merge resources: resources
101
+ security_group = SecurityGroup.new(
102
+ security_group: @security_group,
103
+ instance_guid: @guid,
104
+ vpc_guid: @vpc_guid,
105
+ vpc_cidr: @vpc_cidr
106
+ )
107
+ security_group.merge resources: resources
108
+ resources[@wait_condition_handle_id] =
109
+ Resources::CloudFormation.wait_condition_handle
110
+ instance = Resources::EC2.instance(
111
+ instance_profile: @instance_profile_id,
112
+ availability_zone: @availability_zone,
113
+ instance_type: @instance_type,
114
+ key_name: @key_pair,
115
+ subnet: @subnet_id,
116
+ name: "#{@sub_domain}.#{@hosted_zone_name}",
117
+ wait_condition_handle: @wait_condition_handle_id,
118
+ security_group: @security_group_id,
119
+ logical_id: @instance_id,
120
+ source_dest_check: @source_dest_check
121
+ )
122
+ setup = Setup.new(
123
+ setup: @setup,
124
+ sub_domain: @sub_domain,
125
+ hosted_zone_name: @hosted_zone_name
126
+ )
127
+ setup.merge instance: instance
128
+ resources[@instance_id] = instance
129
+ outputs[@instance_id] = Template.output(
130
+ Template.ref(@instance_id)
131
+ )
132
+ resources[@wait_condition_id] =
133
+ Resources::CloudFormation.wait_condition(
134
+ wait_condition_handle: @wait_condition_handle_id,
135
+ instance: @instance_id
136
+ )
137
+ resources[@private_record_set_id] =
138
+ Resources::Route53.record_set(
139
+ hosted_zone_id: Template.ref(@private_hosted_zone_id),
140
+ sub_domain: @sub_domain,
141
+ hosted_zone_name: @hosted_zone_name,
142
+ instance: @instance_id,
143
+ attribute: 'PrivateIp'
144
+ )
145
+ resources[@public_record_set_id] =
146
+ Resources::Route53.record_set(
147
+ hosted_zone_id: @public_hosted_zone_id,
148
+ sub_domain: @sub_domain,
149
+ hosted_zone_name: @hosted_zone_name,
150
+ instance: @instance_id,
151
+ attribute: 'PublicIp'
152
+ ) unless @public_hosted_zone_id.nil?
153
+ end
154
+ # rubocop:enable Metrics/AbcSize
155
+ # rubocop:enable Metrics/MethodLength
156
+ end
157
+ # rubocop:enable Metrics/ClassLength
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,74 @@
1
+ require 'formatron/cloud_formation/resources/iam'
2
+ require 'formatron/s3/configuration'
3
+
4
+ class Formatron
5
+ module CloudFormation
6
+ class Template
7
+ class VPC
8
+ class Subnet
9
+ class Instance
10
+ # generates CloudFormation policy resource
11
+ class Policy
12
+ POLICY_PREFIX = 'policy'
13
+
14
+ # rubocop:disable Metrics/MethodLength
15
+ # rubocop:disable Metrics/ParameterLists
16
+ def initialize(
17
+ policy:,
18
+ instance_guid:,
19
+ kms_key:,
20
+ bucket:,
21
+ name:,
22
+ target:
23
+ )
24
+ @policy = policy
25
+ @kms_key = kms_key
26
+ @guid = instance_guid
27
+ @bucket = bucket
28
+ @config_key = S3::Configuration.key(
29
+ name: name,
30
+ target: target
31
+ )
32
+ @policy_id = "#{POLICY_PREFIX}#{@guid}"
33
+ @role_id = "#{Instance::ROLE_PREFIX}#{@guid}"
34
+ end
35
+ # rubocop:enable Metrics/ParameterLists
36
+ # rubocop:enable Metrics/MethodLength
37
+
38
+ # rubocop:disable Metrics/MethodLength
39
+ def merge(resources:)
40
+ statements = [{
41
+ actions: %w(kms:Decrypt kms:Encrypt kms:GenerateDataKey*),
42
+ resources: [Template.join(
43
+ 'arn:aws:kms:',
44
+ Template.ref('AWS::Region'),
45
+ ':',
46
+ Template.ref('AWS::AccountId'),
47
+ ":key/#{@kms_key}"
48
+ )]
49
+ }, {
50
+ actions: %w(S3:GetObject),
51
+ resources: ["arn:aws:s3:::#{@bucket}/#{@config_key}"]
52
+ }]
53
+ statements.concat(
54
+ @policy.statement.collect do |statement|
55
+ {
56
+ actions: statement.action,
57
+ resources: statement.resource
58
+ }
59
+ end
60
+ ) unless @policy.nil?
61
+ resources[@policy_id] = Resources::IAM.policy(
62
+ role: @role_id,
63
+ name: @policy_id,
64
+ statements: statements
65
+ )
66
+ end
67
+ # rubocop:enable Metrics/MethodLength
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,117 @@
1
+ require 'formatron/cloud_formation/resources/ec2'
2
+
3
+ class Formatron
4
+ module CloudFormation
5
+ class Template
6
+ class VPC
7
+ class Subnet
8
+ class Instance
9
+ # generates CloudFormation security group resource
10
+ class SecurityGroup
11
+ SECURITY_GROUP_PREFIX = 'securityGroup'
12
+
13
+ # rubocop:disable Metrics/MethodLength
14
+ def initialize(
15
+ security_group:,
16
+ instance_guid:,
17
+ vpc_guid:,
18
+ vpc_cidr:
19
+ )
20
+ @security_group = security_group
21
+ @vpc_guid = vpc_guid
22
+ @cidr = vpc_cidr
23
+ @guid = instance_guid
24
+ @security_group_id = "#{SECURITY_GROUP_PREFIX}#{@guid}"
25
+ @vpc_id = "#{VPC::VPC_PREFIX}#{@vpc_guid}"
26
+ @open_tcp_ports =
27
+ @security_group.open_tcp_port unless @security_group.nil?
28
+ @open_udp_ports =
29
+ @security_group.open_udp_port unless @security_group.nil?
30
+ end
31
+ # rubocop:enable Metrics/MethodLength
32
+
33
+ # rubocop:disable Metrics/MethodLength
34
+ def merge(resources:)
35
+ ingress_rules = _base_ingress_rules
36
+ ingress_rules.concat(
37
+ @open_tcp_ports.collect do |port|
38
+ {
39
+ cidr: '0.0.0.0/0',
40
+ protocol: 'tcp',
41
+ from_port: port,
42
+ to_port: port
43
+ }
44
+ end
45
+ ) unless @open_tcp_ports.nil?
46
+ ingress_rules.concat(
47
+ @open_udp_ports.collect do |port|
48
+ {
49
+ cidr: '0.0.0.0/0',
50
+ protocol: 'udp',
51
+ from_port: port,
52
+ to_port: port
53
+ }
54
+ end
55
+ ) unless @open_udp_ports.nil?
56
+ resources[@security_group_id] = Resources::EC2.security_group(
57
+ group_description: 'Formatron instance security group',
58
+ vpc: @vpc_id,
59
+ egress: _base_egress_rules,
60
+ ingress: ingress_rules
61
+ )
62
+ end
63
+ # rubocop:enable Metrics/MethodLength
64
+
65
+ # rubocop:disable Metrics/MethodLength
66
+ def _base_egress_rules
67
+ [{
68
+ cidr: '0.0.0.0/0',
69
+ protocol: 'tcp',
70
+ from_port: '0',
71
+ to_port: '65535'
72
+ }, {
73
+ cidr: '0.0.0.0/0',
74
+ protocol: 'udp',
75
+ from_port: '0',
76
+ to_port: '65535'
77
+ }, {
78
+ cidr: '0.0.0.0/0',
79
+ protocol: 'icmp',
80
+ from_port: '-1',
81
+ to_port: '-1'
82
+ }]
83
+ end
84
+ # rubocop:enable Metrics/MethodLength
85
+
86
+ # rubocop:disable Metrics/MethodLength
87
+ def _base_ingress_rules
88
+ [{
89
+ cidr: @cidr,
90
+ protocol: 'tcp',
91
+ from_port: '0',
92
+ to_port: '65535'
93
+ }, {
94
+ cidr: @cidr,
95
+ protocol: 'udp',
96
+ from_port: '0',
97
+ to_port: '65535'
98
+ }, {
99
+ cidr: @cidr,
100
+ protocol: 'icmp',
101
+ from_port: '-1',
102
+ to_port: '-1'
103
+ }]
104
+ end
105
+ # rubocop:enable Metrics/MethodLength
106
+
107
+ private(
108
+ :_base_egress_rules,
109
+ :_base_ingress_rules
110
+ )
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,68 @@
1
+ require 'formatron/cloud_formation/scripts'
2
+
3
+ class Formatron
4
+ module CloudFormation
5
+ class Template
6
+ class VPC
7
+ class Subnet
8
+ class Instance
9
+ # Adds setup scripts to an instance
10
+ class Setup
11
+ def initialize(setup:, sub_domain:, hosted_zone_name:)
12
+ @setup = setup
13
+ @sub_domain = sub_domain
14
+ @hosted_zone_name = hosted_zone_name
15
+ @scripts = @setup.script unless @setup.nil?
16
+ @variables = @setup.variable unless @setup.nil?
17
+ end
18
+
19
+ # rubocop:disable Metrics/MethodLength
20
+ # rubocop:disable Metrics/AbcSize
21
+ def merge(instance:)
22
+ files = {
23
+ '/tmp/formatron/script-0.sh' => {
24
+ content: Scripts.hostname(
25
+ sub_domain: @sub_domain,
26
+ hosted_zone_name: @hosted_zone_name
27
+ ),
28
+ mode: '000755',
29
+ owner: 'root',
30
+ group: 'root'
31
+ }
32
+ }
33
+ @scripts.each_index do |index|
34
+ files["/tmp/formatron/script-#{index + 1}.sh"] = {
35
+ content: @scripts[index],
36
+ mode: '000755',
37
+ owner: 'root',
38
+ group: 'root'
39
+ }
40
+ end unless @scripts.nil?
41
+ variables = []
42
+ @variables.each do |key, value|
43
+ variables.concat(["#{key}=", value.value, "\n"])
44
+ end unless @variables.nil?
45
+ files['/tmp/formatron/script-variables'] = {
46
+ content: Template.join(*variables),
47
+ mode: '000644',
48
+ owner: 'root',
49
+ group: 'root'
50
+ } unless variables.length == 0
51
+ instance[:Metadata] = {
52
+ Comment1: 'Create setup scripts',
53
+ 'AWS::CloudFormation::Init' => {
54
+ config: {
55
+ files: files
56
+ }
57
+ }
58
+ }
59
+ end
60
+ # rubocop:enable Metrics/AbcSize
61
+ # rubocop:enable Metrics/MethodLength
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,94 @@
1
+ require_relative 'instance'
2
+
3
+ class Formatron
4
+ module CloudFormation
5
+ class Template
6
+ class VPC
7
+ class Subnet
8
+ # generates CloudFormation Chef Server resources
9
+ class NAT
10
+ ROUTE_TABLE_PREFIX = 'routeTable'
11
+ ROUTE_PREFIX = 'route'
12
+
13
+ # rubocop:disable Metrics/MethodLength
14
+ # rubocop:disable Metrics/ParameterLists
15
+ def initialize(
16
+ nat:,
17
+ key_pair:,
18
+ availability_zone:,
19
+ subnet_guid:,
20
+ hosted_zone_name:,
21
+ vpc_guid:,
22
+ vpc_cidr:,
23
+ kms_key:,
24
+ private_hosted_zone_id:,
25
+ public_hosted_zone_id:,
26
+ bucket:,
27
+ name:,
28
+ target:
29
+ )
30
+ @nat = nat
31
+ guid = @nat.guid
32
+ @vpc_cidr = vpc_cidr
33
+ @vpc_id = "#{VPC::VPC_PREFIX}#{vpc_guid}"
34
+ @instance_id = "#{Instance::INSTANCE_PREFIX}#{guid}"
35
+ @route_table_id = "#{ROUTE_TABLE_PREFIX}#{guid}"
36
+ @route_id = "#{ROUTE_PREFIX}#{guid}"
37
+ _add_setup_script
38
+ _set_source_dest_check
39
+ @instance = Instance.new(
40
+ instance: nat,
41
+ key_pair: key_pair,
42
+ availability_zone: availability_zone,
43
+ subnet_guid: subnet_guid,
44
+ hosted_zone_name: hosted_zone_name,
45
+ vpc_guid: vpc_guid,
46
+ vpc_cidr: @vpc_cidr,
47
+ kms_key: kms_key,
48
+ private_hosted_zone_id: private_hosted_zone_id,
49
+ public_hosted_zone_id: public_hosted_zone_id,
50
+ bucket: bucket,
51
+ name: name,
52
+ target: target
53
+ )
54
+ end
55
+ # rubocop:enable Metrics/ParameterLists
56
+ # rubocop:enable Metrics/MethodLength
57
+
58
+ def _add_setup_script
59
+ @nat.setup do |setup|
60
+ scripts = setup.script
61
+ scripts.unshift Scripts.nat cidr: @vpc_cidr
62
+ end
63
+ end
64
+
65
+ def _set_source_dest_check
66
+ @nat.source_dest_check false
67
+ end
68
+
69
+ def merge(resources:, outputs:)
70
+ _add_route_table resources
71
+ @instance.merge resources: resources, outputs: outputs
72
+ end
73
+
74
+ def _add_route_table(resources)
75
+ resources[@route_table_id] = Resources::EC2.route_table(
76
+ vpc: @vpc_id
77
+ )
78
+ resources[@route_id] = Resources::EC2.route(
79
+ route_table: @route_table_id,
80
+ instance: @instance_id
81
+ )
82
+ end
83
+
84
+ private(
85
+ :_set_source_dest_check,
86
+ :_add_setup_script,
87
+ :_add_route_table
88
+ )
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end