Sha256: b0065cfae3cb627cfb1321a1cae989575bc3b34cf99240e8c4a703073cc5739e

Contents?: true

Size: 1.64 KB

Versions: 10

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

require 'logger'
require 'rake_dependencies'
require 'ruby_terraform'
require 'rake_terraform/version'
require 'rake_terraform/tasks'
require 'rake_terraform/task_sets'

module RakeTerraform
  def self.define_command_tasks(opts = {}, &)
    RakeTerraform::TaskSets::All.define(opts, &)
  end

  def self.define_installation_tasks(opts = {})
    command_task_set = define_command_installation_tasks(opts)
    provider_task_sets = define_providers_installation_tasks(opts)

    configure_ruby_terraform(command_task_set.binary)
    wire_provider_ensure_tasks(opts)

    [command_task_set.delegate, provider_task_sets.map(&:delegate)]
  end

  class << self
    private

    def define_command_installation_tasks(opts = {})
      RakeTerraform::TaskSets::Terraform.define(opts)
    end

    def define_provider_installation_tasks(opts = {})
      RakeTerraform::TaskSets::Provider.define(opts)
    end

    def define_providers_installation_tasks(opts = {})
      namespace = opts[:namespace] || :terraform
      providers = opts[:providers] || []

      providers.map do |provider_opts|
        define_provider_installation_tasks(
          { parent_namespace: namespace }.merge(provider_opts)
        )
      end
    end

    def configure_ruby_terraform(binary)
      RubyTerraform.configure { |c| c.binary = binary }
    end

    def wire_provider_ensure_tasks(opts)
      namespace = opts[:namespace] || :terraform
      providers = opts[:providers] || []

      Rake::Task["#{namespace}:ensure"]
        .enhance(providers.map do |provider_opts|
          "#{namespace}:providers:#{provider_opts[:name]}:ensure"
        end)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rake_terraform-1.25.0.pre.2 lib/rake_terraform.rb
rake_terraform-1.25.0.pre.1 lib/rake_terraform.rb
rake_terraform-1.24.0 lib/rake_terraform.rb
rake_terraform-1.24.0.pre.16 lib/rake_terraform.rb
rake_terraform-1.24.0.pre.15 lib/rake_terraform.rb
rake_terraform-1.24.0.pre.14 lib/rake_terraform.rb
rake_terraform-1.24.0.pre.13 lib/rake_terraform.rb
rake_terraform-1.24.0.pre.12 lib/rake_terraform.rb
rake_terraform-1.24.0.pre.11 lib/rake_terraform.rb
rake_terraform-1.24.0.pre.10 lib/rake_terraform.rb