class Itamae::Plugin::Resource::AwsEbsVolume

Public Instance Methods

action_attach(options) click to toggle source
# File lib/itamae/plugin/resource/aws/ebs_volume.rb, line 53
def action_attach(options)
  # TODO
end
action_create(options) click to toggle source
# File lib/itamae/plugin/resource/aws/ebs_volume.rb, line 14
def action_create(options)
  ec2 = ::Aws::EC2::Client.new
  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.create_tags(
      {
        resources: [ @volume.volume_id ],
        tags: [
          {
            key: 'Name',
            value: attributes.name,
          },
        ],
      }
    )

    updated!
  else
    @volume = volumes[0]
  end
  
end