require 'aws-sdk-core'

module PuppetX
  module Puppetlabs
    class Aws < Puppet::Provider
      def self.regions
        if ENV['AWS_REGION'] and not ENV['AWS_REGION'].empty?
          [ENV['AWS_REGION']]
        else
          ec2_client(region: default_region).describe_regions.data.regions.map(&:region_name)
        end
      end

      def regions
        self.class.regions
      end

      def self.default_region
        ENV['AWS_REGION'] || 'eu-west-1'
      end

      def default_region
        self.class.default_region
      end

      def self.read_only(*methods)
        methods.each do |method|
          define_method("#{method}=") do |v|
            fail "#{method} property is read-only once #{resource.type} created."
          end
        end
      end

      def self.ec2_client(region = default_region)
        ::Aws::EC2::Client.new({region: region})
      end

      def ec2_client(region = default_region)
        self.class.ec2_client(region)
      end

      def self.elb_client(region = default_region)
        ::Aws::ElasticLoadBalancing::Client.new({region: region})
      end

      def elb_client(region = default_region)
        self.class.elb_client(region)
      end
    end
  end
end

require 'aws-sdk-core'

module PuppetX
  module Puppetlabs
    class Aws < Puppet::Provider
      def self.regions
        if ENV['AWS_REGION'] and not ENV['AWS_REGION'].empty?
          [ENV['AWS_REGION']]
        else
          ec2_client(default_region).describe_regions.data.regions.map(&:region_name)
        end
      end

      def regions
        self.class.regions
      end

      def self.default_region
        ENV['AWS_REGION'] || 'eu-west-1'
      end

      def default_region
        self.class.default_region
      end

      def self.read_only(*methods)
        methods.each do |method|
          define_method("#{method}=") do |v|
            fail "#{method} property is read-only once #{resource.type} created."
          end
        end
      end

      def self.ec2_client(region = default_region)
        ::Aws::EC2::Client.new({region: region})
      end

      def ec2_client(region = default_region)
        self.class.ec2_client(region)
      end

      def self.elb_client(region = default_region)
        ::Aws::ElasticLoadBalancing::Client.new({region: region})
      end

      def elb_client(region = default_region)
        self.class.elb_client(region)
      end
    end
  end
end

Fix incorrect parameters to ec2_client
Fix incorrect parameters to ec2_client

 - Code was initially refactored to support 1.9.3, by removing named
    parameters (a Ruby 2 feature), in:
    5a3c0b899c91f7080a12c8faf3d733fbe32e7915

    That fix was incomplete and some additional related changes were
    made to address default params and the Aws client initializers in:
    95ed3e0d2536cf94fcfe17cc158e53ca27873bfb

    Unfortunately, one line was missed that creates the ec2_client
    instance.  Instead of passing an expected string (previously done
    via named argument), the code is now passing a hash where a String
    is expected, and this was caught during acceptance tests.
