class ItamaeMitsurin::Resource::AwsEbsVolume
Public Instance Methods
action_attach(options)
click to toggle source
# File lib/itamae-mitsurin/resource/aws_ebs_volume.rb, line 55 def action_attach(options) ec2 = ::Aws::EC2::Client.new(region: attributes.region) volumes = ec2.describe_volumes({ filters: [ { name: 'tag:Name', values: [ attributes.name ], }, ], }).volumes unless volumes.empty? if volumes[0][:attachments].empty? @volume = ec2.attach_volume({ volume_id: @volume.volume_id, instance_id: attributes.instance_id, device: attributes.device }) ec2.wait_until(:volume_in_use, volume_ids: [ @volume.volume_id ]) ItamaeMitsurin.logger.color(:green) do ItamaeMitsurin.logger.info "attach volume compleated!" end updated! end else @volume = volumes[0] end end
action_create(options)
click to toggle source
# File lib/itamae-mitsurin/resource/aws_ebs_volume.rb, line 17 def action_create(options) ec2 = ::Aws::EC2::Client.new(region: attributes.region) volumes = ec2.describe_volumes({ filters: [ { name: 'tag:Name', values: [ attributes.name ], }, ], }).volumes if volumes.empty? @volume = ec2.create_volume( size: attributes[:size], # attributes.size returns the size of attributes hash availability_zone: attributes.availability_zone, volume_type: attributes.volume_type, ) ec2.wait_until(:volume_available, volume_ids: [ @volume.volume_id ]) ec2.create_tags({ resources: [ @volume.volume_id ], tags: [ { key: 'Name', value: attributes.name, }, ], }) ItamaeMitsurin.logger.color(:green) do ItamaeMitsurin.logger.info "create volume compleated!" end updated! else @volume = volumes[0] end end