Module: Tfrb::Resource::AwsInstance
- Extended by:
- Tfrb::Resource
- Defined in:
- lib/tfrb/resource/aws_instance.rb
Class Method Summary collapse
- .load(base, environment_name, resource_type, new_resources) ⇒ Object
- .preload(base, environment_name, resource_type, new_resources) ⇒ Object
Methods included from Tfrb::Resource
aws_options, extended, get_custom_resource, get_state, import!, load_helpers!, resolve_tfvar, set_default
Class Method Details
.load(base, environment_name, resource_type, new_resources) ⇒ Object
16 17 18 19 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 |
# File 'lib/tfrb/resource/aws_instance.rb', line 16 def self.load(base, environment_name, resource_type, new_resources) new_resources.each do |resource_name, resource| client = ::Aws::EC2::Client.new((base, resource)) response = client.describe_instances({ filters: [ { name: 'tag:Name', values: [ resource_name, ], }, { name: 'instance-state-name', values: [ 'pending', 'running', 'stopping', 'stopped' ], }, ], }) if response.reservations && response.reservations.size >= 1 if response.reservations.first.instances && response.reservations.first.instances.size >= 1 id = response.reservations.first.instances.first.instance_id import!(base, resource_type, resource_name, id) end end end end |
.preload(base, environment_name, resource_type, new_resources) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/tfrb/resource/aws_instance.rb', line 6 def self.preload(base, environment_name, resource_type, new_resources) new_resources.each do |resource_name, resource| resource['tags'] = {} unless resource.has_key?('tags') resource['tags']['Name'] = resource_name unless resource['tags'].has_key?('Name') resource['root_block_device'] = {} unless resource.has_key?('root_block_device') resource['root_block_device']['volume_type'] = 'gp2' unless resource['root_block_device'].has_key?('volume_type') resource['root_block_device']['volume_size'] = 8 unless resource['root_block_device'].has_key?('volume_size') end end |